-
Notifications
You must be signed in to change notification settings - Fork 0
/
N2kMessages.cpp
1664 lines (1457 loc) · 66.2 KB
/
N2kMessages.cpp
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
/*
N2kMessages.cpp
Copyright (c) 2015-2020 Timo Lappalainen, Kave Oy, www.kave.fi
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "N2kMessages.h"
#include <string.h>
//*****************************************************************************
// System time
void SetN2kPGN126992(tN2kMsg &N2kMsg, unsigned char SID, uint16_t SystemDate,
double SystemTime, tN2kTimeSource TimeSource) {
N2kMsg.SetPGN(126992L);
N2kMsg.Priority=3;
N2kMsg.AddByte(SID);
N2kMsg.AddByte((TimeSource & 0x0f) | 0xf0);
N2kMsg.Add2ByteUInt(SystemDate);
N2kMsg.Add4ByteUDouble(SystemTime,0.0001);
}
//*****************************************************************************
bool ParseN2kPGN126992(const tN2kMsg &N2kMsg, unsigned char &SID, uint16_t &SystemDate,
double &SystemTime, tN2kTimeSource &TimeSource) {
if (N2kMsg.PGN!=126992L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
TimeSource=(tN2kTimeSource)(N2kMsg.GetByte(Index) & 0x0f);
SystemDate=N2kMsg.Get2ByteUInt(Index);
SystemTime=N2kMsg.Get4ByteDouble(0.0001,Index);
return true;
}
//*****************************************************************************
// Rudder
// Angles should be in radians
void SetN2kPGN127245(tN2kMsg &N2kMsg, double RudderPosition, unsigned char Instance,
tN2kRudderDirectionOrder RudderDirectionOrder, double AngleOrder) {
N2kMsg.SetPGN(127245L);
N2kMsg.Priority=2;
N2kMsg.AddByte(Instance);
N2kMsg.AddByte(0xf8 | (RudderDirectionOrder&0x07));
N2kMsg.Add2ByteDouble(AngleOrder,0.0001);
N2kMsg.Add2ByteDouble(RudderPosition,0.0001);
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN127245(const tN2kMsg &N2kMsg, double &RudderPosition, unsigned char &Instance,
tN2kRudderDirectionOrder &RudderDirectionOrder, double &AngleOrder) {
if (N2kMsg.PGN!=127245L) return false;
int Index=0;
Instance=N2kMsg.GetByte(Index);
RudderDirectionOrder=(tN2kRudderDirectionOrder)(N2kMsg.GetByte(Index)&0x7);
AngleOrder=N2kMsg.Get2ByteDouble(0.0001,Index);
RudderPosition=N2kMsg.Get2ByteDouble(0.0001,Index);
return true;
}
//*****************************************************************************
// Vessel Heading
// Angles should be in radians
void SetN2kPGN127250(tN2kMsg &N2kMsg, unsigned char SID, double Heading, double Deviation, double Variation, tN2kHeadingReference ref) {
N2kMsg.SetPGN(127250L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.Add2ByteUDouble(Heading,0.0001);
N2kMsg.Add2ByteDouble(Deviation,0.0001);
N2kMsg.Add2ByteDouble(Variation,0.0001);
N2kMsg.AddByte(0xfc | ref);
}
bool ParseN2kPGN127250(const tN2kMsg &N2kMsg, unsigned char &SID, double &Heading, double &Deviation, double &Variation, tN2kHeadingReference &ref) {
if (N2kMsg.PGN!=127250L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
Heading=N2kMsg.Get2ByteUDouble(0.0001,Index);
Deviation=N2kMsg.Get2ByteDouble(0.0001,Index);
Variation=N2kMsg.Get2ByteDouble(0.0001,Index);
ref=(tN2kHeadingReference)(N2kMsg.GetByte(Index)&0x03);
return true;
}
//*****************************************************************************
// Rate of turn
// Angles should be in radians
void SetN2kPGN127251(tN2kMsg &N2kMsg, unsigned char SID, double RateOfTurn) {
N2kMsg.SetPGN(127251L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.Add4ByteUDouble(RateOfTurn,3.125E-08); //1e-6/32.0
N2kMsg.AddByte(0xff);
N2kMsg.Add2ByteUInt(0xffff);
}
bool ParseN2kPGN127251(const tN2kMsg &N2kMsg, unsigned char &SID, double &RateOfTurn) {
if (N2kMsg.PGN!=127251L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
RateOfTurn=N2kMsg.Get4ByteDouble(3.125E-08,Index); //1e-6/32.0
return true;
}
//*****************************************************************************
// Attitude
// Input:
// - SID Sequence ID. If your device is e.g. boat speed and heading at same time, you can set same SID for different messages
// to indicate that they are measured at same time.
// - Yaw Heading in radians.
// - Pitch Pitch in radians. Positive, when your bow rises.
// - Roll Roll in radians. Positive, when tilted right.
// Output:
// - N2kMsg NMEA2000 message ready to be send.
void SetN2kPGN127257(tN2kMsg &N2kMsg, unsigned char SID, double Yaw, double Pitch, double Roll) {
N2kMsg.SetPGN(127257L);
N2kMsg.Priority=3;
N2kMsg.AddByte(SID);
N2kMsg.Add2ByteDouble(Yaw,0.0001);
N2kMsg.Add2ByteDouble(Pitch,0.0001);
N2kMsg.Add2ByteDouble(Roll,0.0001);
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN127257(const tN2kMsg &N2kMsg, unsigned char &SID, double &Yaw, double &Pitch, double &Roll){
if (N2kMsg.PGN!=127257L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
Yaw=N2kMsg.Get2ByteDouble(0.0001,Index);
Pitch=N2kMsg.Get2ByteDouble(0.0001,Index);
Roll=N2kMsg.Get2ByteDouble(0.0001,Index);
return true;
}
//*****************************************************************************
// Magnetic variation
void SetN2kPGN127258(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation) {
N2kMsg.SetPGN(127258L);
N2kMsg.Priority=6;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(Source & 0x0f);
N2kMsg.Add2ByteUInt(DaysSince1970);
N2kMsg.Add2ByteDouble(Variation, 0.0001);
N2kMsg.Add2ByteUInt(0xffff);
}
bool ParseN2kPGN127258(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation) {
if (N2kMsg.PGN!=127258L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
Source=(tN2kMagneticVariation) (N2kMsg.GetByte(Index) & 0x0f);
DaysSince1970=N2kMsg.Get2ByteUInt(Index);
Variation=N2kMsg.Get2ByteDouble(0.0001, Index);
return true;
}
//*****************************************************************************
// Engine rapid param
void SetN2kPGN127488(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineSpeed,
double EngineBoostPressure, int8_t EngineTiltTrim) {
N2kMsg.SetPGN(127488L);
N2kMsg.Priority=2;
N2kMsg.AddByte(EngineInstance);
N2kMsg.Add2ByteUDouble(EngineSpeed,0.25);
N2kMsg.Add2ByteUDouble(EngineBoostPressure, 100);
N2kMsg.AddByte(EngineTiltTrim);
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN127488(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &EngineSpeed,
double &EngineBoostPressure, int8_t &EngineTiltTrim) {
if (N2kMsg.PGN!=127488L) return false;
int Index=0;
EngineInstance=N2kMsg.GetByte(Index);
EngineSpeed=N2kMsg.Get2ByteUDouble(0.25,Index);
EngineBoostPressure=N2kMsg.Get2ByteUDouble(100,Index);
EngineTiltTrim=N2kMsg.GetByte(Index);
return true;
}
//*****************************************************************************
// Engine parameters dynamic
void SetN2kPGN127489(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineOilPress, double EngineOilTemp, double EngineCoolantTemp, double AltenatorVoltage,
double FuelRate, double EngineHours, double EngineCoolantPress, double EngineFuelPress, int8_t EngineLoad, int8_t EngineTorque,
bool flagCheckEngine,
bool flagOverTemp, bool flagLowOilPress, bool flagLowOilLevel, bool flagLowFuelPress, bool flagLowSystemVoltage, bool flagLowCoolantLevel,
bool flagWaterFlow, bool flagWaterInFuel, bool flagChargeIndicator, bool flagPreheatIndicator, bool flagHighBoostPress, bool flagRevLimitExceeded,
bool flagEgrSystem, bool flagTPS, bool flagEmergencyStopMode, bool flagWarning1, bool flagWarning2, bool flagPowerReduction,
bool flagMaintenanceNeeded, bool flagEngineCommError, bool flagSubThrottle, bool flagNeutralStartProtect, bool flagEngineShuttingDown) {
N2kMsg.SetPGN(127489L);
N2kMsg.Priority=2;
N2kMsg.AddByte(EngineInstance);
N2kMsg.Add2ByteUDouble(EngineOilPress, 100);
N2kMsg.Add2ByteUDouble(EngineOilTemp, 0.1);
N2kMsg.Add2ByteUDouble(EngineCoolantTemp, 0.01);
N2kMsg.Add2ByteDouble(AltenatorVoltage, 0.01);
N2kMsg.Add2ByteDouble(FuelRate, 0.1);
N2kMsg.Add4ByteUDouble(EngineHours, 1);
N2kMsg.Add2ByteUDouble(EngineCoolantPress, 100);
N2kMsg.Add2ByteUDouble(EngineFuelPress, 1000);
N2kMsg.AddByte(0xff); // reserved
int engineStatus1P1 = 0;
int engineStatus1P2 = 0;
int engineStatus2 = 0;
if (flagCheckEngine) engineStatus1P1 |= BIT(0);
if (flagOverTemp) engineStatus1P1 |= BIT(1);
if (flagLowOilPress) engineStatus1P1 |= BIT(2);
if (flagLowOilLevel) engineStatus1P1 |= BIT(3);
if (flagLowFuelPress) engineStatus1P1 |= BIT(4);
if (flagLowSystemVoltage) engineStatus1P1 |= BIT(5);
if (flagLowCoolantLevel) engineStatus1P1 |= BIT(6);
if (flagWaterFlow) engineStatus1P1 |= BIT(7);
if (flagWaterInFuel) engineStatus1P2 |= BIT(0);
if (flagChargeIndicator) engineStatus1P2 |= BIT(1);
if (flagPreheatIndicator) engineStatus1P2 |= BIT(2);
if (flagHighBoostPress) engineStatus1P2 |= BIT(3);
if (flagRevLimitExceeded) engineStatus1P2 |= BIT(4);
if (flagEgrSystem) engineStatus1P2 |= BIT(5);
if (flagTPS) engineStatus1P2 |= BIT(6);
if (flagEmergencyStopMode) engineStatus1P2 |= BIT(7);
if (flagWarning1) engineStatus2 |= BIT(0);
if (flagWarning2) engineStatus2 |= BIT(1);
if (flagPowerReduction) engineStatus2 |= BIT(2);
if (flagMaintenanceNeeded) engineStatus2 |= BIT(3);
if (flagEngineCommError) engineStatus2 |= BIT(4);
if (flagSubThrottle) engineStatus2 |= BIT(5);
if (flagNeutralStartProtect) engineStatus2 |= BIT(6);
if (flagEngineShuttingDown) engineStatus2 |= BIT(7);
N2kMsg.Add2ByteInt(engineStatus1P2<<8 | engineStatus1P1); // Discrete Status 1
N2kMsg.Add2ByteInt(engineStatus2); // Discrete Status 1
N2kMsg.AddByte(EngineLoad);
N2kMsg.AddByte(EngineTorque);
}
bool ParseN2kPGN127489(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &EngineOilPress,
double &EngineOilTemp, double &EngineCoolantTemp, double &AltenatorVoltage,
double &FuelRate, double &EngineHours, double &EngineCoolantPress, double &EngineFuelPress,
int8_t &EngineLoad, int8_t &EngineTorque) {
if (N2kMsg.PGN != 127489L) return false;
int Index = 0;
EngineInstance = N2kMsg.GetByte(Index);
EngineOilPress = N2kMsg.Get2ByteUDouble(100, Index);
EngineOilTemp = N2kMsg.Get2ByteUDouble(0.1, Index);
EngineCoolantTemp = N2kMsg.Get2ByteUDouble(0.01, Index);
AltenatorVoltage = N2kMsg.Get2ByteDouble(0.01, Index);
FuelRate = N2kMsg.Get2ByteDouble(0.1, Index);
EngineHours = N2kMsg.Get4ByteUDouble(1, Index);
EngineCoolantPress=N2kMsg.Get2ByteUDouble(100, Index);
EngineFuelPress=N2kMsg.Get2ByteUDouble(1000, Index);
N2kMsg.GetByte(Index); // reserved
N2kMsg.Get2ByteInt(Index); // Discrete Status 1
N2kMsg.Get2ByteInt(Index); // Discrete Status 2
EngineLoad=N2kMsg.GetByte(Index);
EngineTorque=N2kMsg.GetByte(Index);
return true;
}
//*****************************************************************************
// Transmission parameters, dynamic
void SetN2kPGN127493(tN2kMsg &N2kMsg, unsigned char EngineInstance, tN2kTransmissionGear TransmissionGear,
double OilPressure, double OilTemperature, unsigned char DiscreteStatus1) {
N2kMsg.SetPGN(127493L);
N2kMsg.Priority=2;
N2kMsg.AddByte(EngineInstance);
N2kMsg.AddByte((TransmissionGear & 0x03) | 0xfc );
N2kMsg.Add2ByteUDouble(OilPressure, 100);
N2kMsg.Add2ByteUDouble(OilTemperature, 0.1);
N2kMsg.AddByte(DiscreteStatus1);
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN127493(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, tN2kTransmissionGear &TransmissionGear,
double &OilPressure, double &OilTemperature, unsigned char &DiscreteStatus1) {
if (N2kMsg.PGN!=127493L) return false;
int Index=0;
EngineInstance=N2kMsg.GetByte(Index);
TransmissionGear=(tN2kTransmissionGear)(N2kMsg.GetByte(Index) & 0x03);
OilPressure=N2kMsg.Get2ByteUDouble(100,Index);
OilTemperature=N2kMsg.Get2ByteUDouble(0.1,Index);
DiscreteStatus1=N2kMsg.GetByte(Index);
return true;
}
//*****************************************************************************
// Trip Parameters, Engine
void SetN2kPGN127497(tN2kMsg &N2kMsg, unsigned char EngineInstance, double TripFuelUsed,
double FuelRateAverage,
double FuelRateEconomy, double InstantaneousFuelEconomy) {
N2kMsg.SetPGN(127497L);
N2kMsg.Priority=2;
N2kMsg.AddByte(EngineInstance);
N2kMsg.Add2ByteUDouble(TripFuelUsed,1);
N2kMsg.Add2ByteDouble(FuelRateAverage, 0.1);
N2kMsg.Add2ByteDouble(FuelRateEconomy, 0.1);
N2kMsg.Add2ByteDouble(InstantaneousFuelEconomy, 0.1);
}
bool ParseN2kPGN127497(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &TripFuelUsed,
double &FuelRateAverage,
double &FuelRateEconomy, double &InstantaneousFuelEconomy) {
if (N2kMsg.PGN!=127497L) return false;
int Index=0;
EngineInstance=N2kMsg.GetByte(Index);
TripFuelUsed=N2kMsg.Get2ByteUDouble(1,Index);
FuelRateAverage=N2kMsg.Get2ByteDouble(0.1,Index);
FuelRateEconomy=N2kMsg.Get2ByteDouble(0.1,Index);
InstantaneousFuelEconomy=N2kMsg.Get2ByteDouble(0.1,Index);
return true;
}
//*****************************************************************************
// Binary status
//*****************************************************************************
tN2kOnOff N2kGetStatusOnBinaryStatus(tN2kBinaryStatus BankStatus, uint8_t ItemIndex) {
ItemIndex--;
if (ItemIndex>27) return N2kOnOff_Unavailable;
return (tN2kOnOff)((BankStatus >> (2*ItemIndex)) & 0x03);
}
//*****************************************************************************
void N2kSetStatusBinaryOnStatus(tN2kBinaryStatus &BankStatus, tN2kOnOff ItemStatus, uint8_t ItemIndex) {
ItemIndex--;
if (ItemIndex>27) return;
tN2kBinaryStatus Mask = ~(3 << (2*ItemIndex));
BankStatus = (BankStatus & Mask) | (ItemStatus << (2*ItemIndex));
}
//*****************************************************************************
void SetN2kPGN127501(tN2kMsg &N2kMsg, unsigned char DeviceBankInstance, tN2kBinaryStatus BankStatus) {
N2kMsg.SetPGN(127501L);
N2kMsg.Priority=3;
BankStatus = (BankStatus << 8) | DeviceBankInstance;
N2kMsg.AddUInt64(BankStatus);
}
//*****************************************************************************
// Binary status report
void SetN2kPGN127501(tN2kMsg &N2kMsg, unsigned char DeviceBankInstance
,tN2kOnOff Status1
,tN2kOnOff Status2
,tN2kOnOff Status3
,tN2kOnOff Status4
) {
tN2kBinaryStatus BankStatus;
N2kResetBinaryStatus(BankStatus);
BankStatus = (BankStatus << 2) | Status4;
BankStatus = (BankStatus << 2) | Status3;
BankStatus = (BankStatus << 2) | Status2;
BankStatus = (BankStatus << 2) | Status1;
SetN2kPGN127501(N2kMsg,DeviceBankInstance,BankStatus);
}
//*****************************************************************************
bool ParseN2kPGN127501(const tN2kMsg &N2kMsg, unsigned char &DeviceBankInstance
,tN2kOnOff &Status1
,tN2kOnOff &Status2
,tN2kOnOff &Status3
,tN2kOnOff &Status4
) {
if (N2kMsg.PGN!=127501L) return false;
int Index=0;
DeviceBankInstance=N2kMsg.GetByte(Index);
unsigned char b=N2kMsg.GetByte(Index);
Status1=(tN2kOnOff)(b & 0x03);
b>>=2; Status2=(tN2kOnOff)(b & 0x03);
b>>=2; Status3=(tN2kOnOff)(b & 0x03);
b>>=2; Status4=(tN2kOnOff)(b & 0x03);
return true;
}
//*****************************************************************************
bool ParseN2kPGN127501(const tN2kMsg &N2kMsg, unsigned char &DeviceBankInstance, tN2kBinaryStatus &BankStatus) {
if (N2kMsg.PGN!=127501L) return false;
int Index=0;
BankStatus=N2kMsg.GetUInt64(Index);
DeviceBankInstance = BankStatus & 0xff;
BankStatus>>=8;
return true;
}
//*****************************************************************************
// Fluid level
void SetN2kPGN127505(tN2kMsg &N2kMsg, unsigned char Instance, tN2kFluidType FluidType, double Level, double Capacity) {
N2kMsg.SetPGN(127505L);
N2kMsg.Priority=6;
N2kMsg.AddByte((Instance&0x0f) | ((FluidType&0x0f)<<4));
N2kMsg.Add2ByteDouble(Level,0.004);
N2kMsg.Add4ByteUDouble(Capacity,0.1);
N2kMsg.AddByte(0xff); // Reserved
}
//*****************************************************************************
bool ParseN2kPGN127505(const tN2kMsg &N2kMsg, unsigned char &Instance, tN2kFluidType &FluidType, double &Level, double &Capacity) {
if (N2kMsg.PGN!=127505L) return false;
int Index=0;
unsigned char IFt=N2kMsg.GetByte(Index);
Instance=IFt&0x0f;
FluidType=(tN2kFluidType)((IFt>>4)&0x0f);
Level=N2kMsg.Get2ByteDouble(0.004,Index);
Capacity=N2kMsg.Get4ByteUDouble(0.1,Index);
return true;
}
//*****************************************************************************
// DC Detailed Status
//
void SetN2kPGN127506(tN2kMsg &N2kMsg, unsigned char SID, unsigned char DCInstance, tN2kDCType DCType,
uint8_t StateOfCharge, uint8_t StateOfHealth, double TimeRemaining, double RippleVoltage, double Capacity) {
N2kMsg.SetPGN(127506L);
N2kMsg.Priority=6;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(DCInstance);
N2kMsg.AddByte((unsigned char)DCType);
N2kMsg.AddByte(StateOfCharge);
N2kMsg.AddByte(StateOfHealth);
N2kMsg.Add2ByteUDouble(TimeRemaining,60);
N2kMsg.Add2ByteUDouble(RippleVoltage,0.001);
N2kMsg.Add2ByteUDouble(Capacity,3600);
}
//*****************************************************************************
bool ParseN2kPGN127506(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &DCInstance, tN2kDCType &DCType,
uint8_t &StateOfCharge, uint8_t &StateOfHealth, double &TimeRemaining, double &RippleVoltage, double &Capacity){
if (N2kMsg.PGN!=127506L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
DCInstance=N2kMsg.GetByte(Index);
DCType=(tN2kDCType)(N2kMsg.GetByte(Index));
StateOfCharge=N2kMsg.GetByte(Index);
StateOfHealth=N2kMsg.GetByte(Index);
TimeRemaining=N2kMsg.Get2ByteUDouble(60,Index);
RippleVoltage=N2kMsg.Get2ByteUDouble(0.001,Index);
Capacity=N2kMsg.Get2ByteUDouble(3600,Index);
return true;
}
//*****************************************************************************
// Charger Status
// Input:
// - Instance ChargerInstance.
// - BatteryInstance BatteryInstance.
// - Operating State see. tN2kChargeState
// - Charger Mode see. tN2kChargerMode
// - Charger Enable/Disable boolean
// - Equalization Pending boolean
// - Equalization Time Remaining double seconds
//
void SetN2kPGN127507(tN2kMsg &N2kMsg, unsigned char Instance, unsigned char BatteryInstance,
tN2kChargeState ChargeState, tN2kChargerMode ChargerMode,
tN2kOnOff Enabled, tN2kOnOff EqualizationPending, double EqualizationTimeRemaining) {
N2kMsg.SetPGN(127507UL);
N2kMsg.Priority=6;
N2kMsg.AddByte(Instance);
N2kMsg.AddByte(BatteryInstance);
N2kMsg.AddByte((ChargerMode & 0x0f)<<4 | (ChargeState & 0x0f));
N2kMsg.AddByte(0x0f<<4 | (EqualizationPending & 0x03) << 2 | (Enabled & 0x03));
N2kMsg.Add2ByteUDouble(EqualizationTimeRemaining,1);
}
bool ParseN2kPGN127507(tN2kMsg &N2kMsg, unsigned char &Instance, unsigned char &BatteryInstance,
tN2kChargeState &ChargeState, tN2kChargerMode &ChargerMode,
tN2kOnOff &Enabled, tN2kOnOff &EqualizationPending, double &EqualizationTimeRemaining) {
if (N2kMsg.PGN!=127507UL) return false;
int Index=0;
Instance=N2kMsg.GetByte(Index);
BatteryInstance=N2kMsg.GetByte(Index);
unsigned char v;
v=N2kMsg.GetByte(Index);
ChargeState=(tN2kChargeState)(v&0x0f);
ChargerMode=(tN2kChargerMode)((v>>4)&0x0f);
v=N2kMsg.GetByte(Index);
Enabled=(tN2kOnOff)(v&0x03);
EqualizationPending=(tN2kOnOff)((v>>2)&0x03);
EqualizationTimeRemaining=N2kMsg.Get2ByteUDouble(60,Index);
return true;
}
//*****************************************************************************
// Battery Status
// Temperatures should be in Kelvins
void SetN2kPGN127508(tN2kMsg &N2kMsg, unsigned char BatteryInstance, double BatteryVoltage, double BatteryCurrent,
double BatteryTemperature, unsigned char SID) {
N2kMsg.SetPGN(127508L);
N2kMsg.Priority=6;
N2kMsg.AddByte(BatteryInstance);
N2kMsg.Add2ByteDouble(BatteryVoltage,0.01);
N2kMsg.Add2ByteDouble(BatteryCurrent,0.1);
N2kMsg.Add2ByteUDouble(BatteryTemperature,0.01);
N2kMsg.AddByte(SID);
}
//*****************************************************************************
bool ParseN2kPGN127508(const tN2kMsg &N2kMsg, unsigned char &BatteryInstance, double &BatteryVoltage, double &BatteryCurrent,
double &BatteryTemperature, unsigned char &SID) {
if (N2kMsg.PGN!=127508L) return false;
int Index=0;
BatteryInstance=N2kMsg.GetByte(Index);
BatteryVoltage=N2kMsg.Get2ByteDouble(0.01,Index);
BatteryCurrent=N2kMsg.Get2ByteDouble(0.1,Index);
BatteryTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
SID=N2kMsg.GetByte(Index);
return true;
}
//*****************************************************************************
// Battery Configuration Status
void SetN2kPGN127513(tN2kMsg &N2kMsg, unsigned char BatInstance, tN2kBatType BatType, tN2kBatEqSupport SupportsEqual,
tN2kBatNomVolt BatNominalVoltage, tN2kBatChem BatChemistry, double BatCapacity, int8_t BatTemperatureCoefficient,
double PeukertExponent, int8_t ChargeEfficiencyFactor) {
N2kMsg.SetPGN(127513L);
N2kMsg.Priority=6;
N2kMsg.AddByte(BatInstance);
N2kMsg.AddByte(0xc0 | ((SupportsEqual & 0x03) << 4) | (BatType & 0x0f)); // BatType (4 bit), SupportsEqual (2 bit), Reserved (2 bit)
N2kMsg.AddByte( ((BatChemistry & 0x0f) << 4) | (BatNominalVoltage & 0x0f) ); // BatNominalVoltage (4 bit), BatChemistry (4 bit)
N2kMsg.Add2ByteUDouble(BatCapacity,3600);
N2kMsg.AddByte((int8_t)BatTemperatureCoefficient);
PeukertExponent-=1; // Is this right or not I am not yet sure!
if (PeukertExponent<0 || PeukertExponent>0.504) { N2kMsg.AddByte(0xff); } else { N2kMsg.Add1ByteUDouble(PeukertExponent,0.002,-1); }
N2kMsg.AddByte((int8_t)ChargeEfficiencyFactor);
}
//*****************************************************************************
bool ParseN2kPGN127513(const tN2kMsg &N2kMsg, unsigned char &BatInstance, tN2kBatType &BatType, tN2kBatEqSupport &SupportsEqual,
tN2kBatNomVolt &BatNominalVoltage, tN2kBatChem &BatChemistry, double &BatCapacity, int8_t &BatTemperatureCoefficient,
double &PeukertExponent, int8_t &ChargeEfficiencyFactor) {
if (N2kMsg.PGN!=127513L) return false;
int Index=0;
unsigned char v;
BatInstance = N2kMsg.GetByte(Index);
v = N2kMsg.GetByte(Index); BatType=(tN2kBatType)(v & 0x0f); SupportsEqual=(tN2kBatEqSupport)((v>>4) & 0x03);
v = N2kMsg.GetByte(Index); BatNominalVoltage=(tN2kBatNomVolt)(v & 0x0f); BatChemistry=(tN2kBatChem)((v>>4) & 0x0f);
BatCapacity=N2kMsg.Get2ByteDouble(3600,Index);
BatTemperatureCoefficient=N2kMsg.GetByte(Index);
PeukertExponent=N2kMsg.Get1ByteUDouble(0.002,Index); PeukertExponent+=1;
ChargeEfficiencyFactor=N2kMsg.GetByte(Index);
return true;
}
//*****************************************************************************
// Leeway
void SetN2kPGN128000(tN2kMsg &N2kMsg, unsigned char SID, double Leeway) {
N2kMsg.SetPGN(128000L);
N2kMsg.Priority=4;
N2kMsg.AddByte(SID);
N2kMsg.Add2ByteDouble(Leeway,0.0001);
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN128000(const tN2kMsg &N2kMsg, unsigned char &SID, double &Leeway) {
if (N2kMsg.PGN!=128000L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
Leeway=N2kMsg.Get2ByteDouble(0.0001,Index);
return true;
}
//*****************************************************************************
// Boat speed
void SetN2kPGN128259(tN2kMsg &N2kMsg, unsigned char SID, double WaterReferenced, double GroundReferenced, tN2kSpeedWaterReferenceType SWRT) {
N2kMsg.SetPGN(128259L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.Add2ByteUDouble(WaterReferenced,0.01);
N2kMsg.Add2ByteUDouble(GroundReferenced,0.01);
N2kMsg.AddByte(SWRT);
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN128259(const tN2kMsg &N2kMsg, unsigned char &SID, double &WaterReferenced, double &GroundReferenced, tN2kSpeedWaterReferenceType &SWRT) {
if (N2kMsg.PGN!=128259L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
WaterReferenced=N2kMsg.Get2ByteUDouble(0.01,Index);
GroundReferenced=N2kMsg.Get2ByteUDouble(0.01,Index);
SWRT=(tN2kSpeedWaterReferenceType)(N2kMsg.GetByte(Index)&0x0F);
return true;
}
//*****************************************************************************
// Water depth
void SetN2kPGN128267(tN2kMsg &N2kMsg, unsigned char SID, double DepthBelowTransducer, double Offset, double Range) {
N2kMsg.SetPGN(128267L);
N2kMsg.Priority=3;
N2kMsg.AddByte(SID);
N2kMsg.Add4ByteUDouble(DepthBelowTransducer,0.01);
N2kMsg.Add2ByteDouble(Offset,0.001);
N2kMsg.Add1ByteUDouble(Range,10);
}
bool ParseN2kPGN128267(const tN2kMsg &N2kMsg, unsigned char &SID, double &DepthBelowTransducer, double &Offset, double &Range) {
if (N2kMsg.PGN!=128267L) return false;
int Index=0;
SID=N2kMsg.GetByte(Index);
DepthBelowTransducer=N2kMsg.Get4ByteUDouble(0.01,Index);
Offset=N2kMsg.Get2ByteDouble(0.001,Index);
Range=N2kMsg.Get1ByteUDouble(10,Index);
return true;
}
//*****************************************************************************
// Distance log
void SetN2kPGN128275(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, uint32_t Log, uint32_t TripLog) {
N2kMsg.SetPGN(128275L);
N2kMsg.Priority=6;
N2kMsg.Add2ByteUInt(DaysSince1970);
N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
N2kMsg.Add4ByteUInt(Log);
N2kMsg.Add4ByteUInt(TripLog);
}
bool ParseN2kPGN128275(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, uint32_t &Log, uint32_t &TripLog) {
if (N2kMsg.PGN!=128275L) return false;
int Index=0;
DaysSince1970=N2kMsg.Get2ByteUInt(Index);
SecondsSinceMidnight=N2kMsg.Get4ByteDouble(0.0001,Index);
Log=N2kMsg.Get4ByteUDouble(1,Index);
TripLog=N2kMsg.Get4ByteUDouble(1,Index);
return true;
}
//*****************************************************************************
// PGN128776 - Windlass Control Status
//
void SetN2kPGN128776(
tN2kMsg &N2kMsg,
unsigned char SID,
unsigned char WindlassIdentifier,
tN2kWindlassDirectionControl WindlassDirectionControl,
unsigned char SpeedControl,
tN2kSpeedType SpeedControlType,
tN2kGenericStatusPair AnchorDockingControl,
tN2kGenericStatusPair PowerEnable,
tN2kGenericStatusPair MechanicalLock,
tN2kGenericStatusPair DeckAndAnchorWash,
tN2kGenericStatusPair AnchorLight,
double CommandTimeout,
const tN2kWindlassControlEvents &WindlassControlEvents
){
N2kMsg.SetPGN(128776L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(WindlassIdentifier);
N2kMsg.AddByte((unsigned char) ((0x03 << 6) | ((SpeedControlType & 0x03) << 4) | ((AnchorDockingControl & 0x03) << 2) | (WindlassDirectionControl & 0x03)));
N2kMsg.AddByte(SpeedControl);
N2kMsg.AddByte((unsigned char) (((AnchorLight & 0x03) << 6) | ((DeckAndAnchorWash & 0x03) << 4) | ((MechanicalLock & 0x03) << 2) | (PowerEnable & 0x03)));
N2kMsg.Add1ByteUDouble(CommandTimeout, 0.005);
N2kMsg.AddByte(WindlassControlEvents.Events);
}
bool ParseN2kPGN128776(
const tN2kMsg &N2kMsg,
unsigned char &SID,
unsigned char &WindlassIdentifier,
tN2kWindlassDirectionControl &WindlassDirectionControl,
unsigned char &SpeedControl,
tN2kSpeedType &SpeedControlType,
tN2kGenericStatusPair &AnchorDockingControl,
tN2kGenericStatusPair &PowerEnable,
tN2kGenericStatusPair &MechanicalLock,
tN2kGenericStatusPair &DeckAndAnchorWash,
tN2kGenericStatusPair &AnchorLight,
double &CommandTimeout,
tN2kWindlassControlEvents &WindlassControlEvents
) {
if (N2kMsg.PGN!=128776L) return false;
int Index = 0;
unsigned char field;
SID = N2kMsg.GetByte(Index);
WindlassIdentifier = N2kMsg.GetByte(Index);
field = N2kMsg.GetByte(Index);
WindlassDirectionControl = (tN2kWindlassDirectionControl) (field & 0x03);
AnchorDockingControl = (tN2kGenericStatusPair) ((field >> 2) & 0x03);
SpeedControlType = (tN2kSpeedType) ((field >> 4) & 0x03);
SpeedControl = N2kMsg.GetByte(Index);
field = N2kMsg.GetByte(Index);
PowerEnable = (tN2kGenericStatusPair) (field & 0x03);
MechanicalLock = (tN2kGenericStatusPair) ((field >> 2) & 0x03);
DeckAndAnchorWash = (tN2kGenericStatusPair) ((field >> 4) & 0x03);
AnchorLight = (tN2kGenericStatusPair) ((field >> 6) & 0x03);
CommandTimeout = N2kMsg.Get1ByteUDouble(0.005, Index);
WindlassControlEvents.SetEvents(N2kMsg.GetByte(Index));
return true;
}
//*****************************************************************************
// PGN128777 Windlass Operating Status
//
void SetN2kPGN128777(
tN2kMsg &N2kMsg,
unsigned char SID,
unsigned char WindlassIdentifier,
double RodeCounterValue,
double WindlassLineSpeed,
tN2kWindlassMotionStates WindlassMotionStatus,
tN2kRodeTypeStates RodeTypeStatus,
tN2kAnchorDockingStates AnchorDockingStatus,
const tN2kWindlassOperatingEvents &WindlassOperatingEvents
){
N2kMsg.SetPGN(128777L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(WindlassIdentifier);
N2kMsg.AddByte((unsigned char) (0xF0 | ((RodeTypeStatus & 0x03) << 2) | (WindlassMotionStatus & 0x03)));
N2kMsg.Add2ByteUDouble(RodeCounterValue, 0.1);
N2kMsg.Add2ByteUDouble(WindlassLineSpeed, 0.01);
N2kMsg.AddByte((WindlassOperatingEvents.Events << 2) | (AnchorDockingStatus & 0x03));
}
bool ParseN2kPGN128777(
const tN2kMsg &N2kMsg,
unsigned char &SID,
unsigned char &WindlassIdentifier,
double &RodeCounterValue,
double &WindlassLineSpeed,
tN2kWindlassMotionStates &WindlassMotionStatus,
tN2kRodeTypeStates &RodeTypeStatus,
tN2kAnchorDockingStates &AnchorDockingStatus,
tN2kWindlassOperatingEvents &WindlassOperatingEvents
){
if (N2kMsg.PGN!=128777L) return false;
int Index = 0;
unsigned char field;
SID = N2kMsg.GetByte(Index);
WindlassIdentifier = N2kMsg.GetByte(Index);
field = N2kMsg.GetByte(Index);
WindlassMotionStatus = (tN2kWindlassMotionStates) (field & 0x03);
RodeTypeStatus = (tN2kRodeTypeStates) ((field >> 2) & 0x03);
RodeCounterValue = N2kMsg.Get2ByteUDouble(0.1, Index);
WindlassLineSpeed = N2kMsg.Get2ByteUDouble(0.01, Index);
field = N2kMsg.GetByte(Index);
AnchorDockingStatus = (tN2kAnchorDockingStates) (field & 0x03);
WindlassOperatingEvents.SetEvents(field >> 2);
return true;
}
//*****************************************************************************
// PGN128778 - Windlass Monitoring Status
//
void SetN2kPGN128778(
tN2kMsg &N2kMsg,
unsigned char SID,
unsigned char WindlassIdentifier,
double TotalMotorTime,
double ControllerVoltage,
double MotorCurrent,
const tN2kWindlassMonitoringEvents &WindlassMonitoringEvents
){
N2kMsg.SetPGN(128778L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(WindlassIdentifier);
N2kMsg.AddByte(WindlassMonitoringEvents.Events);
N2kMsg.Add1ByteUDouble(ControllerVoltage, 0.2);
N2kMsg.Add1ByteUDouble(MotorCurrent, 1.0);
N2kMsg.Add2ByteUDouble(TotalMotorTime, 60.0);
N2kMsg.AddByte(0xFF);
}
bool ParseN2kPGN128778(
const tN2kMsg &N2kMsg,
unsigned char &SID,
unsigned char &WindlassIdentifier,
double &TotalMotorTime,
double &ControllerVoltage,
double &MotorCurrent,
tN2kWindlassMonitoringEvents &WindlassMonitoringEvents
) {
if (N2kMsg.PGN!=128778L) return false;
int Index = 0;
SID = N2kMsg.GetByte(Index);
WindlassIdentifier = N2kMsg.GetByte(Index);
WindlassMonitoringEvents.SetEvents(N2kMsg.GetByte(Index));
ControllerVoltage = N2kMsg.Get1ByteUDouble(0.2, Index);
MotorCurrent = N2kMsg.Get1ByteUDouble(1.0, Index);
TotalMotorTime = N2kMsg.Get2ByteUDouble(60.0, Index);
return true;
}
//*****************************************************************************
// Lat long rapid
void SetN2kPGN129025(tN2kMsg &N2kMsg, double Latitude, double Longitude) {
N2kMsg.SetPGN(129025L);
N2kMsg.Priority=2;
N2kMsg.Add4ByteDouble(Latitude,1e-7);
N2kMsg.Add4ByteDouble(Longitude,1e-7);
}
bool ParseN2kPGN129025(const tN2kMsg &N2kMsg, double &Latitude, double &Longitude) {
if (N2kMsg.PGN!=129025L) return false;
int Index = 0;
Latitude=N2kMsg.Get4ByteDouble(1e-7, Index);
Longitude=N2kMsg.Get4ByteDouble(1e-7, Index);
return true;
}
//*****************************************************************************
// COG SOG rapid
// COG should be in radians
// SOG should be in m/s
void SetN2kPGN129026(tN2kMsg &N2kMsg, unsigned char SID, tN2kHeadingReference ref, double COG, double SOG) {
N2kMsg.SetPGN(129026L);
N2kMsg.Priority=2;
N2kMsg.AddByte(SID);
N2kMsg.AddByte( (((unsigned char)(ref)) & 0x03) | 0xfc );
N2kMsg.Add2ByteUDouble(COG,0.0001); //0.0057295779513082332);
N2kMsg.Add2ByteUDouble(SOG,0.01);
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // Reserved
}
bool ParseN2kPGN129026(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kHeadingReference &ref, double &COG, double &SOG) {
if (N2kMsg.PGN!=129026L) return false;
int Index=0;
unsigned char b;
SID=N2kMsg.GetByte(Index);
b=N2kMsg.GetByte(Index); ref=(tN2kHeadingReference)( b & 0x03 );
COG=N2kMsg.Get2ByteUDouble(0.0001,Index);
SOG=N2kMsg.Get2ByteUDouble(0.01,Index);
return true;
}
//*****************************************************************************
// GNSS Position Data
void SetN2kPGN129029(tN2kMsg &N2kMsg, unsigned char SID, uint16_t DaysSince1970, double SecondsSinceMidnight,
double Latitude, double Longitude, double Altitude,
tN2kGNSStype GNSStype, tN2kGNSSmethod GNSSmethod,
unsigned char nSatellites, double HDOP, double PDOP, double GeoidalSeparation,
unsigned char nReferenceStations, tN2kGNSStype ReferenceStationType, uint16_t ReferenceSationID,
double AgeOfCorrection
) {
N2kMsg.SetPGN(129029L);
N2kMsg.Priority=3;
N2kMsg.AddByte(SID);
N2kMsg.Add2ByteUInt(DaysSince1970);
N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
N2kMsg.Add8ByteDouble(Latitude,1e-16);
N2kMsg.Add8ByteDouble(Longitude,1e-16);
N2kMsg.Add8ByteDouble(Altitude,1e-6);
N2kMsg.AddByte( (((unsigned char) GNSStype) & 0x0f) | (((unsigned char) GNSSmethod) & 0x0f)<<4 );
N2kMsg.AddByte(1 | 0xfc); // Integrity 2 bit, reserved 6 bits
N2kMsg.AddByte(nSatellites);
N2kMsg.Add2ByteDouble(HDOP,0.01);
N2kMsg.Add2ByteDouble(PDOP,0.01);
N2kMsg.Add4ByteDouble(GeoidalSeparation,0.01);
if (nReferenceStations!=0xff && nReferenceStations>0) {
N2kMsg.AddByte(1); // Note that we have values for only one reference station, so pass only one values.
N2kMsg.Add2ByteInt( (((int)ReferenceStationType) & 0x0f) | ReferenceSationID<<4 );
N2kMsg.Add2ByteUDouble(AgeOfCorrection,0.01);
} else N2kMsg.AddByte(nReferenceStations);
}
bool ParseN2kPGN129029(const tN2kMsg &N2kMsg, unsigned char &SID, uint16_t &DaysSince1970, double &SecondsSinceMidnight,
double &Latitude, double &Longitude, double &Altitude,
tN2kGNSStype &GNSStype, tN2kGNSSmethod &GNSSmethod,
uint8_t &nSatellites, double &HDOP, double &PDOP, double &GeoidalSeparation,
uint8_t &nReferenceStations, tN2kGNSStype &ReferenceStationType, uint16_t &ReferenceSationID,
double &AgeOfCorrection
) {
if (N2kMsg.PGN!=129029L) return false;
int Index=0;
unsigned char vb;
int16_t vi;
SID=N2kMsg.GetByte(Index);
DaysSince1970=N2kMsg.Get2ByteUInt(Index);
SecondsSinceMidnight=N2kMsg.Get4ByteDouble(0.0001,Index);
Latitude=N2kMsg.Get8ByteDouble(1e-16,Index);
Longitude=N2kMsg.Get8ByteDouble(1e-16,Index);
Altitude=N2kMsg.Get8ByteDouble(1e-6,Index);
vb=N2kMsg.GetByte(Index); GNSStype=(tN2kGNSStype)(vb & 0x0f); GNSSmethod=(tN2kGNSSmethod)((vb>>4) & 0x0f);
vb=N2kMsg.GetByte(Index); // Integrity 2 bit, reserved 6 bits
nSatellites=N2kMsg.GetByte(Index);
HDOP=N2kMsg.Get2ByteDouble(0.01,Index);
PDOP=N2kMsg.Get2ByteDouble(0.01,Index);
GeoidalSeparation=N2kMsg.Get4ByteDouble(0.01,Index);
nReferenceStations=N2kMsg.GetByte(Index);
if (nReferenceStations!=N2kUInt8NA && nReferenceStations>0) {
// Note that we return real number of stations, but we only have variabes for one.
vi=N2kMsg.Get2ByteUInt(Index); ReferenceStationType=(tN2kGNSStype)(vi & 0x0f); ReferenceSationID=(vi>>4);
AgeOfCorrection=N2kMsg.Get2ByteUDouble(0.01,Index);
}
return true;
}
//*****************************************************************************
// Date,Time & Local offset
void SetN2kPGN129033(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, int16_t LocalOffset) {
N2kMsg.SetPGN(129033L);
N2kMsg.Priority=3;
N2kMsg.Add2ByteUInt(DaysSince1970);
N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
N2kMsg.Add2ByteInt(LocalOffset);
}
bool ParseN2kPGN129033(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, int16_t &LocalOffset) {
if ( N2kMsg.PGN != 129033L ) return false;
int Index = 0;
DaysSince1970 = N2kMsg.Get2ByteUInt(Index);
SecondsSinceMidnight = N2kMsg.Get4ByteUDouble(0.0001, Index);
LocalOffset = N2kMsg.Get2ByteInt(Index);
return true;
}
//*****************************************************************************
// GNSS DOP data
void SetN2kPGN129539(tN2kMsg& N2kMsg, unsigned char SID, tN2kGNSSDOPmode DesiredMode, tN2kGNSSDOPmode ActualMode,
double HDOP, double VDOP, double TDOP)
{
N2kMsg.SetPGN(129539L);