Skip to content

Commit 61178e1

Browse files
committed
Fix typos, remove unused imports, fix parsing types and values
1 parent 91584d1 commit 61178e1

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

OSCManager.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Net;
1+
using System.Net;
52
using System.Net.Sockets;
6-
using System.Text;
7-
using System.Threading.Tasks;
83
using Microsoft.Extensions.Logging;
9-
using VRCFaceTracking.Core.OSC;
104

115
namespace ETVRTrackingModule
126
{
13-
147
public enum OSCState
158
{
169
IDLE,
@@ -38,7 +31,7 @@ public class OSCManager
3831
public OSCState State { get; private set; } = OSCState.IDLE;
3932

4033
private int _receivingPort;
41-
private const int _defaultPort = 8888;
34+
private const int _defaultPort = 8889;
4235
private const int connectionTimeout = 10000;
4336

4437
public OSCManager(ILogger iLogger, int? port = null) {
@@ -74,8 +67,8 @@ private void OSCListen()
7467
if (_receiver.IsBound)
7568
{
7669
//_logger.LogInformation("we connected");
77-
var lenght = _receiver.Receive(buffer);
78-
OSCMessage msg = ParseOSCMessage(buffer, lenght);
70+
var length = _receiver.Receive(buffer);
71+
OSCMessage msg = ParseOSCMessage(buffer, length);
7972
// map the message
8073
}
8174
}
@@ -107,17 +100,25 @@ OSCMessage ParseOSCMessage(byte[] buffer, int length)
107100
return msg;
108101
// skipping , char
109102
currentStep++;
110-
111-
// we skip the type tag, since ETVR is only sending floats, we're fine.
112-
currentStep++;
113-
103+
// now, let's skip the types section
104+
for (int i=currentStep; i < length; i++)
105+
{
106+
if (buffer[i] == 0)
107+
{
108+
currentStep = i + 1;
109+
// we've reached the end of this segment, let's normalize it to 4 bytes and skip ahead
110+
if (currentStep % 4 != 0) { currentStep += 4 - (currentStep % 4); }
111+
break;
112+
}
113+
}
114+
float value = ParseOSCFloat(buffer, length, ref currentStep);
115+
_logger.LogInformation($"Parse value: {value}");
116+
/*
114117
float value = ParseOSCFloat(buffer, length, ref currentStep);
115-
116-
_logger.LogInformation(msg.address, value.ToString());
117118
118119
msg.value = value;
119120
msg.success = true;
120-
121+
*/
121122
return msg;
122123
}
123124

@@ -131,12 +132,13 @@ string ParseOSCAddress(byte[] buffer, int length, ref int step)
131132

132133
for (int i = 0; i<length; i++)
133134
{
134-
// we've reached the end of the address section, let's update the steps coutner
135+
// we've reached the end of the address section, let's update the steps counter
135136
// to point at the value section
136137
if (buffer[i] == 0)
137138
{
139+
// we need to ensure that we include the null terminator
138140
step = i + 1;
139-
// the size of a packet is a multiple of 4
141+
// the size of a packet is a multiple of 4, we need to round it up
140142
if (step % 4 != 0) { step += 4 - (step % 4); }
141143
break;
142144
}
@@ -152,9 +154,8 @@ float ParseOSCFloat(byte[] buffer, int length, ref int step)
152154
{
153155
Array.Reverse(valueSection);
154156
}
157+
155158
float OSCValue = BitConverter.ToSingle(valueSection, 0);
156-
_logger.LogInformation("value is ", OSCValue.ToString());
157-
Thread.Sleep(100);
158159
return OSCValue;
159160
}
160161
}

0 commit comments

Comments
 (0)