NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
N2kMessages.cpp
Go to the documentation of this file.
1/*
2N2kMessages.cpp
3
4Copyright (c) 2015-2024 Timo Lappalainen, Kave Oy, www.kave.fi
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to use,
9copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10Software, and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23#include "N2kMessages.h"
24#include <string.h>
25
26//*****************************************************************************
27// System time
28void SetN2kPGN126992(tN2kMsg &N2kMsg, unsigned char SID, uint16_t SystemDate,
29 double SystemTime, tN2kTimeSource TimeSource) {
30 N2kMsg.SetPGN(126992L);
31 N2kMsg.Priority=3;
32 N2kMsg.AddByte(SID);
33 N2kMsg.AddByte((TimeSource & 0x0f) | 0xf0);
34 N2kMsg.Add2ByteUInt(SystemDate);
35 N2kMsg.Add4ByteUDouble(SystemTime,0.0001);
36}
37
38//*****************************************************************************
39bool ParseN2kPGN126992(const tN2kMsg &N2kMsg, unsigned char &SID, uint16_t &SystemDate,
40 double &SystemTime, tN2kTimeSource &TimeSource) {
41 if (N2kMsg.PGN!=126992L) return false;
42
43 int Index=0;
44
45 SID=N2kMsg.GetByte(Index);
46 TimeSource=(tN2kTimeSource)(N2kMsg.GetByte(Index) & 0x0f);
47 SystemDate=N2kMsg.Get2ByteUInt(Index);
48 SystemTime=N2kMsg.Get4ByteUDouble(0.0001,Index);
49
50 return true;
51}
52
53//*****************************************************************************
54// AIS Safety Related Broadcast Message
55void SetN2kPGN129802(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t SourceID,
56 tN2kAISTransceiverInformation AISTransceiverInformation, char * SafetyRelatedText)
57{
58 N2kMsg.SetPGN(129802L);
59 N2kMsg.Priority=5;
60 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
61 N2kMsg.Add4ByteUInt(0xc0000000 | (SourceID & 0x3fffffff));
62 N2kMsg.AddByte(0xe0 | (0x1f & AISTransceiverInformation));
63 N2kMsg.AddVarStr(SafetyRelatedText);
64}
65
66bool ParseN2kPGN129802(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &SourceID,
67 tN2kAISTransceiverInformation &AISTransceiverInformation, char * SafetyRelatedText, size_t &SafetyRelatedTextMaxSize)
68{
69 if (N2kMsg.PGN!=129802L) return false;
70
71 int Index=0;
72 unsigned char vb;
73
74 vb=N2kMsg.GetByte(Index);
75 MessageID=(vb & 0x3f);
76 Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
77 SourceID = N2kMsg.Get4ByteUInt(Index) & 0x3fffffff;
78 AISTransceiverInformation = (tN2kAISTransceiverInformation)(N2kMsg.GetByte(Index) & 0x1f);
79 N2kMsg.GetVarStr(SafetyRelatedTextMaxSize, SafetyRelatedText, Index);
80
81 return true;
82}
83
84
85//*****************************************************************************
86// Man Overboard Notification
88 unsigned char SID,
89 uint32_t MobEmitterId,
90 tN2kMOBStatus MOBStatus,
91 double ActivationTime,
92 tN2kMOBPositionSource PositionSource,
93 uint16_t PositionDate,
94 double PositionTime,
95 double Latitude,
96 double Longitude,
97 tN2kHeadingReference COGReference,
98 double COG,
99 double SOG,
100 uint32_t MMSI,
101 tN2kMOBEmitterBatteryStatus MOBEmitterBatteryStatus)
102{
103 N2kMsg.SetPGN(127233L);
104 N2kMsg.Priority=3;
105 N2kMsg.AddByte(SID);
106 N2kMsg.Add4ByteUInt(MobEmitterId);
107 N2kMsg.AddByte((MOBStatus & 0x07) | 0xf8);
108 N2kMsg.Add4ByteUDouble(ActivationTime,0.0001);
109 N2kMsg.AddByte((PositionSource & 0x07) | 0xf8);
110 N2kMsg.Add2ByteUInt(PositionDate);
111 N2kMsg.Add4ByteUDouble(PositionTime,0.0001);
112 N2kMsg.Add4ByteDouble(Latitude,1e-7);
113 N2kMsg.Add4ByteDouble(Longitude,1e-7);
114 N2kMsg.AddByte((COGReference & 0x03) | 0xfc);
115 N2kMsg.Add2ByteUDouble(COG,0.0001);
116 N2kMsg.Add2ByteUDouble(SOG,0.01);
117 N2kMsg.Add4ByteUInt(MMSI);
118 N2kMsg.AddByte((MOBEmitterBatteryStatus & 0x07) | 0xf8);
119}
120
121bool ParseN2kPGN127233(const tN2kMsg &N2kMsg,
122 unsigned char &SID,
123 uint32_t &MobEmitterId,
124 tN2kMOBStatus &MOBStatus,
125 double &ActivationTime,
126 tN2kMOBPositionSource &PositionSource,
127 uint16_t &PositionDate,
128 double &PositionTime,
129 double &Latitude,
130 double &Longitude,
131 tN2kHeadingReference &COGReference,
132 double &COG,
133 double &SOG,
134 uint32_t &MMSI,
135 tN2kMOBEmitterBatteryStatus &MOBEmitterBatteryStatus)
136{
137 if (N2kMsg.PGN!=127233L) return false;
138 int Index = 0;
139 SID = N2kMsg.GetByte(Index);
140 MobEmitterId = N2kMsg.Get4ByteUInt(Index);
141 MOBStatus = (tN2kMOBStatus)(N2kMsg.GetByte(Index) & 0x07);
142 ActivationTime = N2kMsg.Get4ByteUDouble(0.0001,Index);
143 PositionSource = (tN2kMOBPositionSource)(N2kMsg.GetByte(Index) & 0x07);
144 PositionDate = N2kMsg.Get2ByteUInt(Index);
145 PositionTime = N2kMsg.Get4ByteUDouble(0.0001,Index);
146 Latitude = N2kMsg.Get4ByteDouble(1e-7,Index);
147 Longitude = N2kMsg.Get4ByteDouble(1e-7,Index);
148 COGReference = (tN2kHeadingReference)(N2kMsg.GetByte(Index) & 0x03);
149 COG = N2kMsg.Get2ByteUDouble(0.0001,Index);
150 SOG = N2kMsg.Get2ByteUDouble(0.01,Index);
151 MMSI = N2kMsg.Get4ByteUInt(Index);
152 MOBEmitterBatteryStatus = (tN2kMOBEmitterBatteryStatus)(N2kMsg.GetByte(Index) & 0x07);
153 return true;
154}
155
156
157//*****************************************************************************
158// Heading/Track control
159// Angles should be in radians
161 tN2kOnOff RudderLimitExceeded,
162 tN2kOnOff OffHeadingLimitExceeded,
163 tN2kOnOff OffTrackLimitExceeded,
164 tN2kOnOff Override,
165 tN2kSteeringMode SteeringMode,
166 tN2kTurnMode TurnMode,
167 tN2kHeadingReference HeadingReference,
168 tN2kRudderDirectionOrder CommandedRudderDirection,
169 double CommandedRudderAngle,
170 double HeadingToSteerCourse,
171 double Track,
172 double RudderLimit,
173 double OffHeadingLimit,
174 double RadiusOfTurnOrder,
175 double RateOfTurnOrder,
176 double OffTrackLimit,
177 double VesselHeading) {
178
179 N2kMsg.SetPGN(127237L);
180 N2kMsg.Priority=2;
181 N2kMsg.AddByte(
182 (0x03 & RudderLimitExceeded) |
183 (0x03 & OffHeadingLimitExceeded) << 2 |
184 (0x03 & OffTrackLimitExceeded) << 4 |
185 (0x03 & Override) << 6
186 );
187 N2kMsg.AddByte(
188 (0x07 & SteeringMode) |
189 (0x07 & TurnMode) << 3 |
190 (0x03 & HeadingReference) << 6
191 );
192 N2kMsg.AddByte(
193 0x1f |
194 (0x07 & CommandedRudderDirection) << 5
195 );
196 N2kMsg.Add2ByteDouble(CommandedRudderAngle,0.0001);
197 N2kMsg.Add2ByteUDouble(HeadingToSteerCourse,0.0001);
198 N2kMsg.Add2ByteUDouble(Track,0.0001);
199 N2kMsg.Add2ByteUDouble(RudderLimit,0.0001);
200 N2kMsg.Add2ByteUDouble(OffHeadingLimit,0.0001);
201 N2kMsg.Add2ByteDouble(RadiusOfTurnOrder,1);
202 N2kMsg.Add2ByteDouble(RateOfTurnOrder,3.125e-5);
203 N2kMsg.Add2ByteDouble(OffTrackLimit,1);
204 N2kMsg.Add2ByteUDouble(VesselHeading,0.0001);
205}
206
207bool ParseN2kPGN127237(const tN2kMsg &N2kMsg,
208 tN2kOnOff &RudderLimitExceeded,
209 tN2kOnOff &OffHeadingLimitExceeded,
210 tN2kOnOff &OffTrackLimitExceeded,
211 tN2kOnOff &Override,
212 tN2kSteeringMode &SteeringMode,
213 tN2kTurnMode &TurnMode,
214 tN2kHeadingReference &HeadingReference,
215 tN2kRudderDirectionOrder &CommandedRudderDirection,
216 double &CommandedRudderAngle,
217 double &HeadingToSteerCourse,
218 double &Track,
219 double &RudderLimit,
220 double &OffHeadingLimit,
221 double &RadiusOfTurnOrder,
222 double &RateOfTurnOrder,
223 double &OffTrackLimit,
224 double &VesselHeading) {
225
226 if (N2kMsg.PGN!=127237L) return false;
227 int Index = 0;
228 unsigned char v;
229 v = N2kMsg.GetByte(Index);
230 RudderLimitExceeded = (tN2kOnOff)(v & 0x03);
231 OffHeadingLimitExceeded = (tN2kOnOff)((v >> 2) & 0x03);
232 OffTrackLimitExceeded = (tN2kOnOff)((v >> 4) & 0x03);
233 Override = (tN2kOnOff)((v >> 6) & 0x03);
234 v = N2kMsg.GetByte(Index);
235 SteeringMode = (tN2kSteeringMode)(v & 0x07);
236 TurnMode = (tN2kTurnMode)((v >> 3) & 0x07);
237 HeadingReference = (tN2kHeadingReference)((v >> 6) & 0x03);
238 CommandedRudderDirection = (tN2kRudderDirectionOrder)((N2kMsg.GetByte(Index) >> 5) & 0x07);
239 CommandedRudderAngle = N2kMsg.Get2ByteDouble(0.0001,Index);
240 HeadingToSteerCourse = N2kMsg.Get2ByteUDouble(0.0001,Index);
241 Track = N2kMsg.Get2ByteUDouble(0.0001,Index);
242 RudderLimit = N2kMsg.Get2ByteUDouble(0.0001,Index);
243 OffHeadingLimit = N2kMsg.Get2ByteUDouble(0.0001,Index);
244 RadiusOfTurnOrder = N2kMsg.Get2ByteDouble(1,Index);
245 RateOfTurnOrder = N2kMsg.Get2ByteDouble(3.125e-5,Index);
246 OffTrackLimit = N2kMsg.Get2ByteDouble(1,Index);
247 VesselHeading = N2kMsg.Get2ByteUDouble(0.0001,Index);
248 return true;
249}
250
251//*****************************************************************************
252// Rudder
253// Angles should be in radians
254void SetN2kPGN127245(tN2kMsg &N2kMsg, double RudderPosition, unsigned char Instance,
255 tN2kRudderDirectionOrder RudderDirectionOrder, double AngleOrder) {
256 N2kMsg.SetPGN(127245L);
257 N2kMsg.Priority=2;
258 N2kMsg.AddByte(Instance);
259 N2kMsg.AddByte(0xf8 | (RudderDirectionOrder&0x07));
260 N2kMsg.Add2ByteDouble(AngleOrder,0.0001);
261 N2kMsg.Add2ByteDouble(RudderPosition,0.0001);
262 N2kMsg.AddByte(0xff); // Reserved
263 N2kMsg.AddByte(0xff); // Reserved
264}
265
266bool ParseN2kPGN127245(const tN2kMsg &N2kMsg, double &RudderPosition, unsigned char &Instance,
267 tN2kRudderDirectionOrder &RudderDirectionOrder, double &AngleOrder) {
268 if (N2kMsg.PGN!=127245L) return false;
269
270 int Index=0;
271 Instance=N2kMsg.GetByte(Index);
272 RudderDirectionOrder=(tN2kRudderDirectionOrder)(N2kMsg.GetByte(Index)&0x7);
273 AngleOrder=N2kMsg.Get2ByteDouble(0.0001,Index);
274 RudderPosition=N2kMsg.Get2ByteDouble(0.0001,Index);
275 return true;
276}
277
278//*****************************************************************************
279// Vessel Heading
280// Angles should be in radians
281void SetN2kPGN127250(tN2kMsg &N2kMsg, unsigned char SID, double Heading, double Deviation, double Variation, tN2kHeadingReference ref) {
282 N2kMsg.SetPGN(127250L);
283 N2kMsg.Priority=2;
284 N2kMsg.AddByte(SID);
285 N2kMsg.Add2ByteUDouble(Heading,0.0001);
286 N2kMsg.Add2ByteDouble(Deviation,0.0001);
287 N2kMsg.Add2ByteDouble(Variation,0.0001);
288 N2kMsg.AddByte(0xfc | ref);
289}
290
291bool ParseN2kPGN127250(const tN2kMsg &N2kMsg, unsigned char &SID, double &Heading, double &Deviation, double &Variation, tN2kHeadingReference &ref) {
292 if (N2kMsg.PGN!=127250L) return false;
293
294 int Index=0;
295
296 SID=N2kMsg.GetByte(Index);
297 Heading=N2kMsg.Get2ByteUDouble(0.0001,Index);
298 Deviation=N2kMsg.Get2ByteDouble(0.0001,Index);
299 Variation=N2kMsg.Get2ByteDouble(0.0001,Index);
300 ref=(tN2kHeadingReference)(N2kMsg.GetByte(Index)&0x03);
301
302 return true;
303}
304
305//*****************************************************************************
306// Rate of turn
307// Angles should be in radians
308void SetN2kPGN127251(tN2kMsg &N2kMsg, unsigned char SID, double RateOfTurn) {
309 N2kMsg.SetPGN(127251L);
310 N2kMsg.Priority=2;
311 N2kMsg.AddByte(SID);
312 N2kMsg.Add4ByteDouble(RateOfTurn,3.125E-08); //1e-6/32.0
313 N2kMsg.AddByte(0xff);
314 N2kMsg.Add2ByteUInt(0xffff);
315}
316
317bool ParseN2kPGN127251(const tN2kMsg &N2kMsg, unsigned char &SID, double &RateOfTurn) {
318 if (N2kMsg.PGN!=127251L) return false;
319
320 int Index=0;
321
322 SID=N2kMsg.GetByte(Index);
323 RateOfTurn=N2kMsg.Get4ByteDouble(3.125E-08,Index); //1e-6/32.0
324
325 return true;
326}
327
328//*****************************************************************************
329// Heave
330// - SID Sequence ID. If your device is e.g. boat speed and heading at same time, you can set same SID for different messages
331// to indicate that they are measured at same time.
332// - Heave Vertical displacement perpendicular to the earth’s surface in meters
333// - Delay Delay added by calculations in seconds
334// - DelaySource tN2kDelaySource
335// Output:
336// - N2kMsg NMEA2000 message ready to be send.
337void SetN2kPGN127252(tN2kMsg &N2kMsg, unsigned char SID, double Heave,
338 double Delay, tN2kDelaySource DelaySource) {
339
340 N2kMsg.SetPGN(127252L);
341 N2kMsg.Priority=3;
342 N2kMsg.AddByte(SID);
343 N2kMsg.Add2ByteDouble(Heave,0.01);
344 N2kMsg.Add2ByteUDouble(Delay,0.01);
345 N2kMsg.AddByte(0xf0 | (DelaySource & 0x0f));
347}
348
349bool ParseN2kPGN127252(const tN2kMsg &N2kMsg, unsigned char &SID, double &Heave, double &Delay, tN2kDelaySource &DelaySource) {
350 if (N2kMsg.PGN!=127252L) return false;
351 int Index = 0;
352 SID = N2kMsg.GetByte(Index);
353 Heave = N2kMsg.Get2ByteDouble(0.01,Index);
354 Delay = N2kMsg.Get2ByteUDouble(0.01,Index);
355 uint8_t v=N2kMsg.GetByte(Index);
356 DelaySource=(tN2kDelaySource)(v & 0x0f);
357 return true;
358}
359
360//*****************************************************************************
361// Attitude
362// Input:
363// - SID Sequence ID. If your device is e.g. boat speed and heading at same time, you can set same SID for different messages
364// to indicate that they are measured at same time.
365// - Yaw Heading in radians.
366// - Pitch Pitch in radians. Positive, when your bow rises.
367// - Roll Roll in radians. Positive, when tilted right.
368// Output:
369// - N2kMsg NMEA2000 message ready to be send.
370void SetN2kPGN127257(tN2kMsg &N2kMsg, unsigned char SID, double Yaw, double Pitch, double Roll) {
371 N2kMsg.SetPGN(127257L);
372 N2kMsg.Priority=3;
373 N2kMsg.AddByte(SID);
374 N2kMsg.Add2ByteDouble(Yaw,0.0001);
375 N2kMsg.Add2ByteDouble(Pitch,0.0001);
376 N2kMsg.Add2ByteDouble(Roll,0.0001);
377 N2kMsg.AddByte(0xff); // Reserved
378}
379
380bool ParseN2kPGN127257(const tN2kMsg &N2kMsg, unsigned char &SID, double &Yaw, double &Pitch, double &Roll){
381 if (N2kMsg.PGN!=127257L) return false;
382
383 int Index=0;
384 SID=N2kMsg.GetByte(Index);
385 Yaw=N2kMsg.Get2ByteDouble(0.0001,Index);
386 Pitch=N2kMsg.Get2ByteDouble(0.0001,Index);
387 Roll=N2kMsg.Get2ByteDouble(0.0001,Index);
388
389 return true;
390}
391
392//*****************************************************************************
393// Magnetic variation
394void SetN2kPGN127258(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation) {
395 N2kMsg.SetPGN(127258L);
396 N2kMsg.Priority=6;
397 N2kMsg.AddByte(SID);
398 N2kMsg.AddByte(Source & 0x0f);
399 N2kMsg.Add2ByteUInt(DaysSince1970);
400 N2kMsg.Add2ByteDouble(Variation, 0.0001);
401 N2kMsg.Add2ByteUInt(0xffff);
402}
403
404bool ParseN2kPGN127258(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation) {
405 if (N2kMsg.PGN!=127258L) return false;
406
407 int Index=0;
408 SID=N2kMsg.GetByte(Index);
409 Source=(tN2kMagneticVariation) (N2kMsg.GetByte(Index) & 0x0f);
410 DaysSince1970=N2kMsg.Get2ByteUInt(Index);
411 Variation=N2kMsg.Get2ByteDouble(0.0001, Index);
412
413 return true;
414}
415
416//*****************************************************************************
417// Engine rapid param
418void SetN2kPGN127488(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineSpeed,
419 double EngineBoostPressure, int8_t EngineTiltTrim) {
420 N2kMsg.SetPGN(127488L);
421 N2kMsg.Priority=2;
422 N2kMsg.AddByte(EngineInstance);
423 N2kMsg.Add2ByteUDouble(EngineSpeed,0.25);
424 N2kMsg.Add2ByteUDouble(EngineBoostPressure, 100);
425 N2kMsg.AddByte(EngineTiltTrim);
426 N2kMsg.AddByte(0xff); // Reserved
427 N2kMsg.AddByte(0xff); // Reserved
428}
429
430bool ParseN2kPGN127488(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &EngineSpeed,
431 double &EngineBoostPressure, int8_t &EngineTiltTrim) {
432 if (N2kMsg.PGN!=127488L) return false;
433
434 int Index=0;
435
436 EngineInstance=N2kMsg.GetByte(Index);
437 EngineSpeed=N2kMsg.Get2ByteUDouble(0.25,Index);
438 EngineBoostPressure=N2kMsg.Get2ByteUDouble(100,Index);
439 EngineTiltTrim=N2kMsg.GetByte(Index);
440
441 return true;
442}
443
444//*****************************************************************************
445// Engine parameters dynamic
446void SetN2kPGN127489(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineOilPress, double EngineOilTemp, double EngineCoolantTemp, double AltenatorVoltage,
447 double FuelRate, double EngineHours, double EngineCoolantPress, double EngineFuelPress, int8_t EngineLoad, int8_t EngineTorque,
449 N2kMsg.SetPGN(127489L);
450 N2kMsg.Priority=2;
451
452 N2kMsg.AddByte(EngineInstance);
453 N2kMsg.Add2ByteUDouble(EngineOilPress, 100);
454 N2kMsg.Add2ByteUDouble(EngineOilTemp, 0.1);
455 N2kMsg.Add2ByteUDouble(EngineCoolantTemp, 0.01);
456 N2kMsg.Add2ByteDouble(AltenatorVoltage, 0.01);
457 N2kMsg.Add2ByteDouble(FuelRate, 0.1);
458 N2kMsg.Add4ByteUDouble(EngineHours, 1);
459 N2kMsg.Add2ByteUDouble(EngineCoolantPress, 100);
460 N2kMsg.Add2ByteUDouble(EngineFuelPress, 1000);
461 N2kMsg.AddByte(0xff); // reserved
462
463 N2kMsg.Add2ByteUInt(Status1.Status); // Discrete Status 1
464 N2kMsg.Add2ByteUInt(Status2.Status); // Discrete Status 2
465
466 N2kMsg.AddByte(EngineLoad);
467 N2kMsg.AddByte(EngineTorque);
468}
469bool ParseN2kPGN127489(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &EngineOilPress,
470 double &EngineOilTemp, double &EngineCoolantTemp, double &AltenatorVoltage,
471 double &FuelRate, double &EngineHours, double &EngineCoolantPress, double &EngineFuelPress,
472 int8_t &EngineLoad, int8_t &EngineTorque,
474 if (N2kMsg.PGN != 127489L) return false;
475
476 int Index = 0;
477
478 EngineInstance = N2kMsg.GetByte(Index);
479 EngineOilPress = N2kMsg.Get2ByteUDouble(100, Index);
480 EngineOilTemp = N2kMsg.Get2ByteUDouble(0.1, Index);
481 EngineCoolantTemp = N2kMsg.Get2ByteUDouble(0.01, Index);
482 AltenatorVoltage = N2kMsg.Get2ByteDouble(0.01, Index);
483 FuelRate = N2kMsg.Get2ByteDouble(0.1, Index);
484 EngineHours = N2kMsg.Get4ByteUDouble(1, Index);
485 EngineCoolantPress=N2kMsg.Get2ByteUDouble(100, Index);
486 EngineFuelPress=N2kMsg.Get2ByteUDouble(1000, Index);
487 N2kMsg.GetByte(Index); // reserved
488 Status1=N2kMsg.Get2ByteUInt(Index); // Discrete Status 1
489 Status2=N2kMsg.Get2ByteUInt(Index); // Discrete Status 2
490 EngineLoad=N2kMsg.GetByte(Index);
491 EngineTorque=N2kMsg.GetByte(Index);
492
493 return true;
494}
495
496
497//*****************************************************************************
498// Transmission parameters, dynamic
499void SetN2kPGN127493(tN2kMsg &N2kMsg, unsigned char EngineInstance, tN2kTransmissionGear TransmissionGear,
500 double OilPressure, double OilTemperature, unsigned char DiscreteStatus1) {
501 N2kMsg.SetPGN(127493L);
502 N2kMsg.Priority=2;
503 N2kMsg.AddByte(EngineInstance);
504 N2kMsg.AddByte((TransmissionGear & 0x03) | 0xfc );
505 N2kMsg.Add2ByteUDouble(OilPressure, 100);
506 N2kMsg.Add2ByteUDouble(OilTemperature, 0.1);
507 N2kMsg.AddByte(DiscreteStatus1);
508 N2kMsg.AddByte(0xff); // Reserved
509}
510
511bool ParseN2kPGN127493(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, tN2kTransmissionGear &TransmissionGear,
512 double &OilPressure, double &OilTemperature, unsigned char &DiscreteStatus1) {
513 if (N2kMsg.PGN!=127493L) return false;
514
515 int Index=0;
516
517 EngineInstance=N2kMsg.GetByte(Index);
518 TransmissionGear=(tN2kTransmissionGear)(N2kMsg.GetByte(Index) & 0x03);
519 OilPressure=N2kMsg.Get2ByteUDouble(100,Index);
520 OilTemperature=N2kMsg.Get2ByteUDouble(0.1,Index);
521 DiscreteStatus1=N2kMsg.GetByte(Index);
522
523 return true;
524}
525
526//*****************************************************************************
527// Trip Parameters, Engine
528void SetN2kPGN127497(tN2kMsg &N2kMsg, unsigned char EngineInstance, double TripFuelUsed,
529 double FuelRateAverage,
530 double FuelRateEconomy, double InstantaneousFuelEconomy) {
531 N2kMsg.SetPGN(127497L);
532 N2kMsg.Priority=2;
533 N2kMsg.AddByte(EngineInstance);
534 N2kMsg.Add2ByteUDouble(TripFuelUsed,1);
535 N2kMsg.Add2ByteDouble(FuelRateAverage, 0.1);
536 N2kMsg.Add2ByteDouble(FuelRateEconomy, 0.1);
537 N2kMsg.Add2ByteDouble(InstantaneousFuelEconomy, 0.1);
538}
539
540bool ParseN2kPGN127497(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &TripFuelUsed,
541 double &FuelRateAverage,
542 double &FuelRateEconomy, double &InstantaneousFuelEconomy) {
543 if (N2kMsg.PGN!=127497L) return false;
544
545 int Index=0;
546
547 EngineInstance=N2kMsg.GetByte(Index);
548 TripFuelUsed=N2kMsg.Get2ByteUDouble(1,Index);
549 FuelRateAverage=N2kMsg.Get2ByteDouble(0.1,Index);
550 FuelRateEconomy=N2kMsg.Get2ByteDouble(0.1,Index);
551 InstantaneousFuelEconomy=N2kMsg.Get2ByteDouble(0.1,Index);
552
553 return true;
554}
555
556//*****************************************************************************
557// Binary status
558
559//*****************************************************************************
561 ItemIndex--;
562 if (ItemIndex>27) return N2kOnOff_Unavailable;
563
564 return (tN2kOnOff)((BankStatus >> (2*ItemIndex)) & 0x03);
565}
566
567//*****************************************************************************
568void N2kSetStatusBinaryOnStatus(tN2kBinaryStatus &BankStatus, tN2kOnOff ItemStatus, uint8_t ItemIndex) {
569 ItemIndex--;
570 if (ItemIndex>27) return;
571
572 tN2kBinaryStatus Mask = ~((tN2kBinaryStatus)3 << (2*ItemIndex));
573
574 BankStatus = (BankStatus & Mask) | ((tN2kBinaryStatus)ItemStatus << (2*ItemIndex));
575}
576
577//*****************************************************************************
578void SetN2kPGN127501(tN2kMsg &N2kMsg, unsigned char DeviceBankInstance, tN2kBinaryStatus BankStatus) {
579 N2kMsg.SetPGN(127501L);
580 N2kMsg.Priority=3;
581 BankStatus = (BankStatus << 8) | DeviceBankInstance;
582 N2kMsg.AddUInt64(BankStatus);
583}
584
585//*****************************************************************************
586// Binary status report
587void SetN2kPGN127501(tN2kMsg &N2kMsg, unsigned char DeviceBankInstance
588 ,tN2kOnOff Status1
589 ,tN2kOnOff Status2
590 ,tN2kOnOff Status3
591 ,tN2kOnOff Status4
592 ) {
593 tN2kBinaryStatus BankStatus;
594
595 N2kResetBinaryStatus(BankStatus);
596 BankStatus = (BankStatus << 2) | Status4;
597 BankStatus = (BankStatus << 2) | Status3;
598 BankStatus = (BankStatus << 2) | Status2;
599 BankStatus = (BankStatus << 2) | Status1;
600 SetN2kPGN127501(N2kMsg,DeviceBankInstance,BankStatus);
601}
602
603//*****************************************************************************
604bool ParseN2kPGN127501(const tN2kMsg &N2kMsg, unsigned char &DeviceBankInstance
605 ,tN2kOnOff &Status1
606 ,tN2kOnOff &Status2
607 ,tN2kOnOff &Status3
608 ,tN2kOnOff &Status4
609 ) {
610 if (N2kMsg.PGN!=127501L) return false;
611
612 int Index=0;
613 DeviceBankInstance=N2kMsg.GetByte(Index);
614 unsigned char b=N2kMsg.GetByte(Index);
615 Status1=(tN2kOnOff)(b & 0x03);
616 b>>=2; Status2=(tN2kOnOff)(b & 0x03);
617 b>>=2; Status3=(tN2kOnOff)(b & 0x03);
618 b>>=2; Status4=(tN2kOnOff)(b & 0x03);
619
620 return true;
621}
622
623//*****************************************************************************
624bool ParseN2kPGN127501(const tN2kMsg &N2kMsg, unsigned char &DeviceBankInstance, tN2kBinaryStatus &BankStatus) {
625 if (N2kMsg.PGN!=127501L) return false;
626
627 int Index=0;
628 BankStatus=N2kMsg.GetUInt64(Index);
629 DeviceBankInstance = BankStatus & 0xff;
630 BankStatus>>=8;
631
632 return true;
633}
634
635//*****************************************************************************
636// PGN 127502 - Switch Bank Control
637
638bool ParseN2kPGN127502(const tN2kMsg &N2kMsg, unsigned char &TargetBankInstance, tN2kBinaryStatus &BankStatus) {
639 if (N2kMsg.PGN!=127502L) return false;
640
641 int Index=0;
642 BankStatus=N2kMsg.GetUInt64(Index);
643 TargetBankInstance = BankStatus & 0xff;
644 BankStatus>>=8;
645
646 return true;
647}
648
649//*****************************************************************************
650
651void SetN2kPGN127502(tN2kMsg &N2kMsg, unsigned char TargetBankInstance, tN2kBinaryStatus BankStatus) {
652 N2kMsg.SetPGN(127502L);
653 N2kMsg.Priority=3;
654 BankStatus = (BankStatus << 8) | TargetBankInstance;
655 N2kMsg.AddUInt64(BankStatus);
656}
657
658//*****************************************************************************
659// Fluid level
660void SetN2kPGN127505(tN2kMsg &N2kMsg, unsigned char Instance, tN2kFluidType FluidType, double Level, double Capacity) {
661 N2kMsg.SetPGN(127505L);
662 N2kMsg.Priority=6;
663 N2kMsg.AddByte((Instance&0x0f) | ((FluidType&0x0f)<<4));
664 N2kMsg.Add2ByteDouble(Level,0.004);
665 N2kMsg.Add4ByteUDouble(Capacity,0.1);
666 N2kMsg.AddByte(0xff); // Reserved
667}
668
669//*****************************************************************************
670bool ParseN2kPGN127505(const tN2kMsg &N2kMsg, unsigned char &Instance, tN2kFluidType &FluidType, double &Level, double &Capacity) {
671 if (N2kMsg.PGN!=127505L) return false;
672
673 int Index=0;
674 unsigned char IFt=N2kMsg.GetByte(Index);
675
676 Instance=IFt&0x0f;
677 FluidType=(tN2kFluidType)((IFt>>4)&0x0f);
678 Level=N2kMsg.Get2ByteDouble(0.004,Index);
679 Capacity=N2kMsg.Get4ByteUDouble(0.1,Index);
680
681 return true;
682}
683
684//*****************************************************************************
685// DC Detailed Status
686//
687void SetN2kPGN127506(tN2kMsg &N2kMsg, unsigned char SID, unsigned char DCInstance, tN2kDCType DCType,
688 uint8_t StateOfCharge, uint8_t StateOfHealth, double TimeRemaining, double RippleVoltage, double Capacity) {
689 N2kMsg.SetPGN(127506L);
690 N2kMsg.Priority=6;
691 N2kMsg.AddByte(SID);
692 N2kMsg.AddByte(DCInstance);
693 N2kMsg.AddByte((unsigned char)DCType);
694 N2kMsg.AddByte(StateOfCharge);
695 N2kMsg.AddByte(StateOfHealth);
696 N2kMsg.Add2ByteUDouble(TimeRemaining,60);
697 N2kMsg.Add2ByteUDouble(RippleVoltage,0.001);
698 N2kMsg.Add2ByteUDouble(Capacity,3600);
699}
700
701//*****************************************************************************
702bool ParseN2kPGN127506(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &DCInstance, tN2kDCType &DCType,
703 uint8_t &StateOfCharge, uint8_t &StateOfHealth, double &TimeRemaining, double &RippleVoltage, double &Capacity){
704 if (N2kMsg.PGN!=127506L) return false;
705 int Index=0;
706 SID=N2kMsg.GetByte(Index);
707 DCInstance=N2kMsg.GetByte(Index);
708 DCType=(tN2kDCType)(N2kMsg.GetByte(Index));
709 StateOfCharge=N2kMsg.GetByte(Index);
710 StateOfHealth=N2kMsg.GetByte(Index);
711 TimeRemaining=N2kMsg.Get2ByteUDouble(60,Index);
712 RippleVoltage=N2kMsg.Get2ByteUDouble(0.001,Index);
713 Capacity=N2kMsg.Get2ByteUDouble(3600,Index);
714
715 return true;
716}
717
718//*****************************************************************************
719// Charger Status
720// Input:
721// - Instance ChargerInstance.
722// - BatteryInstance BatteryInstance.
723// - Operating State see. tN2kChargeState
724// - Charger Mode see. tN2kChargerMode
725// - Charger Enable/Disable boolean
726// - Equalization Pending boolean
727// - Equalization Time Remaining double seconds
728//
729void SetN2kPGN127507(tN2kMsg &N2kMsg, unsigned char Instance, unsigned char BatteryInstance,
730 tN2kChargeState ChargeState, tN2kChargerMode ChargerMode,
731 tN2kOnOff Enabled, tN2kOnOff EqualizationPending, double EqualizationTimeRemaining) {
732 N2kMsg.SetPGN(127507UL);
733 N2kMsg.Priority=6;
734 N2kMsg.AddByte(Instance);
735 N2kMsg.AddByte(BatteryInstance);
736 N2kMsg.AddByte((ChargerMode & 0x0f)<<4 | (ChargeState & 0x0f));
737 N2kMsg.AddByte(0x0f<<4 | (EqualizationPending & 0x03) << 2 | (Enabled & 0x03));
738 N2kMsg.Add2ByteUDouble(EqualizationTimeRemaining,1);
739}
740
741bool ParseN2kPGN127507(const tN2kMsg &N2kMsg, unsigned char &Instance, unsigned char &BatteryInstance,
742 tN2kChargeState &ChargeState, tN2kChargerMode &ChargerMode,
743 tN2kOnOff &Enabled, tN2kOnOff &EqualizationPending, double &EqualizationTimeRemaining) {
744 if (N2kMsg.PGN!=127507UL) return false;
745 int Index=0;
746 Instance=N2kMsg.GetByte(Index);
747 BatteryInstance=N2kMsg.GetByte(Index);
748 unsigned char v;
749 v=N2kMsg.GetByte(Index);
750 ChargeState=(tN2kChargeState)(v&0x0f);
751 ChargerMode=(tN2kChargerMode)((v>>4)&0x0f);
752 v=N2kMsg.GetByte(Index);
753 Enabled=(tN2kOnOff)(v&0x03);
754 EqualizationPending=(tN2kOnOff)((v>>2)&0x03);
755 EqualizationTimeRemaining=N2kMsg.Get2ByteUDouble(60,Index);
756
757 return true;
758}
759
760//*****************************************************************************
761// Battery Status
762// Temperatures should be in Kelvins
763void SetN2kPGN127508(tN2kMsg &N2kMsg, unsigned char BatteryInstance, double BatteryVoltage, double BatteryCurrent,
764 double BatteryTemperature, unsigned char SID) {
765 N2kMsg.SetPGN(127508L);
766 N2kMsg.Priority=6;
767 N2kMsg.AddByte(BatteryInstance);
768 N2kMsg.Add2ByteDouble(BatteryVoltage,0.01);
769 N2kMsg.Add2ByteDouble(BatteryCurrent,0.1);
770 N2kMsg.Add2ByteUDouble(BatteryTemperature,0.01);
771 N2kMsg.AddByte(SID);
772}
773
774//*****************************************************************************
775bool ParseN2kPGN127508(const tN2kMsg &N2kMsg, unsigned char &BatteryInstance, double &BatteryVoltage, double &BatteryCurrent,
776 double &BatteryTemperature, unsigned char &SID) {
777 if (N2kMsg.PGN!=127508L) return false;
778 int Index=0;
779 BatteryInstance=N2kMsg.GetByte(Index);
780 BatteryVoltage=N2kMsg.Get2ByteDouble(0.01,Index);
781 BatteryCurrent=N2kMsg.Get2ByteDouble(0.1,Index);
782 BatteryTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
783 SID=N2kMsg.GetByte(Index);
784
785 return true;
786}
787
788//*****************************************************************************
789// Battery Configuration Status
790void SetN2kPGN127513(tN2kMsg &N2kMsg, unsigned char BatInstance, tN2kBatType BatType, tN2kBatEqSupport SupportsEqual,
791 tN2kBatNomVolt BatNominalVoltage, tN2kBatChem BatChemistry, double BatCapacity, int8_t BatTemperatureCoefficient,
792 double PeukertExponent, int8_t ChargeEfficiencyFactor) {
793 N2kMsg.SetPGN(127513L);
794 N2kMsg.Priority=6;
795 N2kMsg.AddByte(BatInstance);
796 N2kMsg.AddByte(0xc0 | ((SupportsEqual & 0x03) << 4) | (BatType & 0x0f)); // BatType (4 bit), SupportsEqual (2 bit), Reserved (2 bit)
797 N2kMsg.AddByte( ((BatChemistry & 0x0f) << 4) | (BatNominalVoltage & 0x0f) ); // BatNominalVoltage (4 bit), BatChemistry (4 bit)
798 N2kMsg.Add2ByteUDouble(BatCapacity,3600);
799 N2kMsg.AddByte((int8_t)BatTemperatureCoefficient);
800 PeukertExponent-=1; // Is this right or not I am not yet sure!
801 if (PeukertExponent<0 || PeukertExponent>0.504) { N2kMsg.AddByte(0xff); } else { N2kMsg.Add1ByteUDouble(PeukertExponent,0.002,-1); }
802 N2kMsg.AddByte((int8_t)ChargeEfficiencyFactor);
803}
804
805//*****************************************************************************
806bool ParseN2kPGN127513(const tN2kMsg &N2kMsg, unsigned char &BatInstance, tN2kBatType &BatType, tN2kBatEqSupport &SupportsEqual,
807 tN2kBatNomVolt &BatNominalVoltage, tN2kBatChem &BatChemistry, double &BatCapacity, int8_t &BatTemperatureCoefficient,
808 double &PeukertExponent, int8_t &ChargeEfficiencyFactor) {
809 if (N2kMsg.PGN!=127513L) return false;
810 int Index=0;
811 unsigned char v;
812 BatInstance = N2kMsg.GetByte(Index);
813 v = N2kMsg.GetByte(Index); BatType=(tN2kBatType)(v & 0x0f); SupportsEqual=(tN2kBatEqSupport)((v>>4) & 0x03);
814 v = N2kMsg.GetByte(Index); BatNominalVoltage=(tN2kBatNomVolt)(v & 0x0f); BatChemistry=(tN2kBatChem)((v>>4) & 0x0f);
815 BatCapacity=N2kMsg.Get2ByteDouble(3600,Index);
816 BatTemperatureCoefficient=N2kMsg.GetByte(Index);
817 PeukertExponent=N2kMsg.Get1ByteUDouble(0.002,Index); PeukertExponent+=1;
818 ChargeEfficiencyFactor=N2kMsg.GetByte(Index);
819
820 return true;
821}
822
823//*****************************************************************************
824// Leeway
825void SetN2kPGN128000(tN2kMsg &N2kMsg, unsigned char SID, double Leeway) {
826 N2kMsg.SetPGN(128000L);
827 N2kMsg.Priority=4;
828 N2kMsg.AddByte(SID);
829 N2kMsg.Add2ByteDouble(Leeway,0.0001);
830 N2kMsg.AddByte(0xff); // Reserved
831 N2kMsg.AddByte(0xff); // Reserved
832 N2kMsg.AddByte(0xff); // Reserved
833 N2kMsg.AddByte(0xff); // Reserved
834 N2kMsg.AddByte(0xff); // Reserved
835}
836
837bool ParseN2kPGN128000(const tN2kMsg &N2kMsg, unsigned char &SID, double &Leeway) {
838 if (N2kMsg.PGN!=128000L) return false;
839
840 int Index=0;
841
842 SID=N2kMsg.GetByte(Index);
843 Leeway=N2kMsg.Get2ByteDouble(0.0001,Index);
844
845 return true;
846}
847
848//*****************************************************************************
849// Boat speed
850void SetN2kPGN128259(tN2kMsg &N2kMsg, unsigned char SID, double WaterReferenced, double GroundReferenced, tN2kSpeedWaterReferenceType SWRT) {
851 N2kMsg.SetPGN(128259L);
852 N2kMsg.Priority=2;
853 N2kMsg.AddByte(SID);
854 N2kMsg.Add2ByteUDouble(WaterReferenced,0.01);
855 N2kMsg.Add2ByteUDouble(GroundReferenced,0.01);
856 N2kMsg.AddByte(SWRT);
857 N2kMsg.AddByte(0xff); // Reserved
858 N2kMsg.AddByte(0xff); // Reserved
859}
860
861bool ParseN2kPGN128259(const tN2kMsg &N2kMsg, unsigned char &SID, double &WaterReferenced, double &GroundReferenced, tN2kSpeedWaterReferenceType &SWRT) {
862 if (N2kMsg.PGN!=128259L) return false;
863
864 int Index=0;
865
866 SID=N2kMsg.GetByte(Index);
867 WaterReferenced=N2kMsg.Get2ByteUDouble(0.01,Index);
868 GroundReferenced=N2kMsg.Get2ByteUDouble(0.01,Index);
869 SWRT=(tN2kSpeedWaterReferenceType)(N2kMsg.GetByte(Index)&0x0F);
870
871 return true;
872}
873
874//*****************************************************************************
875// Water depth
876void SetN2kPGN128267(tN2kMsg &N2kMsg, unsigned char SID, double DepthBelowTransducer, double Offset, double Range) {
877 N2kMsg.SetPGN(128267L);
878 N2kMsg.Priority=3;
879 N2kMsg.AddByte(SID);
880 N2kMsg.Add4ByteUDouble(DepthBelowTransducer,0.01);
881 N2kMsg.Add2ByteDouble(Offset,0.001);
882 N2kMsg.Add1ByteUDouble(Range,10);
883}
884
885bool ParseN2kPGN128267(const tN2kMsg &N2kMsg, unsigned char &SID, double &DepthBelowTransducer, double &Offset, double &Range) {
886 if (N2kMsg.PGN!=128267L) return false;
887
888 int Index=0;
889 SID=N2kMsg.GetByte(Index);
890 DepthBelowTransducer=N2kMsg.Get4ByteUDouble(0.01,Index);
891 Offset=N2kMsg.Get2ByteDouble(0.001,Index);
892 Range=N2kMsg.Get1ByteUDouble(10,Index);
893
894 return true;
895}
896
897//*****************************************************************************
898// Distance log
899void SetN2kPGN128275(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, uint32_t Log, uint32_t TripLog) {
900 N2kMsg.SetPGN(128275L);
901 N2kMsg.Priority=6;
902 N2kMsg.Add2ByteUInt(DaysSince1970);
903 N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
904 N2kMsg.Add4ByteUInt(Log);
905 N2kMsg.Add4ByteUInt(TripLog);
906}
907
908bool ParseN2kPGN128275(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, uint32_t &Log, uint32_t &TripLog) {
909 if (N2kMsg.PGN!=128275L) return false;
910
911 int Index=0;
912
913 DaysSince1970=N2kMsg.Get2ByteUInt(Index);
914 SecondsSinceMidnight=N2kMsg.Get4ByteUDouble(0.0001,Index);
915 Log=N2kMsg.Get4ByteUDouble(1,Index);
916 TripLog=N2kMsg.Get4ByteUDouble(1,Index);
917
918 return true;
919}
920
921
922//*****************************************************************************
923// PGN128776 - Windlass Control Status
924//
925
927 tN2kMsg &N2kMsg,
928 unsigned char SID,
929 unsigned char WindlassIdentifier,
930 tN2kWindlassDirectionControl WindlassDirectionControl,
931 unsigned char SpeedControl,
932 tN2kSpeedType SpeedControlType,
933 tN2kGenericStatusPair AnchorDockingControl,
934 tN2kGenericStatusPair PowerEnable,
935 tN2kGenericStatusPair MechanicalLock,
936 tN2kGenericStatusPair DeckAndAnchorWash,
937 tN2kGenericStatusPair AnchorLight,
938 double CommandTimeout,
939 const tN2kWindlassControlEvents &WindlassControlEvents
940){
941 N2kMsg.SetPGN(128776L);
942 N2kMsg.Priority=2;
943 N2kMsg.AddByte(SID);
944 N2kMsg.AddByte(WindlassIdentifier);
945 N2kMsg.AddByte((unsigned char) ((0x03 << 6) | ((SpeedControlType & 0x03) << 4) | ((AnchorDockingControl & 0x03) << 2) | (WindlassDirectionControl & 0x03)));
946 N2kMsg.AddByte(SpeedControl);
947 N2kMsg.AddByte((unsigned char) (((AnchorLight & 0x03) << 6) | ((DeckAndAnchorWash & 0x03) << 4) | ((MechanicalLock & 0x03) << 2) | (PowerEnable & 0x03)));
948 N2kMsg.Add1ByteUDouble(CommandTimeout, 0.005);
949 N2kMsg.AddByte(WindlassControlEvents.Events);
950}
951
953 const tN2kMsg &N2kMsg,
954 unsigned char &SID,
955 unsigned char &WindlassIdentifier,
956 tN2kWindlassDirectionControl &WindlassDirectionControl,
957 unsigned char &SpeedControl,
958 tN2kSpeedType &SpeedControlType,
959 tN2kGenericStatusPair &AnchorDockingControl,
960 tN2kGenericStatusPair &PowerEnable,
961 tN2kGenericStatusPair &MechanicalLock,
962 tN2kGenericStatusPair &DeckAndAnchorWash,
963 tN2kGenericStatusPair &AnchorLight,
964 double &CommandTimeout,
965 tN2kWindlassControlEvents &WindlassControlEvents
966) {
967 if (N2kMsg.PGN!=128776L) return false;
968 int Index = 0;
969 unsigned char field;
970 SID = N2kMsg.GetByte(Index);
971 WindlassIdentifier = N2kMsg.GetByte(Index);
972 field = N2kMsg.GetByte(Index);
973 WindlassDirectionControl = (tN2kWindlassDirectionControl) (field & 0x03);
974 AnchorDockingControl = (tN2kGenericStatusPair) ((field >> 2) & 0x03);
975 SpeedControlType = (tN2kSpeedType) ((field >> 4) & 0x03);
976 SpeedControl = N2kMsg.GetByte(Index);
977 field = N2kMsg.GetByte(Index);
978 PowerEnable = (tN2kGenericStatusPair) (field & 0x03);
979 MechanicalLock = (tN2kGenericStatusPair) ((field >> 2) & 0x03);
980 DeckAndAnchorWash = (tN2kGenericStatusPair) ((field >> 4) & 0x03);
981 AnchorLight = (tN2kGenericStatusPair) ((field >> 6) & 0x03);
982 CommandTimeout = N2kMsg.Get1ByteUDouble(0.005, Index);
983 WindlassControlEvents.SetEvents(N2kMsg.GetByte(Index));
984 return true;
985}
986
987//*****************************************************************************
988// PGN128777 Windlass Operating Status
989//
990
992 tN2kMsg &N2kMsg,
993 unsigned char SID,
994 unsigned char WindlassIdentifier,
995 double RodeCounterValue,
996 double WindlassLineSpeed,
997 tN2kWindlassMotionStates WindlassMotionStatus,
998 tN2kRodeTypeStates RodeTypeStatus,
999 tN2kAnchorDockingStates AnchorDockingStatus,
1000 const tN2kWindlassOperatingEvents &WindlassOperatingEvents
1001){
1002 N2kMsg.SetPGN(128777L);
1003 N2kMsg.Priority=2;
1004 N2kMsg.AddByte(SID);
1005 N2kMsg.AddByte(WindlassIdentifier);
1006 N2kMsg.AddByte((unsigned char) (0xF0 | ((RodeTypeStatus & 0x03) << 2) | (WindlassMotionStatus & 0x03)));
1007 N2kMsg.Add2ByteUDouble(RodeCounterValue, 0.1);
1008 N2kMsg.Add2ByteUDouble(WindlassLineSpeed, 0.01);
1009 N2kMsg.AddByte((WindlassOperatingEvents.Events << 2) | (AnchorDockingStatus & 0x03));
1010}
1011
1013 const tN2kMsg &N2kMsg,
1014 unsigned char &SID,
1015 unsigned char &WindlassIdentifier,
1016 double &RodeCounterValue,
1017 double &WindlassLineSpeed,
1018 tN2kWindlassMotionStates &WindlassMotionStatus,
1019 tN2kRodeTypeStates &RodeTypeStatus,
1020 tN2kAnchorDockingStates &AnchorDockingStatus,
1021 tN2kWindlassOperatingEvents &WindlassOperatingEvents
1022){
1023 if (N2kMsg.PGN!=128777L) return false;
1024 int Index = 0;
1025 unsigned char field;
1026 SID = N2kMsg.GetByte(Index);
1027 WindlassIdentifier = N2kMsg.GetByte(Index);
1028 field = N2kMsg.GetByte(Index);
1029 WindlassMotionStatus = (tN2kWindlassMotionStates) (field & 0x03);
1030 RodeTypeStatus = (tN2kRodeTypeStates) ((field >> 2) & 0x03);
1031 RodeCounterValue = N2kMsg.Get2ByteUDouble(0.1, Index);
1032 WindlassLineSpeed = N2kMsg.Get2ByteUDouble(0.01, Index);
1033 field = N2kMsg.GetByte(Index);
1034 AnchorDockingStatus = (tN2kAnchorDockingStates) (field & 0x03);
1035 WindlassOperatingEvents.SetEvents(field >> 2);
1036 return true;
1037}
1038
1039//*****************************************************************************
1040// PGN128778 - Windlass Monitoring Status
1041//
1042
1044 tN2kMsg &N2kMsg,
1045 unsigned char SID,
1046 unsigned char WindlassIdentifier,
1047 double TotalMotorTime,
1048 double ControllerVoltage,
1049 double MotorCurrent,
1050 const tN2kWindlassMonitoringEvents &WindlassMonitoringEvents
1051){
1052 N2kMsg.SetPGN(128778L);
1053 N2kMsg.Priority=2;
1054 N2kMsg.AddByte(SID);
1055 N2kMsg.AddByte(WindlassIdentifier);
1056 N2kMsg.AddByte(WindlassMonitoringEvents.Events);
1057 N2kMsg.Add1ByteUDouble(ControllerVoltage, 0.2);
1058 N2kMsg.Add1ByteUDouble(MotorCurrent, 1.0);
1059 N2kMsg.Add2ByteUDouble(TotalMotorTime, 60.0);
1060 N2kMsg.AddByte(0xFF);
1061}
1062
1064 const tN2kMsg &N2kMsg,
1065 unsigned char &SID,
1066 unsigned char &WindlassIdentifier,
1067 double &TotalMotorTime,
1068 double &ControllerVoltage,
1069 double &MotorCurrent,
1070 tN2kWindlassMonitoringEvents &WindlassMonitoringEvents
1071) {
1072 if (N2kMsg.PGN!=128778L) return false;
1073 int Index = 0;
1074 SID = N2kMsg.GetByte(Index);
1075 WindlassIdentifier = N2kMsg.GetByte(Index);
1076 WindlassMonitoringEvents.SetEvents(N2kMsg.GetByte(Index));
1077 ControllerVoltage = N2kMsg.Get1ByteUDouble(0.2, Index);
1078 MotorCurrent = N2kMsg.Get1ByteUDouble(1.0, Index);
1079 TotalMotorTime = N2kMsg.Get2ByteUDouble(60.0, Index);
1080 return true;
1081}
1082
1083//*****************************************************************************
1084// Lat long rapid
1085void SetN2kPGN129025(tN2kMsg &N2kMsg, double Latitude, double Longitude) {
1086 N2kMsg.SetPGN(129025L);
1087 N2kMsg.Priority=2;
1088 N2kMsg.Add4ByteDouble(Latitude,1e-7);
1089 N2kMsg.Add4ByteDouble(Longitude,1e-7);
1090}
1091
1092bool ParseN2kPGN129025(const tN2kMsg &N2kMsg, double &Latitude, double &Longitude) {
1093 if (N2kMsg.PGN!=129025L) return false;
1094
1095 int Index = 0;
1096 Latitude=N2kMsg.Get4ByteDouble(1e-7, Index);
1097 Longitude=N2kMsg.Get4ByteDouble(1e-7, Index);
1098 return true;
1099}
1100//*****************************************************************************
1101// COG SOG rapid
1102// COG should be in radians
1103// SOG should be in m/s
1104void SetN2kPGN129026(tN2kMsg &N2kMsg, unsigned char SID, tN2kHeadingReference ref, double COG, double SOG) {
1105 N2kMsg.SetPGN(129026L);
1106 N2kMsg.Priority=2;
1107 N2kMsg.AddByte(SID);
1108 N2kMsg.AddByte( (((unsigned char)(ref)) & 0x03) | 0xfc );
1109 N2kMsg.Add2ByteUDouble(COG,0.0001); //0.0057295779513082332);
1110 N2kMsg.Add2ByteUDouble(SOG,0.01);
1111 N2kMsg.AddByte(0xff); // Reserved
1112 N2kMsg.AddByte(0xff); // Reserved
1113}
1114
1115bool ParseN2kPGN129026(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kHeadingReference &ref, double &COG, double &SOG) {
1116 if (N2kMsg.PGN!=129026L) return false;
1117 int Index=0;
1118 unsigned char b;
1119
1120 SID=N2kMsg.GetByte(Index);
1121 b=N2kMsg.GetByte(Index); ref=(tN2kHeadingReference)( b & 0x03 );
1122 COG=N2kMsg.Get2ByteUDouble(0.0001,Index);
1123 SOG=N2kMsg.Get2ByteUDouble(0.01,Index);
1124
1125 return true;
1126}
1127
1128//*****************************************************************************
1129// GNSS Position Data
1130void SetN2kPGN129029(tN2kMsg &N2kMsg, unsigned char SID, uint16_t DaysSince1970, double SecondsSinceMidnight,
1131 double Latitude, double Longitude, double Altitude,
1132 tN2kGNSStype GNSStype, tN2kGNSSmethod GNSSmethod,
1133 unsigned char nSatellites, double HDOP, double PDOP, double GeoidalSeparation,
1134 unsigned char nReferenceStations, tN2kGNSStype ReferenceStationType, uint16_t ReferenceSationID,
1135 double AgeOfCorrection
1136 ) {
1137
1138
1139 N2kMsg.SetPGN(129029L);
1140 N2kMsg.Priority=3;
1141 N2kMsg.AddByte(SID);
1142 N2kMsg.Add2ByteUInt(DaysSince1970);
1143 N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
1144 N2kMsg.Add8ByteDouble(Latitude,1e-16);
1145 N2kMsg.Add8ByteDouble(Longitude,1e-16);
1146 N2kMsg.Add8ByteDouble(Altitude,1e-6);
1147 N2kMsg.AddByte( (((unsigned char) GNSStype) & 0x0f) | (((unsigned char) GNSSmethod) & 0x0f)<<4 );
1148 N2kMsg.AddByte(1 | 0xfc); // Integrity 2 bit, reserved 6 bits
1149 N2kMsg.AddByte(nSatellites);
1150 N2kMsg.Add2ByteDouble(HDOP,0.01);
1151 N2kMsg.Add2ByteDouble(PDOP,0.01);
1152 N2kMsg.Add4ByteDouble(GeoidalSeparation,0.01);
1153 if (nReferenceStations!=0xff && nReferenceStations>0) {
1154 N2kMsg.AddByte(1); // Note that we have values for only one reference station, so pass only one values.
1155 N2kMsg.Add2ByteInt( (((int)ReferenceStationType) & 0x0f) | ReferenceSationID<<4 );
1156 N2kMsg.Add2ByteUDouble(AgeOfCorrection,0.01);
1157 } else N2kMsg.AddByte(nReferenceStations);
1158}
1159
1160bool ParseN2kPGN129029(const tN2kMsg &N2kMsg, unsigned char &SID, uint16_t &DaysSince1970, double &SecondsSinceMidnight,
1161 double &Latitude, double &Longitude, double &Altitude,
1162 tN2kGNSStype &GNSStype, tN2kGNSSmethod &GNSSmethod,
1163 uint8_t &nSatellites, double &HDOP, double &PDOP, double &GeoidalSeparation,
1164 uint8_t &nReferenceStations, tN2kGNSStype &ReferenceStationType, uint16_t &ReferenceSationID,
1165 double &AgeOfCorrection
1166 ) {
1167 if (N2kMsg.PGN!=129029L) return false;
1168 int Index=0;
1169 unsigned char vb;
1170 int16_t vi;
1171
1172 SID=N2kMsg.GetByte(Index);
1173 DaysSince1970=N2kMsg.Get2ByteUInt(Index);
1174 SecondsSinceMidnight=N2kMsg.Get4ByteUDouble(0.0001,Index);
1175 Latitude=N2kMsg.Get8ByteDouble(1e-16,Index);
1176 Longitude=N2kMsg.Get8ByteDouble(1e-16,Index);
1177 Altitude=N2kMsg.Get8ByteDouble(1e-6,Index);
1178 vb=N2kMsg.GetByte(Index); GNSStype=(tN2kGNSStype)(vb & 0x0f); GNSSmethod=(tN2kGNSSmethod)((vb>>4) & 0x0f);
1179 vb=N2kMsg.GetByte(Index); // Integrity 2 bit, reserved 6 bits
1180 nSatellites=N2kMsg.GetByte(Index);
1181 HDOP=N2kMsg.Get2ByteDouble(0.01,Index);
1182 PDOP=N2kMsg.Get2ByteDouble(0.01,Index);
1183 GeoidalSeparation=N2kMsg.Get4ByteDouble(0.01,Index);
1184 nReferenceStations=N2kMsg.GetByte(Index);
1185 if (nReferenceStations!=N2kUInt8NA && nReferenceStations>0) {
1186 // Note that we return real number of stations, but we only have variabes for one.
1187 vi=N2kMsg.Get2ByteUInt(Index); ReferenceStationType=(tN2kGNSStype)(vi & 0x0f); ReferenceSationID=(vi>>4);
1188 AgeOfCorrection=N2kMsg.Get2ByteUDouble(0.01,Index);
1189 } else {
1190 ReferenceStationType = N2kGNSSt_GPS;
1191 ReferenceSationID = N2kInt16NA;
1192 AgeOfCorrection = N2kDoubleNA;
1193 }
1194
1195 return true;
1196}
1197
1198//*****************************************************************************
1199// Date,Time & Local offset
1200void SetN2kPGN129033(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, int16_t LocalOffset) {
1201 N2kMsg.SetPGN(129033L);
1202 N2kMsg.Priority=3;
1203 N2kMsg.Add2ByteUInt(DaysSince1970);
1204 N2kMsg.Add4ByteUDouble(SecondsSinceMidnight,0.0001);
1205 N2kMsg.Add2ByteInt(LocalOffset);
1206}
1207
1208bool ParseN2kPGN129033(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, int16_t &LocalOffset) {
1209 if ( N2kMsg.PGN != 129033L ) return false;
1210
1211 int Index = 0;
1212
1213 DaysSince1970 = N2kMsg.Get2ByteUInt(Index);
1214 SecondsSinceMidnight = N2kMsg.Get4ByteUDouble(0.0001, Index);
1215 LocalOffset = N2kMsg.Get2ByteInt(Index);
1216 return true;
1217}
1218
1219//*****************************************************************************
1220// GNSS DOP data
1221void SetN2kPGN129539(tN2kMsg& N2kMsg, unsigned char SID, tN2kGNSSDOPmode DesiredMode, tN2kGNSSDOPmode ActualMode,
1222 double HDOP, double VDOP, double TDOP)
1223{
1224 N2kMsg.SetPGN(129539L);
1225 N2kMsg.Priority = 6;
1226 N2kMsg.AddByte(SID);
1227 N2kMsg.AddByte( 0xc0 | ( (ActualMode & 0x07) << 3 ) | (DesiredMode & 0x07) );
1228 N2kMsg.Add2ByteDouble(HDOP, 0.01);
1229 N2kMsg.Add2ByteDouble(VDOP, 0.01);
1230 N2kMsg.Add2ByteDouble(TDOP, 0.01);
1231}
1232
1233bool ParseN2kPgn129539(const tN2kMsg& N2kMsg, unsigned char& SID, tN2kGNSSDOPmode& DesiredMode, tN2kGNSSDOPmode& ActualMode,
1234 double& HDOP, double& VDOP, double& TDOP)
1235{
1236 if(N2kMsg.PGN != 129539L)
1237 return false;
1238
1239 unsigned char modes;
1240 int Index = 0;
1241
1242 SID = N2kMsg.GetByte(Index);
1243 modes = N2kMsg.GetByte(Index);
1244 DesiredMode = (tN2kGNSSDOPmode)( modes & 0x07 );
1245 ActualMode = (tN2kGNSSDOPmode)( (modes>>3) & 0x07 );
1246 HDOP = N2kMsg.Get2ByteDouble(0.01, Index);
1247 VDOP = N2kMsg.Get2ByteDouble(0.01, Index);
1248 TDOP = N2kMsg.Get2ByteDouble(0.01, Index);
1249 return true;
1250}
1251
1252//*****************************************************************************
1253// GNSS Satellites in View
1254
1255#define MaxSatelliteInfoCount 18 // Fast packet can hold this max stellites. Maybe later more with TP message.
1256
1257void SetN2kPGN129540(tN2kMsg& N2kMsg, unsigned char SID, tN2kRangeResidualMode Mode) {
1258 N2kMsg.SetPGN(129540L);
1259 N2kMsg.Priority=6;
1260 N2kMsg.AddByte(SID);
1261 N2kMsg.AddByte(0xfc | (Mode & 0x03) );
1262 N2kMsg.AddByte(0); // Init satellite count to 0
1263}
1264
1265bool AppendN2kPGN129540(tN2kMsg& N2kMsg, const tSatelliteInfo& SatelliteInfo) {
1266 if(N2kMsg.PGN != 129540L) return false;
1267
1268 int Index = 2;
1269 uint8_t NumberOfSVs=N2kMsg.GetByte(Index);
1270
1271 if ( NumberOfSVs>=MaxSatelliteInfoCount ) return false;
1272
1273 NumberOfSVs++;
1274 Index=2;
1275 N2kMsg.SetByte(NumberOfSVs, Index); // increment the number satellites
1276 // add the new satellite info
1277 N2kMsg.AddByte(SatelliteInfo.PRN);
1278 N2kMsg.Add2ByteDouble(SatelliteInfo.Elevation,1e-4L);
1279 N2kMsg.Add2ByteUDouble(SatelliteInfo.Azimuth,1e-4L);
1280 N2kMsg.Add2ByteDouble(SatelliteInfo.SNR,1e-2L);
1281 N2kMsg.Add4ByteDouble(SatelliteInfo.RangeResiduals,1e-5L);
1282 N2kMsg.AddByte(0xf0 | SatelliteInfo.UsageStatus);
1283
1284 return true;
1285}
1286
1287bool ParseN2kPGN129540(const tN2kMsg& N2kMsg, unsigned char& SID, tN2kRangeResidualMode &Mode, uint8_t& NumberOfSVs) {
1288 if(N2kMsg.PGN != 129540L) return false;
1289
1290 int Index = 0;
1291
1292 SID = N2kMsg.GetByte(Index);
1293 Mode = (tN2kRangeResidualMode)(N2kMsg.GetByte(Index) & 0x03);
1294 NumberOfSVs = N2kMsg.GetByte(Index);
1295
1296 return true;
1297}
1298
1299bool ParseN2kPGN129540(const tN2kMsg& N2kMsg, uint8_t SVIndex, tSatelliteInfo& SatelliteInfo) {
1300 if(N2kMsg.PGN != 129540L) return false;
1301
1302 int Index = 2;
1303 uint8_t NumberOfSVs=N2kMsg.GetByte(Index);
1304 bool ret=( NumberOfSVs<MaxSatelliteInfoCount && SVIndex<NumberOfSVs );
1305
1306 if ( ret ) {
1307 Index=3+SVIndex*12;
1308 SatelliteInfo.PRN=N2kMsg.GetByte(Index);
1309 SatelliteInfo.Elevation=N2kMsg.Get2ByteDouble(1e-4L,Index);
1310 SatelliteInfo.Azimuth=N2kMsg.Get2ByteUDouble(1e-4L,Index);
1311 SatelliteInfo.SNR=N2kMsg.Get2ByteDouble(1e-2L,Index);
1312 SatelliteInfo.RangeResiduals=N2kMsg.Get4ByteDouble(1e-5L,Index);;
1313 SatelliteInfo.UsageStatus=(tN2kPRNUsageStatus)(N2kMsg.GetByte(Index) & 0x0f);
1314 } else {
1315 SatelliteInfo.PRN=0xff;
1316 SatelliteInfo.Elevation=N2kDoubleNA;
1317 SatelliteInfo.Azimuth=N2kDoubleNA;
1318 SatelliteInfo.SNR=N2kDoubleNA;
1319 SatelliteInfo.RangeResiduals=N2kDoubleNA;
1320 SatelliteInfo.UsageStatus=N2kDD124_Unavailable;
1321 }
1322
1323 return ret;
1324}
1325
1326//*****************************************************************************
1327// AIS position report (class A 129038)
1328// Latitude and Longitude in degrees (1e7)
1329// COG and Heading in radians (1e4)
1330void SetN2kPGN129038(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID,
1331 double Latitude, double Longitude, bool Accuracy, bool RAIM,
1332 uint8_t Seconds, double COG, double SOG, tN2kAISTransceiverInformation AISTransceiverInformation,
1333 double Heading, double ROT, tN2kAISNavStatus NavStatus)
1334{
1335 N2kMsg.SetPGN(129038L);
1336 N2kMsg.Priority=4;
1337 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
1338 N2kMsg.Add4ByteUInt(UserID);
1339 N2kMsg.Add4ByteDouble(Longitude, 1e-07);
1340 N2kMsg.Add4ByteDouble(Latitude, 1e-07);
1341 N2kMsg.AddByte((Seconds & 0x3f)<<2 | (RAIM & 0x01)<<1 | (Accuracy & 0x01));
1342 N2kMsg.Add2ByteUDouble(COG, 1e-04);
1343 N2kMsg.Add2ByteUDouble(SOG, 0.01);
1344 // Communication State (19 bits) and AIS transceiver information (5 bits)
1345 int32_t CSandTI=0x07ffff | ((AISTransceiverInformation & 0x1f) << 19);
1346 N2kMsg.Add3ByteInt(CSandTI);
1347 N2kMsg.Add2ByteUDouble(Heading, 1e-04);
1348 N2kMsg.Add2ByteDouble(ROT, 3.125E-05); // 1e-3/32.0
1349 N2kMsg.AddByte(0xF0 | (NavStatus & 0x0f));
1350 N2kMsg.AddByte(0xff); // Reserved
1351}
1352
1353bool ParseN2kPGN129038(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID,
1354 double &Latitude, double &Longitude, bool &Accuracy, bool &RAIM, uint8_t &Seconds,
1355 double &COG, double &SOG, double &Heading, double &ROT, tN2kAISNavStatus &NavStatus)
1356{
1357 if (N2kMsg.PGN!=129038L) return false;
1358
1359 int Index=0;
1360 unsigned char vb;
1361
1362 vb=N2kMsg.GetByte(Index); MessageID=(vb & 0x3f); Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1363 UserID=N2kMsg.Get4ByteUInt(Index);
1364 Longitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1365 Latitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1366 vb=N2kMsg.GetByte(Index); Accuracy=(vb & 0x01); RAIM=(vb>>1 & 0x01); Seconds=(vb>>2 & 0x3f);
1367 COG=N2kMsg.Get2ByteUDouble(1e-04, Index);
1368 SOG=N2kMsg.Get2ByteUDouble(0.01, Index);
1369 vb=N2kMsg.GetByte(Index); // Communication State (19 bits)
1370 vb=N2kMsg.GetByte(Index);
1371 vb=N2kMsg.GetByte(Index); // AIS transceiver information (5 bits)
1372 Heading=N2kMsg.Get2ByteUDouble(1e-04, Index);
1373 ROT=N2kMsg.Get2ByteDouble(3.125E-05, Index); // 1e-3/32.0
1374 vb=N2kMsg.GetByte(Index); NavStatus=(tN2kAISNavStatus)(vb & 0x0f);
1375 vb=N2kMsg.GetByte(Index); // Reserved
1376
1377 return true;
1378}
1379
1380//*****************************************************************************
1381// AIS position report (class B 129039)
1382void SetN2kPGN129039(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID,
1383 double Latitude, double Longitude, bool Accuracy, bool RAIM,
1384 uint8_t Seconds, double COG, double SOG, tN2kAISTransceiverInformation AISTransceiverInformation,
1385 double Heading, tN2kAISUnit Unit, bool Display, bool DSC, bool Band, bool Msg22, tN2kAISMode Mode,
1386 bool State, unsigned char SID)
1387{
1388 N2kMsg.SetPGN(129039L);
1389 N2kMsg.Priority=4;
1390 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
1391 N2kMsg.Add4ByteUInt(UserID);
1392 N2kMsg.Add4ByteDouble(Longitude, 1e-07);
1393 N2kMsg.Add4ByteDouble(Latitude, 1e-07);
1394 N2kMsg.AddByte((Seconds & 0x3f)<<2 | (RAIM & 0x01)<<1 | (Accuracy & 0x01));
1395 N2kMsg.Add2ByteUDouble(COG, 1e-04);
1396 N2kMsg.Add2ByteUDouble(SOG, 0.01);
1397 N2kMsg.AddByte(0xff); // Communication State (19 bits)
1398 N2kMsg.AddByte(0xff);
1399 N2kMsg.AddByte(((0x1f & AISTransceiverInformation) << 3) | 0x7);
1400 N2kMsg.Add2ByteUDouble(Heading, 1e-04);
1401 N2kMsg.AddByte(0xff); // Regional application
1402 N2kMsg.AddByte((Mode & 0x01)<<7 | (Msg22 & 0x01)<<6 | (Band & 0x01)<<5 |
1403 (DSC & 0x01)<<4 | (Display & 0x01)<<3 | (Unit & 0x01)<<2);
1404 N2kMsg.AddByte(0xfe | (State & 0x01));
1405 N2kMsg.AddByte(SID);
1406}
1407
1408
1409bool ParseN2kPGN129039(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID,
1410 double &Latitude, double &Longitude, bool &Accuracy, bool &RAIM,
1411 uint8_t &Seconds, double &COG, double &SOG, tN2kAISTransceiverInformation &AISTransceiverInformation,
1412 double &Heading, tN2kAISUnit &Unit, bool &Display, bool &DSC, bool &Band, bool &Msg22,
1413 tN2kAISMode &Mode, bool &State)
1414{
1415 if (N2kMsg.PGN!=129039L) return false;
1416
1417 int Index=0;
1418 unsigned char vb;
1419
1420 vb=N2kMsg.GetByte(Index); MessageID=(vb & 0x3f); Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1421 UserID=N2kMsg.Get4ByteUInt(Index);
1422 Longitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1423 Latitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1424 vb=N2kMsg.GetByte(Index); Accuracy=(vb & 0x01); RAIM=(vb>>1 & 0x01); Seconds=(vb>>2 & 0x3f);
1425 COG=N2kMsg.Get2ByteUDouble(1e-04, Index);
1426 SOG=N2kMsg.Get2ByteUDouble(0.01, Index);
1427 vb=N2kMsg.GetByte(Index); // Communication State (19 bits)
1428 vb=N2kMsg.GetByte(Index);
1429 vb=N2kMsg.GetByte(Index); // AIS transceiver information (5 bits)
1430 AISTransceiverInformation = (tN2kAISTransceiverInformation)((vb >> 3) & 0x1f);
1431 Heading=N2kMsg.Get2ByteUDouble(1e-04, Index);
1432 vb=N2kMsg.GetByte(Index); // Regional application
1433 vb=N2kMsg.GetByte(Index);
1434 Unit=(tN2kAISUnit)(vb>>2 & 0x01); Display=(vb>>3 & 0x01); DSC=(vb>>4 & 0x01);
1435 Band=(vb>>5 & 0x01); Msg22=(vb>>6 & 0x01); Mode=(tN2kAISMode)(vb>>7 & 0x01);
1436 vb=N2kMsg.GetByte(Index); State=(vb & 0x01);
1437
1438 return true;
1439}
1440
1441//*****************************************************************************
1442// AIS Aids to Navigation (AtoN) Report (PGN 129041)
1443void SetN2kPGN129041(tN2kMsg &N2kMsg, const tN2kAISAtoNReportData &N2kData) {
1444 N2kMsg.SetPGN(129041L);
1445 N2kMsg.Priority=4;
1446 N2kMsg.AddByte((N2kData.Repeat & 0x03) << 6 | (N2kData.MessageID & 0x3f));
1447 N2kMsg.Add4ByteUInt(N2kData.UserID);
1448 N2kMsg.Add4ByteDouble(N2kData.Longitude, 1e-07);
1449 N2kMsg.Add4ByteDouble(N2kData.Latitude, 1e-07);
1450 N2kMsg.AddByte((N2kData.Seconds & 0x3f)<<2 | (N2kData.RAIM & 0x01)<<1 | (N2kData.Accuracy & 0x01));
1451 N2kMsg.Add2ByteUDouble(N2kData.Length, 0.1);
1452 N2kMsg.Add2ByteUDouble(N2kData.Beam, 0.1);
1453 N2kMsg.Add2ByteUDouble(N2kData.PositionReferenceStarboard, 0.1);
1454 N2kMsg.Add2ByteUDouble(N2kData.PositionReferenceTrueNorth, 0.1);
1455 N2kMsg.AddByte((N2kData.AssignedModeFlag & 0x01) << 7
1456 | (N2kData.VirtualAtoNFlag & 0x01) << 6
1457 | (N2kData.OffPositionIndicator & 0x01) << 5
1458 | (N2kData.AtoNType & 0x1f));
1459 N2kMsg.AddByte((N2kData.GNSSType & 0x0F) << 1 | 0xe0);
1460 N2kMsg.AddByte(N2kData.AtoNStatus);
1461 N2kMsg.AddByte((N2kData.AISTransceiverInformation & 0x1f) | 0xe0);
1462 N2kMsg.AddVarStr((char*)N2kData.AtoNName);
1463}
1464
1465
1466bool ParseN2kPGN129041(const tN2kMsg &N2kMsg, tN2kAISAtoNReportData &N2kData) {
1467 if (N2kMsg.PGN!=129041L) return false;
1468
1469 int Index=0;
1470 unsigned char vb;
1471 vb=N2kMsg.GetByte(Index); N2kData.MessageID=(vb & 0x3f); N2kData.Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1472 N2kData.UserID=N2kMsg.Get4ByteUInt(Index);
1473 N2kData.Longitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1474 N2kData.Latitude=N2kMsg.Get4ByteDouble(1e-07, Index);
1475 vb=N2kMsg.GetByte(Index); N2kData.Accuracy=(vb & 0x01); N2kData.RAIM=(vb>>1 & 0x01); N2kData.Seconds=(vb>>2 & 0x3f);
1476 N2kData.Length=N2kMsg.Get2ByteDouble(0.1, Index);
1477 N2kData.Beam=N2kMsg.Get2ByteDouble(0.1, Index);
1478 N2kData.PositionReferenceStarboard=N2kMsg.Get2ByteDouble(0.1, Index);
1479 N2kData.PositionReferenceTrueNorth=N2kMsg.Get2ByteDouble(0.1, Index);
1480 vb=N2kMsg.GetByte(Index);
1481 N2kData.AtoNType=(tN2kAISAtoNType)(vb & 0x1f);
1482 N2kData.OffPositionIndicator=(vb >> 5 & 0x01);
1483 N2kData.VirtualAtoNFlag=(vb >> 6 & 0x01);
1484 N2kData.AssignedModeFlag=(vb >> 7 & 0x01);
1485 N2kData.GNSSType = (tN2kGNSStype)((N2kMsg.GetByte(Index) >> 1) & 0x0f);
1486 N2kData.AtoNStatus=N2kMsg.GetByte(Index);
1487 N2kData.AISTransceiverInformation = (tN2kAISTransceiverInformation)(N2kMsg.GetByte(Index) & 0x1f);
1488 size_t AtoNNameSize = sizeof(N2kData.AtoNName);
1489 N2kMsg.GetVarStr(AtoNNameSize, (char*)N2kData.AtoNName, Index);
1490
1491 return true;
1492}
1493
1494//*****************************************************************************
1495// Cross Track Error
1496void SetN2kPGN129283(tN2kMsg &N2kMsg, unsigned char SID, tN2kXTEMode XTEMode, bool NavigationTerminated, double XTE) {
1497 N2kMsg.SetPGN(129283L);
1498 N2kMsg.Priority=3;
1499 N2kMsg.AddByte(SID);
1500 N2kMsg.AddByte((char)XTEMode | (NavigationTerminated?0x40:0));
1501 N2kMsg.Add4ByteDouble(XTE,0.01);
1502 N2kMsg.AddByte(0xff); // Reserved
1503 N2kMsg.AddByte(0xff); // Reserved
1504}
1505
1506bool ParseN2kPGN129283(const tN2kMsg &N2kMsg, unsigned char& SID, tN2kXTEMode& XTEMode, bool& NavigationTerminated, double& XTE) {
1507 if(N2kMsg.PGN != 129283L)
1508 return false;
1509
1510 int Index = 0;
1511 unsigned char c;
1512 SID = N2kMsg.GetByte(Index);
1513 c = N2kMsg.GetByte(Index);
1514 XTEMode = (tN2kXTEMode)(c & 0x0F);
1515 NavigationTerminated = c & 0x40;
1516 XTE = N2kMsg.Get4ByteDouble(0.01, Index);
1517 return true;
1518}
1519
1520//*****************************************************************************
1521// Navigation info
1522void SetN2kPGN129284(tN2kMsg &N2kMsg, unsigned char SID, double DistanceToWaypoint, tN2kHeadingReference BearingReference,
1523 bool PerpendicularCrossed, bool ArrivalCircleEntered, tN2kDistanceCalculationType CalculationType,
1524 double ETATime, int16_t ETADate, double BearingOriginToDestinationWaypoint, double BearingPositionToDestinationWaypoint,
1525 uint32_t OriginWaypointNumber, uint32_t DestinationWaypointNumber,
1526 double DestinationLatitude, double DestinationLongitude, double WaypointClosingVelocity) {
1527 N2kMsg.SetPGN(129284L);
1528 N2kMsg.Priority=3;
1529 N2kMsg.AddByte(SID);
1530 N2kMsg.Add4ByteUDouble(DistanceToWaypoint,0.01);
1531 N2kMsg.AddByte((char)BearingReference | (PerpendicularCrossed?0x04:0) | (ArrivalCircleEntered?0x10:0) | (CalculationType==N2kdct_RhumbLine?0x40:0));
1532 N2kMsg.Add4ByteUDouble(ETATime,0.0001);
1533 N2kMsg.Add2ByteUInt(ETADate);
1534 N2kMsg.Add2ByteUDouble(BearingOriginToDestinationWaypoint,0.0001);
1535 N2kMsg.Add2ByteUDouble(BearingPositionToDestinationWaypoint,0.0001);
1536 N2kMsg.Add4ByteUInt(OriginWaypointNumber);
1537 N2kMsg.Add4ByteUInt(DestinationWaypointNumber);
1538 N2kMsg.Add4ByteDouble(DestinationLatitude,1e-07);
1539 N2kMsg.Add4ByteDouble(DestinationLongitude,1e-07);
1540 N2kMsg.Add2ByteDouble(WaypointClosingVelocity,0.01);
1541}
1542
1543bool ParseN2kPGN129284(const tN2kMsg &N2kMsg, unsigned char& SID, double& DistanceToWaypoint, tN2kHeadingReference& BearingReference,
1544 bool& PerpendicularCrossed, bool& ArrivalCircleEntered, tN2kDistanceCalculationType& CalculationType,
1545 double& ETATime, int16_t& ETADate, double& BearingOriginToDestinationWaypoint, double& BearingPositionToDestinationWaypoint,
1546 uint32_t& OriginWaypointNumber, uint32_t& DestinationWaypointNumber,
1547 double& DestinationLatitude, double& DestinationLongitude, double& WaypointClosingVelocity) {
1548
1549 if(N2kMsg.PGN != 129284L)
1550 return false;
1551
1552 int Index=0;
1553 unsigned char c;
1554 SID = N2kMsg.GetByte(Index);
1555 DistanceToWaypoint = N2kMsg.Get4ByteUDouble(0.01, Index);
1556 c = N2kMsg.GetByte(Index);
1557 BearingReference = c & 0x01 ? N2khr_magnetic : N2khr_true;
1558 PerpendicularCrossed = c & 0x04;
1559 ArrivalCircleEntered = c & 0x10;
1560 CalculationType = c & 0x40 ? N2kdct_RhumbLine : N2kdct_GreatCircle;
1561 ETATime = N2kMsg.Get4ByteUDouble(0.0001, Index);
1562 ETADate = N2kMsg.Get2ByteUInt(Index);
1563 BearingOriginToDestinationWaypoint = N2kMsg.Get2ByteUDouble(0.0001, Index);
1564 BearingPositionToDestinationWaypoint = N2kMsg.Get2ByteUDouble(0.0001, Index);
1565 OriginWaypointNumber = N2kMsg.Get4ByteUInt(Index);
1566 DestinationWaypointNumber = N2kMsg.Get4ByteUInt(Index);
1567 DestinationLatitude = N2kMsg.Get4ByteDouble(1e-07, Index);
1568 DestinationLongitude = N2kMsg.Get4ByteDouble(1e-07, Index);
1569 WaypointClosingVelocity = N2kMsg.Get2ByteDouble(0.01, Index);
1570 return true;
1571}
1572
1573//*****************************************************************************
1574// Waypoint list
1575void SetN2kPGN129285(tN2kMsg &N2kMsg, uint16_t Start, uint16_t Database, uint16_t Route,
1576 tN2kNavigationDirection NavDirection, const char* RouteName, tN2kGenericStatusPair SupplementaryData) {
1577 N2kMsg.SetPGN(129285L);
1578 N2kMsg.Priority=6;
1579 N2kMsg.Add2ByteUInt(Start);
1580 N2kMsg.Add2ByteUInt(0); // number of items initially 0
1581 N2kMsg.Add2ByteUInt(Database);
1582 N2kMsg.Add2ByteUInt(Route);
1583 N2kMsg.AddByte(0xE0 | (SupplementaryData & 0x03)<<3 | (NavDirection & 0x07));
1584 N2kMsg.AddVarStr(RouteName);
1585 N2kMsg.AddByte(0xff); // reserved
1586}
1587
1588bool AppendN2kPGN129285(tN2kMsg &N2kMsg, uint16_t ID, const char* Name, double Latitude, double Longitude) {
1589 if (N2kMsg.PGN!=129285L) return false;
1590
1591 int NumItemsIdx, len;
1592 uint16_t NumItems;
1593
1594 len = 12 + strlen(Name);
1595
1596 if ( N2kMsg.DataLen + len < N2kMsg.MaxDataLen ) {
1597 NumItemsIdx = 2;
1598 NumItems = N2kMsg.Get2ByteUInt(NumItemsIdx); // get and increment the number of items
1599 NumItemsIdx = 2;
1600 N2kMsg.Set2ByteUInt(++NumItems, NumItemsIdx); // increment the number of items
1601 N2kMsg.Add2ByteUInt(ID); // add the new item
1602 N2kMsg.AddVarStr(Name);
1603 N2kMsg.Add4ByteDouble(Latitude,1e-07);
1604 N2kMsg.Add4ByteDouble(Longitude,1e-07);
1605 return true;
1606 } else {
1607 return false;
1608 }
1609}
1610
1611//*****************************************************************************
1612// AIS static data A
1613void SetN2kPGN129794(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID,
1614 uint32_t IMOnumber, const char *Callsign, const char *Name, uint8_t VesselType, double Length,
1615 double Beam, double PosRefStbd, double PosRefBow, uint16_t ETAdate, double ETAtime,
1616 double Draught, const char *Destination, tN2kAISVersion AISversion, tN2kGNSStype GNSStype,
1618{
1619 N2kMsg.SetPGN(129794L);
1620 N2kMsg.Priority=6;
1621 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
1622 N2kMsg.Add4ByteUInt(UserID);
1623 N2kMsg.Add4ByteUInt(IMOnumber);
1624 N2kMsg.AddAISStr(Callsign,7);
1625 N2kMsg.AddAISStr(Name, 20);
1626 N2kMsg.AddByte(VesselType);
1627 N2kMsg.Add2ByteDouble(Length, 0.1);
1628 N2kMsg.Add2ByteDouble(Beam, 0.1);
1629 N2kMsg.Add2ByteDouble(PosRefStbd, 0.1);
1630 N2kMsg.Add2ByteDouble(PosRefBow, 0.1);
1631 N2kMsg.Add2ByteUInt(ETAdate);
1632 N2kMsg.Add4ByteUDouble(ETAtime, 0.0001);
1633 N2kMsg.Add2ByteDouble(Draught, 0.01);
1634 N2kMsg.AddAISStr(Destination, 20);
1635 N2kMsg.AddByte((DTE & 0x01)<<6 | (GNSStype & 0x0f)<<2 | (AISversion & 0x03));
1636 N2kMsg.AddByte(0xe0 | (AISinfo & 0x1f));
1637 N2kMsg.AddByte(0xff);
1638}
1639
1640bool ParseN2kPGN129794(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID,
1641 uint32_t &IMOnumber, char *Callsign, size_t CallsignBufSize, char *Name, size_t NameBufSize,uint8_t &VesselType, double &Length,
1642 double &Beam, double &PosRefStbd, double &PosRefBow, uint16_t &ETAdate, double &ETAtime,
1643 double &Draught, char *Destination, size_t DestinationBufSize, tN2kAISVersion &AISversion, tN2kGNSStype &GNSStype,
1645{
1646 if (N2kMsg.PGN!=129794L) return false;
1647
1648 int Index=0;
1649 unsigned char vb;
1650
1651 vb=N2kMsg.GetByte(Index); MessageID=(vb & 0x3f); Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1652 UserID=N2kMsg.Get4ByteUInt(Index);
1653 IMOnumber=N2kMsg.Get4ByteUInt(Index);
1654 N2kMsg.GetStr(CallsignBufSize, Callsign, 7, '@', Index);
1655 N2kMsg.GetStr(NameBufSize, Name, 20, '@', Index);
1656 VesselType=N2kMsg.GetByte(Index);
1657 Length=N2kMsg.Get2ByteDouble(0.1, Index);
1658 Beam=N2kMsg.Get2ByteDouble(0.1, Index);
1659 PosRefStbd=N2kMsg.Get2ByteDouble(0.1, Index);
1660 PosRefBow=N2kMsg.Get2ByteDouble(0.1, Index);
1661 ETAdate=N2kMsg.Get2ByteUInt(Index);
1662 ETAtime=N2kMsg.Get4ByteUDouble(0.0001, Index);
1663 Draught=N2kMsg.Get2ByteDouble(0.01, Index);
1664 N2kMsg.GetStr(DestinationBufSize, Destination, 20, '@', Index);
1665 vb=N2kMsg.GetByte(Index); AISversion=(tN2kAISVersion)(vb & 0x03); GNSStype=(tN2kGNSStype)(vb>>2 & 0x0f); DTE=(tN2kAISDTE)(vb>>6 & 0x01);
1666 vb=N2kMsg.GetByte(Index); AISinfo=(tN2kAISTransceiverInformation)(vb & 0x1f);
1667
1668 return true;
1669}
1670
1671//*****************************************************************************
1672// AIS static data class B part A
1673void SetN2kPGN129809(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, const char *Name)
1674{
1675 N2kMsg.SetPGN(129809L);
1676 N2kMsg.Priority=6;
1677 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
1678 N2kMsg.Add4ByteUInt(UserID);
1679 N2kMsg.AddAISStr(Name, 20);
1680}
1681
1682bool ParseN2kPGN129809(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, char *Name, size_t NameBufSize)
1683{
1684 if (N2kMsg.PGN!=129809L) return false;
1685
1686 int Index=0;
1687 unsigned char vb;
1688
1689 vb=N2kMsg.GetByte(Index); MessageID=(vb & 0x3f); Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1690 UserID=N2kMsg.Get4ByteUInt(Index);
1691 N2kMsg.GetStr(NameBufSize, Name, 20, '@', Index);
1692
1693 return true;
1694}
1695
1696//*****************************************************************************
1697// AIS static data class B part B
1698void SetN2kPGN129810(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID,
1699 uint8_t VesselType, const char *Vendor, const char *Callsign, double Length, double Beam,
1700 double PosRefStbd, double PosRefBow, uint32_t MothershipID)
1701{
1702 N2kMsg.SetPGN(129810L);
1703 N2kMsg.Priority=6;
1704 N2kMsg.AddByte((Repeat & 0x03)<<6 | (MessageID & 0x3f));
1705 N2kMsg.Add4ByteUInt(UserID);
1706 N2kMsg.AddByte(VesselType);
1707 N2kMsg.AddAISStr(Vendor, 7);
1708 N2kMsg.AddAISStr(Callsign, 7);
1709 N2kMsg.Add2ByteUDouble(Length, 0.1);
1710 N2kMsg.Add2ByteUDouble(Beam, 0.1);
1711 N2kMsg.Add2ByteUDouble(PosRefStbd, 0.1);
1712 N2kMsg.Add2ByteUDouble(PosRefBow, 0.1);
1713 N2kMsg.Add4ByteUInt(MothershipID);
1714 N2kMsg.AddByte(0xff); // Reserved
1715}
1716
1717bool ParseN2kPGN129810(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID,
1718 uint8_t &VesselType, char *Vendor, size_t VendorBufSize, char *Callsign, size_t CallsignBufSize, double &Length, double &Beam,
1719 double &PosRefStbd, double &PosRefBow, uint32_t &MothershipID)
1720{
1721 if (N2kMsg.PGN!=129810L) return false;
1722
1723 int Index=0;
1724 unsigned char vb;
1725
1726 vb=N2kMsg.GetByte(Index); MessageID=(vb & 0x3f); Repeat=(tN2kAISRepeat)(vb>>6 & 0x03);
1727 UserID=N2kMsg.Get4ByteUInt(Index);
1728 VesselType=N2kMsg.GetByte(Index);
1729 N2kMsg.GetStr(VendorBufSize, Vendor, 7, '@', Index);
1730 N2kMsg.GetStr(CallsignBufSize, Callsign, 7, '@', Index);
1731 Length = N2kMsg.Get2ByteUDouble(0.1, Index);
1732 Beam = N2kMsg.Get2ByteUDouble(0.1, Index);
1733 PosRefStbd = N2kMsg.Get2ByteUDouble(0.1, Index);
1734 PosRefBow = N2kMsg.Get2ByteUDouble(0.1, Index);
1735 MothershipID = N2kMsg.Get4ByteUInt(Index);
1736
1737 return true;
1738}
1739
1740//*****************************************************************************
1741// Waypoint list
1742void SetN2kPGN130074(tN2kMsg &N2kMsg, uint16_t Start, uint16_t NumWaypoints, uint16_t Database) {
1743 N2kMsg.SetPGN(130074L);
1744 N2kMsg.Priority=7;
1745 N2kMsg.Add2ByteUInt(Start);
1746 N2kMsg.Add2ByteUInt(0); // set number of items to 0 initially
1747 N2kMsg.Add2ByteUInt(NumWaypoints);
1748 N2kMsg.Add2ByteUInt(Database);
1749 N2kMsg.AddByte(0xff); // Reserved
1750 N2kMsg.AddByte(0xff); // Reserved
1751}
1752
1753bool AppendN2kPGN130074(tN2kMsg &N2kMsg, uint16_t ID, char* Name, double Latitude, double Longitude) {
1754 if (N2kMsg.PGN!=130074L) return false;
1755
1756 unsigned int i;
1757 int NumItemsIdx, len;
1758 uint16_t NumItems;
1759
1760 if (strlen(Name) > 0)
1761 len = 12 + strlen(Name);
1762 else
1763 len = 13;
1764
1765 if (N2kMsg.DataLen + len < N2kMsg.MaxDataLen) {
1766 NumItemsIdx = 2;
1767 NumItems = N2kMsg.Get2ByteUInt(NumItemsIdx); // get and increment the number of items
1768 NumItemsIdx = 2;
1769 N2kMsg.Set2ByteUInt(++NumItems, NumItemsIdx); // increment the number of items
1770
1771 N2kMsg.Add2ByteUInt(ID);
1772 if (strlen(Name) == 0) {
1773 N2kMsg.AddByte(0x03);N2kMsg.AddByte(0x01);N2kMsg.AddByte(0x00);
1774 } else {
1775 N2kMsg.AddByte(strlen(Name)+2);N2kMsg.AddByte(0x01);
1776 for (i=0; i<strlen(Name); i++)
1777 N2kMsg.AddByte(Name[i]);
1778 }
1779 N2kMsg.Add4ByteDouble(Latitude,1e-07);
1780 N2kMsg.Add4ByteDouble(Longitude,1e-07);
1781 return true;
1782 } else
1783 return false;
1784}
1785
1786//*****************************************************************************
1787// Wind Speed
1788void SetN2kPGN130306(tN2kMsg &N2kMsg, unsigned char SID, double WindSpeed, double WindAngle, tN2kWindReference WindReference) {
1789 N2kMsg.SetPGN(130306L);
1790 N2kMsg.Priority=2;
1791 N2kMsg.AddByte(SID);
1792 N2kMsg.Add2ByteUDouble(WindSpeed,0.01);
1793 N2kMsg.Add2ByteUDouble(WindAngle,0.0001);
1794 N2kMsg.AddByte((unsigned char)WindReference);
1795 N2kMsg.AddByte(0xff); // Reserved
1796 N2kMsg.AddByte(0xff); // Reserved
1797}
1798
1799bool ParseN2kPGN130306(const tN2kMsg &N2kMsg, unsigned char &SID, double &WindSpeed, double &WindAngle, tN2kWindReference &WindReference) {
1800 if (N2kMsg.PGN!=130306L) return false;
1801 int Index=0;
1802 SID=N2kMsg.GetByte(Index);
1803 WindSpeed=N2kMsg.Get2ByteUDouble(0.01,Index);
1804 WindAngle=N2kMsg.Get2ByteUDouble(0.0001,Index);
1805 WindReference=(tN2kWindReference)(N2kMsg.GetByte(Index)&0x07);
1806
1807 return true;
1808}
1809
1810//*****************************************************************************
1811// Outside Environmental parameters
1812void SetN2kPGN130310(tN2kMsg &N2kMsg, unsigned char SID, double WaterTemperature,
1813 double OutsideAmbientAirTemperature, double AtmosphericPressure) {
1814 N2kMsg.SetPGN(130310L);
1815 N2kMsg.Priority=5;
1816 N2kMsg.AddByte(SID);
1817 N2kMsg.Add2ByteUDouble(WaterTemperature,0.01);
1818 N2kMsg.Add2ByteUDouble(OutsideAmbientAirTemperature,0.01);
1819 N2kMsg.Add2ByteUDouble(AtmosphericPressure,100);
1820 N2kMsg.AddByte(0xff); // reserved
1821}
1822
1823bool ParseN2kPGN130310(const tN2kMsg &N2kMsg, unsigned char &SID, double &WaterTemperature,
1824 double &OutsideAmbientAirTemperature, double &AtmosphericPressure) {
1825 if (N2kMsg.PGN!=130310L) return false;
1826 int Index=0;
1827 SID=N2kMsg.GetByte(Index);
1828 WaterTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
1829 OutsideAmbientAirTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
1830 AtmosphericPressure=N2kMsg.Get2ByteUDouble(100,Index);
1831
1832 return true;
1833}
1834
1835
1836//*****************************************************************************
1837// Environmental parameters
1838void SetN2kPGN130311(tN2kMsg &N2kMsg, unsigned char SID, tN2kTempSource TempSource, double Temperature,
1839 tN2kHumiditySource HumiditySource, double Humidity, double AtmosphericPressure) {
1840 N2kMsg.SetPGN(130311L);
1841 N2kMsg.Priority=5;
1842 N2kMsg.AddByte(SID);
1843 N2kMsg.AddByte(((HumiditySource) & 0x03)<<6 | (TempSource & 0x3f));
1844 N2kMsg.Add2ByteUDouble(Temperature,0.01);
1845 N2kMsg.Add2ByteDouble(Humidity,0.004);
1846 N2kMsg.Add2ByteUDouble(AtmosphericPressure,100);
1847}
1848
1849bool ParseN2kPGN130311(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kTempSource &TempSource, double &Temperature,
1850 tN2kHumiditySource &HumiditySource, double &Humidity, double &AtmosphericPressure) {
1851 if (N2kMsg.PGN!=130311L) return false;
1852 unsigned char vb;
1853 int Index=0;
1854 SID=N2kMsg.GetByte(Index);
1855 vb=N2kMsg.GetByte(Index); TempSource=(tN2kTempSource)(vb & 0x3f); HumiditySource=(tN2kHumiditySource)(vb>>6 & 0x03);
1856 Temperature=N2kMsg.Get2ByteUDouble(0.01,Index);
1857 Humidity=N2kMsg.Get2ByteDouble(0.004,Index);
1858 AtmosphericPressure=N2kMsg.Get2ByteUDouble(100,Index);
1859
1860 return true;
1861}
1862
1863//*****************************************************************************
1864// Temperature
1865// Temperatures should be in Kelvins
1866void SetN2kPGN130312(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource,
1867 double ActualTemperature, double SetTemperature) {
1868 N2kMsg.SetPGN(130312L);
1869 N2kMsg.Priority=5;
1870 N2kMsg.AddByte(SID);
1871 N2kMsg.AddByte((unsigned char)TempInstance);
1872 N2kMsg.AddByte((unsigned char)TempSource);
1873 N2kMsg.Add2ByteUDouble(ActualTemperature,0.01);
1874 N2kMsg.Add2ByteUDouble(SetTemperature,0.01);
1875 N2kMsg.AddByte(0xff); // Reserved
1876}
1877
1878bool ParseN2kPGN130312(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource,
1879 double &ActualTemperature, double &SetTemperature) {
1880 if (N2kMsg.PGN!=130312L) return false;
1881 int Index=0;
1882 SID=N2kMsg.GetByte(Index);
1883 TempInstance=N2kMsg.GetByte(Index);
1884 TempSource=(tN2kTempSource)(N2kMsg.GetByte(Index));
1885 ActualTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
1886 SetTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
1887
1888 return true;
1889}
1890
1891//*****************************************************************************
1892// Humidity
1893// Humidity should be in percent
1894void SetN2kPGN130313(tN2kMsg &N2kMsg, unsigned char SID, unsigned char HumidityInstance,
1895 tN2kHumiditySource HumiditySource, double ActualHumidity, double SetHumidity) {
1896 N2kMsg.SetPGN(130313L);
1897 N2kMsg.Priority = 5;
1898 N2kMsg.AddByte(SID);
1899 N2kMsg.AddByte((unsigned char) HumidityInstance);
1900 N2kMsg.AddByte((unsigned char) HumiditySource);
1901 N2kMsg.Add2ByteDouble(ActualHumidity, 0.004);
1902 N2kMsg.Add2ByteDouble(SetHumidity, 0.004);
1903 N2kMsg.AddByte(0xff); // reserved
1904}
1905
1906bool ParseN2kPGN130313(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &HumidityInstance,
1907 tN2kHumiditySource &HumiditySource, double &ActualHumidity, double &SetHumidity) {
1908 if (N2kMsg.PGN != 130313L) return false;
1909 int Index = 0;
1910 SID=N2kMsg.GetByte(Index);
1911 HumidityInstance=N2kMsg.GetByte(Index);
1912 HumiditySource=(tN2kHumiditySource)N2kMsg.GetByte(Index);
1913 ActualHumidity=N2kMsg.Get2ByteDouble(0.004, Index);
1914 SetHumidity=N2kMsg.Get2ByteDouble(0.004, Index);
1915 return true;
1916}
1917
1918//*****************************************************************************
1919// Actual Pressure
1920// Pressure should be in Pascals
1921void SetN2kPGN130314(tN2kMsg &N2kMsg, unsigned char SID, unsigned char PressureInstance,
1922 tN2kPressureSource PressureSource, double ActualPressure) {
1923 N2kMsg.SetPGN(130314L);
1924 N2kMsg.Priority = 5;
1925 N2kMsg.AddByte(SID);
1926 N2kMsg.AddByte((unsigned char) PressureInstance);
1927 N2kMsg.AddByte((unsigned char) PressureSource);
1928 N2kMsg.Add4ByteDouble(ActualPressure,0.1);
1929 N2kMsg.AddByte(0xff); // reserved
1930}
1931
1932bool ParseN2kPGN130314(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &PressureInstance,
1933 tN2kPressureSource &PressureSource, double &ActualPressure) {
1934 if (N2kMsg.PGN != 130314L) return false;
1935 int Index = 0;
1936 SID=N2kMsg.GetByte(Index);
1937 PressureInstance=N2kMsg.GetByte(Index);
1938 PressureSource=(tN2kPressureSource)N2kMsg.GetByte(Index);
1939 ActualPressure=N2kMsg.Get4ByteDouble(0.1, Index);
1940 return true;
1941}
1942
1943//*****************************************************************************
1944// Set Pressure
1945// Pressure should be in Pascals
1946void SetN2kPGN130315(tN2kMsg &N2kMsg, unsigned char SID, unsigned char PressureInstance,
1947 tN2kPressureSource PressureSource, double SetPressure) {
1948 N2kMsg.SetPGN(130315L);
1949 N2kMsg.Priority = 5;
1950 N2kMsg.AddByte(SID);
1951 N2kMsg.AddByte((unsigned char) PressureInstance);
1952 N2kMsg.AddByte((unsigned char) PressureSource);
1953 N2kMsg.Add4ByteDouble(SetPressure,0.1);
1954 N2kMsg.AddByte(0xff); // reserved
1955}
1956
1957//*****************************************************************************
1958// Temperature extended range
1959// Temperatures should be in Kelvins
1960void SetN2kPGN130316(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource,
1961 double ActualTemperature, double SetTemperature) {
1962 N2kMsg.SetPGN(130316L);
1963 N2kMsg.Priority=5;
1964 N2kMsg.AddByte(SID);
1965 N2kMsg.AddByte((unsigned char)TempInstance);
1966 N2kMsg.AddByte((unsigned char)TempSource);
1967 N2kMsg.Add3ByteDouble(ActualTemperature,0.001);
1968 N2kMsg.Add2ByteUDouble(SetTemperature,0.1);
1969}
1970
1971bool ParseN2kPGN130316(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource,
1972 double &ActualTemperature, double &SetTemperature) {
1973 if (N2kMsg.PGN!=130316L) return false;
1974 int Index=0;
1975 SID=N2kMsg.GetByte(Index);
1976 TempInstance=N2kMsg.GetByte(Index);
1977 TempSource=(tN2kTempSource)(N2kMsg.GetByte(Index));
1978 ActualTemperature=N2kMsg.Get3ByteDouble(0.001,Index);
1979 SetTemperature=N2kMsg.Get2ByteUDouble(0.1,Index);
1980
1981 return true;
1982}
1983
1984//*****************************************************************************
1985// Meteorological Station Data
1987 N2kMsg.SetPGN(130323L);
1988 N2kMsg.Priority=6;
1989 N2kMsg.AddByte( (((unsigned char) N2kData.Mode) & 0x0f) | 0xf0 );
1990 N2kMsg.Add2ByteUInt(N2kData.SystemDate);
1991 N2kMsg.Add4ByteUDouble(N2kData.SystemTime,0.0001);
1992 N2kMsg.Add4ByteDouble(N2kData.Latitude,1e-7);
1993 N2kMsg.Add4ByteDouble(N2kData.Longitude,1e-7);
1994 N2kMsg.Add2ByteUDouble(N2kData.WindSpeed,0.01);
1995 N2kMsg.Add2ByteUDouble(N2kData.WindDirection,0.0001);
1996 N2kMsg.AddByte( (((unsigned char)N2kData.WindReference) & 0x07) | 0xf8 );
1997 N2kMsg.Add2ByteUDouble(N2kData.WindGusts,0.01);
1998 N2kMsg.Add2ByteUDouble(N2kData.AtmosphericPressure,100);
1999 N2kMsg.Add2ByteUDouble(N2kData.OutsideAmbientAirTemperature,0.01);
2000 N2kMsg.AddVarStr((char*)N2kData.StationID);
2001 N2kMsg.AddVarStr((char*)N2kData.StationName);
2002}
2003
2004
2006 if (N2kMsg.PGN!=130323L) return false;
2007 int Index=0;
2008 unsigned char vb;
2009
2010 vb = N2kMsg.GetByte(Index);
2011 N2kData.Mode=(tN2kAISMode)(vb & 0x0f);
2012 N2kData.SystemDate = N2kMsg.Get2ByteUInt(Index);
2013 N2kData.SystemTime = N2kMsg.Get4ByteUDouble(0.0001,Index);
2014 N2kData.Latitude = N2kMsg.Get4ByteDouble(1e-7,Index);
2015 N2kData.Longitude = N2kMsg.Get4ByteDouble(1e-7,Index);
2016 N2kData.WindSpeed = N2kMsg.Get2ByteUDouble(0.01,Index);
2017 N2kData.WindDirection = N2kMsg.Get2ByteUDouble(0.0001,Index);
2018 vb = N2kMsg.GetByte(Index);
2019 N2kData.WindReference = (tN2kWindReference)(vb & 0x07);
2020 N2kData.WindGusts = N2kMsg.Get2ByteUDouble(0.01,Index);
2021 N2kData.AtmosphericPressure = N2kMsg.Get2ByteUDouble(100,Index);
2022 N2kData.OutsideAmbientAirTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
2023 size_t StationIDSize = sizeof(N2kData.StationID);
2024 size_t StationNameSize = sizeof(N2kData.StationName);
2025 N2kMsg.GetVarStr(StationIDSize, (char*)N2kData.StationID, Index);
2026 N2kMsg.GetVarStr(StationNameSize, (char*)N2kData.StationName, Index);
2027
2028 return true;
2029}
2030
2031//*****************************************************************************
2032// Trim Tab Position
2033// Trim tab position is a percentage 0 to 100% where 0 is fully retracted and 100 is fully extended
2034void SetN2kPGN130576(tN2kMsg &N2kMsg, int8_t PortTrimTab, int8_t StbdTrimTab) {
2035 N2kMsg.SetPGN(130576L);
2036 N2kMsg.Priority=2;
2037 N2kMsg.AddByte(PortTrimTab);
2038 N2kMsg.AddByte(StbdTrimTab);
2039 N2kMsg.Add2ByteUInt(0xFFFF); // Reserved.
2040 N2kMsg.Add4ByteUInt(0xFFFFFFFF); // Reserved.
2041}
2042
2043bool ParseN2kPGN130576(const tN2kMsg &N2kMsg, int8_t &PortTrimTab, int8_t &StbdTrimTab) {
2044
2045 if (N2kMsg.PGN!=130576L) return false;
2046 int Index=0;
2047 PortTrimTab=N2kMsg.GetByte(Index);
2048 StbdTrimTab=N2kMsg.GetByte(Index);
2049
2050 return true;
2051}
2052
2053//*****************************************************************************
2054// Direction Data
2056 tN2kDataMode DataMode,
2057 tN2kHeadingReference CogReference,
2058 unsigned char SID,
2059 double COG,
2060 double SOG,
2061 double Heading,
2062 double SpeedThroughWater,
2063 double Set,
2064 double Drift
2065 )
2066{
2067 N2kMsg.SetPGN(130577L);
2068 N2kMsg.Priority=3;
2069 N2kMsg.AddByte(
2070 (0x0F & DataMode) |
2071 (0x03 & CogReference) << 4 |
2072 0xc0
2073 );
2074 N2kMsg.AddByte(SID);
2075 N2kMsg.Add2ByteUDouble(COG,0.0001);
2076 N2kMsg.Add2ByteUDouble(SOG,0.01);
2077 N2kMsg.Add2ByteUDouble(Heading,0.0001);
2078 N2kMsg.Add2ByteUDouble(SpeedThroughWater,0.01);
2079 N2kMsg.Add2ByteUDouble(Set,0.0001);
2080 N2kMsg.Add2ByteUDouble(Drift,0.01);
2081}
2082
2083bool ParseN2kPGN130577(const tN2kMsg &N2kMsg,
2084 tN2kDataMode &DataMode,
2085 tN2kHeadingReference &CogReference,
2086 unsigned char &SID,
2087 double &COG,
2088 double &SOG,
2089 double &Heading,
2090 double &SpeedThroughWater,
2091 double &Set,
2092 double &Drift)
2093{
2094 if (N2kMsg.PGN!=130577L) return false;
2095 int Index=0;
2096 unsigned char v;
2097 v = N2kMsg.GetByte(Index);
2098 DataMode = (tN2kDataMode)(v & 0x0F);
2099 CogReference = (tN2kHeadingReference)((v >> 4) & 0x03);
2100 SID = N2kMsg.GetByte(Index);
2101 COG = N2kMsg.Get2ByteUDouble(0.0001,Index);
2102 SOG = N2kMsg.Get2ByteUDouble(0.01, Index);
2103 Heading = N2kMsg.Get2ByteUDouble(0.0001, Index);
2104 SpeedThroughWater= N2kMsg.Get2ByteUDouble(0.01, Index);
2105 Set = N2kMsg.Get2ByteUDouble(0.0001, Index);
2106 Drift = N2kMsg.Get2ByteUDouble(0.01, Index);
2107 return true;
2108}
2109
void SetN2kPGN127506(tN2kMsg &N2kMsg, unsigned char SID, unsigned char DCInstance, tN2kDCType DCType, uint8_t StateOfCharge, uint8_t StateOfHealth, double TimeRemaining, double RippleVoltage, double Capacity)
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)
void N2kSetStatusBinaryOnStatus(tN2kBinaryStatus &BankStatus, tN2kOnOff ItemStatus, uint8_t ItemIndex)
Set single status to full binary bank status.
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)
bool ParseN2kPGN129810(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, uint8_t &VesselType, char *Vendor, size_t VendorBufSize, char *Callsign, size_t CallsignBufSize, double &Length, double &Beam, double &PosRefStbd, double &PosRefBow, uint32_t &MothershipID)
tN2kOnOff N2kGetStatusOnBinaryStatus(tN2kBinaryStatus BankStatus, uint8_t ItemIndex)
Get single status to full binary bank status.
#define MaxSatelliteInfoCount
This File contains all SetXXX functions which will be needed to transfer data with a specific PGN.
void N2kResetBinaryStatus(tN2kBinaryStatus &BankStatus)
Reset all single binary status values to not available.
Definition: N2kMessages.h:1616
uint64_t tN2kBinaryStatus
64bit Binary Status value of a full bank status, that can handle up to 28 item states in one value.
Definition: N2kMessages.h:1589
const double N2kDoubleNA
Constant "Not Available" for a double value.
Definition: N2kMsg.h:49
const int16_t N2kInt16NA
Constant "Not Available" for a signed 16bit int value.
Definition: N2kMsg.h:59
const uint16_t N2kUInt16NA
Constant "Not Available" for a unsigned 16bit int value.
Definition: N2kMsg.h:57
const uint8_t N2kUInt8NA
Constant "Not Available" for a unsigned 8bit int value.
Definition: N2kMsg.h:53
@ N2kdct_GreatCircle
great circle calculation
Definition: N2kTypes.h:84
@ N2kdct_RhumbLine
rhumb line calculation
Definition: N2kTypes.h:85
@ N2khr_magnetic
heading magnetic compass direction
Definition: N2kTypes.h:64
@ N2khr_true
heading true (eg. GNSS) direction
Definition: N2kTypes.h:63
@ N2kOnOff_Unavailable
Unavailable.
Definition: N2kTypes.h:492
@ N2kGNSSt_GPS
only GPS satellite network
Definition: N2kTypes.h:109
@ N2kDD124_Unavailable
no selection, unavailable
This class contains all the data of an NMEA2000 message.
Definition: N2kMsg.h:656
void Add2ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 2 bytes.
Definition: N2kMsg.cpp:156
void Add2ByteUInt(uint16_t v)
Add unsigned integer value to the buffer using 2 bytes The value will be added to the end (indicated ...
Definition: N2kMsg.cpp:188
double Get3ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 3 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:324
double Get4ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 4 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:331
bool GetVarStr(size_t &StrBufSize, char *StrBuf, int &Index) const
Get a string out of Data This method determines the length of the string by it self,...
Definition: N2kMsg.cpp:416
void Add4ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 4 bytes.
Definition: N2kMsg.cpp:129
void Add2ByteInt(int16_t v)
Add integer value to the buffer using 2 bytes The value will be added to the end (indicated by DataLe...
Definition: N2kMsg.cpp:183
void Add4ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 4 bytes.
Definition: N2kMsg.cpp:120
void Add3ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 3 bytes.
Definition: N2kMsg.cpp:138
void AddByte(unsigned char v)
Add byte value to the buffer The byte will be added to the end (indicated by DataLen) of the byte arr...
Definition: N2kMsg.cpp:208
void Add2ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 2 bytes.
Definition: N2kMsg.cpp:147
void Add1ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 1 byte.
Definition: N2kMsg.cpp:174
bool Set2ByteUInt(uint16_t v, int &Index)
Set a 2byte unsigned integer in Data.
Definition: N2kMsg.cpp:457
void AddUInt64(uint64_t v)
Add unsigned integer value to the buffer using 8 bytes The value will be added to the end (indicated ...
Definition: N2kMsg.cpp:203
uint16_t Get2ByteUInt(int &Index, uint16_t def=0xffff) const
Get an unsigned integer from 2 bytes out of Data.
Definition: N2kMsg.cpp:268
double Get2ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 2 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:310
void Add8ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 8 bytes.
Definition: N2kMsg.cpp:110
static const int MaxDataLen
Maximum number of bytes that can be stored in the data buffer With fast packet the first frame can ha...
Definition: N2kMsg.h:663
double Get2ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 2 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:317
void AddVarStr(const char *str, bool UsePgm=false)
Add string value to the buffer This method determines the length of the string by it self using strle...
Definition: N2kMsg.cpp:234
unsigned char Priority
Priority of the NMEA2000 message.
Definition: N2kMsg.h:665
bool SetByte(uint8_t v, int &Index)
Set a byte in Data.
Definition: N2kMsg.cpp:447
double Get1ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 1 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:303
void Add3ByteInt(int32_t v)
Add integer value to the buffer using 3 bytes The value will be added to the end (indicated by DataLe...
Definition: N2kMsg.cpp:193
void Add4ByteUInt(uint32_t v)
Add unsigned integer value to the buffer using 4 bytes The value will be added to the end (indicated ...
Definition: N2kMsg.cpp:198
void SetPGN(unsigned long _PGN)
Set the Parameter Group Number of the message *.
Definition: N2kMsg.cpp:68
unsigned char GetByte(int &Index) const
Get the value from a byte out of Data.
Definition: N2kMsg.cpp:254
uint64_t GetUInt64(int &Index, uint64_t def=0xffffffffffffffffULL) const
Get an unsigned integer from 8 bytes out of Data.
Definition: N2kMsg.cpp:289
int16_t Get2ByteInt(int &Index, int16_t def=0x7fff) const
Get an integer from 2 bytes out of Data.
Definition: N2kMsg.cpp:261
bool GetStr(char *StrBuf, size_t Length, int &Index) const
Get a string out of Data.
Definition: N2kMsg.cpp:359
void AddAISStr(const char *str, int len)
Add string value to the buffer after filtering characters as defined in ITU-R M.1371-1 The string wil...
Definition: N2kMsg.cpp:221
double Get4ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 4 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:338
double Get8ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 8 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:345
uint32_t Get4ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 4 bytes out of Data.
Definition: N2kMsg.cpp:282
int DataLen
Number of bytes already stored in tN2kMsg::Data of this message.
Definition: N2kMsg.h:673
unsigned long PGN
Parameter Group Number (PGN) of the NMEA2000 message.
Definition: N2kMsg.h:667
bool ParseN2kPGN127505(const tN2kMsg &N2kMsg, unsigned char &Instance, tN2kFluidType &FluidType, double &Level, double &Capacity)
Parsing the content of message PGN 127505 "Fluid level".
bool ParseN2kPGN129802(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &SourceID, tN2kAISTransceiverInformation &AISTransceiverInformation, char *SafetyRelatedText, size_t &SafetyRelatedTextMaxSize)
Parsing the Content of a PGN129802 Message - "AIS Safety Related Broadcast Message".
Definition: N2kMessages.cpp:66
bool ParseN2kPGN129025(const tN2kMsg &N2kMsg, double &Latitude, double &Longitude)
Parsing the content of PGN 129025 "Position, Rapid Update".
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)
Parsing the content of message PGN 128776 "Anchor Windlass Control Status".
bool ParseN2kPGN129039(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, double &Latitude, double &Longitude, bool &Accuracy, bool &RAIM, uint8_t &Seconds, double &COG, double &SOG, tN2kAISTransceiverInformation &AISTransceiverInformation, double &Heading, tN2kAISUnit &Unit, bool &Display, bool &DSC, bool &Band, bool &Msg22, tN2kAISMode &Mode, bool &State)
Parsing the content of message PGN 129039 "AIS position reports for Class B".
bool ParseN2kPGN128777(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &WindlassIdentifier, double &RodeCounterValue, double &WindlassLineSpeed, tN2kWindlassMotionStates &WindlassMotionStatus, tN2kRodeTypeStates &RodeTypeStatus, tN2kAnchorDockingStates &AnchorDockingStatus, tN2kWindlassOperatingEvents &WindlassOperatingEvents)
Parsing the content of message PGN 128777 "Anchor Windlass Operating Status".
bool ParseN2kPGN128267(const tN2kMsg &N2kMsg, unsigned char &SID, double &DepthBelowTransducer, double &Offset, double &Range)
Parsing the content of message PGN 128267 "Water depth".
bool ParseN2kPGN130311(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kTempSource &TempSource, double &Temperature, tN2kHumiditySource &HumiditySource, double &Humidity, double &AtmosphericPressure)
Parsing the content of message PGN 130311 "Environmental Parameters - DEPRECATED".
bool ParseN2kPGN127251(const tN2kMsg &N2kMsg, unsigned char &SID, double &RateOfTurn)
Parsing the content of Message PGN127251 "Rate of Turn".
bool ParseN2kPGN130576(const tN2kMsg &N2kMsg, int8_t &PortTrimTab, int8_t &StbdTrimTab)
Parsing the content of message PGN 130576 "Trim Tab Status".
bool ParseN2kPGN130306(const tN2kMsg &N2kMsg, unsigned char &SID, double &WindSpeed, double &WindAngle, tN2kWindReference &WindReference)
Parsing the content of message PGN 130306 "Wind Data".
bool ParseN2kPGN127488(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &EngineSpeed, double &EngineBoostPressure, int8_t &EngineTiltTrim)
Parsing the content of Message PGN 127488 "Engine parameters rapid".
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)
Parsing the content of message PGN 127513 "Battery Configuration Status".
bool ParseN2kPGN129794(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, uint32_t &IMOnumber, char *Callsign, size_t CallsignBufSize, char *Name, size_t NameBufSize, uint8_t &VesselType, double &Length, double &Beam, double &PosRefStbd, double &PosRefBow, uint16_t &ETAdate, double &ETAtime, double &Draught, char *Destination, size_t DestinationBufSize, tN2kAISVersion &AISversion, tN2kGNSStype &GNSStype, tN2kAISDTE &DTE, tN2kAISTransceiverInformation &AISinfo)
Parsing the content of message PGN 129794 "AIS static data class A".
bool ParseN2kPgn129539(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kGNSSDOPmode &DesiredMode, tN2kGNSSDOPmode &ActualMode, double &HDOP, double &VDOP, double &TDOP)
Parsing the content of message PGN 129539 "GNSS DOP data".
bool ParseN2kPGN127237(const tN2kMsg &N2kMsg, tN2kOnOff &RudderLimitExceeded, tN2kOnOff &OffHeadingLimitExceeded, tN2kOnOff &OffTrackLimitExceeded, tN2kOnOff &Override, tN2kSteeringMode &SteeringMode, tN2kTurnMode &TurnMode, tN2kHeadingReference &HeadingReference, tN2kRudderDirectionOrder &CommandedRudderDirection, double &CommandedRudderAngle, double &HeadingToSteerCourse, double &Track, double &RudderLimit, double &OffHeadingLimit, double &RadiusOfTurnOrder, double &RateOfTurnOrder, double &OffTrackLimit, double &VesselHeading)
Parsing the Content of Message PGN127237 "Heading/Track control".
bool ParseN2kPGN130577(const tN2kMsg &N2kMsg, tN2kDataMode &DataMode, tN2kHeadingReference &CogReference, unsigned char &SID, double &COG, double &SOG, double &Heading, double &SpeedThroughWater, double &Set, double &Drift)
Parsing the content of message PGN 130577 "Direction Data".
bool ParseN2kPGN129033(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, int16_t &LocalOffset)
Parsing the content of message PGN 129033 "Date,Time & Local offset".
bool ParseN2kPGN127250(const tN2kMsg &N2kMsg, unsigned char &SID, double &Heading, double &Deviation, double &Variation, tN2kHeadingReference &ref)
Parsing Content of Message PGN 127250 "Vessel Heading".
bool ParseN2kPGN127258(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation)
Parsing the content of Message PGN 127258 "Magnetic Variation".
bool ParseN2kPGN129540(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kRangeResidualMode &Mode, uint8_t &NumberOfSVs)
Parsing the content of message PGN 129540 "GNSS Satellites in View".
bool ParseN2kPGN127245(const tN2kMsg &N2kMsg, double &RudderPosition, unsigned char &Instance, tN2kRudderDirectionOrder &RudderDirectionOrder, double &AngleOrder)
Parsing the content of Message PGN127245 "Rudder".
bool ParseN2kPGN129026(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kHeadingReference &ref, double &COG, double &SOG)
Parsing the content of PGN 129026 "COG SOG rapid update".
bool ParseN2kPGN130323(const tN2kMsg &N2kMsg, tN2kMeteorlogicalStationData &N2kData)
Parsing the content of message PGN 130323 "Meterological Station Data".
bool ParseN2kPGN128778(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &WindlassIdentifier, double &TotalMotorTime, double &ControllerVoltage, double &MotorCurrent, tN2kWindlassMonitoringEvents &WindlassMonitoringEvents)
Parsing the content of message PGN128778 "Anchor Windlass Monitoring Status".
bool ParseN2kPGN127493(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, tN2kTransmissionGear &TransmissionGear, double &OilPressure, double &OilTemperature, unsigned char &DiscreteStatus1)
Parsing the content of Message PGN 127493 "Transmission parameters, dynamic".
bool ParseN2kPGN129283(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kXTEMode &XTEMode, bool &NavigationTerminated, double &XTE)
Parsing the content of Message PGN 129283 Message "Cross Track Error".
bool ParseN2kPGN127233(const tN2kMsg &N2kMsg, unsigned char &SID, uint32_t &MobEmitterId, tN2kMOBStatus &MOBStatus, double &ActivationTime, tN2kMOBPositionSource &PositionSource, uint16_t &PositionDate, double &PositionTime, double &Latitude, double &Longitude, tN2kHeadingReference &COGReference, double &COG, double &SOG, uint32_t &MMSI, tN2kMOBEmitterBatteryStatus &MOBEmitterBatteryStatus)
Parsing the Content of Message PGN127233 "Man Overboard Notification".
bool ParseN2kPGN128275(const tN2kMsg &N2kMsg, uint16_t &DaysSince1970, double &SecondsSinceMidnight, uint32_t &Log, uint32_t &TripLog)
Parsing the content of message PGN 128275 "Distance log".
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, tN2kEngineDiscreteStatus1 &Status1, tN2kEngineDiscreteStatus2 &Status2)
Parsing the content of Message PGN 127489 "Engine parameters dynamic".
bool ParseN2kPGN126992(const tN2kMsg &N2kMsg, unsigned char &SID, uint16_t &SystemDate, double &SystemTime, tN2kTimeSource &TimeSource)
Parsing the Content of a PGN126992 Message - "System date/time".
Definition: N2kMessages.cpp:39
bool ParseN2kPGN130314(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &PressureInstance, tN2kPressureSource &PressureSource, double &ActualPressure)
Parsing the content of message PGN 130314 "Actual Pressure".
bool ParseN2kPGN130310(const tN2kMsg &N2kMsg, unsigned char &SID, double &WaterTemperature, double &OutsideAmbientAirTemperature, double &AtmosphericPressure)
Parsing the content of message PGN 130310 "Environmental Parameters - DEPRECATED".
bool ParseN2kPGN127507(const tN2kMsg &N2kMsg, unsigned char &Instance, unsigned char &BatteryInstance, tN2kChargeState &ChargeState, tN2kChargerMode &ChargerMode, tN2kOnOff &Enabled, tN2kOnOff &EqualizationPending, double &EqualizationTimeRemaining)
Parsing the content of message PGN 127507 "DC Charger Status".
bool ParseN2kPGN130316(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource, double &ActualTemperature, double &SetTemperature)
Parsing the content of message PGN 130316 "Temperature, Extended Range".
bool ParseN2kPGN129284(const tN2kMsg &N2kMsg, unsigned char &SID, double &DistanceToWaypoint, tN2kHeadingReference &BearingReference, bool &PerpendicularCrossed, bool &ArrivalCircleEntered, tN2kDistanceCalculationType &CalculationType, double &ETATime, int16_t &ETADate, double &BearingOriginToDestinationWaypoint, double &BearingPositionToDestinationWaypoint, uint32_t &OriginWaypointNumber, uint32_t &DestinationWaypointNumber, double &DestinationLatitude, double &DestinationLongitude, double &WaypointClosingVelocity)
Parsing the content of message PGN 129284 "Navigation Data".
bool ParseN2kPGN127497(const tN2kMsg &N2kMsg, unsigned char &EngineInstance, double &TripFuelUsed, double &FuelRateAverage, double &FuelRateEconomy, double &InstantaneousFuelEconomy)
Parsing the content of Message PGN 127497 "Trip Parameters, Engine".
bool ParseN2kPGN128259(const tN2kMsg &N2kMsg, unsigned char &SID, double &WaterReferenced, double &GroundReferenced, tN2kSpeedWaterReferenceType &SWRT)
Parsing the content of message PGN 128259 "Boat Speed, Water Referenced".
bool ParseN2kPGN127508(const tN2kMsg &N2kMsg, unsigned char &BatteryInstance, double &BatteryVoltage, double &BatteryCurrent, double &BatteryTemperature, unsigned char &SID)
Parsing the content of message PGN 127508 "Battery Status".
bool ParseN2kPGN127502(const tN2kMsg &N2kMsg, unsigned char &TargetBankInstance, tN2kBinaryStatus &BankStatus)
Parse the content of a PGN 127502 (Switch Bank Control) message.
bool ParseN2kPGN130313(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &HumidityInstance, tN2kHumiditySource &HumiditySource, double &ActualHumidity, double &SetHumidity)
Parsing the content of message PGN 130313 "Humidity".
bool ParseN2kPGN127501(const tN2kMsg &N2kMsg, unsigned char &DeviceBankInstance, tN2kOnOff &Status1, tN2kOnOff &Status2, tN2kOnOff &Status3, tN2kOnOff &Status4)
Parsing the content of Message PGN 127501 Message "Universal Binary Status Report".
bool ParseN2kPGN129041(const tN2kMsg &N2kMsg, tN2kAISAtoNReportData &N2kData)
Parsing the content of message PGN 129041 "AIS Aids to Navigation (AtoN) Report".
bool ParseN2kPGN130312(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource, double &ActualTemperature, double &SetTemperature)
Parsing the content of message PGN 130312 "Temperature - DEPRECATED".
bool ParseN2kPGN129038(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, double &Latitude, double &Longitude, bool &Accuracy, bool &RAIM, uint8_t &Seconds, double &COG, double &SOG, double &Heading, double &ROT, tN2kAISNavStatus &NavStatus)
Parsing the content of message PGN 129038 "AIS position reports for Class A".
bool ParseN2kPGN128000(const tN2kMsg &N2kMsg, unsigned char &SID, double &Leeway)
Parsing the content of Message PGN 128000 "Nautical Leeway Angle".
bool ParseN2kPGN127252(const tN2kMsg &N2kMsg, unsigned char &SID, double &Heave, double &Delay, tN2kDelaySource &DelaySource)
Parsing the content of Message PGN127252 "Heave".
bool ParseN2kPGN129809(const tN2kMsg &N2kMsg, uint8_t &MessageID, tN2kAISRepeat &Repeat, uint32_t &UserID, char *Name, size_t NameBufSize)
Parsing the content of message PGN 129809 "AIS static data class B part A".
bool ParseN2kPGN127257(const tN2kMsg &N2kMsg, unsigned char &SID, double &Yaw, double &Pitch, double &Roll)
Parsing the content of Message PGN 127257 "Attitude".
void SetN2kPGN129284(tN2kMsg &N2kMsg, unsigned char SID, double DistanceToWaypoint, tN2kHeadingReference BearingReference, bool PerpendicularCrossed, bool ArrivalCircleEntered, tN2kDistanceCalculationType CalculationType, double ETATime, int16_t ETADate, double BearingOriginToDestinationWaypoint, double BearingPositionToDestinationWaypoint, uint32_t OriginWaypointNumber, uint32_t DestinationWaypointNumber, double DestinationLatitude, double DestinationLongitude, double WaypointClosingVelocity)
Setting up PGN 129284 Message "Navigation Data".
void SetN2kPGN127245(tN2kMsg &N2kMsg, double RudderPosition, unsigned char Instance, tN2kRudderDirectionOrder RudderDirectionOrder, double AngleOrder)
Setting up PGN127245 Message "Rudder".
void SetN2kPGN129540(tN2kMsg &N2kMsg, unsigned char SID, tN2kRangeResidualMode Mode)
Setting up PGN 129540 Message "GNSS Satellites in View".
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)
Setting up PGN 128776 Message "Anchor Windlass Control Status".
void SetN2kPGN130314(tN2kMsg &N2kMsg, unsigned char SID, unsigned char PressureInstance, tN2kPressureSource PressureSource, double ActualPressure)
Setting up PGN 130314 Message "Actual Pressure".
void SetN2kPGN127502(tN2kMsg &N2kMsg, unsigned char TargetBankInstance, tN2kBinaryStatus BankStatus)
Set up PGN 127502 "Switch Bank Control" message.
void SetN2kPGN129809(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, const char *Name)
Setting up PGN 129809 Message "AIS static data class B part A".
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)
Setting up PGN 129029 Message "GNSS Position Data".
void SetN2kPGN127252(tN2kMsg &N2kMsg, unsigned char SID, double Heave, double Delay, tN2kDelaySource DelaySource)
Setting up PGN 127252 Message "Heave".
void SetN2kPGN130311(tN2kMsg &N2kMsg, unsigned char SID, tN2kTempSource TempSource, double Temperature, tN2kHumiditySource HumiditySource, double Humidity, double AtmosphericPressure)
Setting up PGN 130311 Message "Environmental Parameters - DEPRECATED".
bool AppendN2kPGN129285(tN2kMsg &N2kMsg, uint16_t ID, const char *Name, double Latitude, double Longitude)
Append another Waypoint to PGN 129285 "Route/WP information".
void SetN2kPGN130576(tN2kMsg &N2kMsg, int8_t PortTrimTab, int8_t StbdTrimTab)
Setting up PGN 130576 Message "Trim Tab Status".
void SetN2kPGN126992(tN2kMsg &N2kMsg, unsigned char SID, uint16_t SystemDate, double SystemTime, tN2kTimeSource TimeSource)
Setting up PGN126992 Message "System date/time".
Definition: N2kMessages.cpp:28
void SetN2kPGN127497(tN2kMsg &N2kMsg, unsigned char EngineInstance, double TripFuelUsed, double FuelRateAverage, double FuelRateEconomy, double InstantaneousFuelEconomy)
Setting up PGN 127497 Message "Trip Parameters, Engine".
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, tN2kEngineDiscreteStatus1 Status1, tN2kEngineDiscreteStatus2 Status2)
Setting up PGN 127489 Message "Engine parameters dynamic".
void SetN2kPGN128778(tN2kMsg &N2kMsg, unsigned char SID, unsigned char WindlassIdentifier, double TotalMotorTime, double ControllerVoltage, double MotorCurrent, const tN2kWindlassMonitoringEvents &WindlassMonitoringEvents)
Setting up PGN 128778Message "Anchor Windlass Monitoring Status".
void SetN2kPGN129039(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, double Latitude, double Longitude, bool Accuracy, bool RAIM, uint8_t Seconds, double COG, double SOG, tN2kAISTransceiverInformation AISTransceiverInformation, double Heading, tN2kAISUnit Unit, bool Display, bool DSC, bool Band, bool Msg22, tN2kAISMode Mode, bool State, unsigned char SID)
Setting up PGN 129039 Message "AIS position reports for Class B".
void SetN2kPGN128259(tN2kMsg &N2kMsg, unsigned char SID, double WaterReferenced, double GroundReferenced, tN2kSpeedWaterReferenceType SWRT)
Setting up PGN 128259 Message "Boat Speed, Water Referenced".
void SetN2kPGN129539(tN2kMsg &N2kMsg, unsigned char SID, tN2kGNSSDOPmode DesiredMode, tN2kGNSSDOPmode ActualMode, double HDOP, double VDOP, double TDOP)
Setting up PGN 129539 Message "GNSS DOP data".
void SetN2kPGN128777(tN2kMsg &N2kMsg, unsigned char SID, unsigned char WindlassIdentifier, double RodeCounterValue, double WindlassLineSpeed, tN2kWindlassMotionStates WindlassMotionStatus, tN2kRodeTypeStates RodeTypeStatus, tN2kAnchorDockingStates AnchorDockingStatus, const tN2kWindlassOperatingEvents &WindlassOperatingEvents)
Setting up PGN 128777 Message "Anchor Windlass Operating Status".
void SetN2kPGN130306(tN2kMsg &N2kMsg, unsigned char SID, double WindSpeed, double WindAngle, tN2kWindReference WindReference)
Setting up PGN 130306 Message "Wind Data".
void SetN2kPGN127488(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineSpeed, double EngineBoostPressure, int8_t EngineTiltTrim)
Setting up PGN 127488 Message "Engine parameters rapid".
void SetN2kPGN127493(tN2kMsg &N2kMsg, unsigned char EngineInstance, tN2kTransmissionGear TransmissionGear, double OilPressure, double OilTemperature, unsigned char DiscreteStatus1)
Setting up PGN 127493 Message "Transmission parameters, dynamic".
void SetN2kPGN127507(tN2kMsg &N2kMsg, unsigned char Instance, unsigned char BatteryInstance, tN2kChargeState ChargeState, tN2kChargerMode ChargerMode, tN2kOnOff Enabled, tN2kOnOff EqualizationPending, double EqualizationTimeRemaining)
Setting up PGN 127507 Message "DC Charger Status".
void SetN2kPGN128275(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, uint32_t Log, uint32_t TripLog)
Setting up PGN 128275 Message "Distance log".
void SetN2kPGN127257(tN2kMsg &N2kMsg, unsigned char SID, double Yaw, double Pitch, double Roll)
Setting up PGN 127257 Message "Attitude".
void SetN2kPGN127501(tN2kMsg &N2kMsg, unsigned char DeviceBankInstance, tN2kBinaryStatus BankStatus)
Setting up PGN 127501 Message "Universal Binary Status Report".
void SetN2kPGN127250(tN2kMsg &N2kMsg, unsigned char SID, double Heading, double Deviation, double Variation, tN2kHeadingReference ref)
Setting up PGN127250 Message "Vessel Heading".
void SetN2kPGN127508(tN2kMsg &N2kMsg, unsigned char BatteryInstance, double BatteryVoltage, double BatteryCurrent, double BatteryTemperature, unsigned char SID)
Setting up PGN 127508 Message "Battery Status".
void SetN2kPGN130310(tN2kMsg &N2kMsg, unsigned char SID, double WaterTemperature, double OutsideAmbientAirTemperature, double AtmosphericPressure)
Setting up PGN 130310 Message " Environmental Parameters - DEPRECATED".
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)
Setting up PGN 127513 Message "Battery Configuration Status".
bool AppendN2kPGN129540(tN2kMsg &N2kMsg, const tSatelliteInfo &SatelliteInfo)
Append a new satellite info to PGN 129540 Message "GNSS Satellites in View".
void SetN2kPGN129026(tN2kMsg &N2kMsg, unsigned char SID, tN2kHeadingReference ref, double COG, double SOG)
Setting up PGN 129026 Message "COG SOG rapid update".
void SetN2kPGN130323(tN2kMsg &N2kMsg, const tN2kMeteorlogicalStationData &N2kData)
Setting up PGN 130323 Message "Meterological Station Data".
void SetN2kPGN129285(tN2kMsg &N2kMsg, uint16_t Start, uint16_t Database, uint16_t Route, tN2kNavigationDirection NavDirection, const char *RouteName, tN2kGenericStatusPair SupplementaryData)
Setting up PGN 129285 Message "Route/WP information".
void SetN2kPGN129794(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, uint32_t IMOnumber, const char *Callsign, const char *Name, uint8_t VesselType, double Length, double Beam, double PosRefStbd, double PosRefBow, uint16_t ETAdate, double ETAtime, double Draught, const char *Destination, tN2kAISVersion AISversion, tN2kGNSStype GNSStype, tN2kAISDTE DTE, tN2kAISTransceiverInformation AISinfo)
Setting up PGN 129794 Message "AIS static data class A".
void SetN2kPGN127251(tN2kMsg &N2kMsg, unsigned char SID, double RateOfTurn)
Setting up PGN 127251 Message "Rate of Turn".
void SetN2kPGN129802(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t SourceID, tN2kAISTransceiverInformation AISTransceiverInformation, char *SafetyRelatedText)
Setting up PGN129802 Message "AIS Safety Related Broadcast Message".
Definition: N2kMessages.cpp:55
void SetN2kPGN127233(tN2kMsg &N2kMsg, unsigned char SID, uint32_t MobEmitterId, tN2kMOBStatus MOBStatus, double ActivationTime, tN2kMOBPositionSource PositionSource, uint16_t PositionDate, double PositionTime, double Latitude, double Longitude, tN2kHeadingReference COGReference, double COG, double SOG, uint32_t MMSI, tN2kMOBEmitterBatteryStatus MOBEmitterBatteryStatus)
Setting up PGN127233 Message "Man Overboard Notification".
Definition: N2kMessages.cpp:87
void SetN2kPGN129033(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, int16_t LocalOffset)
Setting up PGN 129033 Message "Date,Time & Local offset".
void SetN2kPGN129810(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, uint8_t VesselType, const char *Vendor, const char *Callsign, double Length, double Beam, double PosRefStbd, double PosRefBow, uint32_t MothershipID)
Setting up PGN 129810 Message "AIS static data class B part B".
void SetN2kPGN130316(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource, double ActualTemperature, double SetTemperature)
Setting up PGN 130316 Message "Temperature, Extended Range".
void SetN2kPGN127237(tN2kMsg &N2kMsg, tN2kOnOff RudderLimitExceeded, tN2kOnOff OffHeadingLimitExceeded, tN2kOnOff OffTrackLimitExceeded, tN2kOnOff Override, tN2kSteeringMode SteeringMode, tN2kTurnMode TurnMode, tN2kHeadingReference HeadingReference, tN2kRudderDirectionOrder CommandedRudderDirection, double CommandedRudderAngle, double HeadingToSteerCourse, double Track, double RudderLimit, double OffHeadingLimit, double RadiusOfTurnOrder, double RateOfTurnOrder, double OffTrackLimit, double VesselHeading)
Setting up PGN127237 Message "Heading/Track control".
void SetN2kPGN129041(tN2kMsg &N2kMsg, const tN2kAISAtoNReportData &N2kData)
Setting up PGN 129041 Message "AIS Aids to Navigation (AtoN) Report".
void SetN2kPGN129038(tN2kMsg &N2kMsg, uint8_t MessageID, tN2kAISRepeat Repeat, uint32_t UserID, double Latitude, double Longitude, bool Accuracy, bool RAIM, uint8_t Seconds, double COG, double SOG, tN2kAISTransceiverInformation AISTransceiverInformation, double Heading, double ROT, tN2kAISNavStatus NavStatus)
Setting up PGN 129038 Message "AIS position reports for Class A".
void SetN2kPGN129283(tN2kMsg &N2kMsg, unsigned char SID, tN2kXTEMode XTEMode, bool NavigationTerminated, double XTE)
Setting up PGN 129283 Message "Cross Track Error".
void SetN2kPGN130313(tN2kMsg &N2kMsg, unsigned char SID, unsigned char HumidityInstance, tN2kHumiditySource HumiditySource, double ActualHumidity, double SetHumidity)
Setting up PGN 130313 Message "Humidity".
void SetN2kPGN127505(tN2kMsg &N2kMsg, unsigned char Instance, tN2kFluidType FluidType, double Level, double Capacity)
Setting up PGN 127505 Message "Fluid level".
bool AppendN2kPGN130074(tN2kMsg &N2kMsg, uint16_t ID, char *Name, double Latitude, double Longitude)
Append a Waypoint to PGN 130074 Message " Route and WP Service - WP List - WP Name & Position...
void SetN2kPGN128267(tN2kMsg &N2kMsg, unsigned char SID, double DepthBelowTransducer, double Offset, double Range)
Setting up PGN 128267 Message "Water depth".
void SetN2kPGN130577(tN2kMsg &N2kMsg, tN2kDataMode DataMode, tN2kHeadingReference CogReference, unsigned char SID, double COG, double SOG, double Heading, double SpeedThroughWater, double Set, double Drift)
Setting up PGN 130577 Message "Direction Data".
void SetN2kPGN129025(tN2kMsg &N2kMsg, double Latitude, double Longitude)
Setting up PGN 129025 Message "Position, Rapid Update".
void SetN2kPGN130315(tN2kMsg &N2kMsg, unsigned char SID, unsigned char PressureInstance, tN2kPressureSource PressureSource, double SetPressure)
Setting up PGN 130315 Message "Set Pressure".
void SetN2kPGN127258(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation)
Setting up PGN 127258 Message "Magnetic Variation".
void SetN2kPGN130312(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource, double ActualTemperature, double SetTemperature)
Setting up PGN 130312 Message "Temperature - DEPRECATED".
void SetN2kPGN128000(tN2kMsg &N2kMsg, unsigned char SID, double Leeway)
Setting up PGN 128000 Message "Nautical Leeway Angle".
void SetN2kPGN130074(tN2kMsg &N2kMsg, uint16_t Start, uint16_t NumWaypoints, uint16_t Database)
Setting up PGN 130074 Message " Route and WP Service - WP List - WP Name & Position".
tN2kDistanceCalculationType
Enumeration of distance calculation types for navigation according to PGN129284.
Definition: N2kTypes.h:83
tN2kDD481
DD481 - Rode Type States according to PGN 128777.
tN2kChargerMode
Enumeration of charger modes according to PGN 127507.
Definition: N2kTypes.h:518
tN2kHeadingReference
Enumeration of the heading type according to PGN129233, PGN129237 , PGN129250, PGN129026 and PGN12928...
Definition: N2kTypes.h:62
tN2kAISMode
Enumeration of AIS mode type according to PGN 129039.
Definition: N2kTypes.h:451
tN2kAISDTE
Enumeration of Data Terminal Equipment according to PNG 129794.
Definition: N2kTypes.h:416
tN2kBatNomVolt
Enumeration of nominal battery voltage according to PGN 127513.
Definition: N2kTypes.h:345
tN2kNavigationDirection
Enumeration of the navigation direction according to PGN129285.
Definition: N2kTypes.h:47
tN2kTimeSource
Enumeration of sources for the system time according to PGN126992.
Definition: N2kTypes.h:222
tN2kChargeState
Enumeration of state of the battery charger operation according to PGN127507.
Definition: N2kTypes.h:500
tN2kMagneticVariation
Enumeration of magnetic variation according to PGN 127258.
Definition: N2kTypes.h:473
tN2kDD305 tN2kAISAtoNType
Alias easier for humans to read for tN2kDD305.
Definition: N2kTypes.h:633
tN2kRudderDirectionOrder
Enumeration of Rudder Direction Order according to PGN127237, 127245.
Definition: N2kTypes.h:279
tN2kDD482
DD482 - Anchor Docking States according to PGN 128777.
tN2kDD480 tN2kWindlassMotionStates
Alias easier for humans to read for tN2kDD480.
Definition: N2kTypes.h:718
tN2kMOBPositionSource
Enumeration of ManOverBoard position source according to PGN127233.
Definition: N2kTypes.h:564
tN2kGNSSmethod
Enumeration of GNSS working methods according to PGN129029.
Definition: N2kTypes.h:126
tN2kTransmissionGear
Enumeration of transmission state according to PGN 127493.
Definition: N2kTypes.h:358
tN2kDD025 tN2kDataMode
Alias easier for humans to read for tN2kDD025.
Definition: N2kTypes.h:604
tN2kDCType
Enumeration of DC power sources according to PGN 127506.
Definition: N2kTypes.h:292
tN2kDD072
DD072 - Range Residual Mode.
tN2kDD025
DD025 - Mode, Data.
tN2kMOBEmitterBatteryStatus
Enumeration of MOB emitter battery status according to PGN127233.
Definition: N2kTypes.h:572
tN2kTurnMode
Enumeration of tunr control modes according to PGN127237.
Definition: N2kTypes.h:544
tN2kOnOff
Enumeration of On/Off status at a NMEA 2000 network.
Definition: N2kTypes.h:488
tN2kDD488 tN2kSpeedType
Alias easier for humans to read for tN2kDD488.
Definition: N2kTypes.h:767
tN2kDD482 tN2kAnchorDockingStates
Alias easier for humans to read for tN2kDD482.
Definition: N2kTypes.h:734
tN2kDD124 tN2kPRNUsageStatus
Alias easier for humans to read for tN2kDD124.
Definition: N2kTypes.h:622
tN2kWindReference
Enumeration of wind reference types according to PGN130306.
Definition: N2kTypes.h:252
tN2kSteeringMode
Enumeration of the steering mode according to PGN127237.
Definition: N2kTypes.h:530
tN2kAISUnit
Enumeration of AIS unit (transmission) type according to PGN 129039.
Definition: N2kTypes.h:424
tN2kDD374
Measurement delay source.
tN2kTempSource
Enumeration of sources for a temperature value according to PGN130311, PGN130312 and PGN130316.
Definition: N2kTypes.h:171
tN2kMOBStatus
Enumeration of ManOverBoard state according to PGN127233.
Definition: N2kTypes.h:554
tN2kGNSSDOPmode
Enumeration of GNSS DOP Mode according to PGN129539.
Definition: N2kTypes.h:156
tN2kDD002
DD002 - Generic Status Pair.
tN2kDD484 tN2kWindlassDirectionControl
Alias easier for humans to read for tN2kDD484.
Definition: N2kTypes.h:751
tN2kBatChem
Enumeration of battery chemistries according to PGN 127513.
Definition: N2kTypes.h:332
tN2kBatType
Enumeration of Battery types according to PGN 127513.
Definition: N2kTypes.h:306
tN2kGNSStype
Enumeration of the GPS system which is in use according to PGN129029, PGN129041 and PGN129794.
Definition: N2kTypes.h:108
tN2kAISNavStatus
Enumeration of navigational status of an ship sending out an AIS signal according to PGN 129038.
Definition: N2kTypes.h:398
tN2kDD002 tN2kGenericStatusPair
Alias easier for humans to read for tN2kDD002.
Definition: N2kTypes.h:587
tN2kSpeedWaterReferenceType
Enumeration of speed thru water sensors types according to PGN128259.
Definition: N2kTypes.h:266
tN2kDD481 tN2kRodeTypeStates
Alias easier for humans to read for tN2kDD481.
Definition: N2kTypes.h:726
tN2kDD488
DD488 - Speed Control Type according to PGN 128776.
tN2kBatEqSupport
Enumeration of Supports Equalization according to PGN 127513.
Definition: N2kTypes.h:318
tN2kHumiditySource
Enumeration of sources for a humidity value according to PGN130311 and PGN130313.
Definition: N2kTypes.h:194
tN2kDD480
DD480 - Windlass Motion States according to PGN 128777.
tN2kDD072 tN2kRangeResidualMode
Alias easier for humans to read for tN2kDD072.
Definition: N2kTypes.h:615
tN2kAISTransceiverInformation
Enumeration of 129039, 129041, 129802.
Definition: N2kTypes.h:459
tN2kAISRepeat
Enumeration of AIS repeat indicator according to PGN129802, PGN129809, PGN129810, PGN129038,...
Definition: N2kTypes.h:368
tN2kPressureSource
Enumeration of sources for a pressure value according to PGN130314 and PGN130315.
Definition: N2kTypes.h:204
tN2kFluidType
Enumeration of fluid types according to PGN127505.
Definition: N2kTypes.h:234
tN2kDD484
DD484 - Windlass Direction Control according to PGN 128776.
tN2kXTEMode
Enumeration of Cross Track Error modes according to PGN129283.
Definition: N2kTypes.h:95
tN2kDD374 tN2kDelaySource
Alias easier for humans to read for tN2kDD374.
Definition: N2kTypes.h:669
tN2kAISVersion
Enumeration of AIS version which is used in PGN 129794.
Definition: N2kTypes.h:388
Dedicated structure to handle AIS Aids to Navigation (AtoN) Report.
Definition: N2kMessages.h:3577
tN2kGNSStype GNSSType
Type of electronic position fixing device See tN2kGNSStype.
Definition: N2kMessages.h:3656
bool OffPositionIndicator
Off Position Indicator For floating AtoN, only.
Definition: N2kMessages.h:3636
double Length
AtoN Structure Length/Diameter in meters.
Definition: N2kMessages.h:3615
double PositionReferenceStarboard
Position Reference Point from Starboard Structure Edge/Radius.
Definition: N2kMessages.h:3619
double Beam
AtoN Structure Beam/Diameter in meters.
Definition: N2kMessages.h:3617
double PositionReferenceTrueNorth
Position Reference Point from True North facing Structure Edge/Radius.
Definition: N2kMessages.h:3622
char AtoNName[34+1]
Name of AtoN Object.
Definition: N2kMessages.h:3682
tN2kAISAtoNType AtoNType
Aid to Navigation (AtoN) Type, see tN2kAISAtoNType.
Definition: N2kMessages.h:3624
double Latitude
latitude of position [degree]
Definition: N2kMessages.h:3587
bool VirtualAtoNFlag
Virtual AtoN flag.
Definition: N2kMessages.h:3643
uint8_t AtoNStatus
AtoN Status byte Reserved for the indication of the AtoN status 00000000 = default.
Definition: N2kMessages.h:3662
uint32_t UserID
MMSI number.
Definition: N2kMessages.h:3583
bool AssignedModeFlag
Assigned Mode Flag.
Definition: N2kMessages.h:3650
uint8_t Seconds
TimeStamp UTC second when the report was generated.
Definition: N2kMessages.h:3613
bool RAIM
Receiver autonomous integrity monitoring (RAIM) flag of electronic position fixing device.
Definition: N2kMessages.h:3601
tN2kAISRepeat Repeat
Repeat indicator, Used by the repeater to indicate how many times a message has been repeated....
Definition: N2kMessages.h:3581
tN2kAISTransceiverInformation AISTransceiverInformation
AIS Transceiver Information see tN2kAISTransceiverInformation.
Definition: N2kMessages.h:3667
double Longitude
longitude of position [degree]
Definition: N2kMessages.h:3585
uint8_t MessageID
Message Type ID according to e ITU-R M.1371.
Definition: N2kMessages.h:3579
bool Accuracy
position accuracy
Definition: N2kMessages.h:3594
Dedicated structure to handle Data of a meterological station.
Definition: N2kMessages.h:5301
double AtmosphericPressure
Atmospheric pressure in Pascals. Use mBarToPascal, if you like to use mBar.
Definition: N2kMessages.h:5323
double WindDirection
Measured wind direction in radians. If you have value in degrees, use DegToRad() in call.
Definition: N2kMessages.h:5316
double OutsideAmbientAirTemperature
Outside ambient temperature in K. Use CToKelvin, if you want to use °C.
Definition: N2kMessages.h:5326
double WindSpeed
Measured wind speed in m/s.
Definition: N2kMessages.h:5313
double Longitude
The longitude of the current waypoint [degree].
Definition: N2kMessages.h:5311
char StationID[15+1]
Identifier of the transmitting weather station. (15 bytes max)
Definition: N2kMessages.h:5329
double WindGusts
Measured wind gusts speed in m/s.
Definition: N2kMessages.h:5320
double Latitude
The latitude of the current waypoint [degree].
Definition: N2kMessages.h:5309
char StationName[50+1]
Friendly name of the transmitting weather station. ( 50 bytes max)
Definition: N2kMessages.h:5332
tN2kWindReference WindReference
Wind reference, see definition tN2kWindReference.
Definition: N2kMessages.h:5318
double SystemTime
seconds since midnight
Definition: N2kMessages.h:5307
uint16_t SystemDate
Days since 1970-01-01.
Definition: N2kMessages.h:5305
Dedicated structure to handle GNSS satellite information.
Definition: N2kMessages.h:4130
double Azimuth
Azimuth of the satellite.
Definition: N2kMessages.h:4133
tN2kPRNUsageStatus UsageStatus
Usage Status, see tN2kPRNUsageStatus.
Definition: N2kMessages.h:4136
double RangeResiduals
Range Residual.
Definition: N2kMessages.h:4135
unsigned char PRN
PRN number [ 01 .. 32] of the satellite.
Definition: N2kMessages.h:4131
double SNR
SignalToNoiseRatio of the satellite.
Definition: N2kMessages.h:4134
double Elevation
Elevation of the satellite.
Definition: N2kMessages.h:4132
DD206 - Engine Discrete Warning Status.
uint16_t Status
2byte status with all individual status bits included
DD223 - Engine Discrete Warning Status.
uint16_t Status
2byte status with all individual status bits included
DD477 - Windlass Monitoring Events according to PGN 128778.
void SetEvents(unsigned char _Events)
unsigned char Events
1byte of all Windlass Monitoring Events, 0x00 would be NoErrors present
DD478 - Windlass Control Events according to PGN 128776.
unsigned char Events
1byte of all Windlass Control Events, 0x00 would be NoErrors present
void SetEvents(unsigned char _Events)
DD483 - Windlass Operating Events according to PGN 128777.
void SetEvents(unsigned char _Events)
unsigned char Events
1byte of all Windlass Operating Events, 0x00 would be NoErrors present