NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
N2kGroupFunction.cpp
Go to the documentation of this file.
1/*
2N2kGroupFunction.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
24#include "N2kGroupFunction.h"
25#include "NMEA2000.h"
26
27#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
28
29//*****************************************************************************
31 pNext=0;
32 pNMEA2000=_pNMEA2000;
33 PGN=_PGN;
35}
36
37//*****************************************************************************
38bool tN2kGroupFunctionHandler::Handle(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode GroupFunctionCode, unsigned long PGNForGroupFunction, int iDev) {
39 if ( PGN!=PGNForGroupFunction && PGN!=0 ) return false;
40
41 bool handled=false;
42 uint16_t ManufacturerCode;
43 uint8_t IndustryGroup;
44 uint8_t UniqueID;
45 uint8_t NumberOfSelectionPairs;
46 uint8_t NumberOfParameterPairs;
47 bool Propr=(PGN!=0?Proprietary:tNMEA2000::IsProprietaryMessage(PGNForGroupFunction));
48
49 switch (GroupFunctionCode) {
50 case N2kgfc_Request:
51 uint32_t TransmissionInterval;
52 uint16_t TransmissionIntervalOffset;
53
54 if (ParseRequestParams(N2kMsg,TransmissionInterval,TransmissionIntervalOffset,NumberOfParameterPairs)) {
55 handled=HandleRequest(N2kMsg,TransmissionInterval,TransmissionIntervalOffset,NumberOfParameterPairs,iDev);
56 }
57 break;
58 case N2kgfc_Command:
59 uint8_t PrioritySetting;
60
61 if ( tNMEA2000::IsBroadcast(N2kMsg.Destination) ) {
62 handled=true; // We can mark this handled, since command is not allowed to broadcast.
63 } else {
64 if (ParseCommandParams(N2kMsg,PrioritySetting,NumberOfParameterPairs)) {
65 handled=HandleCommand(N2kMsg,PrioritySetting,NumberOfParameterPairs,iDev);
66 }
67 }
68 break;
71 tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode;
72
73 if (ParseAcknowledgeParams(N2kMsg,PGNErrorCode,TransmissionOrPriorityErrorCode,NumberOfParameterPairs)) {
74 handled=HandleAcknowledge(N2kMsg,PGNErrorCode,TransmissionOrPriorityErrorCode,NumberOfParameterPairs,iDev);
75 }
76 break;
77 case N2kgfc_Read:
78 if ( tNMEA2000::IsBroadcast(N2kMsg.Destination) ) {
79 handled=true; // We can mark this handled, since read is not allowed to broadcast.
80 } else {
81 if (ParseReadOrWriteParams(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Propr)) {
82 handled=HandleReadFields(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,iDev);
83 }
84 }
85 break;
87 handled=true;
88 break;
89 case N2kgfc_Write:
90 if ( tNMEA2000::IsBroadcast(N2kMsg.Destination) ) {
91 handled=true; // We can mark this handled, since write is not allowed to broadcast.
92 } else {
93 if (ParseReadOrWriteParams(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Propr)) {
94 handled=HandleWriteFields(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,iDev);
95 }
96 }
97 break;
99 handled=true;
100 break;
101
102 }
103
104 return handled;
105}
106
107//*****************************************************************************
109 uint32_t TransmissionInterval,
110 uint16_t TransmissionIntervalOffset,
111 bool UseIntervalLimits,
112 uint32_t IntervalMax,
113 uint32_t IntervalMin,
114 bool UseOffsetLimits,
115 uint16_t OffsetMax
116 ) {
117 // On NMEA certification tests "C.3.13.2 Expanded Acknowledgment
118 // Message Timing" old tool does not know interval 0xFFFFFFFE=Restore Default Interval
119 // and so fails test. Use new test tool sw version or comment that out.
120 return ( (TransmissionInterval==0xFFFFFFFF // No change
121 || TransmissionInterval==0xFFFFFFFE // Restore default
122 || TransmissionInterval==0 // Turn off
123 || ( UseIntervalLimits && TransmissionInterval>=IntervalMin && TransmissionInterval<=IntervalMax)
124 )
125 &&
126 // Specification for transmission interval is confusing. To keep test tool
127 // happy, we accept also 0 offset
128 (TransmissionIntervalOffset==0xffff
129 || TransmissionIntervalOffset==0
130 || ( UseOffsetLimits && TransmissionIntervalOffset<=OffsetMax)
131 )
132 ?
135}
136
137//*****************************************************************************
139 uint32_t TransmissionInterval,
140 uint16_t TransmissionIntervalOffset,
141 uint8_t NumberOfParameterPairs,
142 int iDev) {
143
144 // As default we respond with not supported.
145 bool IsTxPGN=pNMEA2000->IsTxPGN(GetPGNForGroupFunction(N2kMsg),iDev);
149
150 if ( PGNec==N2kgfPGNec_PGNNotSupported ) TORec=N2kgfTPec_Acknowledge; // Always acknowledge for unknown PGN.
152 if ( TORec==N2kgfTPec_TransmitIntervalOrPriorityNotSupported ) { // Acknowledge PGN for known PGN but for invalid priority
154 } else {
155 TORec=N2kgfTPec_Acknowledge; //N2kgfTPec_RequestNotSupported;
156 }
157 }
158
159 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) {
161 PGNec,
162 TORec,
163 NumberOfParameterPairs, PARec);
164 }
165
166 return true;
167}
168
169//*****************************************************************************
170bool tN2kGroupFunctionHandler::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev) {
171
172 // As default we respond with not supported.
173 bool IsTxPGN=pNMEA2000->IsTxPGN(GetPGNForGroupFunction(N2kMsg),iDev);
177
178 if ( !(PrioritySetting == 0x08 || PrioritySetting == 0x0f || PrioritySetting == 0x09) ) TORec = N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
179
181 PGNec,
182 TORec,
183 NumberOfParameterPairs, PARec);
184
185 return true;
186}
187
188//*****************************************************************************
190 tN2kGroupFunctionPGNErrorCode /*PGNErrorCode*/,
191 tN2kGroupFunctionTransmissionOrPriorityErrorCode /*TransmissionOrPriorityErrorCode*/,
192 uint8_t /*ParameterCount*/,
193 int /*iDev*/) {
194 // As default, simply return true meaning that received acknowledge has been handled.
195 return true;
196}
197
198//*****************************************************************************
200 uint16_t /*ManufacturerCode*/, // This will be set to 0xffff for non-propprietary PNGs
201 uint8_t /*IndustryGroup*/, // This will be set to 0xff for non-propprietary PNGs
202 uint8_t /*UniqueID*/,
203 uint8_t /*NumberOfSelectionPairs*/,
204 uint8_t NumberOfParameterPairs,
205 int iDev) {
206
207 // As default we respond with not supported.
208 bool IsTxPGN=pNMEA2000->IsTxPGN(GetPGNForGroupFunction(N2kMsg),iDev);
211 PGNec,
213 NumberOfParameterPairs, N2kgfpec_Acknowledge);
214 return true;
215}
216
217//*****************************************************************************
218bool tN2kGroupFunctionHandler::HandleReadFieldsReply(const tN2kMsg &/*N2kMsg*/,int /*iDev*/) {
219 return true;
220}
221
222
223//*****************************************************************************
225 uint16_t /*ManufacturerCode*/, // This will be set to 0xffff for non-propprietary PNGs
226 uint8_t /*IndustryGroup*/, // This will be set to 0xff for non-propprietary PNGs
227 uint8_t /*UniqueID*/,
228 uint8_t /*NumberOfSelectionPairs*/,
229 uint8_t NumberOfParameterPairs,
230 int iDev) {
231 // As default we respond with not supported.
232 bool IsTxPGN=pNMEA2000->IsTxPGN(GetPGNForGroupFunction(N2kMsg),iDev);
235 PGNec,
237 NumberOfParameterPairs, N2kgfpec_Acknowledge);
238
239 return true;
240}
241
242//*****************************************************************************
243bool tN2kGroupFunctionHandler::HandleWriteFieldsReply(const tN2kMsg &/*N2kMsg*/,int /*iDev*/) {
244 return true;
245}
246
247// Static functions for PGN 126208 handling
248//*****************************************************************************
250 int Index=1;
251 return N2kMsg.Get3ByteUInt(Index);
252}
253
254//*****************************************************************************
256 tN2kGroupFunctionCode &GroupFunctionCode,
257 unsigned long &PGNForGroupFunction) {
258 if (N2kMsg.PGN!=126208L) return false;
259
260 GroupFunctionCode=(tN2kGroupFunctionCode)(N2kMsg.Data[0]);
261 PGNForGroupFunction=GetPGNForGroupFunction(N2kMsg);
262
263 return true;
264}
265
266#define N2kgf_OffsetToParams 4
267#define N2kgf_OffsetToRequestPairParameters 11
268#define N2kgf_OffsetToCommandPairParameters 6
269
270//*****************************************************************************
272 uint32_t &TransmissionInterval,
273 uint16_t &TransmissionIntervalOffset,
274 uint8_t &NumberOfParameterPairs) {
275 if (N2kMsg.PGN!=126208L) return false;
276 int Index=N2kgf_OffsetToParams;
277 TransmissionInterval=N2kMsg.Get4ByteUInt(Index);
278 TransmissionIntervalOffset=N2kMsg.Get2ByteUInt(Index);
279 NumberOfParameterPairs=N2kMsg.GetByte(Index);
280
281 return true;
282}
283
284//*****************************************************************************
286 if (N2kMsg.PGN!=126208L) return false;
288
289 return true;
290}
291
292//*****************************************************************************
294 uint8_t &PrioritySetting,
295 uint8_t &NumberOfParameterPairs) {
296 if (N2kMsg.PGN!=126208L) return false;
297 int Index=N2kgf_OffsetToParams;
298 PrioritySetting=N2kMsg.GetByte(Index) & 0x0f;
299 NumberOfParameterPairs=N2kMsg.GetByte(Index);
300
301 return true;
302}
303
304//*****************************************************************************
306 if (N2kMsg.PGN!=126208L) return false;
308
309 return true;
310}
311
312//*****************************************************************************
314 tN2kGroupFunctionPGNErrorCode &PGNErrorCode,
315 tN2kGroupFunctionTransmissionOrPriorityErrorCode &TransmissionOrPriorityErrorCode,
316 uint8_t &NumberOfParameterPairs) {
317 PGNErrorCode=N2kgfPGNec_PGNNotSupported;
318 TransmissionOrPriorityErrorCode=N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
319 NumberOfParameterPairs=0;
320 if (N2kMsg.PGN!=126208L) return false;
321 int Index=N2kgf_OffsetToParams;
322 uint8_t b=N2kMsg.GetByte(Index);
323 PGNErrorCode=(tN2kGroupFunctionPGNErrorCode)(b&0x0f);
324 TransmissionOrPriorityErrorCode=(tN2kGroupFunctionTransmissionOrPriorityErrorCode)(b>>4);
325
326 return true;
327}
328
329//*****************************************************************************
330bool tN2kGroupFunctionHandler::StartParseReadOrWriteParameters(const tN2kMsg &N2kMsg, bool Proprietary, int &Index) {
332 if ( Proprietary ) {
333 Index+=5;
334 } else {
335 Index+=3;
336 }
337
338 return true;
339}
340
341//*****************************************************************************
343 uint16_t &ManufacturerCode,
344 uint8_t &IndustryGroup,
345 uint8_t &UniqueID,
346 uint8_t &NumberOfSelectionPairs,
347 uint8_t &NumberOfParameterPairs,
348 bool Proprietary) {
349 if (N2kMsg.PGN!=126208L) return false;
350 int Index=N2kgf_OffsetToParams;
351 ManufacturerCode=0xffff; // We need here information is PGN proprietary or not
352 IndustryGroup=0xff;
353 if ( Proprietary ) {
354 uint16_t ProprietaryInfo=N2kMsg.Get2ByteUInt(Index);
355 ManufacturerCode=ProprietaryInfo & 0x07ff;
356 IndustryGroup=(ProprietaryInfo>>13) &0x07;
357 }
358 UniqueID=N2kMsg.GetByte(Index);
359 NumberOfSelectionPairs=N2kMsg.GetByte(Index);
360 NumberOfParameterPairs=N2kMsg.GetByte(Index);
361
362 return true;
363}
364
365//*****************************************************************************
366void SetStartReadOrWriteReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN, tN2kGroupFunctionCode cmd,
367 uint16_t ManufacturerCode,
368 uint8_t IndustryGroup,
369 uint8_t UniqueID,
370 uint8_t NumberOfSelectionPairs,
371 uint8_t NumberOfParameterPairs,
372 bool Proprietary) {
373 N2kMsg.SetPGN(126208L);
374 N2kMsg.Priority=3;
375 N2kMsg.Destination=Destination;
376 N2kMsg.AddByte(cmd);
377 N2kMsg.Add3ByteInt(PGN);
378 if ( Proprietary ) {
379 uint16_t ProprietaryInfo = IndustryGroup<<13 | 0x1800 | (ManufacturerCode & 0x07ff);
380 N2kMsg.Add2ByteUInt(ProprietaryInfo);
381 }
382 N2kMsg.AddByte(UniqueID);
383 N2kMsg.AddByte(NumberOfSelectionPairs);
384 N2kMsg.AddByte(NumberOfParameterPairs);
385}
386
387//*****************************************************************************
388void tN2kGroupFunctionHandler::SetStartReadReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN,
389 uint16_t ManufacturerCode,
390 uint8_t IndustryGroup,
391 uint8_t UniqueID,
392 uint8_t NumberOfSelectionPairs,
393 uint8_t NumberOfParameterPairs,
394 bool Proprietary) {
395
397 ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Proprietary
398 );
399}
400
401//*****************************************************************************
402void tN2kGroupFunctionHandler::SetStartWriteReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN,
403 uint16_t ManufacturerCode,
404 uint8_t IndustryGroup,
405 uint8_t UniqueID,
406 uint8_t NumberOfSelectionPairs,
407 uint8_t NumberOfParameterPairs,
408 bool Proprietary) {
409
411 ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Proprietary
412 );
413}
414
415//*****************************************************************************
416void tN2kGroupFunctionHandler::SetStartAcknowledge(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN,
418 tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode,
419 uint8_t NumberOfParameterPairs) {
420 N2kMsg.Clear();
421 N2kMsg.SetPGN(126208L);
422 N2kMsg.Priority=3;
423 N2kMsg.Destination=Destination;
425 N2kMsg.Add3ByteInt(PGN);
426 N2kMsg.AddByte(PGNErrorCode | TransmissionOrPriorityErrorCode<<4);
427 N2kMsg.AddByte(NumberOfParameterPairs);
428}
429
430#define ErrorcodeIndex 4
431
432//*****************************************************************************
434 int Index=ErrorcodeIndex;
435 uint8_t ec=N2kMsg.GetByte(Index);
436 ec = (ec & 0xf0) | PGNErrorCode;
437 N2kMsg.Data[ErrorcodeIndex]=ec;
438}
439
440//*****************************************************************************
442 int Index=ErrorcodeIndex;
443 uint8_t ec=N2kMsg.GetByte(Index);
444 ec = (ec & 0x0f) | (TransmissionOrPriorityErrorCode<<4);
445 N2kMsg.Data[ErrorcodeIndex]=ec;
446}
447
448//*****************************************************************************
450 uint8_t ParameterPairIndex,
452 if ( ((ParameterPairIndex % 2) == 0) && (N2kMsg.DataLen>0) ) {
453 N2kMsg.AddByte((uint8_t)(ErrorCode) | 0x0f << 4);
454 } else {
455 // Should actually add AddBits to N2kMsg
456 N2kMsg.Data[N2kMsg.DataLen-1]=(N2kMsg.Data[N2kMsg.DataLen-1] & 0x0f) | ((uint8_t)(ErrorCode) << 4);
457 }
458}
459
460//*****************************************************************************
461void tN2kGroupFunctionHandler::SendAcknowledge(tNMEA2000 *pNMEA2000, unsigned char Destination, int iDev, unsigned long PGN,
463 tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode,
464 uint8_t NumberOfParameterPairs,
465 tN2kGroupFunctionParameterErrorCode ParameterErrorCodeForAll) {
466 tN2kMsg N2kRMsg;
467
468 // As default we respond with not supported.
469 SetStartAcknowledge(N2kRMsg,Destination,PGN,
470 PGNErrorCode,
471 TransmissionOrPriorityErrorCode,
472 NumberOfParameterPairs);
473 for (uint8_t ParamIndex=0; ParamIndex<NumberOfParameterPairs;ParamIndex++) {
474 AddAcknowledgeParameter(N2kRMsg,ParamIndex,ParameterErrorCodeForAll);
475 }
476 pNMEA2000->SendMsg(N2kRMsg,iDev);
477}
478
479#endif
void SetStartReadOrWriteReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN, tN2kGroupFunctionCode cmd, uint16_t ManufacturerCode, uint8_t IndustryGroup, uint8_t UniqueID, uint8_t NumberOfSelectionPairs, uint8_t NumberOfParameterPairs, bool Proprietary)
#define ErrorcodeIndex
#define N2kgf_OffsetToRequestPairParameters
#define N2kgf_OffsetToCommandPairParameters
#define N2kgf_OffsetToParams
Base and default group function PGN 126208 message handler class.
tN2kGroupFunctionParameterErrorCode
Error Codes Command used by acknowledge group function.
@ N2kgfpec_Acknowledge
tN2kGroupFunctionPGNErrorCode
PGN error code used by acknowledge group function.
@ N2kgfPGNec_PGNTemporarilyNotAvailable
@ N2kgfPGNec_Acknowledge
@ N2kgfPGNec_PGNNotSupported
@ N2kgfPGNec_ReadOrWriteNotSupported
tN2kGroupFunctionTransmissionOrPriorityErrorCode
Error codes Transmit interval used by acknowledge group function.
@ N2kgfTPec_Acknowledge
@ N2kgfTPec_TransmitIntervalOrPriorityNotSupported
tN2kGroupFunctionCode
FunctionCode for the group function.
@ N2kgfc_Command
@ N2kgfc_Write
@ N2kgfc_Request
@ N2kgfc_WriteReply
@ N2kgfc_ReadReply
@ N2kgfc_Acknowledge
@ N2kgfc_Read
This file contains the class tNMEA2000, which consists the main functionality of the library.
static bool ParseRequestParams(const tN2kMsg &N2kMsg, uint32_t &TransmissionInterval, uint16_t &TransmissionIntervalOffset, uint8_t &NumberOfParameterPairs)
Parse parameters from request group function message.
static bool ParseCommandParams(const tN2kMsg &N2kMsg, uint8_t &PrioritySetting, uint8_t &NumberOfParameterPairs)
Parse parameters from command group function message.
virtual bool HandleAcknowledge(const tN2kMsg &N2kMsg, tN2kGroupFunctionPGNErrorCode PGNErrorCode, tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode, uint8_t NumberOfParameterPairs, int iDev)
Default handle function for acknowledge group function.
static bool ParseAcknowledgeParams(const tN2kMsg &N2kMsg, tN2kGroupFunctionPGNErrorCode &PGNErrorCode, tN2kGroupFunctionTransmissionOrPriorityErrorCode &TransmissionOrPriorityErrorCode, uint8_t &NumberOfParameterPairs)
Parse parameters from acknowledge group function message.
bool Proprietary
Flag, if the Parameter Group is proprietary
static bool StartParseRequestPairParameters(const tN2kMsg &N2kMsg, int &Index)
Get start Index of pair parameters from request group function message.
virtual bool HandleReadFieldsReply(const tN2kMsg &N2kMsg, int iDev)
Handle read fields reply group function.
virtual bool Handle(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode GroupFunctionCode, unsigned long PGNForGroupFunction, int iDev)
Handle group function message.
static bool Parse(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode &GroupFunctionCode, unsigned long &PGNForGroupFunction)
Parse group function code and requested/commanded etc. PGN from group function message.
virtual bool HandleWriteFields(const tN2kMsg &N2kMsg, uint16_t ManufacturerCode, uint8_t IndustryGroup, uint8_t UniqueID, uint8_t NumberOfSelectionPairs, uint8_t NumberOfParameterPairs, int iDev)
Handle response for write fields group function.
tN2kGroupFunctionHandler(tNMEA2000 *_pNMEA2000, unsigned long _PGN)
Construct a new tN2kGroupFunctionHandler object.
static unsigned long GetPGNForGroupFunction(const tN2kMsg &N2kMsg)
Get requested/commanded etc. PGN from group function message.
static bool ParseReadOrWriteParams(const tN2kMsg &N2kMsg, uint16_t &ManufacturerCode, uint8_t &IndustryGroup, uint8_t &UniqueID, uint8_t &NumberOfSelectionPairs, uint8_t &NumberOfParameterPairs, bool Proprietary=false)
Parse parameters from read or write group function message.
static void SendAcknowledge(tNMEA2000 *pNMEA2000, unsigned char Destination, int iDev, unsigned long PGN, tN2kGroupFunctionPGNErrorCode PGNErrorCode, tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode, uint8_t NumberOfParameterPairs=0, tN2kGroupFunctionParameterErrorCode ParameterErrorCodeForAll=N2kgfpec_Acknowledge)
Send out an acknowledge group function message.
virtual bool HandleWriteFieldsReply(const tN2kMsg &N2kMsg, int iDev)
Handle write fields reply group function.
virtual tN2kGroupFunctionTransmissionOrPriorityErrorCode GetRequestGroupFunctionTransmissionOrPriorityErrorCode(uint32_t TransmissionInterval, uint16_t TransmissionIntervalOffset, bool UseIntervalLimits=false, uint32_t IntervalMax=N2k_MAX_TRANSMISSION_INTERVAL, uint32_t IntervalMin=50, bool UseOffsetLimits=false, uint16_t OffsetMax=N2k_MAX_TRANSMISSION_INTERVAL_OFFSET)
Get request group function transmission or priority error code.
static void SetStartWriteReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN, uint16_t ManufacturerCode, uint8_t IndustryGroup, uint8_t UniqueID, uint8_t NumberOfSelectionPairs, uint8_t NumberOfParameterPairs, bool Proprietary)
Setup start parameters for write reply group function message.
static void SetStartAcknowledge(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN, tN2kGroupFunctionPGNErrorCode PGNErrorCode, tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode, uint8_t NumberOfParameterPairs=0)
Setting up the group function message for Acknowledge.
virtual bool HandleReadFields(const tN2kMsg &N2kMsg, uint16_t ManufacturerCode, uint8_t IndustryGroup, uint8_t UniqueID, uint8_t NumberOfSelectionPairs, uint8_t NumberOfParameterPairs, int iDev)
Handle response for read fields group function.
tNMEA2000 * pNMEA2000
NMEA2000 object in order to send messages to the bus
static bool StartParseCommandPairParameters(const tN2kMsg &N2kMsg, int &Index)
Get start Index of pair parameters from command group function message.
static void ChangeTransmissionOrPriorityErrorCode(tN2kMsg &N2kMsg, tN2kGroupFunctionTransmissionOrPriorityErrorCode TransmissionOrPriorityErrorCode)
Change transmission interval or priority error code for acknowledge group function message.
unsigned long PGN
Parameter Group Number (PGN) of this Group Function.
virtual bool HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev)
Handle response for command group function.
virtual bool HandleRequest(const tN2kMsg &N2kMsg, uint32_t TransmissionInterval, uint16_t TransmissionIntervalOffset, uint8_t NumberOfParameterPairs, int iDev)
Handle response for request group function.
static void AddAcknowledgeParameter(tN2kMsg &N2kMsg, uint8_t ParameterPairIndex, tN2kGroupFunctionParameterErrorCode ErrorCode=N2kgfpec_ReadOrWriteIsNotSupported)
Add parameter error code to acknowledge group function message.
static void ChangePNGErrorCode(tN2kMsg &N2kMsg, tN2kGroupFunctionPGNErrorCode PGNErrorCode)
Change the PGN error code for a acknowledge group function message.
static bool StartParseReadOrWriteParameters(const tN2kMsg &N2kMsg, bool Proprietary, int &Index)
Get start index of pair parameters on the read or write group function message.
static void SetStartReadReply(tN2kMsg &N2kMsg, unsigned char Destination, unsigned long PGN, uint16_t ManufacturerCode, uint8_t IndustryGroup, uint8_t UniqueID, uint8_t NumberOfSelectionPairs, uint8_t NumberOfParameterPairs, bool Proprietary)
Setup start parameters for read reply group function message.
This class contains all the data of an NMEA2000 message.
Definition: N2kMsg.h:656
unsigned char Data[MaxDataLen]
Byte array which carries all the data of the NMEA2000 message.
Definition: N2kMsg.h:675
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
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
uint16_t Get2ByteUInt(int &Index, uint16_t def=0xffff) const
Get an unsigned integer from 2 bytes out of Data.
Definition: N2kMsg.cpp:268
unsigned char Source
Source of the NMEA2000 message.
Definition: N2kMsg.h:669
unsigned char Priority
Priority of the NMEA2000 message.
Definition: N2kMsg.h:665
uint32_t Get3ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 3 bytes out of Data.
Definition: N2kMsg.cpp:275
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
virtual void Clear()
Clears the content of the N2kMsg object The method sets the PGN, DataLen and MsgTime to zero.
Definition: N2kMsg.cpp:94
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
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
unsigned char Destination
Destination of the NMEA2000 message.
Definition: N2kMsg.h:671
tNMEA2000 device class definition.
Definition: NMEA2000.h:138
bool IsTxPGN(unsigned long PGN, int iDev=0)
Check if this message is a Transmit message of this device.
Definition: NMEA2000.cpp:875
static bool IsBroadcast(unsigned char Source)
Checks if the given Address is a broadcast address.
Definition: NMEA2000.h:2990
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.
Definition: NMEA2000.cpp:1450
static bool IsProprietaryMessage(unsigned long PGN)
Check if the given PGN is proprietary.
Definition: NMEA2000.cpp:583