26#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
32#define DebugStream Serial
41#if defined(NMEA2000_FRAME_ERROR_DEBUG)
42# define N2kFrameErrDbgStart(fmt, args...) DebugStream.print(N2kMillis()); DebugStream.print(": "); DebugStream.print (fmt , ## args)
43# define N2kFrameErrDbg(fmt, args...) DebugStream.print (fmt , ## args)
44# define N2kFrameErrDbgln(fmt, args...) DebugStream.println (fmt , ## args)
46# define N2kFrameErrDbgStart(fmt, args...)
47# define N2kFrameErrDbg(fmt, args...)
48# define N2kFrameErrDbgln(fmt, args...)
51#if defined(NMEA2000_FRAME_IN_DEBUG)
52# define N2kFrameInDbgStart(fmt, args...) DebugStream.print(N2kMillis()); DebugStream.print(": "); DebugStream.print (fmt , ## args)
53# define N2kFrameInDbg(fmt, args...) DebugStream.print (fmt , ## args)
54# define N2kFrameInDbgln(fmt, args...) DebugStream.println (fmt , ## args)
56# define N2kFrameInDbgStart(fmt, args...)
57# define N2kFrameInDbg(fmt, args...)
58# define N2kFrameInDbgln(fmt, args...)
61#if defined(NMEA2000_FRAME_OUT_DEBUG)
62# define N2kFrameOutDbgStart(fmt, args...) DebugStream.print(N2kMillis()); DebugStream.print(": "); DebugStream.print (fmt , ## args)
63# define N2kFrameOutDbg(fmt, args...) DebugStream.print (fmt , ## args)
64# define N2kFrameOutDbgln(fmt, args...) DebugStream.println (fmt , ## args)
66# define N2kFrameOutDbgStart(fmt, args...)
67# define N2kFrameOutDbg(fmt, args...)
68# define N2kFrameOutDbgln(fmt, args...)
71#if defined(NMEA2000_MSG_DEBUG)
72# define N2kMsgDbgStart(fmt, args...) DebugStream.print(N2kMillis()); DebugStream.print(": "); DebugStream.print (fmt , ## args)
73# define N2kMsgDbg(fmt, args...) DebugStream.print (fmt , ## args)
74# define N2kMsgDbgln(fmt, args...) DebugStream.println (fmt , ## args)
76# define N2kMsgDbgStart(fmt, args...)
77# define N2kMsgDbg(fmt, args...)
78# define N2kMsgDbgln(fmt, args...)
81#if defined(NMEA2000_BUF_DEBUG)
82# define DbgPrintBuf(len, buf, addln) PrintBuf(&DebugStream, len, buf, addln)
84# define DbgPrintBuf(len, buf, addln)
87#if defined(NMEA2000_DEBUG)
88# define N2kDbg(fmt, args...) DebugStream.print (fmt , ## args)
89# define N2kDbgln(fmt, args...) DebugStream.println (fmt , ## args)
91# define N2kDbg(fmt, args...)
92# define N2kDbgln(fmt, args...)
97#if defined(NMEA2000_MEMORY_TEST)
98#include <MemoryFree.h>
101 Serial.print(Source);
102 Serial.print(
", free memory=");
103 Serial.println(freeMemory());
106#define N2kPrintFreeMemory(a)
110#define N2kAddressClaimTimeout 250
112#define MaxHeartbeatInterval 655320UL
115#define TP_MAX_FRAMES 5
129#define TP_CM_Abort 255
133#define TP_CM_AbortBusy 1
136#define TP_CM_AbortNoResources 2
139#define TP_CM_AbortTimeout 3
163#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
168#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
172#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
197#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
203#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
580 return ( PGN==126720L ) || ( 130816L<=PGN && PGN<=131071L );
638 if ( buf==0 )
return;
640 for (; i<MaxLen; i++) buf[i]=0;
645 if ( buf==0 || MaxLen==0 )
return;
646 if ( str==0 ) { buf[0]=0;
return; }
648 for (; i<MaxLen-1 && str[i]!=0; i++) buf[i]=str[i];
649 for (; i<MaxLen; i++) buf[i]=0;
662#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
665#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
746 unsigned short _ProductCode,
747 const char *_ModelID,
749 const char *_ModelVersion,
750 unsigned char _LoadEquivalency,
751 unsigned short _N2kVersion,
752 unsigned char _CertificationLevel,
756 if (
Devices[iDev].LocalProductInformation==0) {
765 const char *InstallationDescription1,
766 const char *InstallationDescription2) {
770 size_t ManInfoLen=(ManufacturerInformation?strlen(ManufacturerInformation)+1:0);
771#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
775 size_t InstDesc1Len=(InstallationDescription1?strlen(InstallationDescription1)+1:0);
776 size_t InstDesc2Len=(InstallationDescription2?strlen(InstallationDescription2)+1:0);
783 size_t TotalSize=ManInfoLen+InstDesc1Len+InstDesc2Len;
784 void *mem=(TotalSize>0?malloc(TotalSize):0);
789 SetCharBuf(InstallationDescription1,InstDesc1Len,Info);
793 SetCharBuf(InstallationDescription2,InstDesc2Len,Info);
797 SetCharBuf(ManufacturerInformation,ManInfoLen,Info);
803 const char *InstallationDescription1,
804 const char *InstallationDescription2) {
815 unsigned long ListPGN;
816 size_t FPTxPGNCount=0;
834 if (
Devices[iDev].PGNSequenceCounters==0 ) {
839 if (
Devices[iDev].PGNSequenceCounters==0 )
return 0;
842 for (
size_t i=0; i<last; i++ ) {
843 if (
Devices[iDev].PGNSequenceCounters[i]==0 ) {
847 if ( (
Devices[iDev].PGNSequenceCounters[i]&0x00ffffff) == PGN ) {
849 sc++;
if (sc>7) sc=0;
856 sc++;
if (sc>7) sc=0;
861#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
865 if ( buf==0 || MaxLen==0 )
return;
866 if ( str==0 ) { buf[0]=0;
return; }
869 for (; i<MaxLen-1 && (c=
pgm_read_byte(&(str[i])))!=0; i++) buf[i]=c;
870 for (; i<MaxLen; i++) buf[i]=0;
877 unsigned long ListPGN;
880 if ( ListPGN==PGN )
return true;
884 if ( ListPGN==PGN )
return true;
895 if (
Devices[iPIDev].ProductInformation==0 ) iPIDev=0;
896 if (
Devices[iPIDev].ProductInformation==0 )
return 0;
906 if ( ProductInformation==0 )
return 0;
920 if ( ProductInformation==0 )
return 0;
931 if ( max_len==0 )
return;
936 if ( ProductInformation==0 )
return;
947 if ( max_len==0 )
return;
952 if ( ProductInformation==0 )
return;
963 if ( max_len==0 )
return;
968 if ( ProductInformation==0 )
return;
979 if ( max_len==0 )
return;
984 if ( ProductInformation==0 )
return;
998 if ( ProductInformation==0 )
return 0;
1012 if ( ProductInformation==0 )
return 0;
1094 unsigned char _DeviceFunction,
1095 unsigned char _DeviceClass,
1096 uint16_t _ManufacturerCode,
1097 unsigned char _IndustryGroup,
1111 uint8_t _DeviceInstanceLower,
1112 uint8_t _DeviceInstanceUpper,
1113 uint8_t _SystemInstance,
1121 if (_DeviceInstanceLower!=0xff ) {
1122 DeviceInstance=( (DeviceInstance & ~0x07) | (_DeviceInstanceLower & 0x07) );
1124 if (_DeviceInstanceUpper!=0xff ) {
1125 DeviceInstance=( (DeviceInstance & ~0xF8) | ((_DeviceInstanceUpper&0x1f)<<3) );
1128 if (
Devices[iDev].DeviceInformation.GetDeviceInstance()!=DeviceInstance) {
1133 if (_SystemInstance!=0xff &&
Devices[iDev].DeviceInformation.GetSystemInstance()!=_SystemInstance) {
1212 #if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
1216 #if !defined(N2K_NO_HEARTBEAT_SUPPORT)
1247 #if !defined(N2K_NO_HEARTBEAT_SUPPORT)
1253 unsigned long canId;
1254 unsigned char len = 0;
1255 unsigned char buf[8];
1277void CanIdToN2k(
unsigned long id,
unsigned char &prio,
unsigned long &pgn,
unsigned char &src,
unsigned char &dst) {
1278 unsigned char CanIdPF = (
unsigned char) (
id >> 16);
1279 unsigned char CanIdPS = (
unsigned char) (
id >> 8);
1280 unsigned char CanIdDP = (
unsigned char) (
id >> 24) & 1;
1282 src = (
unsigned char)
id >> 0;
1283 prio = (
unsigned char) ((
id >> 26) & 0x7);
1285 if (CanIdPF < 240) {
1288 pgn = (((
unsigned long)CanIdDP) << 16) | (((
unsigned long)CanIdPF) << 8);
1292 pgn = (((
unsigned long)CanIdDP) << 16) | (((
unsigned long)CanIdPF) << 8) | (
unsigned long)CanIdPS;
1306unsigned long N2ktoCanID(
unsigned char priority,
unsigned long PGN,
unsigned long Source,
unsigned char Destination) {
1307 unsigned char CanIdPF = (
unsigned char) (PGN >> 8);
1309 if (CanIdPF < 240) {
1310 if ( (PGN & 0xff) != 0 )
return 0;
1311 return ( ((
unsigned long)(priority & 0x7))<<26 | PGN<<8 | ((
unsigned long)Destination)<<8 | (
unsigned long)Source);
1313 return ( ((
unsigned long)(priority & 0x7))<<26 | PGN<<8 | (
unsigned long)Source);
1328 }
else return false;
1343 len=N2kMin<unsigned char>(len,8);
1347 for (
int i=0; i<len; i++) Frame->
buf[i]=buf[i];
1354#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
1357 if ( interval==0xffffffff && offset==0xffff )
return;
1359 for (
int i=(iDev<0?0:iDev); i<
DeviceCount && (iDev<0?
true:i<iDev+1); i++) {
1360 if ( interval==0xffffffff ) {
1362 }
else if (interval==0xfffffffe) {
1367 if ( interval==0 ) {
1371 if ( interval<1000 ) interval=1000;
1401 if ( force ||
Devices[iDev].HeartbeatScheduler.IsTime() ) {
1433 if (
Devices[i].HasPendingInformation ) {
1434 #if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1437 if (
Devices[i].QueryPendingIsoAddressClaim() ) {
1461 if (DeviceIndex>=0) { N2kMsg.
ForceSource(
Devices[DeviceIndex].N2kSource); }
else { DeviceIndex=0; }
1474 if (N2kMsg.
PGN==0)
return false;
1488#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1494 unsigned char temp[8];
1499 for (
int i = 0; i<frames && result; i++) {
1504 for (
int j = 2; j<8; j++) {
1505 temp[j]=N2kMsg.
Data[cur];
1512 for (; j<8 && cur<N2kMsg.
DataLen; j++) {
1513 temp[j]=N2kMsg.
Data[cur];
1573 if (N2kMsg.
Priority>=0x80)
return false;
1583 SystemMessage=
false;
1584 if ( PGN==0 ) {
return false; }
1633#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1638 unsigned long OldestMsgTime,CurTime;
1647#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1654 OldestIndex=MsgIndex;
1659 MsgIndex=OldestIndex;
1665#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1680 N2kMsg.
AddByte(nBytes/7+(nBytes%7!=0?1:0));
1698 N2kMsg.
AddByte(nBytes/7+(nBytes%7!=0?1:0));
1704unsigned char TPCtsPackets(
unsigned char nPackets) {
return tNMEA2000::N2kMax<unsigned char>(1,tNMEA2000::N2kMin<unsigned char>(nPackets,
TP_MAX_FRAMES)); }
1707void tNMEA2000::SendTPCM_CTS(
unsigned long PGN,
unsigned char Destination,
int iDev,
unsigned char nPackets,
unsigned char NextPacketNumber) {
1717 N2kMsg.
AddByte(NextPacketNumber);
1770 for (
int i=0; i<7; i++,iByteToSend++ ) {
1771 if ( iByteToSend<
Devices[iDev].PendingTPMsg.DataLen ) {
1782 return (
Devices[iDev].NextDTSequence*7>=
Devices[iDev].PendingTPMsg.DataLen );
1787 unsigned char len,
unsigned char *buf,
1788 uint8_t &MsgIndex) {
1793 unsigned char TP_CM_Control=buf[0];
1797 switch (TP_CM_Control) {
1803 uint8_t TPMaxPackets=buf[Index++];
1810 if ( (TP_CM_Control==
TP_CM_RTS) && (iDev>=0) ) {
1826 if ( (TP_CM_Control==
TP_CM_RTS) && (iDev>=0) ) {
1833 if ( (TP_CM_Control==
TP_CM_RTS) && (iDev>=0) ) {
1844 if (
Devices[iDev].PendingTPMsg.PGN!=TransportPGN ) {
1850 if ( buf[2]-1!=
Devices[iDev].NextDTSequence ) {
1854 uint8_t MaxTPSequences=buf[1];
1855 bool TPDTResult=
true;
1856 for ( uint8_t iSeq=0; TPDTResult &&iSeq<MaxTPSequences && !
HasAllTPDTSent(iDev); iSeq++ ) TPDTResult&=
SendTPDT(iDev);
1878 }
else if ( PGN==
TP_DT ) {
1885 &&
N2kCANMsgBuf[MsgIndex].N2kMsg.Destination==Destination
1901 if (
N2kCANMsgBuf[MsgIndex].TPRequireCTS>0 && iDev>=0 ) {
1911 if (
N2kCANMsgBuf[MsgIndex].TPRequireCTS>0 && iDev>=0 ) {
1929 if (
Devices[iDev].PendingTPMsg.PGN!=0 )
return false;
1978 unsigned char Priority;
1980 unsigned char Source;
1981 unsigned char Destination;
1987 CanIdToN2k(canId,Priority,PGN,Source,Destination);
1988#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2001#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2022#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2033#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2065 if ( Source<=253 ) {
2102 if (Destination==0xff && DeviceIndex==-1) DeviceIndex=0;
2104 if ( DeviceIndex<0 || DeviceIndex>=
DeviceCount)
return;
2116 SendMsg(RespondMsg,DeviceIndex);
2121 memcpy_P (&dest, sce,
sizeof (T));
2124#define MAX_PGNS_IN_LIST 74
2127#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2132 if (Destination==0xff && DeviceIndex==-1) DeviceIndex=0;
2140 RespondMsg.
SetPGN(126464L);
2142#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2156 SendMsg(RespondMsg,DeviceIndex);
2160#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2165 if (Destination==0xff && DeviceIndex==-1) DeviceIndex=0;
2173 RespondMsg.
SetPGN(126464L);
2175#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2184 if (
Devices[DeviceIndex].ReceiveMessages!=0) {
2189 SendMsg(RespondMsg,DeviceIndex);
2206 if (OptionalSerialCode) {
2217#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2230 if (
Devices[iPIDev].ProductInformation==0 ) iPIDev=0;
2231 if (
Devices[iPIDev].ProductInformation==0 )
return false;
2233 if (
Devices[iPIDev].ProductInformation==
Devices[iPIDev].LocalProductInformation ) {
2245#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2249 if (
SendMsg(RespondMsg,iDev) ) {
2259#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2283#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2287 if (
SendMsg(RespondMsg,DeviceIndex) ) {
2300 switch (RequestedPGN) {
2334 unsigned long RequestedPGN;
2348#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
2356 for ( pGroupFunctionHandler=
pGroupFunctionHandlers; pGroupFunctionHandler!=0; pGroupFunctionHandler=pGroupFunctionHandler->pNext) {
2357 if ( pGroupFunctionHandler->
PGN==PGNForGroupFunction ) {
2359 pGroupFunctionHandler->
Handle(N2kMsg,GroupFunctionCode, PGNForGroupFunction,iDev);
2361 }
else if ( pGroupFunctionHandler->
PGN==0 &&
2362 pGroupFunctionHandler->
Handle(N2kMsg,GroupFunctionCode, PGNForGroupFunction,iDev)
2377 unsigned long PGNForGroupFunction;
2418 if (
Devices[iDev].AddressClaimTimer.IsTime() ) {
2435 uint64_t CallerName=N2kMsg.
GetUInt64(Index);
2437 if (
Devices[iDev].DeviceInformation.GetName()<CallerName) {
2457 if (
Devices[iDev].DeviceInformation.GetName() == CommandedName &&
2476 uint64_t CommandedName=N2kMsg.
GetUInt64(Index);
2477 unsigned char NewAddress=N2kMsg.
GetByte(Index);
2478 if ( NewAddress>=252 )
return;
2519 if ( RestartAtEnd ) {
2524 }
else if (
Devices[DeviceIndex].N2kSource!=
Devices[DeviceIndex].AddressClaimEndSource) {
2538 }
while (FoundSame);
2563#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
2578 unsigned long canId;
2579 unsigned char len = 0;
2580 unsigned char buf[8];
2582 static const int MaxReadFramesOnParse=20;
2594#if defined(DEBUG_NMEA2000_ISR)
2598 while (FramesRead<MaxReadFramesOnParse &&
CANGetFrame(canId,len,buf) ) {
2614#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
2644 if ( _MsgHandler==0 )
return;
2646 if ( _MsgHandler->pNMEA2000==
this )
return;
2664 _MsgHandler->pNMEA2000=
this;
2669 if ( _MsgHandler==0 || _MsgHandler->pNMEA2000==0 )
return;
2679 _MsgHandler->pNext=0;
2680 _MsgHandler->pNMEA2000=0;
2688#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
2695 if ( pPrevGroupFunctionHandler==pGroupFunctionHandler ) {
2698 for ( ;pPrevGroupFunctionHandler!=0 && pPrevGroupFunctionHandler->pNext!=pGroupFunctionHandler;
2699 pPrevGroupFunctionHandler = pPrevGroupFunctionHandler->pNext);
2700 if ( pPrevGroupFunctionHandler!=0 && pPrevGroupFunctionHandler->pNext==pGroupFunctionHandler ) {
2701 pPrevGroupFunctionHandler->pNext=pGroupFunctionHandler->pNext;
2704 pGroupFunctionHandler->pNext=0;
2709 if (pGroupFunctionHandler==0)
return;
2718 pLastGroupFunctionHandler->pNext != 0 && pLastGroupFunctionHandler->pNext->
PGN != 0;
2719 pLastGroupFunctionHandler = pLastGroupFunctionHandler->pNext);
2721 if ( pLastGroupFunctionHandler->pNext != 0 && pLastGroupFunctionHandler->pNext->
PGN == 0 ) {
2722 pGroupFunctionHandler->pNext = pLastGroupFunctionHandler->pNext;
2725 pLastGroupFunctionHandler->pNext = pGroupFunctionHandler;
2737 N2kMsg.
AddByte(GroupFunction);
2747 unsigned char DeviceFunction,
unsigned char DeviceClass,
2748 unsigned char DeviceInstance,
unsigned char SystemInstance,
unsigned char IndustryGroup
2753 N2kMsg.
Add4ByteUInt((UniqueNumber&0x1FFFFF) | ((
unsigned long)(ManufacturerCode&0x7ff))<<21);
2754 N2kMsg.
AddByte(DeviceInstance);
2755 N2kMsg.
AddByte(DeviceFunction);
2756 N2kMsg.
AddByte((DeviceClass&0x7f)<<1);
2757 N2kMsg.
AddByte( 0x80 | ((IndustryGroup&0x7)<<4) | (SystemInstance&0x0f) );
2772 const char *ModelID,
const char *SwCode,
2773 const char *ModelVersion,
const char *ModelSerialCode,
2774 unsigned char CertificationLevel,
unsigned char LoadEquivalency) {
2784 N2kMsg.
AddByte(CertificationLevel);
2785 N2kMsg.
AddByte(LoadEquivalency);
2789 int ModelIDSize,
char *ModelID,
int SwCodeSize,
char *SwCode,
2790 int ModelVersionSize,
char *ModelVersion,
int ModelSerialCodeSize,
char *ModelSerialCode,
2791 unsigned char &CertificationLevel,
unsigned char &LoadEquivalency) {
2801 CertificationLevel=N2kMsg.
GetByte(Index);
2802 LoadEquivalency=N2kMsg.
GetByte(Index);
2810 if (str==0)
return 0;
2817 if (str==0)
return 0;
2824 const char *ManufacturerInformation,
2825 const char *InstallationDescription1,
2826 const char *InstallationDescription2,
2831 size_t InstDesc1Len;
2832 size_t InstDesc2Len;
2839 ManInfoLen=
StrLen(ManufacturerInformation);
2840 InstDesc1Len=
StrLen(InstallationDescription1);
2841 InstDesc2Len=
StrLen(InstallationDescription2);
2849 if (TotalLen+ManInfoLen>MaxLen) ManInfoLen=MaxLen-TotalLen;
2850 TotalLen+=ManInfoLen;
2851 if (TotalLen+InstDesc1Len>MaxLen) InstDesc1Len=MaxLen-TotalLen;
2852 TotalLen+=InstDesc1Len;
2853 if (TotalLen+InstDesc2Len>MaxLen) InstDesc2Len=MaxLen-TotalLen;
2854 TotalLen+=InstDesc2Len;
2859 N2kMsg.
AddByte(InstDesc1Len+2);
2861 N2kMsg.
AddStr(InstallationDescription1,InstDesc1Len,UsePgm);
2864 N2kMsg.
AddByte(InstDesc2Len+2);
2866 N2kMsg.
AddStr(InstallationDescription2,InstDesc2Len,UsePgm);
2870 N2kMsg.
AddStr(ManufacturerInformation,ManInfoLen,UsePgm);
2874 size_t &ManufacturerInformationSize,
char *ManufacturerInformation,
2875 size_t &InstallationDescription1Size,
char *InstallationDescription1,
2876 size_t &InstallationDescription2Size,
char *InstallationDescription2) {
2880 return ( N2kMsg.
GetVarStr(InstallationDescription1Size,InstallationDescription1,Index) &&
2881 N2kMsg.
GetVarStr(InstallationDescription2Size,InstallationDescription2,Index) &&
2882 N2kMsg.
GetVarStr(ManufacturerInformationSize,ManufacturerInformation,Index) );
2920#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
2931 N2kMsg.
AddByte(sequenceCounter);
Type definitions and utility macros used in the NMEA2000 libraries.
#define pgm_read_byte(var)
#define pgm_read_dword(var)
#define pgm_read_word(var)
tN2kGroupFunctionCode
FunctionCode for the group function.
The file contains default group function handler classes.
uint16_t GetBuf2ByteUInt(int &index, const unsigned char *buf)
Extracts 2 bytes out of the given buffer and converts it to an integer value.
uint32_t GetBuf3ByteUInt(int &index, const unsigned char *buf)
Extracts 3 bytes out of the given buffer and converts it to an integer value.
bool N2kHasElapsed(uint32_t Start, uint32_t Elapsed, uint32_t Now=N2kMillis())
Has time elapsed since start.
bool N2kIsTimeBefore(uint32_t T1, uint32_t T2)
Comparing 2 values even after 32 bit time roll over situation.
#define N2kMsgDbg(fmt, args...)
size_t ProgmemStrLen(const char *str)
#define N2kFrameErrDbgln(fmt, args...)
#define N2kFrameErrDbg(fmt, args...)
#define N2kMsgDbgln(fmt, args...)
#define DbgPrintBuf(len, buf, addln)
bool IsSingleFrameSystemMessage(unsigned long PGN)
Checks if the given PGN is a Single Frame System Message.
bool IsDefaultFastPacketMessage(unsigned long PGN)
Checks if the PGN is a Default Fast Packet Message.
bool IsFastPacketSystemMessage(unsigned long PGN)
Checks if the given PGN is a Fast Packet System Message.
#define N2kDbg(fmt, args...)
bool ParseN2kPGN126996(const tN2kMsg &N2kMsg, unsigned short &N2kVersion, unsigned short &ProductCode, int ModelIDSize, char *ModelID, int SwCodeSize, char *SwCode, int ModelVersionSize, char *ModelVersion, int ModelSerialCodeSize, char *ModelSerialCode, unsigned char &CertificationLevel, unsigned char &LoadEquivalency)
Parsing the content of message PGN 126996 "Product information".
#define N2kFrameOutDbgStart(fmt, args...)
void SetN2kPGN126993(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter)
Setting up PGN 126993 Message "Heartbeat".
bool IsProprietaryFastPacketMessage(unsigned long PGN)
Checks if the PGN is a Proprietary Fast Packet Message.
#define TP_CM_BAM
Multi packet connection management, Broadcast Announce Message.
#define TP_MAX_FRAMES
Max frames, which can be received at time.
const char DefInstallationDescription1[]
Default Installation Description (Field1)
#define TP_CM_Abort
Multi packet connection management, Abort Connection.
#define TP_CM_AbortTimeout
A timeout occurred and this is the connection abort to close the session.
const tNMEA2000::tProductInformation DefProductInformation
Default Product Information.
void SetN2kPGN126464(tN2kMsg &N2kMsg, uint8_t Destination, tN2kPGNList tr, const unsigned long *PGNs)
Setting up PGN 126464 Message "PGN List - Transmit PGNs group function".
#define TP_DT
Multi packet data transfer.
#define N2kDbgln(fmt, args...)
unsigned long N2ktoCanID(unsigned char priority, unsigned long PGN, unsigned long Source, unsigned char Destination)
Convert NMEA2000 values into a CAN Id.
bool ParseN2kPGN126998(const tN2kMsg &N2kMsg, size_t &ManufacturerInformationSize, char *ManufacturerInformation, size_t &InstallationDescription1Size, char *InstallationDescription1, size_t &InstallationDescription2Size, char *InstallationDescription2)
Parsing the content of message PGN 126998 "Configuration information".
#define N2kFrameInDbg(fmt, args...)
#define MaxHeartbeatInterval
Maximum value for the ISO Heartbeat interval in ms.
void PROGMEM_readAnything(const T *sce, T &dest)
void SetN2kPGN126996Progmem(tN2kMsg &N2kMsg, const tNMEA2000::tProductInformation *ProductInformation, char *OptionalSerialCode=0)
void CanIdToN2k(unsigned long id, unsigned char &prio, unsigned long &pgn, unsigned char &src, unsigned char &dst)
Convert a CAN Id to NMEA2000 values.
#define N2kFrameOutDbgln(fmt, args...)
bool IsMandatoryFastPacketMessage(unsigned long PGN)
Checks if the PGN is a Mandatory Fast Packet Message.
bool IsFastPacketFirstFrame(unsigned char b)
void SetN2kPGN59904(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN)
Setting up PGN 59904 Message "ISO request".
#define N2kMsgDbgStart(fmt, args...)
#define N2kFrameErrDbgStart(fmt, args...)
#define TP_CM_CTS
Multi packet connection management, Clear To Send.
void SetN2kPGN59392(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN)
ISO Acknowledgement.
#define N2kPrintFreeMemory(a)
void SetN2kPGN126998(tN2kMsg &N2kMsg, const char *ManufacturerInformation, const char *InstallationDescription1, const char *InstallationDescription2, bool UsePgm)
Setting up PGN 126998 Message "Configuration information".
#define N2kFrameInDbgStart(fmt, args...)
bool ParseN2kPGN59904(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN)
Parsing the content of message PGN 59904 "ISO request".
void SetN2kPGN60928(tN2kMsg &N2kMsg, unsigned long UniqueNumber, int ManufacturerCode, unsigned char DeviceFunction, unsigned char DeviceClass, unsigned char DeviceInstance, unsigned char SystemInstance, unsigned char IndustryGroup)
Setting up PGN 60928 Message "ISO Address Claim".
const unsigned long DefTransmitMessages[]
Default list of Transmit Messages.
#define N2kAddressClaimTimeout
Timeout value for the ISO Address Claim in ms.
void SetN2kPGN126996(tN2kMsg &N2kMsg, unsigned int N2kVersion, unsigned int ProductCode, const char *ModelID, const char *SwCode, const char *ModelVersion, const char *ModelSerialCode, unsigned char CertificationLevel, unsigned char LoadEquivalency)
Setting up PGN 126996 Message "Product information".
#define N2kFrameInDbgln(fmt, args...)
#define TP_CM_AbortBusy
Already in one or more connection managed sessions and cannot support another.
const char DefManufacturerInformation[]
Default Manufacturer Information.
unsigned char TPCtsPackets(unsigned char nPackets)
const unsigned long DefReceiveMessages[]
Default list of Received Messages.
#define TP_CM_RTS
Multi packet connection management, Request To Send.
void CopyProgmemString(const char *str, size_t MaxLen, char *buf)
bool IsDefaultSingleFrameMessage(unsigned long PGN)
Checks if the given PGN is a Default Single Frame Message.
#define TP_CM
Multi packet connection management, TP.CM.
void CopyBufToCANMsg(tN2kCANMsg &CANMsg, unsigned char start, unsigned char len, unsigned char *buf)
Copy a Buffer to a CAN Message.
size_t StrLen(const char *str)
#define TP_CM_ACK
Multi packet connection management, End of Message Acknowledgement.
const char DefInstallationDescription2[]
Default Installation Description (Field2)
This file contains the class tNMEA2000, which consists the main functionality of the library.
void SetN2kProductInformation(tN2kMsg &N2kMsg, unsigned int N2kVersion, unsigned int ProductCode, const char *ModelID, const char *SwCode, const char *ModelVersion, const char *ModelSerialCode, unsigned char CertificationLevel=1, unsigned char LoadEquivalency=1)
Setting up Message "Product information" - PGN 126996.
#define Max_N2kModelSerialCode_len
Max length of SerialCode Document says for length 32 but then values has not been translated right on...
#define N2kPGNIsoAddressClaim
PGN for an ISO Address Claim message.
#define N2kPGNProductInformation
PGN for a Production Information message.
#define Max_N2kSwCode_len
Max length of Software Code Document says for length 40 but then values has not been translated right...
void SetN2kConfigurationInformation(tN2kMsg &N2kMsg, const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0, bool UsePgm=false)
Setting up Message "Configuration information" - PGN 126998.
#define DefaultHeartbeatInterval
Interval for Heartbeat.
#define N2kMessageGroups
Number of message groups.
#define Max_N2kMsgBuf_Time
Message buffer time.
#define Max_N2kModelVersion_len
Max length of Model Version Document says for length 24 but then values has not been translated right...
#define Max_N2kConfigurationInfoField_len
Max length of Configuration Info Fields.
#define N2kPGNConfigurationInformation
PGN for an Configuration Information message.
void SetN2kISOAddressClaim(tN2kMsg &N2kMsg, unsigned long UniqueNumber, int ManufacturerCode, unsigned char DeviceFunction, unsigned char DeviceClass, unsigned char DeviceInstance=0, unsigned char SystemInstance=0, unsigned char IndustryGroup=4)
Setting up Message "ISO Address Claim" - PGN 60928.
#define Max_N2kModelID_len
Max length of ModelID Document says for length 33 but then values has not been translated right on de...
void SetHeartbeat(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter)
Setting up Message "Heartbeat" - PGN 126993.
#define N2kNullCanBusAddress
Null Address (???)
void SetN2kPGNISOAcknowledgement(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN)
Setting up Message "ISO Acknowledgement" - PGN 59392.
#define N2kMaxCanBusAddress
Max CAN Bus Address given by the library.
bool ParseN2kPGNISORequest(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN)
Parsing the content of a "ISO request" message - PGN 59904.
tN2kPGNList
Enumeration of types for PGN lists according to PGN 126464.
const unsigned long TransmitMessages[]
size_t print(const char *str)
Print string to stream.
size_t println(const char *str)
Print string and newline to stream.
Class used internally on tNMEA2000 to handle incoming NMEA2000 messages.
unsigned char TPMaxPackets
=0 not TP message. >0 number of packets can be received
bool KnownMessage
Message is already known
bool Ready
Message ready for handling?
tN2kMsg N2kMsg
Reference to a N2kMsg Object, Output: NMEA2000 message ready to be send.
bool SystemMessage
Message is a system message.
void FreeMessage()
Free the message.
unsigned char TPRequireCTS
=0 no, n=after each n frames
unsigned char LastFrame
Last received frame sequence number on fast packets or multi packet
bool FreeMsg
Message is free for fill up
unsigned char CopiedLen
Length of copied bytes.
Default Group Function Handler for PGN 126464 - "PGN List - Transmit/Receive PGNs group function".
Default Group Function Handler for PGN 126993 - "Heartbeat".
Default Group Function Handler for PGN 126996 - Product Information.
Default Group Function Handler for PGN 126998 - "Configuration Information".
Default Group Function Handler for PGN 60928 - "ISO Address Claim".
Base handler class for Group Functions.
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.
unsigned long PGN
Parameter Group Number (PGN) of this Group Function.
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 AddStr(const char *str, int len, bool UsePgm=false, unsigned char fillChar=0xff)
Add string value to the buffer The string will be added to the end (indicated by DataLen) of the byte...
void Add2ByteUInt(uint16_t v)
Add unsigned integer value to the buffer using 2 bytes The value will be added to the end (indicated ...
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,...
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...
bool IsTPMessage() const
Determine if the message is flagged as MultiPacket Message.
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...
void ForceSource(unsigned char _Source) const
Set the Source of the message.
void Print(N2kStream *port, bool NoData=false) const
Print out the whole content of the N2kMsg Object.
void AddUInt64(uint64_t v)
Add unsigned integer value to the buffer using 8 bytes The value will be added to the end (indicated ...
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.
static const int MaxDataLen
Maximum number of bytes that can be stored in the data buffer With fast packet the first frame can ha...
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.
unsigned long MsgTime
timestamp (ms since start [max 49days]) of the NMEA2000 message
void Add4ByteUInt(uint32_t v)
Add unsigned integer value to the buffer using 4 bytes The value will be added to the end (indicated ...
void CheckDestination() const
Validation check for the message destination We can send to specified destination only for PGN:s low ...
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.
uint64_t GetUInt64(int &Index, uint64_t def=0xffffffffffffffffULL) const
Get an unsigned integer from 8 bytes out of Data.
bool GetStr(char *StrBuf, size_t Length, int &Index) const
Get a string out of Data.
void Init(unsigned char _Priority, unsigned long _PGN, unsigned char _Source, unsigned char _Destination=0xff)
Initialisation of the N2kMsg object.
void SetIsTPMessage(bool tp=true)
Set the MultiPacket Message status.
void SendInActisenseFormat(N2kStream *port) const
Print out the whole content of the N2kMsg Object using the Actisense Format.
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.
void Disable()
Disable the Scheduler.
bool IsEnabled() const
Check if the scheduler is enabled.
void FromNow(uint32_t _Add)
Set Timestamp for next event relative to now.
bool IsTime() const
Is it time for the next event.
static void SetSyncOffset()
Set the SyncOffset of the scheduler.
void SetPeriodAndOffset(uint32_t _Period, uint32_t _Offset)
Set the Period And Offset of the Scheduler.
uint32_t GetOffset() const
Get the Offset of the Scheduler.
uint32_t GetPeriod() const
Get the Period of the Scheduler.
void UpdateNextTime()
Update the timestamp for NextTime.
void Disable()
Disable Scheduler.
Structure holds all the data needed for a valid CAN-Message.
unsigned char buf[8]
Data payload for the CAN Message.
unsigned char len
Length of carried data of the CAN Message.
bool wait_sent
Has the CAN Message to wait before sending.
unsigned long id
ID of the CAN Message.
This class represents an internal device.
void UpdateAddressClaimEndSource()
Updates AddressClaimEndSource.
bool HasPendingInformation
internal device has pending information
const unsigned long * ReceiveMessages
Pointer to a buffer that holds all supported receive PGNs for this device.
void ClearPendingConfigurationInformation()
Resets PendingConfigurationInformation to zero.
void SetPendingProductInformation()
Set the timestamp for Pending a ProductInformation message.
void SetPendingConfigurationInformation()
Set the timestamp for Pending a ConfigurationInformation message.
uint8_t NextDTSequence
Next Sequence.
uint8_t HeartbeatSequence
Heartbeat Sequence.
tN2kScheduler NextDTSendTime
Timestamp, when next data packet can be send on TP broadcast.
tProductInformation * LocalProductInformation
This holds all the local (???) Product Informations for this specific device.
tN2kSyncScheduler HeartbeatScheduler
Scheduler for the heartbeat message.
uint8_t N2kSource
Source address of this device on the NMEA2000 bus.
size_t MaxPGNSequenceCounters
Fast packet PGNs sequence counters.
const tProductInformation * ProductInformation
This holds all the Product Informations for this specific device.
tN2kScheduler AddressClaimTimer
Timer value for AddressClaim.
void UpdateHasPendingInformation()
tN2kMsg PendingTPMsg
Pending N2k message.
tDeviceInformation DeviceInformation
This holds all the Device Informations for this specific device.
const unsigned long * TransmitMessages
Pointer to a buffer that holds all supported transmit PGNs for this device.
void SetPendingIsoAddressClaim(unsigned long FromNow=2)
Set the timestamp for Pending an ISO Address Claim message.
void ClearPendingIsoAddressClaim()
Resets PendingIsoAddressClaim to zero.
unsigned long * PGNSequenceCounters
Fast packet PGNs sequence counters.
void ClearPendingProductInformation()
Resets PendingProductInformation to zero.
unsigned long GetPGN() const
Return the PGN that is handled by this message handler.
bool SendTPCM_RTS(int iDev)
Send ISO Transport Protocol message RTS.
bool IsMySource(unsigned char Source)
Checks if the source belongs to a device on Devices.
void SetFastPacketMessages(const unsigned long *_FastPacketMessages)
Set the list of known Fast Packet Messages.
bool IsReadyToSend() const
Checks if the device is ready to start address claiming.
void SendHeartbeat(int iDev)
Send heartbeat for specific device.
void SendPendingInformation()
Send ISO AddressClaim, Product Information and Config Information.
void SetProductInformation(const char *_ModelSerialCode, unsigned short _ProductCode=0xffff, const char *_ModelID=0, const char *_SwCode=0, const char *_ModelVersion=0, unsigned char _LoadEquivalency=0xff, unsigned short _N2kVersion=0xffff, unsigned char _CertificationLevel=0xff, int iDev=0)
Set the Product Information of this device.
bool(* ISORqstHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex)
Handler callbacks for 'ISORequest' messages.
static void ClearSetCharBuf(const char *str, size_t MaxLen, char *buf)
Setting up a clean Char Buffer.
bool IsTxPGN(unsigned long PGN, int iDev=0)
Check if this message is a Transmit message of this device.
size_t GetFastPacketTxPGNCount(int iDev)
Get the Fast Packet Tx PGN Count.
int DeviceCount
Number of devices.
static void ClearCharBuf(size_t MaxLen, char *buf)
Clears a char array buffer with 0s.
void InitDevices()
Initialize all devices.
tN2kCANMsg * N2kCANMsgBuf
Buffer for receiving messages.
void ExtendSingleFrameMessages(const unsigned long *_SingleFrameMessages)
Set the list of known Extended Single Frame Messages.
void EnableForward(bool v=true)
Enable message forwarding to stream.
void ParseMessages()
Parse all incoming Messages.
void SetISORqstHandler(bool(*ISORequestHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex))
Set the message handler for incoming ISO Requests.
tDebugMode dbMode
Attribute that holds the actual Debug Mode (default = md_none)
void SetDeviceInformation(unsigned long _UniqueNumber, unsigned char _DeviceFunction=0xff, unsigned char _DeviceClass=0xff, uint16_t _ManufacturerCode=0xffff, unsigned char _IndustryGroup=4, int iDev=0)
Set the Device Information. See also NAME.
bool HasAllTPDTSent(int iDev)
Check if all data bytes of the multi packet message has been send successful.
void RemoveGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler)
Remove a message handler for incoming Group Function messages.
void SetForwardSystemMessages(bool v=true)
Enable System Messages for forwarding.
unsigned int ForwardMode
Actual message forward operation mode (default = all messages - also system and own)
void SetSingleFrameMessages(const unsigned long *_SingleFrameMessages)
Set the list of known Single Frame Messages.
void SetInstallationDescription1(const char *InstallationDescription1)
Set the Installation Description 1 of this device.
void HandleISORequest(const tN2kMsg &N2kMsg)
Handles an ISO Request.
N2kStream * ForwardStream
Actual stream to be used for forward messaging.
void SetMsgHandler(void(*_MsgHandler)(const tN2kMsg &N2kMsg))
Set the message handler for incoming NMEA2000 messages.
tN2kGroupFunctionHandler * pGroupFunctionHandlers
Pointer to Buffer for GRoup Function Handlers.
bool SendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true)
Sends a single CAN frame.
bool StartSendTPMessage(const tN2kMsg &msg, int iDev)
Start sending an ISO-TP message.
void HandleGroupFunction(const tN2kMsg &N2kMsg)
Handles a Group Function.
bool SendConfigurationInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Config Information message.
bool ReadResetInstallationDescriptionChanged()
Check if this device has changed its Install Description.
void SetForwardOwnMessages(bool v=true)
Enable Own Messages for forwarding.
bool IsInitialized()
Determines if the CAN BUS is already initialized.
unsigned char GetCertificationLevel(int iDev=0) const
Get the Certification Level of the device.
void AttachMsgHandler(tMsgHandler *_MsgHandler)
Attach a message handler for incoming N2kMessages.
bool AddressChanged
Flag that the address has changed.
bool CheckKnownMessage(unsigned long PGN, bool &SystemMessage, bool &FastPacket)
Check if this Message is known to the system.
void SetDebugMode(tDebugMode _dbMode)
Set the Debug Mode of the system.
bool IsValidDevice(int iDev) const
Checks if the device index on Devices is valid.
void ExtendReceiveMessages(const unsigned long *_ReceiveMessages, int iDev=0)
Extend the list of Received Messages.
uint8_t MaxN2kCANMsgs
Size of N2kCANMsgBuf receiving message buffer.
virtual bool CANGetFrame(unsigned long &id, unsigned char &len, unsigned char *buf)=0
Abstract class for reading frame from driver class.
static bool IsBroadcast(unsigned char Source)
Checks if the given Address is a broadcast address.
void SendIsoAddressClaim(unsigned char Destination=0xff, int DeviceIndex=0, unsigned long FromNow=0)
Send an IsoAddressClaim message.
bool ForwardEnabled() const
Is message forwarding enabled.
bool Open()
Open the CAN device.
tN2kMode
System mode defines how the device will behave on the NMEA2000 bus.
void GetManufacturerInformation(char *buf, size_t max_len)
Get the Manufacturer Information of this device.
void SetHeartbeatInterval(unsigned long interval, bool SetAsDefault=true, int iDev=-1) __attribute__((deprecated))
Deprecated. Use function SetHeartbeatIntervalAndOffset.
bool ForwardSystemMessages() const
Is forwarding enabled for system messages.
void SendPendingTPMessage(int iDev)
Send pending ISO-TP Messages.
void SendTPCM_EndAck(unsigned long PGN, unsigned char Destination, int iDev, uint16_t nBytes, unsigned char nPackets)
Send ISO Transport Protocol message End Acknowledge.
tN2kScheduler OpenScheduler
bool IsFastPacketPGN(unsigned long PGN)
Check if this PNG is a fast packet message.
void AddGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler)
Add a message handler for incoming Group Function messages.
void Restart()
Restart the device.
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.
void ExtendTransmitMessages(const unsigned long *_TransmitMessages, int iDev=0)
Extend the list of Transmitted Messages.
bool SendTPDT(int iDev)
Send ISO Transport Protocol data packet.
virtual bool CANOpen()=0
Abstract class for initializing and opening CAN interface.
static bool IsProprietaryMessage(unsigned long PGN)
Check if the given PGN is proprietary.
void HandleISOAddressClaim(const tN2kMsg &N2kMsg)
Handles an IsoAddressClaim.
tNMEA2000()
Construct a new NMEA2000 object.
uint16_t MaxCANSendFrames
Size of CANSendFrameBuf or before initialization requested total frame buffering size.
void GetInstallationDescription1(char *buf, size_t max_len)
Get the Install Description 1 of this device.
@ os_OpenCAN
State Open CAN.
@ os_WaitOpen
State Wait Open.
uint16_t CANSendFrameBufferRead
Next write index for the library CAN send frame buffer.
void SetHeartbeatIntervalAndOffset(uint32_t interval, uint32_t offset=0, int iDev=-1)
Set the Heartbeat Interval and Offset for a device.
uint16_t CANSendFrameBufferWrite
Next read index for the library CAN send frame buffer.
bool SendFrames()
Sends pending all frames.
void SetOnOpen(void(*_OnOpen)())
Set OnOpen callback function.
bool IsAddressClaimStarted(int iDev)
Checks if the IsoAddressClaim is already started.
void ExtendFastPacketMessages(const unsigned long *_FastPacketMessages)
Set the list of known Extended Fast Packet Messages.
void RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev)
Respond to an ISO request.
void SendRxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Receive messages.
tMsgHandler * MsgHandlers
Pointer to a buffer for Message Handlers.
uint8_t SetN2kCANBufMsg(unsigned long canId, unsigned char len, unsigned char *buf)
Function handles received CAN frame and adds it to tN2kCANMsg.
void SendTxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Transmit messages.
void FindFreeCANMsgIndex(unsigned long PGN, unsigned char Source, unsigned char Destination, bool TPMsg, uint8_t &MsgIndex)
Find index for free space for a message on N2kCANMsgBuf.
void StartAddressClaim()
Starting the ISO Address Claim for all devices.
tCANSendFrame * GetNextFreeCANSendFrame()
Get the Next Free CAN Frame from CANSendFrameBuf.
tConfigurationInformation ConfigurationInformation
Configuration Information of the device.
void SetProgmemConfigurationInformation(const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0)
Set the Configuration Information located on PROGMEM.
void GetModelVersion(char *buf, size_t max_len, int iDev=0) const
Get the Model Version of the device.
int GetSequenceCounter(unsigned long PGN, int iDev)
Get the Sequence Counter for the PGN.
const tNMEA2000::tProductInformation * GetProductInformation(int iDev, bool &IsProgMem) const
Get the Product Information of the device.
void SendTPCM_Abort(unsigned long PGN, unsigned char Destination, int iDev, unsigned char AbortCode)
Send ISO Transport Protocol message Abort.
void EndSendTPMessage(int iDev)
Ends sending of ISO-TP message.
tForwardType ForwardType
Actual message forward type (default = fwdt_Actisense)
const unsigned long * SingleFrameMessages[N2kMessageGroups]
bool HandleReceivedSystemMessage(int MsgIndex)
Handles a received system message.
tN2kMode N2kMode
Actual operation mode of this device (default = N2km_ListenOnly)
const unsigned long * FastPacketMessages[N2kMessageGroups]
void(* MsgHandler)(const tN2kMsg &N2kMsg)
Handler callbacks for normal messages.
bool HandleOnlyKnownMessages() const
Is handle only known messages enabled.
char * LocalConfigurationInformationData
Pointer to a buffer for local Configuration Information.
static void SetCharBuf(const char *str, size_t MaxLen, char *buf)
Setting up a Char Buffer.
unsigned short GetN2kVersion(int iDev=0) const
Get the N2k standard version of the device.
uint16_t MaxCANReceiveFrames
Max number received CAN messages that can go to the buffer.
int FindSourceDeviceIndex(unsigned char Source) const
Finds a device on Devices by its source address.
bool SendProductInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Product Information message.
virtual void InitCANFrameBuffers()
Initialize CAN Frame buffers.
bool DeviceInformationChanged
Flag that the device information has changed.
void SendTPCM_CTS(unsigned long PGN, unsigned char Destination, int iDev, unsigned char nPackets, unsigned char NextPacketNumber)
Send ISO Transport Protocol message CTS.
bool SendTPCM_BAM(int iDev)
Send ISO Transport Protocol message BAM.
bool IsActiveNode()
Returns if this node is active on the bus.
void GetModelSerialCode(char *buf, size_t max_len, int iDev=0) const
Get the Model Serial of the device.
bool ReadResetAddressChanged()
Check if this device has changed its address.
void SetMode(tN2kMode _N2kMode, uint8_t _N2kSource=15)
Set the library mode and start source address.
void ForwardMessage(const tN2kMsg &N2kMsg)
Forwards a N2k message.
bool ForwardOnlyKnownMessages() const
Is forwarding enabled for known messages only.
virtual bool CANSendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true)=0
Abstract class for sending a CAN Frame.
void SetInstallationDescription2(const char *InstallationDescription2)
Set the Installation Description 2 of this device.
bool TestHandleTPMessage(unsigned long PGN, unsigned char Source, unsigned char Destination, unsigned char len, unsigned char *buf, uint8_t &MsgIndex)
ISO Transport Protocol handlers for multi packet support.
void SetDeviceInformationInstances(uint8_t _DeviceInstanceLower=0xff, uint8_t _DeviceInstanceUpper=0xff, uint8_t _SystemInstance=0xff, int iDev=0)
Set the Device Information Instances.
void HandleCommandedAddress(uint64_t CommandedName, unsigned char NewAddress, int iDev)
Handles if we get commanded to set a new address.
bool IsFastPacket(const tN2kMsg &N2kMsg)
Check if this PNG is a fast packet message.
void GetInstallationDescription2(char *buf, size_t max_len)
Get the Install Description 2 of this device.
bool ForwardOwnMessages() const
Is forwarding enabled for own messages.
unsigned short GetProductCode(int iDev=0) const
Get the Product Code of the device.
tDebugMode
For debugging we have some cases for SendMsg.
bool ReadResetDeviceInformationChanged()
Check if this device has changed its DeviceInstances or SystemInstance.
void GetSwCode(char *buf, size_t max_len, int iDev=0) const
Get the Sw Code of the device.
void SetN2kSource(unsigned char _iAddr, int _iDev=0)
Set source for the given device.
void GetModelID(char *buf, size_t max_len, int iDev=0) const
Get the ModelID of the device.
void DetachMsgHandler(tMsgHandler *_MsgHandler)
Detach a message handler for incoming N2kMessages.
void CopyProgmemConfigurationInformationToLocal()
Copy Configuration Information to local memory.
void(* OnOpen)()
Callback function, which will be called when library start bus communication.
unsigned char GetLoadEquivalency(int iDev=0) const
Get the Load Equivalency of this device.
void GetNextAddress(int DeviceIndex, bool RestartAtEnd=false)
Get the next free address for the device.
void RespondGroupFunction(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode GroupFunctionCode, unsigned long PGNForGroupFunction, int iDev)
Respond to an Group Function.
bool InstallationDescriptionChanged
Flag the Installation description has changed.
void SetConfigurationInformation(const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0)
Set the Configuration Information of this device.
tInternalDevice * Devices
Pointer to a buffer for all internal devices.
void SetDeviceCount(const uint8_t _DeviceCount)
Set the count of devices library shows on bus.
tCANSendFrame * CANSendFrameBuf
Buffer for library send out CAN frames.
void RunMessageHandlers(const tN2kMsg &N2kMsg)
Run all message handlers.