5namespace tinyrobotics {
11constexpr const char* messageContentStr[] = {
35constexpr const char* unitStr[] = {
52constexpr const char* originStr[] = {
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
93 MessageHandlerBinary() : printer_(*
static_cast<Print*>(
nullptr)) {}
94 MessageHandlerBinary(Print& printer) : printer_(printer) {}
96 size_t written = printer_.write((
const uint8_t*)&msg,
sizeof(msg));
97 return written ==
sizeof(msg);
101 size_t written = printer_.write((
const uint8_t*)&msg,
sizeof(msg));
102 return written ==
sizeof(msg);
106 size_t written = printer_.write((
const uint8_t*)&msg,
sizeof(msg));
107 return written ==
sizeof(msg);
111 size_t written = printer_.write((
const uint8_t*)&msg,
sizeof(msg));
112 return written ==
sizeof(msg);
115 void setOutput(Print& printer) { printer_ = printer; }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
142 MessageHandlerPrint() : printer_(*
static_cast<Print*>(
nullptr)) {}
143 MessageHandlerPrint(Print& printer) : printer_(printer) {}
144 void setOutput(Print& printer) { printer_ = printer; }
146 printer_.print(
"[Message] Type: ");
147 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
148 printer_.print(
", Value: ");
149 printer_.print(msg.value);
151 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
152 printer_.print(
", Source: ");
153 printer_.println(originStr[
static_cast<
int>(msg.origin)]);
158 printer_.print(
"[Message] Type: ");
159 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
160 printer_.print(
", X: ");
161 printer_.print(msg.value.x);
162 printer_.print(
", Y: ");
163 printer_.print(msg.value.y);
164 printer_.print(
", Unit: ");
165 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
166 printer_.print(
", Source: ");
167 printer_.println(originStr[
static_cast<
int>(msg.origin)]);
172 printer_.print(
"[Message] Type: ");
173 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
174 printer_.print(
", Lat: ");
175 printer_.print(msg.value.latitude);
176 printer_.print(
", Lon: ");
177 printer_.print(msg.value.longitude);
178 printer_.print(
", Alt: ");
179 printer_.print(msg.value.altitude);
180 printer_.print(
", Unit: ");
181 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
182 printer_.print(
", Source: ");
183 printer_.println(originStr[
static_cast<
int>(msg.origin)]);
188 printer_.print(
"[Message] Type: MotionState3D");
189 printer_.print(
", Pos: (");
190 printer_.print(msg.value.getPosition().x);
191 printer_.print(
", ");
192 printer_.print(msg.value.getPosition().y);
193 printer_.print(
", ");
194 printer_.print(msg.value.getPosition().z);
196 printer_.print(
", Orientation: (");
197 printer_.print(msg.value.getOrientation().roll);
198 printer_.print(
", ");
199 printer_.print(msg.value.getOrientation().pitch);
200 printer_.print(
", ");
201 printer_.print(msg.value.getOrientation().yaw);
203 printer_.print(
", Speed: (");
204 printer_.print(msg.value.getSpeed().x);
205 printer_.print(
", ");
206 printer_.print(msg.value.getSpeed().y);
207 printer_.print(
", ");
208 printer_.print(msg.value.getSpeed().z);
210 printer_.print(
", AngularVel: (");
211 printer_.print(msg.value.getAngularVelocity().x);
212 printer_.print(
", ");
213 printer_.print(msg.value.getAngularVelocity().y);
214 printer_.print(
", ");
215 printer_.print(msg.value.getAngularVelocity().z);
217 printer_.println(
"");
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
247 MessageHandlerPrintXML() : printer_(*
static_cast<Print*>(
nullptr)) {}
248 MessageHandlerPrintXML(Print& printer) : printer_(printer) {}
249 void setOutput(Print& printer) { printer_ = printer; }
252 printer_.print(
"<Message type=\"");
253 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
254 printer_.print(
"\" unit=\"");
255 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
256 printer_.print(
"\" source=\"");
257 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
258 printer_.print(
"\" value=\"");
259 printer_.print(msg.value);
260 printer_.println(
"\"/>");
265 printer_.print(
"<Message type=\"");
266 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
267 printer_.print(
"\" unit=\"");
268 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
269 printer_.print(
"\" source=\"");
270 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
271 printer_.print(
"\"><X>");
272 printer_.print(msg.value.x);
273 printer_.print(
"</X><Y>");
274 printer_.print(msg.value.y);
275 printer_.println(
"</Y></Message>");
280 printer_.print(
"<Message type=\"");
281 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
282 printer_.print(
"\" unit=\"");
283 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
284 printer_.print(
"\" source=\"");
285 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
286 printer_.print(
"\"><Lat>");
287 printer_.print(msg.value.latitude);
288 printer_.print(
"</Lat><Lon>");
289 printer_.print(msg.value.longitude);
290 printer_.print(
"</Lon><Alt>");
291 printer_.print(msg.value.altitude);
292 printer_.println(
"</Alt></Message>");
297 printer_.print(
"<Message type=\"MotionState3D\"");
298 printer_.print(
" pos=\"");
299 printer_.print(msg.value.getPosition().x);
301 printer_.print(msg.value.getPosition().y);
303 printer_.print(msg.value.getPosition().z);
304 printer_.print(
"\" orientation=\"");
305 printer_.print(msg.value.getOrientation().roll);
307 printer_.print(msg.value.getOrientation().pitch);
309 printer_.print(msg.value.getOrientation().yaw);
310 printer_.print(
"\" speed=\"");
311 printer_.print(msg.value.getSpeed().x);
313 printer_.print(msg.value.getSpeed().y);
315 printer_.print(msg.value.getSpeed().z);
316 printer_.print(
"\" angularVel=\"");
317 printer_.print(msg.value.getAngularVelocity().x);
319 printer_.print(msg.value.getAngularVelocity().y);
321 printer_.print(msg.value.getAngularVelocity().z);
322 printer_.println(
"\"/>");
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
352 MessageHandlerPrintJSON() : printer_(*
static_cast<Print*>(
nullptr)) {}
353 MessageHandlerPrintJSON(Print& printer) : printer_(printer) {}
354 void setOutput(Print& printer) { printer_ = printer; }
357 printer_.print(
"{\"type\":\"");
358 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
359 printer_.print(
"\",\"value\":");
360 printer_.print(msg.value);
361 printer_.print(
",\"unit\":\"");
362 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
363 printer_.print(
"\",\"source\":\"");
364 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
365 printer_.println(
"\"}");
370 printer_.print(
"{\"type\":\"");
371 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
372 printer_.print(
"\",\"x\":");
373 printer_.print(msg.value.x);
374 printer_.print(
",\"y\":");
375 printer_.print(msg.value.y);
376 printer_.print(
",\"unit\":\"");
377 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
378 printer_.print(
"\",\"source\":\"");
379 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
380 printer_.println(
"\"}");
385 printer_.print(
"{\"type\":\"");
386 printer_.print(messageContentStr[
static_cast<
int>(msg.content)]);
387 printer_.print(
"\",\"lat\":");
388 printer_.print(msg.value.latitude);
389 printer_.print(
",\"lon\":");
390 printer_.print(msg.value.longitude);
391 printer_.print(
",\"alt\":");
392 printer_.print(msg.value.altitude);
393 printer_.print(
",\"unit\":\"");
394 printer_.print(unitStr[
static_cast<
int>(msg.unit)]);
395 printer_.print(
"\",\"source\":\"");
396 printer_.print(originStr[
static_cast<
int>(msg.origin)]);
397 printer_.println(
"\"}");
402 printer_.print(
"{\"type\":\"MotionState3D\"");
403 printer_.print(
",\"pos\":[");
404 printer_.print(msg.value.getPosition().x);
406 printer_.print(msg.value.getPosition().y);
408 printer_.print(msg.value.getPosition().z);
409 printer_.print(
"],\"orientation\":[");
410 printer_.print(msg.value.getOrientation().roll);
412 printer_.print(msg.value.getOrientation().pitch);
414 printer_.print(msg.value.getOrientation().yaw);
415 printer_.print(
"],\"speed\":[");
416 printer_.print(msg.value.getSpeed().x);
418 printer_.print(msg.value.getSpeed().y);
420 printer_.print(msg.value.getSpeed().z);
421 printer_.print(
"],\"angularVel\":[");
422 printer_.print(msg.value.getAngularVelocity().x);
424 printer_.print(msg.value.getAngularVelocity().y);
426 printer_.print(msg.value.getAngularVelocity().z);
427 printer_.println(
"]}");
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Represents a geodetic GPS coordinate with latitude, longitude, and optional altitude.
Definition: GPSCoordinate.h:52
Message handler that writes all received messages as raw binary to a Print stream.
Definition: MessageHandlerPrint.h:91
bool onMessage(const Message< float > &msg) override
Handle an incoming message (pure virtual).
Definition: MessageHandlerPrint.h:95
Message handler that prints all received messages as JSON to a Print stream.
Definition: MessageHandlerPrint.h:350
bool onMessage(const Message< float > &msg) override
Handle an incoming message (pure virtual).
Definition: MessageHandlerPrint.h:356
Message handler that prints all received messages as XML to a Print stream.
Definition: MessageHandlerPrint.h:245
bool onMessage(const Message< float > &msg) override
Handle an incoming message (pure virtual).
Definition: MessageHandlerPrint.h:251
Message handler that prints all received messages to a Print stream.
Definition: MessageHandlerPrint.h:140
bool onMessage(const Message< float > &msg) override
Handle an incoming message (pure virtual).
Definition: MessageHandlerPrint.h:145
Interface for handling messages in the TinyRobotics framework.
Definition: MessageHandler.h:18
Represents the full 3D motion state of a robot or vehicle.
Definition: MotionState3D.h:53
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72