Revize a9ef8967
Přidáno uživatelem Oto Šťáva před téměř 4 roky(ů)
deltarobot-protoclient/.gitignore | ||
---|---|---|
1 |
bin |
|
2 |
.vs |
|
3 |
obj |
deltarobot-protoclient/ConsoleApp1.csproj | ||
---|---|---|
1 |
<Project Sdk="Microsoft.NET.Sdk"> |
|
2 |
|
|
3 |
<PropertyGroup> |
|
4 |
<OutputType>Exe</OutputType> |
|
5 |
<TargetFramework>net5.0</TargetFramework> |
|
6 |
</PropertyGroup> |
|
7 |
|
|
8 |
</Project> |
deltarobot-protoclient/ConsoleApp1.sln | ||
---|---|---|
1 |
|
|
2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
3 |
# Visual Studio Version 16 |
|
4 |
VisualStudioVersion = 16.0.31205.134 |
|
5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1.csproj", "{12586309-0C91-4F56-9BF0-BC726D66FE58}" |
|
7 |
EndProject |
|
8 |
Global |
|
9 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
10 |
Debug|Any CPU = Debug|Any CPU |
|
11 |
Release|Any CPU = Release|Any CPU |
|
12 |
EndGlobalSection |
|
13 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
14 |
{12586309-0C91-4F56-9BF0-BC726D66FE58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
15 |
{12586309-0C91-4F56-9BF0-BC726D66FE58}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
16 |
{12586309-0C91-4F56-9BF0-BC726D66FE58}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
17 |
{12586309-0C91-4F56-9BF0-BC726D66FE58}.Release|Any CPU.Build.0 = Release|Any CPU |
|
18 |
EndGlobalSection |
|
19 |
GlobalSection(SolutionProperties) = preSolution |
|
20 |
HideSolutionNode = FALSE |
|
21 |
EndGlobalSection |
|
22 |
GlobalSection(ExtensibilityGlobals) = postSolution |
|
23 |
SolutionGuid = {7CC35946-E646-4889-BF96-6E68EA7D7355} |
|
24 |
EndGlobalSection |
|
25 |
EndGlobal |
deltarobot-protoclient/Program.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Net.Sockets; |
|
3 |
using System.Threading; |
|
4 |
using System.IO; |
|
5 |
|
|
6 |
namespace ConsoleApp1 |
|
7 |
{ |
|
8 |
class Program |
|
9 |
{ |
|
10 |
static void Main(string[] args) |
|
11 |
{ |
|
12 |
Console.WriteLine("Hello World!"); |
|
13 |
Singleton client = Singleton.Instance; |
|
14 |
client.start(); |
|
15 |
while (client.IsRunning) |
|
16 |
{ |
|
17 |
Console.WriteLine(client.X + " " + client.Y + " " + client.Z); |
|
18 |
Thread.Sleep(100); |
|
19 |
} |
|
20 |
} |
|
21 |
} |
|
22 |
|
|
23 |
public sealed class Singleton |
|
24 |
{ |
|
25 |
private static readonly Singleton instance = new Singleton(); |
|
26 |
|
|
27 |
private const string SERVER = "127.0.0.1"; |
|
28 |
private const Int32 PORT = 4242; |
|
29 |
|
|
30 |
private const UInt16 PROTOCOL_MAGIC = 0x3001; |
|
31 |
private const UInt16 PROTOCOL_VERSION = 0x2002; |
|
32 |
private const UInt16 PING = 0x3004; |
|
33 |
private const UInt16 EOT = 0xF006; |
|
34 |
private const UInt16 CURACTPOS = 0x4003; |
|
35 |
|
|
36 |
private const UInt16 SIZE_8 = 0x0000; |
|
37 |
private const UInt16 SIZE_16 = 0x1000; |
|
38 |
private const UInt16 SIZE_32 = 0x2000; |
|
39 |
private const UInt16 SIZE_64 = 0x3000; |
|
40 |
private const UInt16 SIZE_128 = 0x4000; |
|
41 |
private const UInt16 SIZE_VARIABLE = 0xF000; |
|
42 |
|
|
43 |
private const UInt64 PROTOCOL_MAGIC_VALUE = 0x44656C7461525672; // `DeltaRVr` in ASCII |
|
44 |
private const UInt32 PROTOCOL_VERSION_VALUE = 1; |
|
45 |
|
|
46 |
private TcpClient client; |
|
47 |
private NetworkStream stream; |
|
48 |
private Boolean isRunning; |
|
49 |
private Thread t; |
|
50 |
|
|
51 |
private Single x; |
|
52 |
private Single y; |
|
53 |
private Single z; |
|
54 |
private string eotMsg; |
|
55 |
|
|
56 |
static Singleton() |
|
57 |
{ |
|
58 |
} |
|
59 |
|
|
60 |
private Singleton() |
|
61 |
{ |
|
62 |
} |
|
63 |
|
|
64 |
public static Singleton Instance |
|
65 |
{ |
|
66 |
get |
|
67 |
{ |
|
68 |
return instance; |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
public string EotMsg |
|
73 |
{ |
|
74 |
get |
|
75 |
{ |
|
76 |
lock (this) |
|
77 |
{ |
|
78 |
return eotMsg; |
|
79 |
} |
|
80 |
} |
|
81 |
set |
|
82 |
{ |
|
83 |
lock (this) |
|
84 |
{ |
|
85 |
eotMsg = value; |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
public Single X |
|
91 |
{ |
|
92 |
get |
|
93 |
{ |
|
94 |
lock (this) |
|
95 |
{ |
|
96 |
return x; |
|
97 |
} |
|
98 |
} |
|
99 |
set |
|
100 |
{ |
|
101 |
lock (this) |
|
102 |
{ |
|
103 |
x = value; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
public Single Y |
|
108 |
{ |
|
109 |
get |
|
110 |
{ |
|
111 |
lock (this) |
|
112 |
{ |
|
113 |
return y; |
|
114 |
} |
|
115 |
} |
|
116 |
set |
|
117 |
{ |
|
118 |
lock (this) |
|
119 |
{ |
|
120 |
y = value; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
public Single Z |
|
126 |
{ |
|
127 |
get |
|
128 |
{ |
|
129 |
lock (this) |
|
130 |
{ |
|
131 |
return z; |
|
132 |
} |
|
133 |
} |
|
134 |
set |
|
135 |
{ |
|
136 |
lock(this) |
|
137 |
{ |
|
138 |
z = value; |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
public Boolean IsRunning |
|
144 |
{ |
|
145 |
get |
|
146 |
{ |
|
147 |
lock(this) |
|
148 |
{ |
|
149 |
return isRunning; |
|
150 |
} |
|
151 |
} |
|
152 |
private set |
|
153 |
{ |
|
154 |
lock (this) |
|
155 |
{ |
|
156 |
isRunning = value; |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
private void connect() |
|
162 |
{ |
|
163 |
try |
|
164 |
{ |
|
165 |
client = new TcpClient(SERVER, PORT); |
|
166 |
stream = client.GetStream(); |
|
167 |
BinaryReader reader = new BinaryReader(stream); |
|
168 |
UInt16 sizeIdentifier = 0; |
|
169 |
UInt16 messageIdentifier = 0; |
|
170 |
|
|
171 |
|
|
172 |
try |
|
173 |
{ |
|
174 |
while (IsRunning) |
|
175 |
{ |
|
176 |
messageIdentifier = reader.ReadUInt16(); |
|
177 |
//Console.WriteLine(String.Format("{0:X}", messageIdentifier)); |
|
178 |
switch (messageIdentifier) |
|
179 |
{ |
|
180 |
case PROTOCOL_MAGIC: |
|
181 |
protocolMagicProcessing(reader); |
|
182 |
break; |
|
183 |
case PROTOCOL_VERSION: |
|
184 |
protocolVersionProcessing(reader); |
|
185 |
break; |
|
186 |
case PING: |
|
187 |
pingProcessing(reader); |
|
188 |
break; |
|
189 |
case EOT: |
|
190 |
eotProcessing(reader); |
|
191 |
break; |
|
192 |
case CURACTPOS: |
|
193 |
currentActuatorPositionProcessing(reader); |
|
194 |
break; |
|
195 |
default: //client tuto zpravu nezna |
|
196 |
sizeIdentifier = (UInt16)(messageIdentifier & 0xF000); |
|
197 |
switch (sizeIdentifier) |
|
198 |
{ |
|
199 |
case SIZE_8: |
|
200 |
skip8(reader); |
|
201 |
break; |
|
202 |
case SIZE_16: |
|
203 |
skip16(reader); |
|
204 |
break; |
|
205 |
case SIZE_32: |
|
206 |
skip32(reader); |
|
207 |
break; |
|
208 |
case SIZE_64: |
|
209 |
skip64(reader); |
|
210 |
break; |
|
211 |
case SIZE_128: |
|
212 |
skip128(reader); |
|
213 |
break; |
|
214 |
case SIZE_VARIABLE: |
|
215 |
skipV(reader); |
|
216 |
break; |
|
217 |
} |
|
218 |
break; |
|
219 |
} |
|
220 |
} |
|
221 |
} |
|
222 |
finally |
|
223 |
{ |
|
224 |
stream.Close(); |
|
225 |
client.Close(); |
|
226 |
} |
|
227 |
} |
|
228 |
catch(Exception) |
|
229 |
{ |
|
230 |
Console.WriteLine("failed to connect"); |
|
231 |
} |
|
232 |
|
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
private void skip8(BinaryReader reader) |
|
238 |
{ |
|
239 |
reader.ReadByte(); |
|
240 |
} |
|
241 |
|
|
242 |
private void skip16(BinaryReader reader) |
|
243 |
{ |
|
244 |
reader.ReadUInt16(); |
|
245 |
} |
|
246 |
|
|
247 |
private void skip32(BinaryReader reader) |
|
248 |
{ |
|
249 |
reader.ReadUInt32(); |
|
250 |
} |
|
251 |
|
|
252 |
private void skip64(BinaryReader reader) |
|
253 |
{ |
|
254 |
reader.ReadUInt64(); |
|
255 |
} |
|
256 |
|
|
257 |
private void skip128(BinaryReader reader) |
|
258 |
{ |
|
259 |
reader.ReadUInt64(); |
|
260 |
reader.ReadUInt64(); |
|
261 |
} |
|
262 |
|
|
263 |
private void skipV(BinaryReader reader) |
|
264 |
{ |
|
265 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
|
266 |
reader.ReadBytes((int)numberOfBytes); |
|
267 |
} |
|
268 |
|
|
269 |
private void currentActuatorPositionProcessing(BinaryReader reader) |
|
270 |
{ |
|
271 |
//Console.WriteLine("got position"); |
|
272 |
lock(this) |
|
273 |
{ |
|
274 |
X = reader.ReadSingle(); |
|
275 |
Y = reader.ReadSingle(); |
|
276 |
Z = reader.ReadSingle(); |
|
277 |
} |
|
278 |
reader.ReadSingle(); |
|
279 |
} |
|
280 |
|
|
281 |
private void eotProcessing(BinaryReader reader) |
|
282 |
{ |
|
283 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
|
284 |
Byte[] buffer = reader.ReadBytes((int)numberOfBytes); |
|
285 |
EotMsg = System.Text.Encoding.ASCII.GetString(buffer); |
|
286 |
IsRunning = false; |
|
287 |
} |
|
288 |
|
|
289 |
private void protocolMagicProcessing(BinaryReader reader) |
|
290 |
{ |
|
291 |
UInt64 value = reader.ReadUInt64(); |
|
292 |
if(value != PROTOCOL_MAGIC_VALUE) |
|
293 |
{ |
|
294 |
IsRunning = false; // mozna vyhodit vyjimku |
|
295 |
} |
|
296 |
} |
|
297 |
|
|
298 |
private void protocolVersionProcessing(BinaryReader reader) |
|
299 |
{ |
|
300 |
UInt32 value = reader.ReadUInt32(); |
|
301 |
if(value != PROTOCOL_VERSION_VALUE) |
|
302 |
{ |
|
303 |
IsRunning = false; // mozna vyhodit vyjimku |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
private void pingProcessing(BinaryReader reader) |
|
308 |
{ |
|
309 |
UInt64 pingValue = reader.ReadUInt64(); |
|
310 |
|
|
311 |
// send pong |
|
312 |
Byte[] buffer = BitConverter.GetBytes(pingValue); |
|
313 |
stream.Write(buffer, 0, buffer.Length); |
|
314 |
} |
|
315 |
|
|
316 |
public void start() |
|
317 |
{ |
|
318 |
t = new Thread(new ThreadStart(connect)); |
|
319 |
IsRunning = true; |
|
320 |
t.Start(); |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
public void stop() |
|
325 |
{ |
|
326 |
IsRunning = false; |
|
327 |
t.Join(); |
|
328 |
} |
|
329 |
|
|
330 |
} |
|
331 |
} |
deltarobot-vr/.gitignore | ||
---|---|---|
26 | 26 |
# Visual Studio cache directory |
27 | 27 |
.vs/ |
28 | 28 |
|
29 |
# Rider project directory |
|
30 |
.idea/ |
|
31 |
|
|
29 | 32 |
# Gradle cache directory |
30 | 33 |
.gradle/ |
31 | 34 |
|
deltarobot-vr/Assets/CubeMaterial.mat | ||
---|---|---|
1 |
%YAML 1.1 |
|
2 |
%TAG !u! tag:unity3d.com,2011: |
|
3 |
--- !u!21 &2100000 |
|
4 |
Material: |
|
5 |
serializedVersion: 6 |
|
6 |
m_ObjectHideFlags: 0 |
|
7 |
m_CorrespondingSourceObject: {fileID: 0} |
|
8 |
m_PrefabInstance: {fileID: 0} |
|
9 |
m_PrefabAsset: {fileID: 0} |
|
10 |
m_Name: CubeMaterial |
|
11 |
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} |
|
12 |
m_ShaderKeywords: |
|
13 |
m_LightmapFlags: 4 |
|
14 |
m_EnableInstancingVariants: 0 |
|
15 |
m_DoubleSidedGI: 0 |
|
16 |
m_CustomRenderQueue: -1 |
|
17 |
stringTagMap: {} |
|
18 |
disabledShaderPasses: [] |
|
19 |
m_SavedProperties: |
|
20 |
serializedVersion: 3 |
|
21 |
m_TexEnvs: |
|
22 |
- _BumpMap: |
|
23 |
m_Texture: {fileID: 0} |
|
24 |
m_Scale: {x: 1, y: 1} |
|
25 |
m_Offset: {x: 0, y: 0} |
|
26 |
- _DetailAlbedoMap: |
|
27 |
m_Texture: {fileID: 0} |
|
28 |
m_Scale: {x: 1, y: 1} |
|
29 |
m_Offset: {x: 0, y: 0} |
|
30 |
- _DetailMask: |
|
31 |
m_Texture: {fileID: 0} |
|
32 |
m_Scale: {x: 1, y: 1} |
|
33 |
m_Offset: {x: 0, y: 0} |
|
34 |
- _DetailNormalMap: |
|
35 |
m_Texture: {fileID: 0} |
|
36 |
m_Scale: {x: 1, y: 1} |
|
37 |
m_Offset: {x: 0, y: 0} |
|
38 |
- _EmissionMap: |
|
39 |
m_Texture: {fileID: 0} |
|
40 |
m_Scale: {x: 1, y: 1} |
|
41 |
m_Offset: {x: 0, y: 0} |
|
42 |
- _MainTex: |
|
43 |
m_Texture: {fileID: 0} |
|
44 |
m_Scale: {x: 1, y: 1} |
|
45 |
m_Offset: {x: 0, y: 0} |
|
46 |
- _MetallicGlossMap: |
|
47 |
m_Texture: {fileID: 0} |
|
48 |
m_Scale: {x: 1, y: 1} |
|
49 |
m_Offset: {x: 0, y: 0} |
|
50 |
- _OcclusionMap: |
|
51 |
m_Texture: {fileID: 0} |
|
52 |
m_Scale: {x: 1, y: 1} |
|
53 |
m_Offset: {x: 0, y: 0} |
|
54 |
- _ParallaxMap: |
|
55 |
m_Texture: {fileID: 0} |
|
56 |
m_Scale: {x: 1, y: 1} |
|
57 |
m_Offset: {x: 0, y: 0} |
|
58 |
m_Floats: |
|
59 |
- _BumpScale: 1 |
|
60 |
- _Cutoff: 0.5 |
|
61 |
- _DetailNormalMapScale: 1 |
|
62 |
- _DstBlend: 0 |
|
63 |
- _GlossMapScale: 1 |
|
64 |
- _Glossiness: 0.5 |
|
65 |
- _GlossyReflections: 1 |
|
66 |
- _Metallic: 0 |
|
67 |
- _Mode: 0 |
|
68 |
- _OcclusionStrength: 1 |
|
69 |
- _Parallax: 0.02 |
|
70 |
- _SmoothnessTextureChannel: 0 |
|
71 |
- _SpecularHighlights: 1 |
|
72 |
- _SrcBlend: 1 |
|
73 |
- _UVSec: 0 |
|
74 |
- _ZWrite: 1 |
|
75 |
m_Colors: |
|
76 |
- _Color: {r: 0, g: 0.61987686, b: 1, a: 1} |
|
77 |
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|
78 |
m_BuildTextureStacks: [] |
deltarobot-vr/Assets/CubeMaterial.mat.meta | ||
---|---|---|
1 |
fileFormatVersion: 2 |
|
2 |
guid: 62f2cab33e7d65346be49f4912bdd9ee |
|
3 |
NativeFormatImporter: |
|
4 |
externalObjects: {} |
|
5 |
mainObjectFileID: 2100000 |
|
6 |
userData: |
|
7 |
assetBundleName: |
|
8 |
assetBundleVariant: |
deltarobot-vr/Assets/CubeScript.cs | ||
---|---|---|
1 |
using DeltaRobotVr; |
|
2 |
using UnityEngine; |
|
3 |
|
|
4 |
public class CubeScript : MonoBehaviour |
|
5 |
{ |
|
6 |
private const float PositionScale = 0.001f; |
|
7 |
private const float LerpParam = 0.5f; |
|
8 |
|
|
9 |
private Transform _transform; |
|
10 |
|
|
11 |
void Start() |
|
12 |
{ |
|
13 |
_transform = GetComponent<Transform>(); |
|
14 |
|
|
15 |
Client.Instance.Start(); |
|
16 |
} |
|
17 |
|
|
18 |
void Update() |
|
19 |
{ |
|
20 |
if (Client.Instance.IsConnected) |
|
21 |
{ |
|
22 |
var serverPosition = Client.Instance.ActuatorPosition; |
|
23 |
var newPosition = new Vector3(serverPosition.X, serverPosition.Y, -serverPosition.Z) * PositionScale; |
|
24 |
_transform.position = Vector3.Lerp(_transform.position, newPosition, LerpParam); |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
private void OnDestroy() |
|
29 |
{ |
|
30 |
Client.Instance.Stop(); |
|
31 |
} |
|
32 |
} |
deltarobot-vr/Assets/CubeScript.cs.meta | ||
---|---|---|
1 |
fileFormatVersion: 2 |
|
2 |
guid: cfafba4e0e8b6e0adb6dda9dbc5076f8 |
|
3 |
MonoImporter: |
|
4 |
externalObjects: {} |
|
5 |
serializedVersion: 2 |
|
6 |
defaultReferences: [] |
|
7 |
executionOrder: 0 |
|
8 |
icon: {instanceID: 0} |
|
9 |
userData: |
|
10 |
assetBundleName: |
|
11 |
assetBundleVariant: |
deltarobot-vr/Assets/DeltaRobotVr.meta | ||
---|---|---|
1 |
fileFormatVersion: 2 |
|
2 |
guid: 86e3e33271dc4393bf31f3412d95575b |
|
3 |
timeCreated: 1620467739 |
deltarobot-vr/Assets/DeltaRobotVr/Client.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Net.Sockets; |
|
3 |
using System.Threading; |
|
4 |
using System.IO; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
|
|
8 |
namespace DeltaRobotVr |
|
9 |
{ |
|
10 |
public readonly struct Single3 |
|
11 |
{ |
|
12 |
public float X { get; } |
|
13 |
public float Y { get; } |
|
14 |
public float Z { get; } |
|
15 |
|
|
16 |
public Single3(float x, float y, float z) |
|
17 |
{ |
|
18 |
X = x; |
|
19 |
Y = y; |
|
20 |
Z = z; |
|
21 |
} |
|
22 |
|
|
23 |
public override string ToString() => "Single3[ " + X + " " + Y + " " + Z + " ]"; |
|
24 |
} |
|
25 |
|
|
26 |
public sealed class Client |
|
27 |
{ |
|
28 |
// singleton instance |
|
29 |
public static readonly Client Instance = new Client(); |
|
30 |
|
|
31 |
// default server |
|
32 |
private const string DefaultServer = "127.0.0.1"; |
|
33 |
private const int DefaultPort = 4242; |
|
34 |
|
|
35 |
// protocol constants |
|
36 |
private const UInt16 ProtocolMagicId = 0x3001; |
|
37 |
private const UInt16 ProtocolVersionId = 0x2002; |
|
38 |
private const UInt16 PingId = 0x3004; |
|
39 |
private const UInt16 EotId = 0xF006; |
|
40 |
private const UInt16 CurrentActuatorPositionId = 0x4003; |
|
41 |
|
|
42 |
private const UInt16 Size8 = 0x0000; |
|
43 |
private const UInt16 Size16 = 0x1000; |
|
44 |
private const UInt16 Size32 = 0x2000; |
|
45 |
private const UInt16 Size64 = 0x3000; |
|
46 |
private const UInt16 Size128 = 0x4000; |
|
47 |
private const UInt16 SizeVariable = 0xF000; |
|
48 |
|
|
49 |
private static readonly byte[] ProtocolMagicValue = Encoding.ASCII.GetBytes("DeltaRVr"); |
|
50 |
private const UInt32 ProtocolVersionValue = 1; |
|
51 |
|
|
52 |
|
|
53 |
private Thread _thread; |
|
54 |
|
|
55 |
private readonly object _isRunningLock = new object(); |
|
56 |
private bool _isRunning; |
|
57 |
|
|
58 |
private readonly object _actuatorPositionLock = new object(); |
|
59 |
private Single3 _actuatorPosition; |
|
60 |
|
|
61 |
private volatile bool _isConnected; |
|
62 |
private volatile string _eotMsg; |
|
63 |
|
|
64 |
static Client() |
|
65 |
{ |
|
66 |
} |
|
67 |
|
|
68 |
private Client() |
|
69 |
{ |
|
70 |
} |
|
71 |
|
|
72 |
public void Start() |
|
73 |
{ |
|
74 |
_thread = new Thread(ThreadProcedure); |
|
75 |
IsRunning = true; |
|
76 |
_thread.Start(); |
|
77 |
} |
|
78 |
|
|
79 |
public void Stop() |
|
80 |
{ |
|
81 |
IsRunning = false; |
|
82 |
_thread.Join(); |
|
83 |
} |
|
84 |
|
|
85 |
public string EotMsg |
|
86 |
{ |
|
87 |
get => _eotMsg; |
|
88 |
private set => _eotMsg = value; |
|
89 |
} |
|
90 |
|
|
91 |
public bool IsConnected |
|
92 |
{ |
|
93 |
get => _isConnected; |
|
94 |
private set => _isConnected = value; |
|
95 |
} |
|
96 |
|
|
97 |
public Single3 ActuatorPosition |
|
98 |
{ |
|
99 |
get |
|
100 |
{ |
|
101 |
lock (_actuatorPositionLock) |
|
102 |
{ |
|
103 |
return _actuatorPosition; |
|
104 |
} |
|
105 |
} |
|
106 |
private set |
|
107 |
{ |
|
108 |
lock (_actuatorPositionLock) |
|
109 |
{ |
|
110 |
_actuatorPosition = value; |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
public bool IsRunning |
|
116 |
{ |
|
117 |
get { |
|
118 |
lock (_isRunningLock) |
|
119 |
{ |
|
120 |
return _isRunning; |
|
121 |
} |
|
122 |
} |
|
123 |
private set |
|
124 |
{ |
|
125 |
lock (_isRunningLock) |
|
126 |
{ |
|
127 |
_isRunning = value; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
private void ThreadProcedure() |
|
133 |
{ |
|
134 |
try |
|
135 |
{ |
|
136 |
var client = new TcpClient(DefaultServer, DefaultPort); |
|
137 |
var stream = client.GetStream(); |
|
138 |
BinaryReader reader = new BinaryReader(stream); |
|
139 |
BinaryWriter writer = new BinaryWriter(stream); |
|
140 |
IsConnected = true; |
|
141 |
|
|
142 |
writer.Write(ProtocolMagicId); |
|
143 |
writer.Write(ProtocolMagicValue); |
|
144 |
writer.Write(ProtocolVersionId); |
|
145 |
writer.Write(ProtocolVersionValue); |
|
146 |
|
|
147 |
try |
|
148 |
{ |
|
149 |
while (IsRunning && IsConnected) |
|
150 |
{ |
|
151 |
var messageIdentifier = reader.ReadUInt16(); |
|
152 |
switch (messageIdentifier) |
|
153 |
{ |
|
154 |
case ProtocolMagicId: |
|
155 |
ProcessProtocolMagic(reader); |
|
156 |
break; |
|
157 |
case ProtocolVersionId: |
|
158 |
ProcessProtocolVersion(reader); |
|
159 |
break; |
|
160 |
case PingId: |
|
161 |
ProcessPing(reader, writer); |
|
162 |
break; |
|
163 |
case EotId: |
|
164 |
ProcessEot(reader); |
|
165 |
break; |
|
166 |
case CurrentActuatorPositionId: |
|
167 |
ProcessCurrentActuatorPosition(reader); |
|
168 |
break; |
|
169 |
default: //client tuto zpravu nezna |
|
170 |
var sizeIdentifier = (UInt16) (messageIdentifier & 0xF000); |
|
171 |
switch (sizeIdentifier) |
|
172 |
{ |
|
173 |
case Size8: |
|
174 |
Skip8(reader); |
|
175 |
break; |
|
176 |
case Size16: |
|
177 |
Skip16(reader); |
|
178 |
break; |
|
179 |
case Size32: |
|
180 |
Skip32(reader); |
|
181 |
break; |
|
182 |
case Size64: |
|
183 |
Skip64(reader); |
|
184 |
break; |
|
185 |
case Size128: |
|
186 |
Skip128(reader); |
|
187 |
break; |
|
188 |
case SizeVariable: |
|
189 |
SkipVariableLength(reader); |
|
190 |
break; |
|
191 |
} |
|
192 |
|
|
193 |
break; |
|
194 |
} |
|
195 |
} |
|
196 |
} |
|
197 |
finally |
|
198 |
{ |
|
199 |
stream.Close(); |
|
200 |
client.Close(); |
|
201 |
IsConnected = true; |
|
202 |
} |
|
203 |
} |
|
204 |
catch (Exception) |
|
205 |
{ |
|
206 |
Console.WriteLine("failed to connect"); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
private void Skip8(BinaryReader reader) |
|
212 |
{ |
|
213 |
reader.ReadByte(); |
|
214 |
} |
|
215 |
|
|
216 |
private void Skip16(BinaryReader reader) |
|
217 |
{ |
|
218 |
reader.ReadUInt16(); |
|
219 |
} |
|
220 |
|
|
221 |
private void Skip32(BinaryReader reader) |
|
222 |
{ |
|
223 |
reader.ReadUInt32(); |
|
224 |
} |
|
225 |
|
|
226 |
private void Skip64(BinaryReader reader) |
|
227 |
{ |
|
228 |
reader.ReadUInt64(); |
|
229 |
} |
|
230 |
|
|
231 |
private void Skip128(BinaryReader reader) |
|
232 |
{ |
|
233 |
reader.ReadUInt64(); |
|
234 |
reader.ReadUInt64(); |
|
235 |
} |
|
236 |
|
|
237 |
private void SkipVariableLength(BinaryReader reader) |
|
238 |
{ |
|
239 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
|
240 |
reader.ReadBytes((int) numberOfBytes); |
|
241 |
} |
|
242 |
|
|
243 |
private void ProcessCurrentActuatorPosition(BinaryReader reader) |
|
244 |
{ |
|
245 |
var x = reader.ReadSingle(); |
|
246 |
var y = reader.ReadSingle(); |
|
247 |
var z = reader.ReadSingle(); |
|
248 |
reader.ReadSingle(); // skip unused |
|
249 |
|
|
250 |
ActuatorPosition = new Single3(x, y, z); |
|
251 |
} |
|
252 |
|
|
253 |
private void ProcessEot(BinaryReader reader) |
|
254 |
{ |
|
255 |
UInt32 numberOfBytes = reader.ReadUInt32(); |
|
256 |
Byte[] buffer = reader.ReadBytes((int) numberOfBytes); |
|
257 |
EotMsg = Encoding.ASCII.GetString(buffer); |
|
258 |
IsConnected = false; |
|
259 |
} |
|
260 |
|
|
261 |
private void ProcessProtocolMagic(BinaryReader reader) |
|
262 |
{ |
|
263 |
byte[] value = reader.ReadBytes(8); |
|
264 |
if (!value.SequenceEqual(ProtocolMagicValue)) |
|
265 |
{ |
|
266 |
IsConnected = false; // mozna vyhodit vyjimku |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
private void ProcessProtocolVersion(BinaryReader reader) |
|
271 |
{ |
|
272 |
UInt32 value = reader.ReadUInt32(); |
|
273 |
if (value != ProtocolVersionValue) |
|
274 |
{ |
|
275 |
IsConnected = false; // mozna vyhodit vyjimku |
|
276 |
} |
|
277 |
} |
|
278 |
|
|
279 |
private void ProcessPing(BinaryReader reader, BinaryWriter writer) |
|
280 |
{ |
|
281 |
UInt64 pingValue = reader.ReadUInt64(); |
|
282 |
writer.Write(pingValue); |
|
283 |
} |
|
284 |
} |
|
285 |
} |
deltarobot-vr/Assets/DeltaRobotVr/Client.cs.meta | ||
---|---|---|
1 |
fileFormatVersion: 2 |
|
2 |
guid: 141220c40b1654d5e808231e9ef350e9 |
|
3 |
MonoImporter: |
|
4 |
externalObjects: {} |
|
5 |
serializedVersion: 2 |
|
6 |
defaultReferences: [] |
|
7 |
executionOrder: 0 |
|
8 |
icon: {instanceID: 0} |
|
9 |
userData: |
|
10 |
assetBundleName: |
|
11 |
assetBundleVariant: |
deltarobot-vr/Assets/Scenes/SampleScene.unity | ||
---|---|---|
325 | 325 |
m_PrefabAsset: {fileID: 0} |
326 | 326 |
m_GameObject: {fileID: 599916901} |
327 | 327 |
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
328 |
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
328 |
m_LocalPosition: {x: 0, y: -4, z: 0}
|
|
329 | 329 |
m_LocalScale: {x: 10, y: 10, z: 10} |
330 | 330 |
m_Children: [] |
331 | 331 |
m_Father: {fileID: 0} |
... | ... | |
501 | 501 |
m_PrefabInstance: {fileID: 0} |
502 | 502 |
m_PrefabAsset: {fileID: 0} |
503 | 503 |
m_GameObject: {fileID: 963194225} |
504 |
m_LocalRotation: {x: 0.18897976, y: 0.30442163, z: -0.061756246, w: 0.9315581}
|
|
505 |
m_LocalPosition: {x: -1.836, y: 0.39100003, z: -1.539}
|
|
504 |
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
505 |
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
506 | 506 |
m_LocalScale: {x: 1, y: 1, z: 1} |
507 | 507 |
m_Children: [] |
508 | 508 |
m_Father: {fileID: 1045848416} |
509 | 509 |
m_RootOrder: 0 |
510 |
m_LocalEulerAnglesHint: {x: 22.935, y: 36.194, z: 0}
|
|
510 |
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
511 | 511 |
--- !u!114 &963194229 |
512 | 512 |
MonoBehaviour: |
513 | 513 |
m_ObjectHideFlags: 0 |
... | ... | |
599 | 599 |
m_PrefabAsset: {fileID: 0} |
600 | 600 |
m_GameObject: {fileID: 1725982592} |
601 | 601 |
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
602 |
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
602 |
m_LocalPosition: {x: 0, y: -1, z: -15}
|
|
603 | 603 |
m_LocalScale: {x: 1, y: 1, z: 1} |
604 | 604 |
m_Children: |
605 | 605 |
- {fileID: 1045848416} |
... | ... | |
745 | 745 |
- component: {fileID: 2021860139} |
746 | 746 |
- component: {fileID: 2021860138} |
747 | 747 |
- component: {fileID: 2021860137} |
748 |
- component: {fileID: 2021860141} |
|
748 | 749 |
m_Layer: 0 |
749 | 750 |
m_Name: MyTestCube |
750 | 751 |
m_TagString: Untagged |
... | ... | |
784 | 785 |
m_RenderingLayerMask: 1 |
785 | 786 |
m_RendererPriority: 0 |
786 | 787 |
m_Materials: |
787 |
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
|
788 |
- {fileID: 2100000, guid: 62f2cab33e7d65346be49f4912bdd9ee, type: 2}
|
|
788 | 789 |
m_StaticBatchInfo: |
789 | 790 |
firstSubMesh: 0 |
790 | 791 |
subMeshCount: 0 |
... | ... | |
822 | 823 |
m_PrefabAsset: {fileID: 0} |
823 | 824 |
m_GameObject: {fileID: 2021860136} |
824 | 825 |
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
825 |
m_LocalPosition: {x: 0, y: 0.506, z: 0}
|
|
826 |
m_LocalPosition: {x: 0, y: 0, z: 0} |
|
826 | 827 |
m_LocalScale: {x: 1, y: 1, z: 1} |
827 | 828 |
m_Children: [] |
828 | 829 |
m_Father: {fileID: 0} |
829 | 830 |
m_RootOrder: 3 |
830 | 831 |
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
832 |
--- !u!114 &2021860141 |
|
833 |
MonoBehaviour: |
|
834 |
m_ObjectHideFlags: 0 |
|
835 |
m_CorrespondingSourceObject: {fileID: 0} |
|
836 |
m_PrefabInstance: {fileID: 0} |
|
837 |
m_PrefabAsset: {fileID: 0} |
|
838 |
m_GameObject: {fileID: 2021860136} |
|
839 |
m_Enabled: 1 |
|
840 |
m_EditorHideFlags: 0 |
|
841 |
m_Script: {fileID: 11500000, guid: cfafba4e0e8b6e0adb6dda9dbc5076f8, type: 3} |
|
842 |
m_Name: |
|
843 |
m_EditorClassIdentifier: |
|
831 | 844 |
--- !u!1001 &2038249430 |
832 | 845 |
PrefabInstance: |
833 | 846 |
m_ObjectHideFlags: 0 |
deltarobot/curvedataserver.cpp | ||
---|---|---|
138 | 138 |
message[0] = 0x02; |
139 | 139 |
message[1] = 0x20; |
140 | 140 |
|
141 |
message[5] = 0x01;
|
|
141 |
message[2] = 0x01;
|
|
142 | 142 |
|
143 | 143 |
socket->write(message); |
144 | 144 |
|
Také k dispozici: Unified diff
Re #8733 - Refactor protoclient into Unity + server fix