NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
N2kGroupFunctionDefaultHandlers.cpp
Go to the documentation of this file.
1/*
2N2kGroupFunctionDefaultHandlers.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 <string.h>
26#include "NMEA2000.h"
27
28#define N2kPGN60928_UniqueNumber_field 1
29#define N2kPGN60928_ManufacturerCode_field 2
30#define N2kPGN60928_DeviceInstanceLower_field 3
31#define N2kPGN60928_DeviceInstanceUpper_field 4
32#define N2kPGN60928_DeviceFunction_field 5
33#define N2kPGN60928_Reserved_field 6
34#define N2kPGN60928_DeviceClass_field 7
35#define N2kPGN60928_SystemInstance_field 8
36#define N2kPGN60928_IndustryGroup_field 9
37#define N2kPGN60928_ISOSelfConfigurable_field 10
38
39#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
40
41//*****************************************************************************
42// See document https://web.archive.org/web/20150910070107/http://www.nmea.org/Assets/20140710%20nmea-2000-060928%20iso%20address%20claim%20pgn%20corrigendum.pdf
43// For requirements for handling Group function request for PGN 60928
45 uint32_t TransmissionInterval,
46 uint16_t TransmissionIntervalOffset,
47 uint8_t NumberOfParameterPairs,
48 int iDev) {
50 bool MatchFilter=true;
51 tN2kMsg N2kRMsg;
52
53 // Start to build response
54 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
55 N2kgfPGNec_Acknowledge, // Always acknowledge for mandatory PGN
56 pec,
57 NumberOfParameterPairs);
58 N2kRMsg.Destination=N2kMsg.Source;
59
60 if ( NumberOfParameterPairs>0 ) { // We need to filter according to fields
61 int i;
62 int Index;
63 uint8_t field;
66 bool FoundInvalidField=false;
67
69 // Next read new field values. Note that if message is not broadcast, we need to parse all fields always.
70 for (i=0; i<NumberOfParameterPairs && (MatchFilter || !tNMEA2000::IsBroadcast(N2kMsg.Destination)); i++) {
71 if ( !FoundInvalidField) {
72 field=N2kMsg.GetByte(Index);
73 switch (field) {
75 MatchRequestField(N2kMsg.Get3ByteUInt(Index),(uint32_t)DI.GetUniqueNumber(),(uint32_t)0x001fffff,MatchFilter,FieldErrorCode);
76 break;
78 MatchRequestField(N2kMsg.Get2ByteUInt(Index),DI.GetManufacturerCode(),(uint16_t)0x07ff,MatchFilter,FieldErrorCode);
79 break;
81 MatchRequestField(N2kMsg.GetByte(Index),DI.GetDeviceInstanceLower(),(uint8_t)0x07,MatchFilter,FieldErrorCode);
82 break;
84 MatchRequestField(N2kMsg.GetByte(Index),DI.GetDeviceInstanceUpper(),(uint8_t)0x1f,MatchFilter,FieldErrorCode);
85 break;
87 MatchRequestField(N2kMsg.GetByte(Index),DI.GetDeviceFunction(),(uint8_t)0xff,MatchFilter,FieldErrorCode);
88 break;
90 N2kMsg.GetByte(Index);
91 FieldErrorCode=N2kgfpec_Acknowledge;
92 break;
94 MatchRequestField(N2kMsg.GetByte(Index),DI.GetDeviceClass(),(uint8_t)0x7f,MatchFilter,FieldErrorCode);
95 break;
97 MatchRequestField(N2kMsg.GetByte(Index),DI.GetSystemInstance(),(uint8_t)0x0f,MatchFilter,FieldErrorCode);
98 break;
100 MatchRequestField(N2kMsg.GetByte(Index),DI.GetIndustryGroup(),(uint8_t)0x07,MatchFilter,FieldErrorCode);
101 break;
103 N2kMsg.GetByte(Index);
104 FieldErrorCode=N2kgfpec_Acknowledge;
105 break;
106 default:
108 MatchFilter=false;
109 FoundInvalidField=true;
110 }
111 } else {
112 // If there is any invalid field, we can not parse others, since we do not
113 // know right data length. So for rest of the fields we can only send response below.
115 }
116 AddAcknowledgeParameter(N2kRMsg,i,FieldErrorCode);
117 }
118 }
119
120 bool RequestOK=(MatchFilter && pec==N2kgfTPec_Acknowledge);
121
122 // Send Acknowledge, if request was not broadcast and it did not match
123 if ( !RequestOK ) {
124 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) pNMEA2000->SendMsg(N2kRMsg,iDev);
125 } else {
126 // Send delayed - there was problems with test tool with too fast response.
127 pNMEA2000->SendIsoAddressClaim(0xff,iDev,2);
128 }
129
130 return true;
131}
132
133//*****************************************************************************
134// Command group function for 60928 can be used to set Device Instance Lower, Device Instance Upper and System Instance
135// values on device name. They all are in padded to one byte.
136bool tN2kGroupFunctionHandlerForPGN60928::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev) {
137 int i;
138 int Index;
139 uint8_t field;
140 uint8_t DILower=0xff;
141 uint8_t DIUpper=0xff;
142 uint8_t SI=0xff;
145 tN2kMsg N2kRMsg;
146
147 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
148 N2kgfPGNec_Acknowledge, // What we actually should response as PGN error, if we have invalid field?
149 pec,
150 NumberOfParameterPairs);
151
152 if (PrioritySetting!=8) pec=N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
154 // Next read new field values
155 for (i=0; i<NumberOfParameterPairs; i++) {
156 field=N2kMsg.GetByte(Index);
158 switch (field) {
160 DILower=N2kMsg.GetByte(Index) & 0x7;
161 break;
163 DIUpper=N2kMsg.GetByte(Index) & 0x1f;
164 break;
166 SI=N2kMsg.GetByte(Index) & 0x0f;
167 break;
168 default:
170 }
171
172 AddAcknowledgeParameter(N2kRMsg,i,PARec);
173 }
174
175 pNMEA2000->SendMsg(N2kRMsg,iDev);
176 pNMEA2000->SetDeviceInformationInstances(DILower,DIUpper,SI,iDev);
177
178 return true;
179}
180
181//*****************************************************************************
182// See document https://web.archive.org/web/20150910070107/http://www.nmea.org/Assets/20140710%20nmea-2000-060928%20iso%20address%20claim%20pgn%20corrigendum.pdf
183// For requirements for handling Group function request for PGN 60928
185 uint32_t TransmissionInterval,
186 uint16_t TransmissionIntervalOffset,
187 uint8_t NumberOfParameterPairs,
188 int iDev) {
190 bool MatchFilter=true;
191 uint8_t RespondTxRx=0xff;
192 tN2kMsg N2kRMsg;
193
194 // Start to build response
195 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
196 N2kgfPGNec_Acknowledge, // What we actually should response as PGN error, if we have invalid field?
197 pec,
198 NumberOfParameterPairs);
199 N2kRMsg.Destination=N2kMsg.Source;
200
201 if ( NumberOfParameterPairs>0 ) { // We need to filter according to fields
202 int i;
203 int Index;
204 uint8_t field;
206 bool FoundInvalidField=false;
207
209 // Next read new field values. Note that if message is not broadcast, we need to parse all fields always.
210 for (i=0; i<NumberOfParameterPairs && (MatchFilter || !tNMEA2000::IsBroadcast(N2kMsg.Destination)); i++) {
211 if ( !FoundInvalidField) {
212 field=N2kMsg.GetByte(Index);
213 switch (field) {
214 case 1: // Selection of Tx or Rx
215 RespondTxRx=N2kMsg.GetByte(Index);
216 if ( RespondTxRx==N2kpgnl_transmit || RespondTxRx==N2kpgnl_receive ) {
217 FieldErrorCode=N2kgfpec_Acknowledge;
218 } else {
220 MatchFilter=false;
221 }
222 break;
223 default:
225 MatchFilter=false;
226 FoundInvalidField=true;
227 }
228 } else {
229 // If there is any invalid field, we can not parse others, since we do not
230 // know right data length. So fo rest of the fields we can only send response below.
232 }
233 AddAcknowledgeParameter(N2kRMsg,i,FieldErrorCode);
234 }
235 }
236
237 bool RequestOK=(MatchFilter && pec==N2kgfTPec_Acknowledge);
238
239 // Send Acknowledge, if request was not broadcast and it did not match
240 if ( !RequestOK ) {
241 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) pNMEA2000->SendMsg(N2kRMsg,iDev);
242 } else {
243#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
244 unsigned char dest=N2kMsg.Source;
245 if ( N2kMsg.IsTPMessage() && tNMEA2000::IsBroadcast(N2kMsg.Destination) ) dest=N2kMsg.Destination;
246 if ( (RespondTxRx==N2kpgnl_transmit) || (RespondTxRx==0xff) ) pNMEA2000->SendTxPGNList(dest,iDev,N2kMsg.IsTPMessage());
247 if ( (RespondTxRx==N2kpgnl_receive) || (RespondTxRx==0xff) ) pNMEA2000->SendRxPGNList(dest,iDev,N2kMsg.IsTPMessage());
248#else
249 if ( (RespondTxRx==N2kpgnl_transmit) || (RespondTxRx==0xff) ) pNMEA2000->SendTxPGNList(N2kMsg.Source,iDev);
250 if ( (RespondTxRx==N2kpgnl_receive) || (RespondTxRx==0xff) ) pNMEA2000->SendRxPGNList(N2kMsg.Source,iDev);
251#endif
252 }
253
254 return true;
255}
256
257#define N2kPGN126996_NMEA2000DatabaseVersion_field 1
258#define N2kPGN126996_NMEAManufacturersProductCode_field 2
259#define N2kPGN126996_ManufacturersModelID_field 3
260#define N2kPGN126996_ManufacturersSoftwareVersionCode_field 4
261#define N2kPGN126996_ManufacturersModelVersion_field 5
262#define N2kPGN126996_ManufacturersModelSerialCode_field 6
263#define N2kPGN126996_NMEA2000CertificationLevel_field 7
264#define N2kPGN126996_LoadEquivalency_field 8
265
266//*****************************************************************************
267// See document https://web.archive.org/web/20150910070107/http://www.nmea.org/Assets/20140710%20nmea-2000-060928%20iso%20address%20claim%20pgn%20corrigendum.pdf
268// For requirements for handling Group function request for PGN 60928
270 uint32_t TransmissionInterval,
271 uint16_t TransmissionIntervalOffset,
272 uint8_t NumberOfParameterPairs,
273 int iDev) {
275 bool MatchFilter=true;
276 tN2kMsg N2kRMsg;
277
278 // Start to build response
279 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
280 N2kgfPGNec_Acknowledge, // What we actually should response as PGN error, if we have invalid field?
281 pec,
282 NumberOfParameterPairs);
283 N2kRMsg.Destination=N2kMsg.Source;
284
285 if ( NumberOfParameterPairs>0 ) { // We need to filter according to fields
286 int i;
287 int Index;
288 uint8_t field;
290 bool FoundInvalidField=false;
291 size_t strSize=Max_N2kProductInfoStrLen;
292 char Query[strSize];
293 char CurVal[strSize];
294
296 // Next read new field values. Note that if message is not broadcast, we need to parse all fields always.
297 for (i=0; i<NumberOfParameterPairs && (MatchFilter || !tNMEA2000::IsBroadcast(N2kMsg.Destination)); i++) {
298 if ( !FoundInvalidField) {
299 field=N2kMsg.GetByte(Index);
300 switch (field) {
302 MatchRequestField(N2kMsg.Get2ByteUInt(Index),(uint16_t)pNMEA2000->GetN2kVersion(iDev),(uint16_t)0xffff,MatchFilter,FieldErrorCode);
303 break;
305 MatchRequestField(N2kMsg.Get2ByteUInt(Index),(uint16_t)pNMEA2000->GetProductCode(iDev),(uint16_t)0xffff,MatchFilter,FieldErrorCode);
306 break;
308 N2kMsg.GetStr(strSize,Query,Max_N2kModelID_len,0xff,Index);
309 pNMEA2000->GetModelID(CurVal,strSize,iDev);
310 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
311 break;
313 N2kMsg.GetStr(strSize,Query,Max_N2kSwCode_len,0xff,Index);
314 pNMEA2000->GetModelID(CurVal,strSize,iDev);
315 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
316 break;
318 N2kMsg.GetStr(strSize,Query,Max_N2kModelVersion_len,0xff,Index);
319 pNMEA2000->GetModelID(CurVal,strSize,iDev);
320 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
321 break;
323 N2kMsg.GetStr(strSize,Query,Max_N2kModelSerialCode_len,0xff,Index);
324 pNMEA2000->GetModelID(CurVal,strSize,iDev);
325 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
326 break;
328 MatchRequestField(N2kMsg.GetByte(Index),(uint8_t)pNMEA2000->GetCertificationLevel(iDev),(uint8_t)0xff,MatchFilter,FieldErrorCode);
329 break;
331 MatchRequestField(N2kMsg.GetByte(Index),(uint8_t)pNMEA2000->GetLoadEquivalency(iDev),(uint8_t)0xff,MatchFilter,FieldErrorCode);
332 break;
333 default:
335 MatchFilter=false;
336 FoundInvalidField=true;
337 }
338 } else {
339 // If there is any invalid field, we can not parse others, since we do not
340 // know right data length. So for rest of the fields we can only send response below.
342 }
343 AddAcknowledgeParameter(N2kRMsg,i,FieldErrorCode);
344 }
345 }
346
347 bool RequestOK=(MatchFilter && pec==N2kgfTPec_Acknowledge);
348
349 // Send Acknowledge, if request was not broadcast and it did not match
350 if ( !RequestOK ) {
351 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) pNMEA2000->SendMsg(N2kRMsg,iDev);
352 } else {
353#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
354 unsigned char dest=N2kMsg.Source;
355 if ( N2kMsg.IsTPMessage() && tNMEA2000::IsBroadcast(N2kMsg.Destination) ) dest=N2kMsg.Destination;
356 pNMEA2000->SendProductInformation(dest,iDev,N2kMsg.IsTPMessage());
357#else
359#endif
360 }
361
362 return true;
363}
364
365#define N2kPGN126998_InstallationDescription1_field 1
366#define N2kPGN126998_InstallationDescription2_field 2
367#define N2kPGN126998_ManufacturerInformation_field 3
368
369//*****************************************************************************
370// See document https://web.archive.org/web/20150910070107/http://www.nmea.org/Assets/20140710%20nmea-2000-060928%20iso%20address%20claim%20pgn%20corrigendum.pdf
371// For requirements for handling Group function request for PGN 60928
373 uint32_t TransmissionInterval,
374 uint16_t TransmissionIntervalOffset,
375 uint8_t NumberOfParameterPairs,
376 int iDev) {
378 bool MatchFilter=true;
379 tN2kMsg N2kRMsg;
380
381 // Start to build response
382 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
383 N2kgfPGNec_Acknowledge, // What we actually should response as PGN error, if we have invalid field?
384 pec,
385 NumberOfParameterPairs);
386 N2kRMsg.Destination=N2kMsg.Source;
387
388 if ( NumberOfParameterPairs>0 ) { // We need to filter according to fields
389 int i;
390 int Index;
391 uint8_t field;
393 bool FoundInvalidField=false;
396 size_t QueryStrSize;
397
399 // Next read new field values. Note that if message is not broadcast, we need to parse all fields always.
400 for (i=0; i<NumberOfParameterPairs && (MatchFilter || !tNMEA2000::IsBroadcast(N2kMsg.Destination)); i++) {
401 if ( !FoundInvalidField) {
402 field=N2kMsg.GetByte(Index);
403 switch (field) {
406 N2kMsg.GetVarStr(QueryStrSize,Query,Index);
408 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
409 break;
412 N2kMsg.GetVarStr(QueryStrSize,Query,Index);
414 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
415 break;
418 N2kMsg.GetVarStr(QueryStrSize,Query,Index);
420 MatchRequestField(Query,CurVal,MatchFilter,FieldErrorCode);
421 break;
422 default:
424 MatchFilter=false;
425 FoundInvalidField=true;
426 }
427 } else {
428 // If there is any invalid field, we can not parse others, since we do not
429 // know right data length. So for rest of the fields we can only send response below.
431 }
432 AddAcknowledgeParameter(N2kRMsg,i,FieldErrorCode);
433 }
434
435 }
436
437 bool RequestOK=(MatchFilter && pec==N2kgfTPec_Acknowledge);
438
439 // Send Acknowledge, if request was not broadcast and it did not match
440 if ( !RequestOK ) {
441 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) pNMEA2000->SendMsg(N2kRMsg,iDev);
442 } else {
443#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
444 unsigned char dest=N2kMsg.Source;
445 if ( N2kMsg.IsTPMessage() && tNMEA2000::IsBroadcast(N2kMsg.Destination) ) dest=N2kMsg.Destination;
447#else
449#endif
450 }
451
452 return true;
453}
454
455//*****************************************************************************
456// Command group function for 126998 can be used to set installation description 1 and 2 fields
457bool tN2kGroupFunctionHandlerForPGN126998::HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev) {
458 int i;
459 int Index;
460 uint8_t field;
461 size_t InstallationDescriptionSize;
462 char InstallationDescription[Max_N2kConfigurationInfoField_len];
464 tN2kMsg N2kRMsg;
465
466 if ( !(PrioritySetting == 0x08 || PrioritySetting == 0x0f || PrioritySetting == 0x09) ) pec = N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
467
468 SetStartAcknowledge(N2kRMsg,N2kMsg.Source,PGN,
469 N2kgfPGNec_Acknowledge, // What we actually should response as PGN error, if we have invalid field?
470 pec,
471 NumberOfParameterPairs);
472
474 // Next read new field values
475 for (i=0; i<NumberOfParameterPairs; i++) {
476 field=N2kMsg.GetByte(Index);
477 switch (field) {
478 case 1: // Installation description 1
479 InstallationDescriptionSize=Max_N2kConfigurationInfoField_len;
480 N2kMsg.GetVarStr(InstallationDescriptionSize,InstallationDescription,Index);
481 pNMEA2000->SetInstallationDescription1(InstallationDescription);
483 break;
484 case 2: // Installation description 2
485 InstallationDescriptionSize=Max_N2kConfigurationInfoField_len;
486 N2kMsg.GetVarStr(InstallationDescriptionSize,InstallationDescription,Index);
487 pNMEA2000->SetInstallationDescription2(InstallationDescription);
489 break;
490 default:
492 }
493 }
494
495 pNMEA2000->SendMsg(N2kRMsg,iDev);
496
497 return true;
498}
499
500#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
501//*****************************************************************************
502// See document https://web.archive.org/web/20170609023206/https://www.nmea.org/Assets/20140102%20nmea-2000-126993%20heartbeat%20pgn%20corrigendum.pdf for
503// Heartbeat settings
505 uint32_t TransmissionInterval,
506 uint16_t TransmissionIntervalOffset,
507 uint8_t NumberOfParameterPairs,
508 int iDev) {
509 tN2kGroupFunctionTransmissionOrPriorityErrorCode pec = GetRequestGroupFunctionTransmissionOrPriorityErrorCode(TransmissionInterval,TransmissionIntervalOffset,true,60000U,1000U,true,6000U);
510 // Turn off is not allowed for heartbeat.
511 if ( TransmissionInterval==0 ) pec=N2kgfTPec_TransmitIntervalOrPriorityNotSupported;
512
513 if ( NumberOfParameterPairs==0 ) { // According to doc, there should not be any parameter pairs defined
514 if ( TransmissionInterval==0xffffffff && TransmissionIntervalOffset==0xffff ) {
515 // Request for 126993 with 0xffffffff and 0xffff is prohibited so use default response.
516 return tN2kGroupFunctionHandler::HandleRequest(N2kMsg,TransmissionInterval,TransmissionIntervalOffset,NumberOfParameterPairs,iDev);
517 }
518 if ( pec==N2kgfTPec_Acknowledge ) {
519 // Request specification with offset is confusing and there is no clear explanation. So to keep
520 // test tool happy, we respond always immediately and set offset, if it is >0
521 uint32_t Offset=TransmissionIntervalOffset;
522 Offset=(Offset==0xffff || Offset==0?0xffffffff:Offset*10); // Offset comes in 10 ms, convert to ms.
523 pNMEA2000->SetHeartbeatIntervalAndOffset(TransmissionInterval,Offset,iDev);
525 } else if (!tNMEA2000::IsBroadcast(N2kMsg.Destination)) {
527 }
528 } else {
529 if ( !tNMEA2000::IsBroadcast(N2kMsg.Destination) ) {
532 pec, //N2kgfTPec_TransmitIntervalOrPriorityNotSupported,
533 NumberOfParameterPairs, N2kgfpec_RequestOrCommandNotSupported);
534 }
535 }
536 return true;
537}
538#endif
539
540#endif
tN2kGroupFunctionParameterErrorCode
Error Codes Command used by acknowledge group function.
@ N2kgfpec_TemporarilyUnableToComply
@ N2kgfpec_RequestOrCommandNotSupported
@ N2kgfpec_InvalidRequestOrCommandParameterField
@ N2kgfpec_RequestOrCommandParameterOutOfRange
@ N2kgfpec_Acknowledge
@ N2kgfPGNec_Acknowledge
tN2kGroupFunctionTransmissionOrPriorityErrorCode
Error codes Transmit interval used by acknowledge group function.
@ N2kgfTPec_Acknowledge
@ N2kgfTPec_TransmitIntervalOrPriorityNotSupported
#define N2kPGN60928_DeviceInstanceUpper_field
#define N2kPGN60928_DeviceFunction_field
#define N2kPGN60928_UniqueNumber_field
#define N2kPGN126996_LoadEquivalency_field
#define N2kPGN60928_ManufacturerCode_field
#define N2kPGN60928_Reserved_field
#define N2kPGN126996_ManufacturersSoftwareVersionCode_field
#define N2kPGN60928_ISOSelfConfigurable_field
#define N2kPGN126996_NMEA2000CertificationLevel_field
#define N2kPGN60928_SystemInstance_field
#define N2kPGN126996_ManufacturersModelVersion_field
#define N2kPGN126996_NMEA2000DatabaseVersion_field
#define N2kPGN126996_ManufacturersModelSerialCode_field
#define N2kPGN126998_InstallationDescription1_field
#define N2kPGN60928_DeviceInstanceLower_field
#define N2kPGN126996_NMEAManufacturersProductCode_field
#define N2kPGN60928_DeviceClass_field
#define N2kPGN60928_IndustryGroup_field
#define N2kPGN126998_InstallationDescription2_field
#define N2kPGN126998_ManufacturerInformation_field
#define N2kPGN126996_ManufacturersModelID_field
The file contains default group function handler classes.
This file contains the class tNMEA2000, which consists the main functionality of the library.
#define Max_N2kModelSerialCode_len
Max length of SerialCode Document says for length 32 but then values has not been translated right on...
Definition: NMEA2000.h:82
#define Max_N2kProductInfoStrLen
Define length of longest info string Define length of longest info string (from Max_N2kModelID_len,...
Definition: NMEA2000.h:90
#define Max_N2kSwCode_len
Max length of Software Code Document says for length 40 but then values has not been translated right...
Definition: NMEA2000.h:74
#define Max_N2kModelVersion_len
Max length of Model Version Document says for length 24 but then values has not been translated right...
Definition: NMEA2000.h:78
#define Max_N2kConfigurationInfoField_len
Max length of Configuration Info Fields.
Definition: NMEA2000.h:99
#define Max_N2kModelID_len
Max length of ModelID Document says for length 33 but then values has not been translated right on de...
Definition: NMEA2000.h:70
@ N2kpgnl_receive
Definition: NMEA2000.h:3262
@ N2kpgnl_transmit
Definition: NMEA2000.h:3262
virtual bool HandleRequest(const tN2kMsg &N2kMsg, uint32_t TransmissionInterval, uint16_t TransmissionIntervalOffset, uint8_t NumberOfParameterPairs, int iDev)
Handle response for request 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.
virtual bool HandleRequest(const tN2kMsg &N2kMsg, uint32_t TransmissionInterval, uint16_t TransmissionIntervalOffset, uint8_t NumberOfParameterPairs, int iDev)
Handle response for request 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.
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.
virtual bool HandleCommand(const tN2kMsg &N2kMsg, uint8_t PrioritySetting, uint8_t NumberOfParameterPairs, int iDev)
Handle response for command group function.
static bool StartParseRequestPairParameters(const tN2kMsg &N2kMsg, int &Index)
Get start Index of pair parameters from request group function message.
void MatchRequestField(T FieldVal, T MatchVal, T Mask, bool &Match, tN2kGroupFunctionParameterErrorCode &ErrorCode)
Template class to test does field on group function match to PGN field value.
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 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 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.
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.
unsigned long PGN
Parameter Group Number (PGN) of this 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.
This class contains all the data of an NMEA2000 message.
Definition: N2kMsg.h:656
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
bool IsTPMessage() const
Determine if the message is flagged as MultiPacket Message.
Definition: N2kMsg.h:699
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
uint32_t Get3ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 3 bytes out of Data.
Definition: N2kMsg.cpp:275
unsigned char GetByte(int &Index) const
Get the value from a byte out of Data.
Definition: N2kMsg.cpp:254
bool GetStr(char *StrBuf, size_t Length, int &Index) const
Get a string out of Data.
Definition: N2kMsg.cpp:359
unsigned char Destination
Destination of the NMEA2000 message.
Definition: N2kMsg.h:671
Class that holds all the device informations and several helper functions to that.
Definition: NMEA2000.h:297
uint16_t GetManufacturerCode() const
Get the Manufacturer Code from the Device Information.
Definition: NMEA2000.h:382
unsigned char GetSystemInstance() const
Get the System Instance from the Device Information.
Definition: NMEA2000.h:457
unsigned char GetIndustryGroup() const
Get the Industry Group from the Device Information.
Definition: NMEA2000.h:445
unsigned char GetDeviceInstanceLower() const
Get the Device Instance (lower bits) from the Device Information.
Definition: NMEA2000.h:400
unsigned char GetDeviceInstanceUpper() const
Get the Device Instance (upper bits) from the Device Information.
Definition: NMEA2000.h:405
uint32_t GetUniqueNumber() const
Get the unique Number from the Device Information.
Definition: NMEA2000.h:370
unsigned char GetDeviceFunction() const
Get the Device Function from the Device Information.
Definition: NMEA2000.h:419
unsigned char GetDeviceClass() const
Get the Device Class from the Device Information.
Definition: NMEA2000.h:433
void SendHeartbeat(int iDev)
Send heartbeat for specific device.
Definition: NMEA2000.cpp:1388
void SetInstallationDescription1(const char *InstallationDescription1)
Set the Installation Description 1 of this device.
Definition: NMEA2000.cpp:1037
const tDeviceInformation GetDeviceInformation(int iDev=0)
Get the Device Information.
Definition: NMEA2000.h:2386
bool SendConfigurationInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Config Information message.
Definition: NMEA2000.cpp:2264
unsigned char GetCertificationLevel(int iDev=0) const
Get the Certification Level of the device.
Definition: NMEA2000.cpp:994
static bool IsBroadcast(unsigned char Source)
Checks if the given Address is a broadcast address.
Definition: NMEA2000.h:2990
void SendIsoAddressClaim(unsigned char Destination=0xff, int DeviceIndex=0, unsigned long FromNow=0)
Send an IsoAddressClaim message.
Definition: NMEA2000.cpp:2097
void GetManufacturerInformation(char *buf, size_t max_len)
Get the Manufacturer Information of this device.
Definition: NMEA2000.cpp:1074
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.
Definition: NMEA2000.cpp:1450
void GetInstallationDescription1(char *buf, size_t max_len)
Get the Install Description 1 of this device.
Definition: NMEA2000.cpp:1056
void SetHeartbeatIntervalAndOffset(uint32_t interval, uint32_t offset=0, int iDev=-1)
Set the Heartbeat Interval and Offset for a device.
Definition: NMEA2000.cpp:1356
void SendRxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Receive messages.
Definition: NMEA2000.cpp:2161
void SendTxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Transmit messages.
Definition: NMEA2000.cpp:2128
unsigned short GetN2kVersion(int iDev=0) const
Get the N2k standard version of the device.
Definition: NMEA2000.cpp:902
bool SendProductInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Product Information message.
Definition: NMEA2000.cpp:2222
void SetInstallationDescription2(const char *InstallationDescription2)
Set the Installation Description 2 of this device.
Definition: NMEA2000.cpp:1047
void SetDeviceInformationInstances(uint8_t _DeviceInstanceLower=0xff, uint8_t _DeviceInstanceUpper=0xff, uint8_t _SystemInstance=0xff, int iDev=0)
Set the Device Information Instances.
Definition: NMEA2000.cpp:1110
void GetInstallationDescription2(char *buf, size_t max_len)
Get the Install Description 2 of this device.
Definition: NMEA2000.cpp:1065
unsigned short GetProductCode(int iDev=0) const
Get the Product Code of the device.
Definition: NMEA2000.cpp:916
void GetModelID(char *buf, size_t max_len, int iDev=0) const
Get the ModelID of the device.
Definition: NMEA2000.cpp:930
unsigned char GetLoadEquivalency(int iDev=0) const
Get the Load Equivalency of this device.
Definition: NMEA2000.cpp:1008