-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiso22133.c
3868 lines (3330 loc) · 157 KB
/
iso22133.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "iso22133.h"
#include "header.h"
#include "footer.h"
#include "defines.h"
#include "timeconversions.h"
#include "iohelpers.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#pragma pack(push,1) // Ensure sizeof() is useable for (most) network byte lengths
/*! OPRO message */
typedef struct {
HeaderType header;
uint16_t objectTypeValueID;
uint16_t objectTypeContentLength;
uint8_t objectType;
uint16_t actorTypeValueID;
uint16_t actorTypeContentLength;
uint8_t actorType;
uint16_t operationModeValueID;
uint16_t operationModeContentLength;
uint8_t operationMode;
uint16_t massValueID;
uint16_t massContentLength;
uint32_t mass;
uint16_t objectLengthXValueID;
uint16_t objectLengthXContentLength;
uint32_t objectLengthX;
uint16_t objectLengthYValueID;
uint16_t objectLengthYContentLength;
uint32_t objectLengthY;
uint16_t objectLengthZValueID;
uint16_t objectLengthZContentLength;
uint32_t objectLengthZ;
uint16_t positionDisplacementXValueID;
uint16_t positionDisplacementXContentLength;
int16_t positionDisplacementX;
uint16_t positionDisplacementYValueID;
uint16_t positionDisplacementYContentLength;
int16_t positionDisplacementY;
uint16_t positionDisplacementZValueID;
uint16_t positionDisplacementZContentLength;
int16_t positionDisplacementZ;
FooterType footer;
} OPROType;
#define VALUE_ID_OPRO_OBJECT_TYPE 0x0100
#define VALUE_ID_OPRO_ACTOR_TYPE 0x0101
#define VALUE_ID_OPRO_OPERATION_MODE 0x0102
#define VALUE_ID_OPRO_MASS 0x0103
#define VALUE_ID_OPRO_OBJECT_LENGTH_X 0x0104
#define VALUE_ID_OPRO_OBJECT_LENGTH_Y 0x0105
#define VALUE_ID_OPRO_OBJECT_LENGTH_Z 0x0106
#define VALUE_ID_OPRO_POSITION_DISPLACEMENT_X 0x0107
#define VALUE_ID_OPRO_POSITION_DISPLACEMENT_Y 0x0108
#define VALUE_ID_OPRO_POSITION_DISPLACEMENT_Z 0x0109
//! OPRO field descriptions
static DebugStrings_t OPROObjectTypeDescription = {"ObjectType", "", &printU8};
static DebugStrings_t OPROActorTypeDescription = {"ActorType", "", &printU8};
static DebugStrings_t OPROOperationModeDescription = {"OperationMode", "", &printU8};
static DebugStrings_t OPROMassDescription = {"Mass", "[g]", &printU32};
static DebugStrings_t OPROObjectLengthXDescription = {"Object length X", "[mm]", &printU32};
static DebugStrings_t OPROObjectLengthYDescription = {"Object length Y", "[mm]", &printU32};
static DebugStrings_t OPROObjectLengthZDescription = {"Object length Z", "[mm]", &printU32};
static DebugStrings_t OPROPositionDisplacementXDescription = {"Position displacement X", "[mm]", &printI16};
static DebugStrings_t OPROPositionDisplacementYDescription = {"Position displacement Y", "[mm]", &printI16};
static DebugStrings_t OPROPositionDisplacementZDescription = {"Position displacement Z", "[mm]", &printI16};
/*! FOPR message */
typedef struct {
HeaderType header;
uint16_t foreignTransmitterIDValueID;
uint16_t foreignTransmitterIDContentLength;
uint32_t foreignTransmitterID;
uint16_t objectTypeValueID;
uint16_t objectTypeContentLength;
uint8_t objectType;
uint16_t actorTypeValueID;
uint16_t actorTypeContentLength;
uint8_t actorType;
uint16_t operationModeValueID;
uint16_t operationModeContentLength;
uint8_t operationMode;
uint16_t massValueID;
uint16_t massContentLength;
uint32_t mass;
uint16_t objectLengthXValueID;
uint16_t objectLengthXContentLength;
uint32_t objectLengthX;
uint16_t objectLengthYValueID;
uint16_t objectLengthYContentLength;
uint32_t objectLengthY;
uint16_t objectLengthZValueID;
uint16_t objectLengthZContentLength;
uint32_t objectLengthZ;
uint16_t positionDisplacementXValueID;
uint16_t positionDisplacementXContentLength;
int16_t positionDisplacementX;
uint16_t positionDisplacementYValueID;
uint16_t positionDisplacementYContentLength;
int16_t positionDisplacementY;
uint16_t positionDisplacementZValueID;
uint16_t positionDisplacementZContentLength;
int16_t positionDisplacementZ;
FooterType footer;
} FOPRType;
#define VALUE_ID_FOPR_FOREIGN_TRANSMITTER_ID 0x00FF
#define VALUE_ID_FOPR_OBJECT_TYPE 0x0100
#define VALUE_ID_FOPR_ACTOR_TYPE 0x0101
#define VALUE_ID_FOPR_OPERATION_MODE 0x0102
#define VALUE_ID_FOPR_MASS 0x0103
#define VALUE_ID_FOPR_OBJECT_LENGTH_X 0x0104
#define VALUE_ID_FOPR_OBJECT_LENGTH_Y 0x0105
#define VALUE_ID_FOPR_OBJECT_LENGTH_Z 0x0106
#define VALUE_ID_FOPR_POSITION_DISPLACEMENT_X 0x0107
#define VALUE_ID_FOPR_POSITION_DISPLACEMENT_Y 0x0108
#define VALUE_ID_FOPR_POSITION_DISPLACEMENT_Z 0x0109
static DebugStrings_t FOPRForeignTransmitterIDDescription = {"Foreign transmitter ID", "", &printU32};
static DebugStrings_t FOPRObjectTypeDescription = {"ObjectType", "", &printU8};
static DebugStrings_t FOPRActorTypeDescription = {"ActorType", "", &printU8};
static DebugStrings_t FOPROperationModeDescription = {"OperationMode", "", &printU8};
static DebugStrings_t FOPRMassDescription = {"Mass", "[g]", &printU32};
static DebugStrings_t FOPRObjectLengthXDescription = {"Object length X", "[mm]", &printU32};
static DebugStrings_t FOPRObjectLengthYDescription = {"Object length Y", "[mm]", &printU32};
static DebugStrings_t FOPRObjectLengthZDescription = {"Object length Z", "[mm]", &printU32};
static DebugStrings_t FOPRPositionDisplacementXDescription = {"Position displacement X", "[mm]", &printI16};
static DebugStrings_t FOPRPositionDisplacementYDescription = {"Position displacement Y", "[mm]", &printI16};
static DebugStrings_t FOPRPositionDisplacementZDescription = {"Position displacement Z", "[mm]", &printI16};
/*! STRT message */
typedef struct {
HeaderType header;
uint16_t StartTimeValueIdU16;
uint16_t StartTimeContentLengthU16;
uint32_t StartTimeU32;
uint16_t GPSWeekValueID;
uint16_t GPSWeekContentLength;
uint16_t GPSWeek;
FooterType footer;
} STRTType; //27 bytes
//! STRT value IDs
#define VALUE_ID_STRT_GPS_QMS_OF_WEEK 0x0002
#define VALUE_ID_STRT_GPS_WEEK 0x0003
/*! HEAB message */
typedef struct {
HeaderType header;
uint16_t HEABStructValueID;
uint16_t HEABStructContentLength;
uint32_t GPSQmsOfWeek;
uint8_t controlCenterStatus;
FooterType footer;
} HEABType; //16 bytes
//! HEAB value IDs
#define VALUE_ID_HEAB_STRUCT 0x0090
/*! SYPM message */
typedef struct {
HeaderType header;
uint16_t syncPointTimeValueID;
uint16_t syncPointTimeContentLength;
uint32_t syncPointTime;
uint16_t freezeTimeValueID;
uint16_t freezeTimeContentLength;
uint32_t freezeTime;
FooterType footer;
} SYPMType;
//! SYPM value IDs
#define VALUE_ID_SYPM_SYNC_POINT_TIME 0x0001
#define VALUE_ID_SYPM_FREEZE_TIME 0x0002
/*! MTSP message */
typedef struct {
HeaderType header;
uint16_t estSyncPointTimeValueID;
uint16_t estSyncPointTimeContentLength;
uint32_t estSyncPointTime;
FooterType footer;
} MTSPType;
//! MTSP value IDs
#define VALUE_ID_MTSP_EST_SYNC_POINT_TIME 0x0001
/*! TRCM message */
typedef struct {
HeaderType header;
uint16_t triggerIDValueID;
uint16_t triggerIDContentLength;
uint16_t triggerID;
uint16_t triggerTypeValueID;
uint16_t triggerTypeContentLength;
uint16_t triggerType;
uint16_t triggerTypeParameter1ValueID;
uint16_t triggerTypeParameter1ContentLength;
uint32_t triggerTypeParameter1;
uint16_t triggerTypeParameter2ValueID;
uint16_t triggerTypeParameter2ContentLength;
uint32_t triggerTypeParameter2;
uint16_t triggerTypeParameter3ValueID;
uint16_t triggerTypeParameter3ContentLength;
uint32_t triggerTypeParameter3;
FooterType footer;
} TRCMType;
//! TRCM value IDs
#define VALUE_ID_TRCM_TRIGGER_ID 0x0001
#define VALUE_ID_TRCM_TRIGGER_TYPE 0x0002
#define VALUE_ID_TRCM_TRIGGER_TYPE_PARAM1 0x0011
#define VALUE_ID_TRCM_TRIGGER_TYPE_PARAM2 0x0012
#define VALUE_ID_TRCM_TRIGGER_TYPE_PARAM3 0x0013
/*! TREO message */
typedef struct {
HeaderType header;
uint16_t triggerIDValueID;
uint16_t triggerIDContentLength;
uint16_t triggerID;
uint16_t timestamp_qmsowValueID;
uint16_t timestamp_qmsowContentLength;
uint32_t timestamp_qmsow;
FooterType footer;
} TREOType;
//! TREO value IDs
#define VALUE_ID_TREO_TRIGGER_ID 0x0001
#define VALUE_ID_TREO_TRIGGER_TIMESTAMP 0x0002
/*! ACCM message */
typedef struct {
HeaderType header;
uint16_t actionIDValueID;
uint16_t actionIDContentLength;
uint16_t actionID;
uint16_t actionTypeValueID;
uint16_t actionTypeContentLength;
uint16_t actionType;
uint16_t actionTypeParameter1ValueID;
uint16_t actionTypeParameter1ContentLength;
uint32_t actionTypeParameter1;
uint16_t actionTypeParameter2ValueID;
uint16_t actionTypeParameter2ContentLength;
uint32_t actionTypeParameter2;
uint16_t actionTypeParameter3ValueID;
uint16_t actionTypeParameter3ContentLength;
uint32_t actionTypeParameter3;
FooterType footer;
} ACCMType;
//! ACCM value IDs
#define VALUE_ID_ACCM_ACTION_ID 0x0002
#define VALUE_ID_ACCM_ACTION_TYPE 0x0003
#define VALUE_ID_ACCM_ACTION_TYPE_PARAM1 0x00A1
#define VALUE_ID_ACCM_ACTION_TYPE_PARAM2 0x00A2
#define VALUE_ID_ACCM_ACTION_TYPE_PARAM3 0x00A3
/*! EXAC message */
typedef struct {
HeaderType header;
uint16_t actionIDValueID;
uint16_t actionIDContentLength;
uint16_t actionID;
uint16_t executionTime_qmsoWValueID;
uint16_t executionTime_qmsoWContentLength;
uint32_t executionTime_qmsoW;
FooterType footer;
} EXACType;
//! EXAC value IDs
#define VALUE_ID_EXAC_ACTION_ID 0x0002
#define VALUE_ID_EXAC_ACTION_EXECUTE_TIME 0x0003
/*! CATA message */
// TODO
//! CATA value IDs
// TODO
/*! INSUP message */
typedef struct {
HeaderType header;
uint16_t modeValueID;
uint16_t modeContentLength;
uint8_t mode;
FooterType footer;
} INSUPType;
//! INSUP value IDs
#define VALUE_ID_INSUP_MODE 0x0200
/*! PODI message */
typedef struct {
HeaderType header;
uint16_t foreignTransmitterIDValueID;
uint16_t foreignTransmitterIDContentLength;
uint32_t foreignTransmitterID;
uint16_t gpsQmsOfWeekValueID;
uint16_t gpsQmsOfWeekContentLength;
uint32_t gpsQmsOfWeek;
uint16_t objectStateValueID;
uint16_t objectStateContentLength;
uint8_t objectState;
uint16_t xPositionValueID;
uint16_t xPositionContentLength;
int32_t xPosition;
uint16_t yPositionValueID;
uint16_t yPositionContentLength;
int32_t yPosition;
uint16_t zPositionValueID;
uint16_t zPositionContentLength;
int32_t zPosition;
uint16_t headingValueID;
uint16_t headingContentLength;
uint16_t heading;
uint16_t pitchValueID;
uint16_t pitchContentLength;
uint16_t pitch;
uint16_t rollValueID;
uint16_t rollContentLength;
uint16_t roll;
uint16_t longitudinalSpeedValueID;
uint16_t longitudinalSpeedContentLength;
int16_t longitudinalSpeed;
uint16_t lateralSpeedValueID;
uint16_t lateralSpeedContentLength;
int16_t lateralSpeed;
FooterType footer;
} PODIType;
//! PODI value IDs
#define VALUE_ID_PODI_FOREIGN_TRANSMITTER_ID 0x00FF
#define VALUE_ID_PODI_GPS_QMS_OF_WEEK 0x010A
#define VALUE_ID_PODI_OBJECT_STATE 0x010C
#define VALUE_ID_PODI_X_POSITION 0x010D
#define VALUE_ID_PODI_Y_POSITION 0x010E
#define VALUE_ID_PODI_Z_POSITION 0x010F
#define VALUE_ID_PODI_HEADING 0x0110
#define VALUE_ID_PODI_PITCH 0x0111
#define VALUE_ID_PODI_ROLL 0x0112
#define VALUE_ID_PODI_LONGITUDINAL_SPEED 0x0113
#define VALUE_ID_PODI_LATERAL_SPEED 0x0114
//! PODI field descriptions
static DebugStrings_t PODIForeignTransmitterIdDescription = {"ForeignTransmitterID", "", &printU32};
static DebugStrings_t PODIGpsQmsOfWeekDescription = {"GpsQmsOfWeek", "[¼ ms]", &printU32};
static DebugStrings_t PODIObjectStateDescription = {"ObjectState", "", &printU8};
static DebugStrings_t PODIxPositionDescription = {"Object X position", "[mm]", &printI32};
static DebugStrings_t PODIyPositionDescription = {"Object Y position", "[mm]", &printI32};
static DebugStrings_t PODIzPositionDescription = {"Object Z position", "[mm]", &printI32};
static DebugStrings_t PODIHeadingDescription = {"Object heading (yaw)", "[cdeg]", &printU16};
static DebugStrings_t PODIPitchDescription = {"Object pitch", "[cdeg]", &printU16};
static DebugStrings_t PODIRollDescription = {"Object roll", "[cdeg]", &printU16};
static DebugStrings_t PODILongitudinalSpeedDescription = {"Longitudinal speed", "[cm/s]", &printI16};
static DebugStrings_t PODILateralSpeedDescription = {"Lateral speed", "[cm/s]", &printI16};
/*! RCMM message */
typedef struct {
HeaderType header;
uint16_t controlStatusValueID;
uint16_t controlStatusContentLength;
uint8_t controlStatus;
uint16_t speedValueID;
uint16_t speedContentLength;
int16_t speed;
uint16_t steeringValueID;
uint16_t steeringContentLength;
int16_t steering;
uint16_t throttleValueID;
uint16_t throttleContentLength;
int16_t throttle;
uint16_t brakeValueID;
uint16_t brakeContentLength;
int16_t brake;
uint16_t commandValueID;
uint16_t commandContentLength;
uint8_t command;
FooterType footer;
} RCMMType;
//! RCMM value IDs
#define VALUE_ID_RCMM_CONTROL_STATUS 0x0001
#define VALUE_ID_RCMM_SPEED_METER_PER_SECOND 0x0011
#define VALUE_ID_RCMM_STEERING_ANGLE 0x0012
#define VALUE_ID_RCMM_STEERING_PERCENTAGE 0x0031
#define VALUE_ID_RCMM_SPEED_PERCENTAGE 0x0032
#define VALUE_ID_RCMM_THROTTLE_PERCENTAGE 0x0033
#define VALUE_ID_RCMM_BRAKE_PERCENTAGE 0x0034
#define VALUE_ID_RCMM_CONTROL 0xA201
static DebugStrings_t RCMMControlStatusDescription = {"Control Status", "", &printU8};
static DebugStrings_t RCMMSpeedDescription_m_s = {"Speed", "[m/s]", &printI16};
static DebugStrings_t RCMMSpeedDescriptionPct = {"Speed", "[%%]", &printI16};
static DebugStrings_t RCMMThrottleDescriptionPct = {"Throttle", "[%%]", &printI16};
static DebugStrings_t RCMMBrakeDescriptionPct = {"Brake", "[%%]", &printI16};
static DebugStrings_t RCMMSteeringDescriptionDeg = {"Steering", "[deg]", &printI16};
static DebugStrings_t RCMMSteeringDescriptionPct = {"Steering", "[%%]", &printI16};
static DebugStrings_t RCMMCommandDescription = {"Command (AstaZero)", "", &printU8};
/*! RDCA message - Request Direct Control Action*/
typedef struct {
HeaderType header;
uint16_t intendedReceiverIDValueID;
uint16_t intendedReceiverIDContentLength;
uint32_t intendedReceiverID;
uint16_t gpsQmsOfWeekValueID;
uint16_t gpsQmsOfWeekContentLength;
uint32_t gpsQmsOfWeek;
uint16_t steeringActionValueID;
uint16_t steeringActionContentLength;
int16_t steeringAction;
uint16_t speedActionValueID;
uint16_t speedActionContentLength;
int16_t speedAction;
FooterType footer;
} RDCAType; //27 bytes
//! RDCA value IDs
#define VALUE_ID_RDCA_GPS_QMS_OF_WEEK 0x010A
#define VALUE_ID_RDCA_STEERING_ANGLE 0x0204
#define VALUE_ID_RDCA_STEERING_PERCENTAGE 0x0205
#define VALUE_ID_RDCA_SPEED_METER_PER_SECOND 0x0206
#define VALUE_ID_RDCA_SPEED_PERCENTAGE 0x0207
#define VALUE_ID_RDCA_INTENDED_RECEIVER 0x0100
//! RDCA field descriptions
static DebugStrings_t RDCAIntendedReceiverDescription = {"Intended receiver ID", "", &printU32};
static DebugStrings_t RDCAGpsQmsOfWeekDescription = {"GpsQmsOfWeek", "[¼ ms]", &printU32};
static DebugStrings_t RDCASteeringDescriptionDeg = {"Steering", "[deg]", &printI16};
static DebugStrings_t RDCASteeringDescriptionPct = {"Steering", "%%", &printI16};
static DebugStrings_t RDCASpeedDescription_m_s = {"Speed", "[m/s]", &printI16};
static DebugStrings_t RDCASpeedDescriptionPct = {"Speed", "%%", &printI16};
/*! GDRM message - General Data Request Message*/
typedef struct {
HeaderType header;
uint16_t DataCodeValueIdU16;
uint16_t DataCodeContentLengthU16;
uint16_t DataCode;
FooterType footer;
} GDRMType; //19 bytes
//! GDRM value IDs
#define VALUE_ID_GDRM_DATA_CODE 0x0205
//! GDRM field descriptions
static DebugStrings_t GDRMDataCodeDescription = {"Data code", "", &printU32};
/*! DCTI message - Direct Control Transmitter Ids*/
typedef struct {
HeaderType header;
uint16_t TotalCountValueIdU16;
uint16_t TotalCountContentLengthU16;
uint16_t TotalCount;
uint16_t CounterValueIdU16;
uint16_t CounterContentLengthU16;
uint16_t Counter;
uint16_t TransmitterIDValueIdU16;
uint16_t TransmitterIDContentLengthU16;
uint32_t TransmitterID;
FooterType footer;
} DCTIType; //33 bytes
//! DCTI value IDs
#define VALUE_ID_DCTI_TOTAL_COUNT 0x0202
#define VALUE_ID_DCTI_COUNTER 0x0203
#define VALUE_ID_DCTI_TRANSMITTER_ID 0x0010
//! DCTI field descriptions
static DebugStrings_t DCTITotalCountDescription = {"Total count", "", &printU32};
static DebugStrings_t DCTICounterDescription = {"Counter", "", &printU32};
static DebugStrings_t DCTITransmitterIdDescription = {"TransmitterID", "", &printU32};
#pragma pack(pop)
// ************************** static function declarations ********************************************************
static char isValidMessageID(const uint16_t id);
static double_t mapISOHeadingToHostHeading(const double_t isoHeading_rad);
static double_t mapHostHeadingToISOHeading(const double_t hostHeading_rad);
static enum ISOMessageReturnValue convertHEABToHostRepresentation(
HEABType* HEABData,
const struct timeval *currentTime,
const uint8_t TransmitterId,
HeabMessageDataType* heabData);
static enum ISOMessageReturnValue convertGDRMToHostRepresentation(
GDRMType* GDRMData,
GdrmMessageDataType* gdrmData);
static enum ISOMessageReturnValue convertDCTIToHostRepresentation(DCTIType* DCTIData,
DctiMessageDataType* dctiData);
static enum ISOMessageReturnValue convertRDCAToHostRepresentation(
RDCAType* RDCAData,const struct timeval* currentTime,
RequestControlActionType* rdcaData);
static enum ISOMessageReturnValue convertPODIToHostRepresentation(
PODIType* PODIData,
const struct timeval* currentTime,
PeerObjectInjectionType* peerData);
static enum ISOMessageReturnValue convertOPROToHostRepresentation(
const OPROType* OPROData,
ObjectPropertiesType* objectProperties);
static enum ISOMessageReturnValue convertFOPRToHostRepresentation(
const FOPRType* FOPRData,
ForeignObjectPropertiesType* foreignObjectProperties);
static enum ISOMessageReturnValue convertRCMMToHostRepresentation(RCMMType * RCMMData,
RemoteControlManoeuvreMessageType* rcmmData);
static enum ISOMessageReturnValue convertSTRTToHostRepresentation(const STRTType * STRTData, const struct timeval* currentTime,
StartMessageType * startdata);
/*!
* \brief isValidMessageID Determines if specified id is a valid ISO message ID. The reserved range is deemed
* invalid and vendor specific range is deemed valid.
* \param id An ISO message id to be checked
* \return 1 if valid, 0 if not
*/
char isValidMessageID(const uint16_t id) {
return id == MESSAGE_ID_MONR || id == MESSAGE_ID_HEAB || id == MESSAGE_ID_TRAJ || id == MESSAGE_ID_OSEM
|| id == MESSAGE_ID_OSTM || id == MESSAGE_ID_STRT || id == MESSAGE_ID_MONR2 || id == MESSAGE_ID_SOWM
|| id == MESSAGE_ID_INFO || id == MESSAGE_ID_RCMM || id == MESSAGE_ID_SYPM || id == MESSAGE_ID_MTSP
|| id == MESSAGE_ID_TRCM || id == MESSAGE_ID_ACCM || id == MESSAGE_ID_TREO || id == MESSAGE_ID_EXAC
|| id == MESSAGE_ID_CATA || id == MESSAGE_ID_RCCM || id == MESSAGE_ID_RCRT || id == MESSAGE_ID_PIME
|| id == MESSAGE_ID_COSE || id == MESSAGE_ID_MOMA || id == MESSAGE_ID_GREM
|| (id >= MESSAGE_ID_VENDOR_SPECIFIC_LOWER_LIMIT && id <= MESSAGE_ID_VENDOR_SPECIFIC_UPPER_LIMIT);
}
/*!
* \brief getISOMessageType Determines the ISO message type of a raw data buffer
* \param messageData Buffer containing raw data to be parsed into an ISO message
* \param length Size of buffer to be parsed
* \param debug Flag for enabling debugging information
* \return Value according to ::ISOMessageID
*/
enum ISOMessageID getISOMessageType(const char *messageData, const size_t length, const char debug) {
HeaderType header;
// Decode header
if (decodeISOHeader(messageData, length, &header, debug) != MESSAGE_OK) {
fprintf(stderr, "Unable to parse raw data into ISO message header\n");
return MESSAGE_ID_INVALID;
}
// Check if header contains valid message ID, if so return it
if (isValidMessageID(header.messageID))
return (enum ISOMessageID) header.messageID;
else {
printf("Message ID %u does not match any known ISO message\n", header.messageID);
return MESSAGE_ID_INVALID;
}
}
/*!
* \brief encodeSTRTMessage Constructs an ISO STRT message based on start time parameters
* \param inputHeader data to create header with
* \param timeOfStart Time when test shall start, a value of NULL indicates that the time is not known
* \param strtDataBuffer Data buffer in which to place encoded STRT message
* \param bufferLength Size of data buffer in which to place encoded STRT message
* \param debug Flag for enabling debugging
* \return number of bytes written to the data buffer, or -1 if an error occurred
*/
ssize_t encodeSTRTMessage(const MessageHeaderType *inputHeader, const StartMessageType* startData, char *strtDataBuffer,
const size_t bufferLength, const char debug) {
STRTType STRTData;
memset(strtDataBuffer, 0, bufferLength);
// If buffer too small to hold STRT data, generate an error
if (bufferLength < sizeof (STRTType)) {
fprintf(stderr, "Buffer too small to hold necessary STRT data\n");
return -1;
}
STRTData.header = buildISOHeader(MESSAGE_ID_STRT, inputHeader, sizeof (STRTType), debug);
// Fill contents
STRTData.StartTimeValueIdU16 = VALUE_ID_STRT_GPS_QMS_OF_WEEK;
STRTData.StartTimeContentLengthU16 = sizeof (STRTData.StartTimeU32);
int64_t startTime = getAsGPSQuarterMillisecondOfWeek(&startData->startTime);
STRTData.StartTimeU32 = startData == NULL || startTime < 0 || !startData->isTimestampValid ?
GPS_SECOND_OF_WEEK_UNAVAILABLE_VALUE : (uint32_t) startTime;
STRTData.GPSWeekValueID = VALUE_ID_STRT_GPS_WEEK;
STRTData.GPSWeekContentLength = sizeof (STRTData.GPSWeek);
int32_t GPSWeek = getAsGPSWeek(&startData->startTime);
STRTData.GPSWeek = startData == NULL || GPSWeek < 0 || !startData->isTimestampValid ?
GPS_WEEK_UNAVAILABLE_VALUE : (uint16_t) GPSWeek;
if (debug) {
printf("STRT message:\n\tGPS second of week value ID: 0x%x\n\t"
"GPS second of week content length: %u\n\tGPS second of week: %u [¼ ms]\n\t"
"GPS week value ID: 0x%x\n\tGPS week content length: %u\n\t"
"GPS week: %u\n", STRTData.StartTimeValueIdU16, STRTData.StartTimeContentLengthU16,
STRTData.StartTimeU32, STRTData.GPSWeekValueID, STRTData.GPSWeekContentLength,
STRTData.GPSWeek);
}
// Swap from host endianness to little endian
STRTData.StartTimeValueIdU16 = htole16(STRTData.StartTimeValueIdU16);
STRTData.StartTimeContentLengthU16 = htole16(STRTData.StartTimeContentLengthU16);
STRTData.StartTimeU32 = htole32(STRTData.StartTimeU32);
STRTData.GPSWeekValueID = htole16(STRTData.GPSWeekValueID);
STRTData.GPSWeekContentLength = htole16(STRTData.GPSWeekContentLength);
STRTData.GPSWeek = htole16(STRTData.GPSWeek);
// Construct footer
STRTData.footer = buildISOFooter(&STRTData, sizeof (STRTType), debug);
memcpy(strtDataBuffer, &STRTData, sizeof (STRTType));
return sizeof (STRTType);
}
/*!
* \brief decodeSTRTMessage Fills a start message struct from a buffer of raw data
* \param strtDataBuffer Raw data to be decoded
* \param bufferLength Number of bytes in buffer of raw data to be decoded
* \param currentTime Current system time, for determining current GPS week
* \param startData Struct to be filled
* \param debug Flag for enabling of debugging
* \return Number of bytes decoded, or negative value according to ::ISOMessageReturnValue
*/
ssize_t decodeSTRTMessage(
const char *strtDataBuffer,
const size_t bufferLength,
const struct timeval* currentTime,
StartMessageType * startData,
const char debug) {
STRTType STRTData;
const char *p = strtDataBuffer;
const uint16_t ExpectedSTRTStructSize = (uint16_t) (sizeof (STRTData) - sizeof (STRTData.header)
- sizeof (STRTData.footer.Crc));
ssize_t retval = MESSAGE_OK;
if (startData == NULL || strtDataBuffer == NULL) {
errno = EINVAL;
fprintf(stderr, "Input pointers to STRT parsing function cannot be null\n");
return ISO_FUNCTION_ERROR;
}
// Init struct with zeros
memset(startData, 0, sizeof (*startData));
// Decode ISO header
if ((retval = decodeISOHeader(p, bufferLength, &STRTData.header, debug)) != MESSAGE_OK) {
memset(startData, 0, sizeof (*startData));
return retval;
}
p += sizeof (STRTData.header);
// If message is not a STRT message, generate an error
if (STRTData.header.messageID != MESSAGE_ID_STRT) {
fprintf(stderr, "Attempted to pass non-STRT message into STRT parsing function\n");
return MESSAGE_TYPE_ERROR;
}
if (STRTData.header.messageLength > sizeof (STRTType) - sizeof (HeaderType) - sizeof (FooterType)) {
fprintf(stderr, "STRT message exceeds expected message length\n");
return MESSAGE_LENGTH_ERROR;
}
// Decode content
memcpy(&STRTData.StartTimeValueIdU16, p, sizeof (STRTData.StartTimeValueIdU16));
p += sizeof (STRTData.StartTimeValueIdU16);
STRTData.StartTimeValueIdU16 = le16toh(STRTData.StartTimeValueIdU16);
if (STRTData.StartTimeValueIdU16 != VALUE_ID_STRT_GPS_QMS_OF_WEEK) {
fprintf(stderr, "StartTime Value Id differs from expected\n");
return MESSAGE_VALUE_ID_ERROR;
}
memcpy(&STRTData.StartTimeContentLengthU16, p, sizeof (STRTData.StartTimeContentLengthU16));
p += sizeof (STRTData.StartTimeContentLengthU16);
STRTData.StartTimeContentLengthU16 = le16toh(STRTData.StartTimeContentLengthU16);
if (STRTData.StartTimeContentLengthU16 != sizeof(STRTData.StartTimeU32)) {
fprintf(stderr, "StartTime Content Length %u differs from the expected length %lu\n",
STRTData.StartTimeContentLengthU16, sizeof(STRTData.StartTimeU32));
return MESSAGE_CONTENT_OUT_OF_RANGE;
}
memcpy(&STRTData.StartTimeU32, p, sizeof (STRTData.StartTimeU32));
p += sizeof (STRTData.StartTimeU32);
STRTData.StartTimeU32 = le32toh(STRTData.StartTimeU32);
memcpy(&STRTData.GPSWeekValueID, p, sizeof (STRTData.GPSWeekValueID));
p += sizeof (STRTData.GPSWeekValueID);
STRTData.GPSWeekValueID = le16toh(STRTData.GPSWeekValueID);
if (STRTData.GPSWeekValueID != VALUE_ID_STRT_GPS_WEEK) {
fprintf(stderr, "GPSWeek Value Id differs from expected\n");
return MESSAGE_VALUE_ID_ERROR;
}
memcpy(&STRTData.GPSWeekContentLength, p, sizeof (STRTData.GPSWeekContentLength));
p += sizeof (STRTData.GPSWeekContentLength);
STRTData.GPSWeekContentLength = le16toh(STRTData.GPSWeekContentLength);
if (STRTData.GPSWeekContentLength != sizeof(STRTData.GPSWeek)) {
fprintf(stderr, "GPSWeek Content Length %u differs from the expected length %lu\n",
STRTData.GPSWeekContentLength, sizeof(STRTData.GPSWeek));
return MESSAGE_CONTENT_OUT_OF_RANGE;
}
memcpy(&STRTData.GPSWeek, p, sizeof (STRTData.GPSWeek));
p += sizeof (STRTData.GPSWeek);
STRTData.GPSWeek = le16toh(STRTData.GPSWeek);
// Decode footer
if ((retval =
decodeISOFooter(p, bufferLength - (size_t) (p - strtDataBuffer), &STRTData.footer,
debug)) != MESSAGE_OK) {
fprintf(stderr, "Error decoding STRT footer\n");
return retval;
}
p += sizeof (STRTData.footer);
if ((retval = verifyChecksum(&STRTData, sizeof (STRTData) - sizeof (STRTData.footer),
STRTData.footer.Crc, debug)) == MESSAGE_CRC_ERROR) {
fprintf(stderr, "STRT checksum error\n");
return retval;
}
if (debug) {
printf("STRT:\n");
printf("SyncWord = %x\n", STRTData.header.syncWord);
printf("TransmitterId = %d\n", STRTData.header.transmitterID);
printf("PackageCounter = %d\n", STRTData.header.messageCounter);
printf("AckReq = %d\n", STRTData.header.ackReqProtVer);
printf("MessageId = %d\n", STRTData.header.messageID);
printf("MessageLength = %d\n", STRTData.header.messageLength);
printf("StartTime value ID: 0x%x\n", STRTData.StartTimeValueIdU16);
printf("StartTime content length: %u\n", STRTData.StartTimeContentLengthU16);
printf("StartTime value: %u\n", STRTData.StartTimeU32);
printf("GPSWeek value ID: 0x%x\n", STRTData.GPSWeekValueID);
printf("GPSWeek content length: %u\n", STRTData.GPSWeekContentLength);
printf("GPSWeek value: %u\n", STRTData.GPSWeek);
}
// Fill output struct with parsed data
convertSTRTToHostRepresentation(&STRTData,currentTime,startData);
return retval < 0 ? retval : p - strtDataBuffer;
}
/*!
* \brief convertSTRTToHostRepresentation Converts a STRT message to the internal representation for
* start data
* \param STRTData STRT message to be converted
* \param startData Struct in which result is to be placed
*/
enum ISOMessageReturnValue convertSTRTToHostRepresentation(
const STRTType * STRTData,
const struct timeval* currentTime,
StartMessageType * startData) {
uint16_t gpsWeek = 0;
startData->isTimestampValid = 1;
if (currentTime) {
gpsWeek = (uint16_t)getAsGPSWeek(currentTime);
}
if (!STRTData || !startData) {
errno = EINVAL;
fprintf(stderr, "STRT input pointer error");
return ISO_FUNCTION_ERROR;
}
if (STRTData->StartTimeU32 == GPS_SECOND_OF_WEEK_UNAVAILABLE_VALUE) {
startData->isTimestampValid = 0;
return MESSAGE_OK;
}
else if (STRTData->GPSWeek == GPS_WEEK_UNAVAILABLE_VALUE) {
if (!currentTime) {
startData->isTimestampValid = 0;
return MESSAGE_OK;
}
setToGPStime(&startData->startTime, gpsWeek, STRTData->StartTimeU32);
}
else {
if (currentTime && STRTData->GPSWeek != gpsWeek) {
startData->isTimestampValid = 0;
return MESSAGE_OK;
}
setToGPStime(&startData->startTime, STRTData->GPSWeek, STRTData->StartTimeU32);
}
return MESSAGE_OK;
}
/*!
* \brief encodeHEABMessage Constructs an ISO HEAB message based on current control center status and system time
* \param inputHeader data to create header with
* \param heabTime Timestamp to be placed in heab struct
* \param status Current control center status according to ::ControlCenterStatusType. Entering an unaccepable value
* makes this parameter default to ABORT
* \param heabDataBuffer Buffer to which HEAB message is to be written
* \param bufferLength Size of buffer to which HEAB message is to be written
* \param debug Flag for enabling debugging
* \return Number of bytes written or -1 in case of an error
*/
ssize_t encodeHEABMessage(const MessageHeaderType *inputHeader, const struct timeval *heabTime, const enum ControlCenterStatusType status,
char *heabDataBuffer, const size_t bufferLength, const char debug) {
HEABType HEABData;
memset(heabDataBuffer, 0, bufferLength);
// If buffer too small to hold HEAB data, generate an error
if (bufferLength < sizeof (HEABType)) {
fprintf(stderr, "Buffer too small to hold necessary HEAB data\n");
return -1;
}
// Construct header
HEABData.header = buildISOHeader(MESSAGE_ID_HEAB, inputHeader, sizeof (HEABData), debug);
// Fill contents
HEABData.HEABStructValueID = VALUE_ID_HEAB_STRUCT;
HEABData.HEABStructContentLength = sizeof (HEABType) - sizeof (HeaderType) - sizeof (FooterType)
- sizeof (HEABData.HEABStructValueID) - sizeof (HEABData.HEABStructContentLength);
int64_t GPSQmsOfWeek = getAsGPSQuarterMillisecondOfWeek(heabTime);
HEABData.GPSQmsOfWeek =
GPSQmsOfWeek >= 0 ? (uint32_t) GPSQmsOfWeek : GPS_SECOND_OF_WEEK_UNAVAILABLE_VALUE;
if (!
(status == CONTROL_CENTER_STATUS_INIT || status == CONTROL_CENTER_STATUS_READY
|| status == CONTROL_CENTER_STATUS_ABORT || status == CONTROL_CENTER_STATUS_RUNNING
|| status == CONTROL_CENTER_STATUS_TEST_DONE || status == CONTROL_CENTER_STATUS_NORMAL_STOP)) {
printf("HEAB does not support status ID %u - defaulting to ABORT\n", (uint8_t) status);
HEABData.controlCenterStatus = (uint8_t) CONTROL_CENTER_STATUS_ABORT;
}
else {
HEABData.controlCenterStatus = (uint8_t) status;
}
if (debug) {
printf("HEAB message:\n\tHEAB struct value ID: 0x%x\n\t"
"HEAB struct content length: %u\n\tGPS second of week: %u [¼ ms]\n\t"
"Control center status: 0x%x\n", HEABData.HEABStructValueID, HEABData.HEABStructContentLength,
HEABData.GPSQmsOfWeek, HEABData.controlCenterStatus);
}
// Switch from host endianness to little endian
HEABData.HEABStructValueID = htole16(HEABData.HEABStructValueID);
HEABData.HEABStructContentLength = htole16(HEABData.HEABStructContentLength);
HEABData.GPSQmsOfWeek = htole32(HEABData.GPSQmsOfWeek);
HEABData.footer = buildISOFooter(&HEABData, sizeof (HEABData), debug);
memcpy(heabDataBuffer, &HEABData, sizeof (HEABData));
return sizeof (HEABType);
}
/*!
* \brief decodeHEABMessage Fills HEAB data elements from a buffer of raw data
* \param heabDataBuffer Raw data to be decoded
* \param bufferLength Number of bytes in buffer of raw data to be decoded
* \param currentTime Current system time, used for determining the GPS week
* \param heabData Struct to be filled
* \param debug Flag for enabling of debugging
* \return value according to ::ISOMessageReturnValue
*/
ssize_t decodeHEABMessage(const char *heabDataBuffer,
const size_t bufferLength,
const struct timeval currentTime,
HeabMessageDataType* heabData,
const char debug) {
HEABType HEABData;
const char *p = heabDataBuffer;
enum ISOMessageReturnValue retval = MESSAGE_OK;
uint16_t valueID = 0;
uint16_t contentLength = 0;
ssize_t expectedContentLength = 0;
if (heabDataBuffer == NULL || heabData == NULL) {
errno = EINVAL;
fprintf(stderr, "Input pointers to HEAB parsing function cannot be null\n");
return ISO_FUNCTION_ERROR;
}
memset(&HEABData, 0, sizeof (HEABData));
memset(heabData, 0, sizeof (*heabData));
// Decode ISO header
if ((retval = decodeISOHeader(p, bufferLength, &HEABData.header, debug)) != MESSAGE_OK) {
return retval;
}
p += sizeof (HEABData.header);
// If message is not a HEAB message, generate an error
if (HEABData.header.messageID != MESSAGE_ID_HEAB) {
fprintf(stderr, "Attempted to pass non-HEAB message into HEAB parsing function\n");
return MESSAGE_TYPE_ERROR;
}
if (HEABData.header.messageLength > sizeof (HEABType) - sizeof (HeaderType) - sizeof (FooterType)) {
fprintf(stderr, "HEAB message exceeds expected message length\n");
return MESSAGE_LENGTH_ERROR;
}
memcpy(&valueID, p, sizeof (valueID));
p += sizeof (valueID);
memcpy(&contentLength, p, sizeof (contentLength));
p += sizeof (contentLength);
valueID = le16toh(valueID);
contentLength = le16toh(contentLength);
HEABData.HEABStructValueID = valueID;
HEABData.HEABStructContentLength = contentLength;
if (contentLength != (sizeof(HEABData.GPSQmsOfWeek) + sizeof(HEABData.controlCenterStatus))) {
fprintf(stderr, "Content length %u for value ID 0x%x does not match the expected %ld",
contentLength, valueID, sizeof(HEABData.GPSQmsOfWeek) + sizeof(HEABData.controlCenterStatus));
return MESSAGE_LENGTH_ERROR;
}
memcpy(&HEABData.GPSQmsOfWeek, p, sizeof (HEABData.GPSQmsOfWeek));
HEABData.GPSQmsOfWeek = le32toh(HEABData.GPSQmsOfWeek);
p += sizeof (HEABData.GPSQmsOfWeek);
memcpy(&HEABData.controlCenterStatus, p, sizeof (HEABData.controlCenterStatus));
p += sizeof (HEABData.controlCenterStatus);
// Decode footer
if ((retval =
decodeISOFooter(p, bufferLength - (size_t) (p - heabDataBuffer), &HEABData.footer,
debug)) != MESSAGE_OK) {
fprintf(stderr, "Error decoding HEAB footer\n");
return retval;
}
p += sizeof (HEABData.footer);
if (debug) {
printf("HEAB message:\n");
printf("\tStruct value ID: 0x%x\n", HEABData.HEABStructValueID);
printf("\tStruct content length: %u\n", HEABData.HEABStructContentLength);
printf("\tGPSQmsOfWeek: %u\n", HEABData.GPSQmsOfWeek);
printf("\tControlCenterStatus: %u\n", HEABData.controlCenterStatus);
}
retval = convertHEABToHostRepresentation(&HEABData, ¤tTime, HEABData.header.transmitterID, heabData);
return retval < 0 ? retval : p - heabDataBuffer;
}
/*!
* \brief convertHEABToHostRepresentation Converts a HEAB message to be used by host
* \param HEABData Data struct containing ISO formatted data
* \param currentTime Current system time, used for determining the GPS week
* \param transmitterId of the HEAB sender
* \param heabData Output data struct, to be used by host
* \return Value according to ::ISOMessageReturnValue
*/
enum ISOMessageReturnValue convertHEABToHostRepresentation(HEABType* HEABData,
const struct timeval *currentTime,
const uint8_t transmitterId,
HeabMessageDataType* heabData) {
if (HEABData == NULL || heabData == NULL) {
errno = EINVAL;
fprintf(stderr, "HEAB input pointer error");
return ISO_FUNCTION_ERROR;
}
heabData->transmitterID = transmitterId;
setToGPStime(&heabData->dataTimestamp, (uint16_t) getAsGPSWeek(currentTime), HEABData->GPSQmsOfWeek);
heabData->controlCenterStatus = HEABData->controlCenterStatus;