Revize 306eb3ca
Přidáno uživatelem Miloslav Kovář před téměř 4 roky(ů)
deltarobot-vr/Assets/DeltaRobotVr/Client.cs | ||
---|---|---|
38 | 38 |
private const UInt16 PingId = 0x3004; |
39 | 39 |
private const UInt16 EotId = 0xF006; |
40 | 40 |
private const UInt16 CurrentActuatorPositionId = 0x4003; |
41 |
private const UInt16 CurrentDirectionVectorId = 0x4007; |
|
42 |
private const UInt16 DesiredDirectionVectorId = 0x4008; |
|
43 |
private const UInt16 CurveId = 0xF009; |
|
41 | 44 |
|
42 | 45 |
private const UInt16 Size8 = 0x0000; |
43 | 46 |
private const UInt16 Size16 = 0x1000; |
... | ... | |
49 | 52 |
private static readonly byte[] ProtocolMagicValue = Encoding.ASCII.GetBytes("DeltaRVr"); |
50 | 53 |
private const UInt32 ProtocolVersionValue = 1; |
51 | 54 |
|
55 |
private const UInt32 PointLength = 12; |
|
56 |
|
|
52 | 57 |
|
53 | 58 |
private Thread _thread; |
54 | 59 |
|
... | ... | |
58 | 63 |
private readonly object _actuatorPositionLock = new object(); |
59 | 64 |
private Single3 _actuatorPosition; |
60 | 65 |
|
66 |
private readonly object _currentDirectionVectorLock = new object(); |
|
67 |
private Single3 _currentDirectionVector; |
|
68 |
|
|
69 |
private readonly object _desiredDirectionVectorLock = new object(); |
|
70 |
private Single3 _desiredDirectionVector; |
|
71 |
|
|
72 |
private readonly object _curveLock = new object(); |
|
73 |
private Single3[] _curve; |
|
74 |
private long _curveCounter = 0; |
|
75 |
|
|
61 | 76 |
private volatile bool _isConnected; |
62 | 77 |
private volatile string _eotMsg; |
63 | 78 |
|
... | ... | |
112 | 127 |
} |
113 | 128 |
} |
114 | 129 |
|
130 |
public Single3 CurrentDirectionVector |
|
131 |
{ |
|
132 |
get |
|
133 |
{ |
|
134 |
lock (_currentDirectionVectorLock) |
|
135 |
{ |
|
136 |
return _currentDirectionVector; |
|
137 |
} |
|
138 |
} |
|
139 |
private set |
|
140 |
{ |
|
141 |
lock (_currentDirectionVectorLock) |
|
142 |
{ |
|
143 |
_currentDirectionVector = value; |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
public Single3 DesiredDirectionVector |
|
149 |
{ |
|
150 |
get |
|
151 |
{ |
|
152 |
lock (_desiredDirectionVectorLock) |
|
153 |
{ |
|
154 |
return _desiredDirectionVector; |
|
155 |
} |
|
156 |
} |
|
157 |
private set |
|
158 |
{ |
|
159 |
lock (_desiredDirectionVectorLock) |
|
160 |
{ |
|
161 |
_desiredDirectionVector = value; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
public Single3[] Curve |
|
167 |
{ |
|
168 |
get |
|
169 |
{ |
|
170 |
lock (_curveLock) |
|
171 |
{ |
|
172 |
return _curve; |
|
173 |
} |
|
174 |
} |
|
175 |
private set |
|
176 |
{ |
|
177 |
lock (_curveLock) |
|
178 |
{ |
|
179 |
_curve = value; |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
public long CurveCounter |
|
185 |
{ |
|
186 |
get |
|
187 |
{ |
|
188 |
lock (_curveLock) |
|
189 |
{ |
|
190 |
return _curveCounter; |
|
191 |
} |
|
192 |
} |
|
193 |
private set |
|
194 |
{ |
|
195 |
lock (_curveLock) |
|
196 |
{ |
|
197 |
_curveCounter = value; |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
115 | 202 |
public bool IsRunning |
116 | 203 |
{ |
117 | 204 |
get { |
... | ... | |
166 | 253 |
case CurrentActuatorPositionId: |
167 | 254 |
ProcessCurrentActuatorPosition(reader); |
168 | 255 |
break; |
256 |
case CurrentDirectionVectorId: |
|
257 |
ProcessCurrentDirectionVector(reader); |
|
258 |
break; |
|
259 |
case DesiredDirectionVectorId: |
|
260 |
ProcessDesiredDirectionVector(reader); |
|
261 |
break; |
|
262 |
case CurveId: |
|
263 |
ProcessCurve(reader); |
|
264 |
break; |
|
169 | 265 |
default: //client tuto zpravu nezna |
170 | 266 |
var sizeIdentifier = (UInt16) (messageIdentifier & 0xF000); |
171 | 267 |
switch (sizeIdentifier) |
... | ... | |
250 | 346 |
ActuatorPosition = new Single3(x, y, z); |
251 | 347 |
} |
252 | 348 |
|
349 |
private void ProcessCurrentDirectionVector(BinaryReader reader) |
|
350 |
{ |
|
351 |
var x = reader.ReadSingle(); |
|
352 |
var y = reader.ReadSingle(); |
|
353 |
var z = reader.ReadSingle(); |
|
354 |
reader.ReadSingle(); // skip unused |
|
355 |
|
|
356 |
CurrentDirectionVector = new Single3(x, y, z); |
|
357 |
} |
|
358 |
|
|
359 |
private void ProcessDesiredDirectionVector(BinaryReader reader) |
|
360 |
{ |
|
361 |
var x = reader.ReadSingle(); |
|
362 |
var y = reader.ReadSingle(); |
|
363 |
var z = reader.ReadSingle(); |
|
364 |
reader.ReadSingle(); // skip unused |
|
365 |
|
|
366 |
DesiredDirectionVector = new Single3(x, y, z); |
|
367 |
} |
|
368 |
|
|
369 |
private void ProcessCurve(BinaryReader reader) |
|
370 |
{ |
|
371 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
|
372 |
UInt32 numberOfPoints = numberOfBytes / PointLength; |
|
373 |
Single3[] curve = new Single3[numberOfPoints]; |
|
374 |
var x, y, z; |
|
375 |
|
|
376 |
for(int i = 0; i < numberOfPoints; i++) |
|
377 |
{ |
|
378 |
x = reader.ReadSingle(); |
|
379 |
y = reader.ReadSingle(); |
|
380 |
z = reader.ReadSingle(); |
|
381 |
curve[i] = new Single3(x, y, z); |
|
382 |
} |
|
383 |
|
|
384 |
lock(_curveLock) |
|
385 |
{ |
|
386 |
CurveCounter++; |
|
387 |
Curve = curve; |
|
388 |
} |
|
389 |
} |
|
390 |
|
|
253 | 391 |
private void ProcessEot(BinaryReader reader) |
254 | 392 |
{ |
255 | 393 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
... | ... | |
263 | 401 |
byte[] value = reader.ReadBytes(8); |
264 | 402 |
if (!value.SequenceEqual(ProtocolMagicValue)) |
265 | 403 |
{ |
266 |
IsConnected = false; // mozna vyhodit vyjimku
|
|
404 |
IsConnected = false; |
|
267 | 405 |
} |
268 | 406 |
} |
269 | 407 |
|
... | ... | |
272 | 410 |
UInt32 value = reader.ReadUInt32(); |
273 | 411 |
if (value != ProtocolVersionValue) |
274 | 412 |
{ |
275 |
IsConnected = false; // mozna vyhodit vyjimku
|
|
413 |
IsConnected = false; |
|
276 | 414 |
} |
277 | 415 |
} |
278 | 416 |
|
Také k dispozici: Unified diff
Re #8738 - Client - additional messages