Skip to content

Commit

Permalink
Test out cscore
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Feb 8, 2024
1 parent 116fcf7 commit 6671471
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
66 changes: 66 additions & 0 deletions dev/desktopDev/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,89 @@
using System;
using System.Runtime.InteropServices;
using System.Text.Json;
using CsCore;
using CsCore.Raw;
using NetworkTables;
using UnitsNet.NumberExtensions.NumberToAngle;
using WPIMath.Geometry;
using WPIUtil;
using WPIUtil.Natives;
using WPIUtil.Serialization.Struct;

namespace DesktopDev;

class Program
{


static void Main(string[] args)
{
Rotation2d rot = new(5.Radians());
string serialized = JsonSerializer.Serialize(rot);
Console.WriteLine(serialized);

NativeLibrary.SetDllImportResolver(typeof(MJpegServer).Assembly, (name, assembly, searchpath) =>
{
if (name != "cscore")
{
throw new InvalidOperationException();
}
Console.WriteLine(searchpath);
return NativeLibrary.Load(@"C:\Users\thadh\Documents\GitHub\thadhouse\allwpilib\myRobot\build\install\myRobotCpp\windowsx86-64\lib\cscored.dll");
});

NativeLibrary.SetDllImportResolver(typeof(NativeRawFrame).Assembly, (name, assembly, searchpath) =>
{
if (name != "wpiutil")
{
throw new InvalidOperationException();
}
return NativeLibrary.Load(@"C:\Users\thadh\Documents\GitHub\thadhouse\allwpilib\myRobot\build\install\myRobotCpp\windowsx86-64\lib\wpiutild.dll");
});

Rotation2d r = JsonSerializer.Deserialize<Rotation2d>(serialized);
Console.WriteLine(r.Angle.Radians);

UsbCamera camera = new UsbCamera("Camera", 0)
{
ConnectionStrategy = ConnectionStrategy.ConnectionKeepOpen
};
MJpegServer server = new MJpegServer("Server", 1181)
{
Source = camera
};

RawSink sink = new RawSink("Sink") {
Source = camera
};

RawSource source = new RawSource("Source", new VideoMode
{
Fps = 30,
Width = 640,
Height = 480,
PixelFormat = WPIUtil.PixelFormat.Yuyv
})
{
ConnectionStrategy = ConnectionStrategy.ConnectionKeepOpen
};

MJpegServer sinkServer = new MJpegServer("SinkServer", 1182) {
Source = source
};

RawFrameReader reader = new RawFrameReader();

while (true) {
long ts = sink.GrabFrame(reader);
if (ts <= 0) {
continue;
}

source.PutFrame(reader.ToWriter());
}


// StructArrayTopic<TrackedTag> n = null!;
// var subscriber = n.Subscribe([], PubSubOptions.None);
// TrackedTag[] tags = subscriber.Get();
Expand Down
8 changes: 8 additions & 0 deletions dev/desktopDev/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"desktopDev": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
1 change: 1 addition & 0 deletions dev/desktopDev/desktopDev.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


<ItemGroup>
<ProjectReference Include="..\..\src\cscore\cscore.csproj" />
<ProjectReference Include="..\..\src\hal\hal.csproj" />
<ProjectReference Include="..\..\src\ntcore\ntcore.csproj" />
<ProjectReference Include="..\..\src\wpinet\wpinet.csproj" />
Expand Down

0 comments on commit 6671471

Please sign in to comment.