OSCQuery
This commit is contained in:
parent
3467e13715
commit
36520e8426
@ -1,5 +1,8 @@
|
||||
using BuildSoft.OscCore;
|
||||
using System.Net;
|
||||
using BuildSoft.OscCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using VRC.OSCQuery;
|
||||
using Extensions = VRC.OSCQuery.Extensions;
|
||||
|
||||
namespace VRC_Console;
|
||||
|
||||
@ -13,7 +16,6 @@ public class OSCCollar
|
||||
{
|
||||
var jObject = JObject.Parse(File.ReadAllText(configFilePath));
|
||||
string ip = jObject.GetValue("ip")?.ToObject<string>() ?? "127.0.0.1";
|
||||
int portReceive = jObject.GetValue("portReceive")?.ToObject<int>() ?? 9001;
|
||||
int portSend = jObject.GetValue("portSend")?.ToObject<int>() ?? 9000;
|
||||
double radius = jObject.GetValue("radius")?.ToObject<double>() ?? 100;
|
||||
double calibrationX = jObject.GetValue("calibrationX")?.ToObject<double>() ?? 0;
|
||||
@ -21,7 +23,7 @@ public class OSCCollar
|
||||
double walkStretchDeadzone = jObject.GetValue("walkStretchDeadzone")?.ToObject<double>() ?? 0.1;
|
||||
double runStretch = jObject.GetValue("runStretch")?.ToObject<double>() ?? 0.4;
|
||||
bool skipSetup = jObject.GetValue("skipSetup")?.ToObject<bool>() ?? true;
|
||||
var _ = new OSCCollar(ip, portReceive, portSend, radius, calibrationX, calibrationY, walkStretchDeadzone, runStretch, skipSetup);
|
||||
var _ = new OSCCollar(ip, portSend, radius, calibrationX, calibrationY, walkStretchDeadzone, runStretch, skipSetup);
|
||||
}else
|
||||
{
|
||||
var _ = new OSCCollar();
|
||||
@ -31,6 +33,7 @@ public class OSCCollar
|
||||
private readonly string _ip;
|
||||
private readonly int _portReceive, _portSend;
|
||||
|
||||
private OSCQueryService _oscQueryService { get; init; }
|
||||
private OscServer Server { get; init; }
|
||||
private OscClient Client { get; init; }
|
||||
private float _leashStretch;
|
||||
@ -57,10 +60,28 @@ public class OSCCollar
|
||||
private double GPSConstantD { get; init; }
|
||||
private double GPSConstantE { get; init; }
|
||||
|
||||
private OSCCollar(string ip = "127.0.0.1", int portReceive = 9001, int portSend = 9000, double radius = 100, double calibrationX = 0, double calibrationY = 0, double walkStretch = 0.1, double runStretch = 0.4, bool skipSetup = true)
|
||||
private OSCCollar(string ip = "127.0.0.1", int portSend = 9000, double radius = 100, double calibrationX = 0, double calibrationY = 0, double walkStretch = 0.1, double runStretch = 0.4, bool skipSetup = true)
|
||||
{
|
||||
this._ip = ip;
|
||||
this._portReceive = portReceive;
|
||||
var tcpPort = Extensions.GetAvailableTcpPort();
|
||||
var udpPort = Extensions.GetAvailableUdpPort();
|
||||
this._oscQueryService = new OSCQueryServiceBuilder()
|
||||
.WithHostIP(IPAddress.Parse(ip))
|
||||
.WithOscIP(IPAddress.Parse(ip))
|
||||
.WithDiscovery(new MeaModDiscovery())
|
||||
.WithTcpPort(tcpPort)
|
||||
.WithUdpPort(udpPort)
|
||||
.WithServiceName("Collar")
|
||||
.StartHttpServer()
|
||||
.AdvertiseOSC()
|
||||
.AdvertiseOSCQuery()
|
||||
.Build();
|
||||
this._oscQueryService.AddEndpoint<float>("/avatar/parameters/GPS1", Attributes.AccessValues.WriteOnly);
|
||||
this._oscQueryService.AddEndpoint<float>("/avatar/parameters/GPS2", Attributes.AccessValues.WriteOnly);
|
||||
this._oscQueryService.AddEndpoint<float>("/avatar/parameters/GPS3", Attributes.AccessValues.WriteOnly);
|
||||
this._oscQueryService.AddEndpoint<float>("/avatar/parameters/Leash_Stretch", Attributes.AccessValues.WriteOnly);
|
||||
this._oscQueryService.AddEndpoint<bool>("/avatar/parameters/Leash_Toggle", Attributes.AccessValues.WriteOnly);
|
||||
this._portReceive = this._oscQueryService.OscPort;
|
||||
this._portSend = portSend;
|
||||
this._walkStretch = walkStretch;
|
||||
this._runStretch = runStretch;
|
||||
@ -79,15 +100,17 @@ public class OSCCollar
|
||||
|
||||
if (!skipSetup)
|
||||
{
|
||||
Console.WriteLine($"OSC Port: {this._portReceive} TCP Port: {this._oscQueryService.TcpPort}");
|
||||
Console.WriteLine("Position your GPS receivers:");
|
||||
Console.WriteLine($"GPS 1 x: {GPS1.X} y: {GPS1.Y}");
|
||||
Console.WriteLine($"GPS 2 x: {GPS2.X} y: {GPS2.Y}");
|
||||
Console.WriteLine($"GPS 3 x: {GPS3.X} y: {GPS3.Y}");
|
||||
Console.WriteLine($"Radius of each receiver (sphere): {radius * 2}");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
this.Server = new OscServer(portReceive);
|
||||
this.Client = new OscClient(ip, portSend);
|
||||
this.Server = new OscServer(this._portReceive);
|
||||
this.Client = new OscClient(this._ip, this._portSend);
|
||||
this.Server.TryAddMethod("/avatar/parameters/GPS1", GPS1Handle);
|
||||
this.Server.TryAddMethod("/avatar/parameters/GPS2", GPS2Handle);
|
||||
this.Server.TryAddMethod("/avatar/parameters/GPS3", GPS3Handle);
|
||||
@ -97,13 +120,15 @@ public class OSCCollar
|
||||
|
||||
Thread runningThread = new Thread(RunningThread);
|
||||
runningThread.Start();
|
||||
|
||||
this._oscQueryService.RefreshServices();
|
||||
}
|
||||
|
||||
private void PrintOutput()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine($"OSC Collar - Status: {(_allowMoving ? "enabled" : "disabled")} IP: {_ip} Send: {_portSend} Receive: {_portReceive}");
|
||||
Console.WriteLine($"OSC Collar - Status: {(_allowMoving ? "enabled" : "disabled")} IP: {_ip} Send: {_portSend} Receive: {_portReceive} HTTP: {this._oscQueryService.TcpPort}");
|
||||
Console.WriteLine("==============================");
|
||||
Console.WriteLine($"GPS 1:................{GPS1.Distance:00.00000}");
|
||||
Console.WriteLine($"GPS 2:................{GPS2.Distance:00.00000}");
|
||||
|
@ -10,7 +10,15 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BuildSoft.OscCore" Version="1.2.1.1" />
|
||||
<PackageReference Include="MeaMod.DNS" Version="1.0.70" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="vrc-oscquery-lib">
|
||||
<HintPath>..\..\vrc-oscquery-lib\vrc-oscquery-lib\bin\Debug\net6.0\vrc-oscquery-lib.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
2
VRC_Collar.sln.DotSettings.user
Normal file
2
VRC_Collar.sln.DotSettings.user
Normal file
@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005Cvrc_002Doscquery_002Dlib_005Cvrc_002Doscquery_002Dlib_005Cbin_005CDebug_005Cnet6_002E0_005Cvrc_002Doscquery_002Dlib_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
Reference in New Issue
Block a user