27#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
39 if (
PGN!=PGNForGroupFunction &&
PGN!=0 )
return false;
42 uint16_t ManufacturerCode;
43 uint8_t IndustryGroup;
45 uint8_t NumberOfSelectionPairs;
46 uint8_t NumberOfParameterPairs;
49 switch (GroupFunctionCode) {
51 uint32_t TransmissionInterval;
52 uint16_t TransmissionIntervalOffset;
54 if (
ParseRequestParams(N2kMsg,TransmissionInterval,TransmissionIntervalOffset,NumberOfParameterPairs)) {
55 handled=
HandleRequest(N2kMsg,TransmissionInterval,TransmissionIntervalOffset,NumberOfParameterPairs,iDev);
59 uint8_t PrioritySetting;
65 handled=
HandleCommand(N2kMsg,PrioritySetting,NumberOfParameterPairs,iDev);
74 handled=
HandleAcknowledge(N2kMsg,PGNErrorCode,TransmissionOrPriorityErrorCode,NumberOfParameterPairs,iDev);
81 if (
ParseReadOrWriteParams(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Propr)) {
82 handled=
HandleReadFields(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,iDev);
93 if (
ParseReadOrWriteParams(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,Propr)) {
94 handled=
HandleWriteFields(N2kMsg,ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,iDev);
109 uint32_t TransmissionInterval,
110 uint16_t TransmissionIntervalOffset,
111 bool UseIntervalLimits,
112 uint32_t IntervalMax,
113 uint32_t IntervalMin,
114 bool UseOffsetLimits,
120 return ( (TransmissionInterval==0xFFFFFFFF
121 || TransmissionInterval==0xFFFFFFFE
122 || TransmissionInterval==0
123 || ( UseIntervalLimits && TransmissionInterval>=IntervalMin && TransmissionInterval<=IntervalMax)
128 (TransmissionIntervalOffset==0xffff
129 || TransmissionIntervalOffset==0
130 || ( UseOffsetLimits && TransmissionIntervalOffset<=OffsetMax)
139 uint32_t TransmissionInterval,
140 uint16_t TransmissionIntervalOffset,
141 uint8_t NumberOfParameterPairs,
163 NumberOfParameterPairs, PARec);
183 NumberOfParameterPairs, PARec);
204 uint8_t NumberOfParameterPairs,
229 uint8_t NumberOfParameterPairs,
257 unsigned long &PGNForGroupFunction) {
258 if (N2kMsg.
PGN!=126208L)
return false;
266#define N2kgf_OffsetToParams 4
267#define N2kgf_OffsetToRequestPairParameters 11
268#define N2kgf_OffsetToCommandPairParameters 6
272 uint32_t &TransmissionInterval,
273 uint16_t &TransmissionIntervalOffset,
274 uint8_t &NumberOfParameterPairs) {
275 if (N2kMsg.
PGN!=126208L)
return false;
279 NumberOfParameterPairs=N2kMsg.
GetByte(Index);
286 if (N2kMsg.
PGN!=126208L)
return false;
294 uint8_t &PrioritySetting,
295 uint8_t &NumberOfParameterPairs) {
296 if (N2kMsg.
PGN!=126208L)
return false;
298 PrioritySetting=N2kMsg.
GetByte(Index) & 0x0f;
299 NumberOfParameterPairs=N2kMsg.
GetByte(Index);
306 if (N2kMsg.
PGN!=126208L)
return false;
316 uint8_t &NumberOfParameterPairs) {
319 NumberOfParameterPairs=0;
320 if (N2kMsg.
PGN!=126208L)
return false;
322 uint8_t b=N2kMsg.
GetByte(Index);
343 uint16_t &ManufacturerCode,
344 uint8_t &IndustryGroup,
346 uint8_t &NumberOfSelectionPairs,
347 uint8_t &NumberOfParameterPairs,
349 if (N2kMsg.
PGN!=126208L)
return false;
351 ManufacturerCode=0xffff;
355 ManufacturerCode=ProprietaryInfo & 0x07ff;
356 IndustryGroup=(ProprietaryInfo>>13) &0x07;
358 UniqueID=N2kMsg.
GetByte(Index);
359 NumberOfSelectionPairs=N2kMsg.
GetByte(Index);
360 NumberOfParameterPairs=N2kMsg.
GetByte(Index);
367 uint16_t ManufacturerCode,
368 uint8_t IndustryGroup,
370 uint8_t NumberOfSelectionPairs,
371 uint8_t NumberOfParameterPairs,
379 uint16_t ProprietaryInfo = IndustryGroup<<13 | 0x1800 | (ManufacturerCode & 0x07ff);
383 N2kMsg.
AddByte(NumberOfSelectionPairs);
384 N2kMsg.
AddByte(NumberOfParameterPairs);
389 uint16_t ManufacturerCode,
390 uint8_t IndustryGroup,
392 uint8_t NumberOfSelectionPairs,
393 uint8_t NumberOfParameterPairs,
397 ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,
Proprietary
403 uint16_t ManufacturerCode,
404 uint8_t IndustryGroup,
406 uint8_t NumberOfSelectionPairs,
407 uint8_t NumberOfParameterPairs,
411 ManufacturerCode,IndustryGroup,UniqueID,NumberOfSelectionPairs,NumberOfParameterPairs,
Proprietary
419 uint8_t NumberOfParameterPairs) {
426 N2kMsg.
AddByte(PGNErrorCode | TransmissionOrPriorityErrorCode<<4);
427 N2kMsg.
AddByte(NumberOfParameterPairs);
430#define ErrorcodeIndex 4
435 uint8_t ec=N2kMsg.
GetByte(Index);
436 ec = (ec & 0xf0) | PGNErrorCode;
443 uint8_t ec=N2kMsg.
GetByte(Index);
444 ec = (ec & 0x0f) | (TransmissionOrPriorityErrorCode<<4);
450 uint8_t ParameterPairIndex,
452 if ( ((ParameterPairIndex % 2) == 0) && (N2kMsg.
DataLen>0) ) {
453 N2kMsg.
AddByte((uint8_t)(ErrorCode) | 0x0f << 4);
464 uint8_t NumberOfParameterPairs,
471 TransmissionOrPriorityErrorCode,
472 NumberOfParameterPairs);
473 for (uint8_t ParamIndex=0; ParamIndex<NumberOfParameterPairs;ParamIndex++) {
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 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.
tN2kGroupFunctionPGNErrorCode
PGN error code used by acknowledge group function.
@ N2kgfPGNec_PGNTemporarilyNotAvailable
@ N2kgfPGNec_PGNNotSupported
@ N2kgfPGNec_ReadOrWriteNotSupported
tN2kGroupFunctionTransmissionOrPriorityErrorCode
Error codes Transmit interval used by acknowledge group function.
@ N2kgfTPec_TransmitIntervalOrPriorityNotSupported
tN2kGroupFunctionCode
FunctionCode for the group function.
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.
unsigned char Data[MaxDataLen]
Byte array which carries all the data of the NMEA2000 message.
void Add2ByteUInt(uint16_t v)
Add unsigned integer value to the buffer using 2 bytes The value will be added to the end (indicated ...
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...
uint16_t Get2ByteUInt(int &Index, uint16_t def=0xffff) const
Get an unsigned integer from 2 bytes out of Data.
unsigned char Source
Source of the NMEA2000 message.
unsigned char Priority
Priority of the NMEA2000 message.
uint32_t Get3ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 3 bytes out of Data.
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...
virtual void Clear()
Clears the content of the N2kMsg object The method sets the PGN, DataLen and MsgTime to zero.
void SetPGN(unsigned long _PGN)
Set the Parameter Group Number of the message *.
unsigned char GetByte(int &Index) const
Get the value from a byte out of Data.
uint32_t Get4ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 4 bytes out of Data.
int DataLen
Number of bytes already stored in tN2kMsg::Data of this message.
unsigned long PGN
Parameter Group Number (PGN) of the NMEA2000 message.
unsigned char Destination
Destination of the NMEA2000 message.
tNMEA2000 device class definition.
bool IsTxPGN(unsigned long PGN, int iDev=0)
Check if this message is a Transmit message of this device.
static bool IsBroadcast(unsigned char Source)
Checks if the given Address is a broadcast address.
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.
static bool IsProprietaryMessage(unsigned long PGN)
Check if the given PGN is proprietary.