Low-Level C++ SDK  v1.2.0
Loading...
Searching...
No Matches
WeArtMessages.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "WeArtCommon.h"
5#include <string>
6#include <vector>
7#include <cassert>
8#include <map>
9#include "nlohmann/json.hpp"
10
11// Utility Methods, called to serialize/deserialize types
12HandSide StringToHandside(std::string& str);
13
14std::string HandsideToString(HandSide hs);
15
17
19
20ActuationPoint StringToActuationPoint(std::string& str);
21
22std::string ActuationPointToString(ActuationPoint ap);
23
24TrackingType StringToTrackingType(const std::string& str);
25
26std::string TrackingTypeToString(TrackingType trackType);
27
29
32class WeArtMessage {
33public:
36 virtual std::string getID() = 0;
37
40 virtual void setHandSide(HandSide hs) = 0;
41
44 virtual void setActuationPoint(ActuationPoint ap) = 0;
45
46 virtual std::string serialize() = 0;
47 virtual void deserialize(std::string message) = 0;
48};
49
51class WeArtCsvMessage : public WeArtMessage {
52public:
53 const char field_separator = ':';
54
55 virtual std::vector<std::string> getValues() = 0;
56 virtual void setValues(std::vector<std::string>& values) = 0;
57
58 virtual std::string serialize() override;
59 virtual void deserialize(std::string message) override;
60};
61
63class WeArtJsonMessage : public WeArtMessage {
64public:
65 WeArtJsonMessage();
66
67 virtual std::string serialize() override;
68 virtual void deserialize(std::string message) override;
69 std::uint64_t timestamp() { return _timestamp; }
70
71 virtual void setHandSide(HandSide hs) override {};
72 virtual void setActuationPoint(ActuationPoint ap) override {};
73
74protected:
75 virtual nlohmann::json serializePayload() { return nlohmann::json(); }
76 virtual void deserializePayload(nlohmann::json payload) {}
77 std::uint64_t _timestamp;
78};
79
80
83class WeArtMessageNoParams : public WeArtCsvMessage {
84public:
85 virtual void setHandSide(HandSide hs) override {};
86 virtual void setActuationPoint(ActuationPoint ap) override {};
87
88 // This message carries no values.
89 virtual std::vector<std::string> getValues() override {
90 return std::vector<std::string>();
91 };
92 virtual void setValues(std::vector<std::string>& values) override {};
93};
94
97class WeArtMessageHandSpecific : public WeArtCsvMessage {
98public:
99 HandSide getHand() {
100 return handSide;
101 }
102protected:
103 HandSide handSide;
104public:
105 virtual void setHandSide(HandSide hs) override {
106 handSide = hs;
107 };
108 virtual void setActuationPoint(ActuationPoint ap) override {};
109};
110
113class WeArtMessageObjectSpecific : public WeArtCsvMessage {
114public:
115 HandSide getHand() {
116 return handSide;
117 }
118
119 virtual void setHandSide(HandSide hs) override {
120 handSide = hs;
121 };
122
123 ActuationPoint getActuationPoint() {
124 return actuationPoint;
125 }
126
127 virtual void setActuationPoint(ActuationPoint ap) override {
128 actuationPoint = ap;
129 };
130
131
132protected:
133 HandSide handSide;
134 ActuationPoint actuationPoint;
135};
136
137
139class StartFromClientMessage : public WeArtMessageNoParams {
140public:
141 static constexpr const char* ID = "StartFromClient";
142
143 StartFromClientMessage(TrackingType trackType = TrackingType::WEART_HAND) : _trackType(trackType) {}
144
145 virtual std::string getID() override {
146 return ID;
147 };
148
149 virtual std::vector<std::string> getValues() override;
150 virtual void setValues(std::vector<std::string>& values) override;
151private:
152 TrackingType _trackType;
153};
154
156class StopFromClientMessage : public WeArtMessageNoParams {
157public:
158 static constexpr const char* ID = "StopFromClient";
159
160 virtual std::string getID() override {
161 return ID;
162 };
163};
164
166class StartCalibrationMessage : public WeArtMessageNoParams {
167public:
168 static constexpr const char* ID = "StartCalibration";
169
170 virtual std::string getID() override {
171 return ID;
172 }
173};
174
176class StopCalibrationMessage : public WeArtMessageNoParams {
177public:
178 static constexpr const char* ID = "StopCalibration";
179
180 virtual std::string getID() override {
181 return ID;
182 }
183};
184
186class CalibrationStatusMessage : public WeArtMessageHandSpecific {
187public:
188 static constexpr const char* ID = "CalibrationStatus";
189
190 virtual std::string getID() override {
191 return ID;
192 }
193
194 CalibrationStatus getStatus() {
195 return status;
196 }
197
198 virtual std::vector<std::string> getValues() override;
199
200 virtual void setValues(std::vector<std::string>& values) override;
201
202protected:
203 CalibrationStatus status;
204};
205
207class CalibrationResultMessage : public WeArtMessageHandSpecific {
208public:
209 static constexpr const char* ID = "CalibrationResult";
210
211 virtual std::string getID() override {
212 return ID;
213 }
214
215 bool getSuccess() {
216 return success;
217 }
218
219 virtual std::vector<std::string> getValues() override;
220
221 virtual void setValues(std::vector<std::string>& values) override;
222
223protected:
224 bool success;
225};
226
228class ExitMessage : public WeArtMessageNoParams {
229public:
230 static constexpr const char* ID = "exit";
231
232 virtual std::string getID() override {
233 return std::string("exit");
234 };
235};
236
238class DisconnectMessage : public WeArtMessageNoParams {
239public:
240 static constexpr const char* ID = "disconnect";
241
242 virtual std::string getID() override {
243 return ID;
244 };
245};
246
248class SetTemperatureMessage : public WeArtMessageObjectSpecific {
249public:
250 static constexpr const char* ID = "temperature";
251
252 SetTemperatureMessage(const float t) : temperature(t) {};
253 SetTemperatureMessage() {};
254 virtual std::string getID() override {
255 return ID;
256 };
257
258 virtual std::vector<std::string> getValues() override;
259
260 virtual void setValues(std::vector<std::string>& values) override;
261
262protected:
263 float temperature;
264};
265
267class StopTemperatureMessage : public WeArtMessageObjectSpecific {
268public:
269 static constexpr const char* ID = "stopTemperature";
270
271 virtual std::string getID() override {
272 return ID;
273 };
274
275 virtual std::vector<std::string> getValues() override;
276
277 virtual void setValues(std::vector<std::string>& values) override;
278};
279
281class SetForceMessage : public WeArtMessageObjectSpecific {
282public:
283 static constexpr const char* ID = "force";
284
285 SetForceMessage(const float f[3]) : force{ f[0], f[1], f[2] } {};
286 SetForceMessage() {};
287 virtual std::string getID() override {
288 return ID;
289 };
290
291 virtual std::vector<std::string> getValues() override;
292
293 virtual void setValues(std::vector<std::string>& values) override;
294
295protected:
296 float force[3];
297};
298
300class StopForceMessage : public WeArtMessageObjectSpecific {
301public:
302 static constexpr const char* ID = "stopForce";
303
304 virtual std::string getID() override {
305 return ID;
306 };
307
308 virtual std::vector<std::string> getValues() override;
309
310 virtual void setValues(std::vector<std::string>& values) override;
311};
312
314class SetTextureMessage : public WeArtMessageObjectSpecific {
315public:
316 static constexpr const char* ID = "texture";
317
318 SetTextureMessage(const int idx, const float vel, const float vol) : index(idx), velocity{ 0.5f, 0.0f, vel }, volume(vol) {};
319 SetTextureMessage() {};
320 virtual std::string getID() override {
321 return ID;
322 };
323
324 virtual std::vector<std::string> getValues() override;
325
326 virtual void setValues(std::vector<std::string>& values) override;
327
328protected:
329 int index;
330 float velocity[3] = { 0.5f, 0.0f, 0.0f };
331 float volume;
332};
333
335class StopTextureMessage : public WeArtMessageObjectSpecific {
336public:
337 static constexpr const char* ID = "stopTexture";
338
339 virtual std::string getID() override {
340 return ID;
341 };
342
343 virtual std::vector<std::string> getValues() override;
344
345 virtual void setValues(std::vector<std::string>& values) override;
346};
347
359class TrackingMessage : public WeArtMessageNoParams {
360public:
361 static constexpr const char* ID = "Tracking";
362
363 virtual std::string getID() override {
364 return std::string(ID);
365 };
366
367 struct Angles {
368 float X;
369 float Y;
370 float Z;
371 };
372
373 virtual std::vector<std::string> getValues() override;
374
375 virtual void setValues(std::vector<std::string>& values) override;
376
377 TrackingType GetType() {
378 return _trackingType;
379 }
380
385 float GetAbduction(HandSide handSide, ActuationPoint actuationPoint);
386
391 float GetClosure(HandSide handSide, ActuationPoint actuationPoint);
392private:
393 TrackingType _trackingType;
394
395 // Closures
396 uint8 RightThumbClosure;
397 uint8 RightIndexClosure;
398 uint8 RightMiddleClosure;
399 uint8 RightPalmClosure;
400 uint8 LeftThumbClosure;
401 uint8 LeftIndexClosure;
402 uint8 LeftMiddleClosure;
403 uint8 LeftPalmClosure;
404
405 // Abductions
406 uint8 RightThumbAbduction;
407 uint8 LeftThumbAbduction;
408};
409
411class RawDataOn : public WeArtJsonMessage {
412public:
413 static constexpr const char* ID = "RAW_DATA_ON";
414
415 virtual std::string getID() override { return ID; }
416 virtual void setHandSide(HandSide hs) override {}
417 virtual void setActuationPoint(ActuationPoint ap) override {}
418};
419
421class RawDataOff : public WeArtJsonMessage {
422public:
423 static constexpr const char* ID = "RAW_DATA_OFF";
424
425 virtual std::string getID() override { return ID; }
426 virtual void setHandSide(HandSide hs) override {}
427 virtual void setActuationPoint(ActuationPoint ap) override {}
428};
429
431class RawSensorsData : public WeArtJsonMessage {
432public:
433 static constexpr const char* ID = "RAW_DATA";
434
435 virtual std::string getID() override { return ID; };
436 virtual void setHandSide(HandSide hs) override { hand = hs; }
437 virtual void setActuationPoint(ActuationPoint ap) override {}
438
439 HandSide getHand() { return hand; }
440 bool hasSensor(ActuationPoint ap);
441 SensorData getSensor(ActuationPoint ap);
442
443protected:
444 virtual nlohmann::json serializePayload() override;
445 virtual void deserializePayload(nlohmann::json payload) override;
446
447 HandSide hand;
448 std::map<ActuationPoint, SensorData> sensors;
449
450};
451
453class AnalogSensorsData : public WeArtJsonMessage {
454public:
455 static constexpr const char* ID = "RAW_SENSOR_ON_MASK";
456
457 virtual std::string getID() override { return ID; };
458 virtual void setHandSide(HandSide hs) override { hand = hs; }
459 virtual void setActuationPoint(ActuationPoint ap) override {}
460
461 HandSide getHand() { return hand; }
462 bool hasSensor(ActuationPoint ap);
463 AnalogSensorRawData getSensor(ActuationPoint ap);
464
465protected:
466 virtual nlohmann::json serializePayload() override;
467 virtual void deserializePayload(nlohmann::json payload) override;
468
469 HandSide hand;
470 std::map<ActuationPoint, AnalogSensorRawData> sensors;
471};
472
474class GetMiddlewareStatus : public WeArtJsonMessage {
475public:
476 GetMiddlewareStatus() : WeArtJsonMessage() {}
477
478 static constexpr const char* ID = "MW_GET_STATUS";
479 virtual std::string getID() override { return ID; };
480};
481
483class MiddlewareStatusMessage : public WeArtJsonMessage {
484public:
485 MiddlewareStatusMessage() : WeArtJsonMessage() {}
486
487 static constexpr const char* ID = "MW_STATUS";
488 virtual std::string getID() override { return ID; };
489
490 MiddlewareStatusData data() { return _data; }
491
492protected:
493 virtual nlohmann::json serializePayload() override;
494 virtual void deserializePayload(nlohmann::json payload) override;
495
496private:
498};
499
501class GetDevicesStatusMessage : public WeArtJsonMessage {
502public:
503 GetDevicesStatusMessage() : WeArtJsonMessage() {}
504 static constexpr const char* ID = "DEVICES_GET_STATUS";
505 virtual std::string getID() override { return ID; };
506};
507
509class DevicesStatusMessage : public WeArtJsonMessage {
510public:
511 DevicesStatusMessage() : WeArtJsonMessage() {}
512
513 static constexpr const char* ID = "DEVICES_STATUS";
514 virtual std::string getID() override { return ID; };
515
516 std::vector<ConnectedDeviceStatus> devices() { return _devices; }
517
518protected:
519 virtual nlohmann::json serializePayload() override;
520 virtual void deserializePayload(nlohmann::json payload) override;
521
522private:
523 std::vector<ConnectedDeviceStatus> _devices;
524};
CalibrationStatus
Definition: WeArtCommon.h:55
MiddlewareStatus
Definition: WeArtCommon.h:61
HandSide
Definition: WeArtCommon.h:17
TrackingType
Definition: WeArtCommon.h:12
HandSide StringToHandside(std::string &str)
Definition: WeArtMessages.cpp:7
std::string TrackingTypeToString(TrackingType trackType)
Definition: WeArtMessages.cpp:91
std::string HandsideToString(HandSide hs)
Definition: WeArtMessages.cpp:20
HandSide StringToCalibrationHandSide(std::string &str)
Definition: WeArtMessages.cpp:37
TrackingType StringToTrackingType(const std::string &str)
Definition: WeArtMessages.cpp:85
std::string MiddlewareStatusToString(MiddlewareStatus status)
Definition: WeArtMessages.cpp:101
std::string CalibrationHandSideToString(HandSide hs)
Definition: WeArtMessages.cpp:33
std::string ActuationPointToString(ActuationPoint ap)
Definition: WeArtMessages.cpp:66
ActuationPoint StringToActuationPoint(std::string &str)
Definition: WeArtMessages.cpp:47
Definition: WeArtCommon.h:130
Definition: WeArtCommon.h:144
Definition: WeArtCommon.h:123
Definition: WeArtMessages.h:367
float Y
Definition: WeArtMessages.h:369
float Z
Definition: WeArtMessages.h:370
float X
Definition: WeArtMessages.h:368