NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
NMEA2000.h
Go to the documentation of this file.
1/*
2 * NMEA2000.h
3 *
4 * The MIT License
5 *
6 * Copyright (c) 2015-2024 Timo Lappalainen, Kave Oy, www.kave.fi
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24*/
25
26/*************************************************************************/
46#ifndef _NMEA2000_H_
47#define _NMEA2000_H_
48
50#include "N2kStream.h"
51#include "N2kMsg.h"
52#include "N2kCANMsg.h"
53#include "N2kTimer.h"
54
55#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
56#include "N2kGroupFunction.h"
57#endif
59#define N2kPGNIsoAddressClaim 60928L
61#define N2kPGNProductInformation 126996L
63#define N2kPGNConfigurationInformation 126998L
64
65// Document says for lengths 33,40,24,32, but then values
66// has not been translated right on devices.
70#define Max_N2kModelID_len 32
74#define Max_N2kSwCode_len 32
78#define Max_N2kModelVersion_len 32
82#define Max_N2kModelSerialCode_len 32
83
90#define Max_N2kProductInfoStrLen 33
91
92/************************************************************************/
99#define Max_N2kConfigurationInfoField_len 71 // 70 + '/0'
100
102#define Max_N2kMsgBuf_Time 100
104#define N2kMessageGroups 2
106#define N2kMaxCanBusAddress 251
108#define N2kNullCanBusAddress 254
109
110/************************************************************************/
138{
139public:
140 /************************************************************************/
153 static bool IsProprietaryMessage(unsigned long PGN);
154 /************************************************************************/
160 static void ClearCharBuf(size_t MaxLen, char *buf);
161 /************************************************************************/
170 static void SetCharBuf(const char *str, size_t MaxLen, char *buf);
171 /************************************************************************/
181 static void ClearSetCharBuf(const char *str, size_t MaxLen, char *buf);
182
183 /************************************************************************/
193 template <typename T> static T N2kMax(T a, T b) { return (a>b?a:b); }
194
195 /************************************************************************/
205 template <typename T> static T N2kMin(T a, T b) { return (a<b?a:b); }
206
207 /************************************************************************/
217
219 unsigned short N2kVersion;
221 unsigned short ProductCode;
222 //
236 unsigned char CertificationLevel;
243 unsigned char LoadEquivalency;
244
245 /********************************************************************/
262 void Set(const char *_ModelSerialCode,
263 unsigned short _ProductCode=0xffff,
264 const char *_ModelID=0,
265 const char *_SwCode=0,
266 const char *_ModelVersion=0,
267 unsigned char _LoadEquivalency=0xff,
268 unsigned short _N2kVersion=0xffff,
269 unsigned char _CertificationLevel=0xff
270 ) {
271 N2kVersion=(_N2kVersion!=0xffff?_N2kVersion:2101);
272 ProductCode=_ProductCode;
273 ClearSetCharBuf(_ModelID,sizeof(N2kModelID),N2kModelID);
274 ClearSetCharBuf(_SwCode,sizeof(N2kSwCode),N2kSwCode);
275 ClearSetCharBuf(_ModelVersion,sizeof(N2kModelVersion),N2kModelVersion);
276 ClearSetCharBuf(_ModelSerialCode,sizeof(N2kModelSerialCode),N2kModelSerialCode);
277 CertificationLevel=(_CertificationLevel!=0xff?_CertificationLevel:0);
278 LoadEquivalency=(_LoadEquivalency!=0xff?_LoadEquivalency:1);
279 }
280 /*******************************************************************/
282 void Clear();
283 /*******************************************************************/
290 bool IsSame(const tProductInformation &Other);
291 };
292 /**********************************************************************/
298 protected:
299 /********************************************************************/
304 typedef union {
306 uint64_t Name;
307 /******************************************************************/
311 struct {
319 unsigned char DeviceInstance;
325 unsigned char DeviceFunction;
331 unsigned char DeviceClass;
332
348 };
349 } tUnionDeviceInformation;
350
353
354 public:
355 /*******************************************************************/
359
360 /*******************************************************************/
364 void SetUniqueNumber(uint32_t _UniqueNumber) { DeviceInformation.UnicNumberAndManCode=(DeviceInformation.UnicNumberAndManCode&0xffe00000) | (_UniqueNumber&0x1fffff); }
365
366 /*******************************************************************/
370 uint32_t GetUniqueNumber() const { return DeviceInformation.UnicNumberAndManCode&0x1fffff; }
371
372 /*******************************************************************/
376 void SetManufacturerCode(uint16_t _ManufacturerCode) { DeviceInformation.UnicNumberAndManCode=(DeviceInformation.UnicNumberAndManCode&0x1fffff) | (((unsigned long)(_ManufacturerCode&0x7ff))<<21); }
377
378 /*******************************************************************/
383
384 /*******************************************************************/
388 void SetDeviceInstance(unsigned char _DeviceInstance) { DeviceInformation.DeviceInstance=_DeviceInstance; }
389
390 /*******************************************************************/
394 unsigned char GetDeviceInstance() const { return DeviceInformation.DeviceInstance; }
395
396 /*******************************************************************/
400 unsigned char GetDeviceInstanceLower() const { return DeviceInformation.DeviceInstance & 0x07; }
401 /*******************************************************************/
405 unsigned char GetDeviceInstanceUpper() const { return (DeviceInformation.DeviceInstance>>3) & 0x1f; }
406
407 /*******************************************************************/
412 void SetDeviceFunction(unsigned char _DeviceFunction) { DeviceInformation.DeviceFunction=_DeviceFunction; }
413
414 /*******************************************************************/
419 unsigned char GetDeviceFunction() const { return DeviceInformation.DeviceFunction; }
420
421 /*******************************************************************/
426 void SetDeviceClass(unsigned char _DeviceClass) { DeviceInformation.DeviceClass=((_DeviceClass&0x7f)<<1); }
427
428 /*******************************************************************/
433 unsigned char GetDeviceClass() const { return DeviceInformation.DeviceClass>>1; }
434
435 /********************************************************************/
439 void SetIndustryGroup(unsigned char _IndustryGroup) { DeviceInformation.IndustryGroupAndSystemInstance=(DeviceInformation.IndustryGroupAndSystemInstance&0x0f) | (_IndustryGroup<<4) | 0x80; }
440
441 /********************************************************************/
445 unsigned char GetIndustryGroup() const { return (DeviceInformation.IndustryGroupAndSystemInstance>>4) & 0x07; }
446
447 /********************************************************************/
451 void SetSystemInstance(unsigned char _SystemInstance) { DeviceInformation.IndustryGroupAndSystemInstance=(DeviceInformation.IndustryGroupAndSystemInstance&0xf0) | (_SystemInstance&0x0f); }
452
453 /********************************************************************/
458 /*** ****************************************************************/
462 uint64_t GetName() const { return DeviceInformation.Name; }
463 /********************************************************************/
467 void SetName(uint64_t _Name) { DeviceInformation.Name=_Name; }
468 /********************************************************************/
474 inline bool IsSame(uint64_t Other) { return GetName()==Other; }
475 };
476 /************************************************************************/
481 class tDevice {
482 protected:
486 unsigned long CreateTime;
488 uint8_t Source;
489
490 public:
491 /*******************************************************************/
499 tDevice(uint64_t _Name, uint8_t _Source=255) { Source=_Source; DevI.SetName(_Name); CreateTime=N2kMillis(); }
500 /*******************************************************************/
502 virtual ~tDevice() {;}
503
505 uint8_t GetSource() const { return Source; }
507 unsigned long GetCreateTime() const { return CreateTime; }
508
509 /******************************************************************/
513 inline uint64_t GetName() const { return DevI.GetName(); }
514 /******************************************************************/
520 inline bool IsSame(uint64_t Other) { return DevI.IsSame(Other); }
521 /*******************************************************************/
525 inline uint32_t GetUniqueNumber() const { return DevI.GetUniqueNumber(); }
526 /*******************************************************************/
530 inline uint16_t GetManufacturerCode() const { return DevI.
532 /*******************************************************************/
536 inline unsigned char GetDeviceInstance() const { return DevI.GetDeviceInstance(); }
537 /*******************************************************************/
541 inline unsigned char GetDeviceInstanceLower() const { return DevI.GetDeviceInstanceLower(); }
542 /*******************************************************************/
546 inline unsigned char GetDeviceInstanceUpper() const { return DevI.GetDeviceInstanceUpper(); }
547 /*******************************************************************/
552 inline unsigned char GetDeviceFunction() const { return DevI.GetDeviceFunction(); }
553 /*******************************************************************/
558 inline unsigned char GetDeviceClass() const { return DevI.GetDeviceClass(); }
559 /********************************************************************/
563 inline unsigned char GetIndustryGroup() const { return DevI.GetIndustryGroup(); }
564 /********************************************************************/
568 inline unsigned char GetSystemInstance() const { return DevI.GetSystemInstance(); }
569
570 // Product information
573 virtual unsigned short GetN2kVersion() const=0;
576 virtual unsigned short GetProductCode() const=0;
578 virtual const char * GetModelID() const=0;
581 virtual const char * GetSwCode() const=0;
584 virtual const char * GetModelVersion() const=0;
587 virtual const char * GetModelSerialCode() const=0;
590 virtual unsigned short GetCertificationLevel() const=0;
593 virtual unsigned short GetLoadEquivalency() const=0;
594
595 // Configuration information
598 virtual const char * GetManufacturerInformation() const { return 0; }
601 virtual const char * GetInstallationDescription1() const { return 0; }
604 virtual const char * GetInstallationDescription2() const { return 0; }
605
607 virtual const unsigned long * GetTransmitPGNs() const { return 0; }
609 virtual const unsigned long * GetReceivePGNs() const { return 0; }
610 };
611 /************************************************************************/
617 private:
618 friend class tNMEA2000;
620 tMsgHandler *pNext;
622 tNMEA2000 *pNMEA2000;
623 protected:
625 unsigned long PGN;
626 /*******************************************************************/
630 virtual void HandleMsg(const tN2kMsg &N2kMsg)=0;
633 tNMEA2000 *GetNMEA2000() { return pNMEA2000; }
634 public:
635 /******************************************************************/
644 tMsgHandler(unsigned long _PGN=0, tNMEA2000 *_pNMEA2000=0) {
645 PGN=_PGN; pNext=0; pNMEA2000=0;
646 if ( _pNMEA2000!=0 ) _pNMEA2000->AttachMsgHandler(this);
647 }
648 /*******************************************************************/
651 virtual ~tMsgHandler() { if ( pNMEA2000!=0 ) pNMEA2000->DetachMsgHandler(this); }
652 /*******************************************************************/
656 inline unsigned long GetPGN() const { return PGN; }
657 };
658
659public:
660 /************************************************************************/
664 typedef enum {
668
671 fwdt_Text
673
674 /************************************************************************/
683 typedef enum {
713
714 /************************************************************************/
718 typedef enum {
728 } tDebugMode;
729
730 /************************************************************************/
741 };
742
743protected:
744
745 /************************************************************************/
751 typedef enum {
754 os_None
765
766 /************************************************************************/
772 public:
774 uint8_t N2kSource;
777 // Product information
801 const unsigned long *TransmitMessages;
804 const unsigned long *ReceiveMessages;
806 unsigned long *PGNSequenceCounters;
813
814#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
821#endif
822#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
824 #define DefaultHeartbeatInterval 60000
829#endif
830
831 public:
832 /********************************************************************/
838 N2kSource=0;
841 AddressClaimEndSource=N2kMaxCanBusAddress; //GetNextAddressFromBeginning=true;
844#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
846#endif
847
848#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
850#endif
851 }
852 /*********************************************************************/
857 void SetPendingIsoAddressClaim(unsigned long FromNow=2) { PendingIsoAddressClaim.FromNow(FromNow); HasPendingInformation=true; }
858 /*********************************************************************/
871
872 /*********************************************************************/
879 void SetPendingProductInformation() { PendingProductInformation.FromNow(187+N2kSource*8); HasPendingInformation=true; } // Use strange increment to avoid synchronize
882 /*********************************************************************/
893
894 /*********************************************************************/
901 void SetPendingConfigurationInformation() { PendingConfigurationInformation.FromNow(187+N2kSource*10); HasPendingInformation=true; } // Use strange increment to avoid synchronize
904 /*********************************************************************/
915 /*********************************************************************/
921 }
926 #if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
928 #endif
929 ;
930 }
931 };
932
933protected:
934
936 static const int FwdModeBit_EnableForward = BIT(0);
938 static const int FwdModeBit_SystemMessages = BIT(1);
941 static const int FwdModeBit_OnlyKnownMessages = BIT(2);
944 static const int FwdModeBit_OwnMessages = BIT(3);
946 static const int HandleModeBit_OnlyKnownMessages = BIT(4);
947
948protected:
959 unsigned int ForwardMode;
964
973
978// unsigned long N2kSource[Max_N2kDevices];
979
984
987
988 /*********************************************************************/
993 {
994 public:
996 unsigned long id;
998 unsigned char len;
1000 unsigned char buf[8];
1003
1004 public:
1006 void Clear() {id=0; len=0; for (int i=0; i<8; i++) { buf[i]=0; } }
1007 };
1008
1009protected:
1022
1062
1074 void (*OnOpen)();
1075
1077 void (*MsgHandler)(const tN2kMsg &N2kMsg);
1079 bool (*ISORqstHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex);
1080
1081#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
1084#endif
1085
1086protected:
1087 /*********************************************************************/
1105 virtual bool CANSendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true)=0;
1106
1107 /*********************************************************************/
1120 virtual bool CANOpen()=0;
1121
1122 /*********************************************************************/
1135 virtual bool CANGetFrame(unsigned long &id, unsigned char &len, unsigned char *buf)=0;
1136
1137 /*********************************************************************/
1159 virtual void InitCANFrameBuffers();
1160#if defined(DEBUG_NMEA2000_ISR)
1161 virtual void TestISR() {;}
1162#endif
1163
1164protected:
1165 /**********************************************************************/
1171 bool SendFrames();
1172 /**********************************************************************/
1186 bool SendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true);
1187
1188 /*********************************************************************/
1192 tCANSendFrame *GetNextFreeCANSendFrame();
1193
1194 /*********************************************************************/
1208
1209protected:
1210 /*********************************************************************/
1228 void InitDevices();
1229 /*********************************************************************/
1234 bool IsInitialized() { return (N2kCANMsgBuf!=0); }
1235
1236#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1237 /*********************************************************************/
1252 void FindFreeCANMsgIndex(unsigned long PGN, unsigned char Source, unsigned char Destination, bool TPMsg, uint8_t &MsgIndex);
1253#else
1254 /*********************************************************************/
1268 void FindFreeCANMsgIndex(unsigned long PGN, unsigned char Source, unsigned char Destination, uint8_t &MsgIndex);
1269#endif
1270 /*********************************************************************/
1283 uint8_t SetN2kCANBufMsg(unsigned long canId, unsigned char len, unsigned char *buf);
1284
1285 /*********************************************************************/
1296 bool IsFastPacketPGN(unsigned long PGN);
1297
1298 /*********************************************************************/
1309 bool IsFastPacket(const tN2kMsg &N2kMsg);
1310
1311 /*********************************************************************/
1328 bool CheckKnownMessage(unsigned long PGN, bool &SystemMessage, bool &FastPacket);
1329
1330 /*********************************************************************/
1346 bool HandleReceivedSystemMessage(int MsgIndex);
1347
1348 /*********************************************************************/
1357 void ForwardMessage(const tN2kMsg &N2kMsg);
1358
1359 /*********************************************************************/
1368 void ForwardMessage(const tN2kCANMsg &N2kCanMsg);
1369
1370 /*********************************************************************/
1384 void RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev);
1385
1386 /*********************************************************************/
1394 void HandleISORequest(const tN2kMsg &N2kMsg);
1395
1396#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
1397
1398 /*********************************************************************/
1412 void RespondGroupFunction(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode GroupFunctionCode, unsigned long PGNForGroupFunction, int iDev);
1413
1414 /*********************************************************************/
1424 void HandleGroupFunction(const tN2kMsg &N2kMsg);
1425#endif
1426
1427 /*********************************************************************/
1432 void StartAddressClaim(int iDev);
1433
1434 /*********************************************************************/
1438 void StartAddressClaim();
1439
1440 /*********************************************************************/
1447 bool IsAddressClaimStarted(int iDev);
1448
1449 /**********************************************************************/
1454 void HandleISOAddressClaim(const tN2kMsg &N2kMsg);
1455
1456 /**********************************************************************/
1464 void HandleCommandedAddress(uint64_t CommandedName, unsigned char NewAddress, int iDev);
1465
1466 /**********************************************************************/
1471 void HandleCommandedAddress(const tN2kMsg &N2kMsg);
1472
1473 /**********************************************************************/
1481 void GetNextAddress(int DeviceIndex, bool RestartAtEnd=false);
1482
1483 /**********************************************************************/
1490 bool IsMySource(unsigned char Source);
1491
1492 /**********************************************************************/
1499 int GetSequenceCounter(unsigned long PGN, int iDev);
1500
1501 /*********************************************************************/
1507 size_t GetFastPacketTxPGNCount(int iDev);
1508
1509 /*********************************************************************/
1521
1522 /*********************************************************************/
1529
1530 /*********************************************************************/
1537
1538 /*********************************************************************/
1545
1546 /*********************************************************************/
1553
1554 /*********************************************************************/
1559 void RunMessageHandlers(const tN2kMsg &N2kMsg);
1560
1561 /*********************************************************************/
1572 bool HandleReceivedMessage(unsigned char Destination) {
1573 return (/* HandleMessagesToAnyDestination() */ true ||
1574 tNMEA2000::IsBroadcast(Destination) ||
1575 FindSourceDeviceIndex(Destination)>=0);
1576 }
1577
1578 /*********************************************************************/
1585
1586 /*********************************************************************/
1593 bool IsValidDevice(int iDev) const { return (iDev>=0 && iDev<DeviceCount ); }
1594
1595 /*********************************************************************/
1601 bool IsReadyToSend() const {
1602 return ( (OpenState==os_Open || dbMode!=dm_None) &&
1606 );
1607 }
1608
1609
1610#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
1611 /*********************************************************************/
1624 bool TestHandleTPMessage(unsigned long PGN, unsigned char Source, unsigned char Destination,
1625 unsigned char len, unsigned char *buf,
1626 uint8_t &MsgIndex);
1627
1628 /*********************************************************************/
1638 bool SendTPCM_BAM(int iDev);
1639
1640 /*********************************************************************/
1648 bool SendTPCM_RTS(int iDev);
1649
1650 /*********************************************************************/
1660 void SendTPCM_CTS(unsigned long PGN, unsigned char Destination, int iDev, unsigned char nPackets, unsigned char NextPacketNumber);
1661
1662 /**********************************************************************/
1671 void SendTPCM_EndAck(unsigned long PGN, unsigned char Destination, int iDev, uint16_t nBytes, unsigned char nPackets);
1672
1673 /*********************************************************************/
1681 void SendTPCM_Abort(unsigned long PGN, unsigned char Destination, int iDev, unsigned char AbortCode);
1682
1683 /**********************************************************************/
1694 bool SendTPDT(int iDev);
1695
1696 /*********************************************************************/
1705 bool HasAllTPDTSent(int iDev);
1706
1707 /*********************************************************************/
1716 bool StartSendTPMessage(const tN2kMsg& msg, int iDev);
1717
1718 /*********************************************************************/
1723 void EndSendTPMessage(int iDev);
1724
1725 /*********************************************************************/
1730 void SendPendingTPMessage(int iDev);
1731#endif
1732#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
1733 /*********************************************************************/
1742
1743 /*********************************************************************/
1747#endif
1748
1749public:
1750 /*********************************************************************/
1755 tNMEA2000();
1756
1757 /**********************************************************************/
1763 int FindSourceDeviceIndex(unsigned char Source) const;
1764
1765 /*********************************************************************/
1779 void SetDeviceCount(const uint8_t _DeviceCount);
1780
1781 /*********************************************************************/
1816 void SetN2kCANMsgBufSize(const uint8_t _MaxN2kCANMsgs) { if (N2kCANMsgBuf==0) { MaxN2kCANMsgs=_MaxN2kCANMsgs; }; }
1817
1818 /*********************************************************************/
1853 virtual void SetN2kCANSendFrameBufSize(const uint16_t _MaxCANSendFrames) { if ( !IsInitialized() ) { MaxCANSendFrames=_MaxCANSendFrames; }; }
1854
1855 /*********************************************************************/
1870 virtual void SetN2kCANReceiveFrameBufSize(const uint16_t _MaxCANReceiveFrames) { if ( !IsInitialized() ) MaxCANReceiveFrames=_MaxCANReceiveFrames; }
1871
1872 /*********************************************************************/
1904 void SetProductInformation(const char *_ModelSerialCode,
1905 unsigned short _ProductCode=0xffff,
1906 const char *_ModelID=0,
1907 const char *_SwCode=0,
1908 const char *_ModelVersion=0,
1909 unsigned char _LoadEquivalency=0xff,
1910 unsigned short _N2kVersion=0xffff,
1911 unsigned char _CertificationLevel=0xff,
1912 int iDev=0
1913 );
1914
1915 /*********************************************************************/
1928 void SetProductInformation(const tProductInformation *_ProductInformation, int iDev=0);
1929
1930 /*********************************************************************/
1959 void SetConfigurationInformation(const char *ManufacturerInformation,
1960 const char *InstallationDescription1=0,
1961 const char *InstallationDescription2=0);
1962
1963 /*********************************************************************/
1983 void SetProgmemConfigurationInformation(const char *ManufacturerInformation,
1984 const char *InstallationDescription1=0,
1985 const char *InstallationDescription2=0);
1986
1987#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
1988
1989 /**********************************************************************/
1997 bool IsTxPGN(unsigned long PGN, int iDev=0);
1998
1999 /**********************************************************************/
2006 const tNMEA2000::tProductInformation * GetProductInformation(int iDev, bool &IsProgMem) const;
2007
2008 /**********************************************************************/
2014 unsigned short GetN2kVersion(int iDev=0) const;
2015
2016 /**********************************************************************/
2022 unsigned short GetProductCode(int iDev=0) const;
2023
2024 /**********************************************************************/
2031 void GetModelID(char *buf, size_t max_len, int iDev=0) const;
2032
2033 /**********************************************************************/
2040 void GetSwCode(char *buf, size_t max_len, int iDev=0) const;
2041
2042 /**********************************************************************/
2049 void GetModelVersion(char *buf, size_t max_len, int iDev=0) const;
2050
2051 /**********************************************************************/
2058 void GetModelSerialCode(char *buf, size_t max_len, int iDev=0) const;
2059
2060 /**********************************************************************/
2066 unsigned char GetCertificationLevel(int iDev=0) const;
2067
2068 /*********************************************************************/
2079 unsigned char GetLoadEquivalency(int iDev=0) const;
2080
2081 /*********************************************************************/
2089 void SetInstallationDescription1(const char *InstallationDescription1);
2090
2091 /*********************************************************************/
2099 void SetInstallationDescription2(const char *InstallationDescription2);
2100
2101 /*********************************************************************/
2108 void GetInstallationDescription1(char *buf, size_t max_len);
2109
2110 /*********************************************************************/
2117 void GetInstallationDescription2(char *buf, size_t max_len);
2118
2119 /*********************************************************************/
2126 void GetManufacturerInformation(char *buf, size_t max_len);
2127
2128 /*********************************************************************/
2140#endif
2141
2142 /*********************************************************************/
2165 void SetSingleFrameMessages(const unsigned long *_SingleFrameMessages);
2166
2167 /*********************************************************************/
2190 void SetFastPacketMessages (const unsigned long *_FastPacketMessages);
2191
2192 /*********************************************************************/
2212 void ExtendSingleFrameMessages(const unsigned long *_SingleFrameMessages);
2213
2214 /*********************************************************************/
2237 void ExtendFastPacketMessages (const unsigned long *_FastPacketMessages);
2238
2239 /*********************************************************************/
2266 void ExtendTransmitMessages(const unsigned long *_TransmitMessages, int iDev=0);
2267
2268 /*********************************************************************/
2293 void ExtendReceiveMessages(const unsigned long *_ReceiveMessages, int iDev=0);
2294
2295 /*********************************************************************/
2333 void SetDeviceInformation(unsigned long _UniqueNumber,
2334 unsigned char _DeviceFunction=0xff,
2335 unsigned char _DeviceClass=0xff,
2336 uint16_t _ManufacturerCode=0xffff,
2337 unsigned char _IndustryGroup=4,
2338 int iDev=0
2339 );
2340
2341 /*********************************************************************/
2360 uint8_t _DeviceInstanceLower=0xff,
2361 uint8_t _DeviceInstanceUpper=0xff,
2362 uint8_t _SystemInstance=0xff,
2363 int iDev=0
2364 );
2365
2366 /*********************************************************************/
2386 const tDeviceInformation GetDeviceInformation(int iDev=0) { if (iDev<0 || iDev>=DeviceCount) return tDeviceInformation(); return Devices[iDev].DeviceInformation; }
2387
2388 /*********************************************************************/
2398 void SendIsoAddressClaim(unsigned char Destination=0xff, int DeviceIndex=0, unsigned long FromNow=0);
2399
2400#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
2401 /*********************************************************************/
2413 bool SendProductInformation(unsigned char Destination, int DeviceIndex, bool UseTP);
2414
2415 /*********************************************************************/
2427 bool SendConfigurationInformation(unsigned char Destination, int DeviceIndex, bool UseTP);
2428
2429 /*********************************************************************/
2439 void SendTxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false);
2440
2441 /*********************************************************************/
2451 void SendRxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false);
2452#else
2453 void SendTxPGNList(unsigned char Destination, int DeviceIndex);
2454 void SendRxPGNList(unsigned char Destination, int DeviceIndex);
2455#endif
2456
2457 /*********************************************************************/
2467 bool SendProductInformation(int DeviceIndex=0);
2468
2469 /*********************************************************************/
2479 bool SendConfigurationInformation(int DeviceIndex=0);
2480
2481#if !defined(N2K_NO_HEARTBEAT_SUPPORT)
2482
2483
2484 /*********************************************************************/
2501 void SetHeartbeatIntervalAndOffset(uint32_t interval, uint32_t offset=0, int iDev=-1);
2502
2503 /*********************************************************************/
2513 uint32_t GetHeartbeatInterval(int iDev=0) { if (iDev<0 || iDev>=DeviceCount) return 60000; return Devices[iDev].HeartbeatScheduler.GetPeriod(); }
2514 /*********************************************************************/
2524 uint32_t GetHeartbeatOffset(int iDev=0) { if (iDev<0 || iDev>=DeviceCount) return 0; return Devices[iDev].HeartbeatScheduler.GetOffset(); }
2525
2526 /*********************************************************************/
2534 void SendHeartbeat(int iDev);
2535
2536 /*********************************************************************/
2544 void SendHeartbeat(bool force=false);
2545
2546 /*********************************************************************/
2549 void SetHeartbeatInterval(unsigned long interval, bool SetAsDefault=true, int iDev=-1) __attribute__ ((deprecated));
2550#endif
2551
2552 /*********************************************************************/
2575 void SetMode(tN2kMode _N2kMode, uint8_t _N2kSource=15);
2576
2577 /*********************************************************************/
2591 void SetForwardType(tForwardType fwdType) { ForwardType=fwdType; }
2592
2593 /*********************************************************************/
2603 void SetForwardStream(N2kStream* _stream) { ForwardStream=_stream; }
2604
2605 /*********************************************************************/
2611
2612 /*********************************************************************/
2626 bool Open();
2627
2628 /*********************************************************************/
2634 inline bool IsOpen() const { return OpenState==os_Open; }
2635
2636 /*********************************************************************/
2645 void Restart();
2646
2647 /*********************************************************************/
2688 bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0);
2689
2690 /*********************************************************************/
2714 void ParseMessages();
2715
2716 /*********************************************************************/
2727 void SetOnOpen(void (*_OnOpen)());
2728
2729 /*********************************************************************/
2743 void SetMsgHandler(void (*_MsgHandler)(const tN2kMsg &N2kMsg));
2744
2745 /*********************************************************************/
2761 void AttachMsgHandler(tMsgHandler *_MsgHandler);
2762
2763 /*********************************************************************/
2775 void DetachMsgHandler(tMsgHandler *_MsgHandler);
2776
2777 /*********************************************************************/
2793 void SetISORqstHandler(bool(*ISORequestHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex));
2794
2795#if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT)
2796
2797 /**********************************************************************/
2803 void RemoveGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler);
2804
2805 /**********************************************************************/
2811 void AddGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler);
2812#endif
2813
2814 /*********************************************************************/
2827 unsigned char GetN2kSource(int DeviceIndex=0) const { if (DeviceIndex>=0 && DeviceIndex<DeviceCount) return Devices[DeviceIndex].N2kSource; return Devices[0].N2kSource; }
2828
2829 /*********************************************************************/
2846 void SetN2kSource(unsigned char _iAddr, int _iDev=0);
2847
2848 /*********************************************************************/
2870
2871 /*********************************************************************/
2889
2890 /*********************************************************************/
2900 void EnableForward(bool v=true) {
2901 if (v) { ForwardMode |= FwdModeBit_EnableForward; } else { ForwardMode &= ~FwdModeBit_EnableForward; }
2902 }
2903
2904 /*********************************************************************/
2914 void SetForwardSystemMessages(bool v=true) {
2915 if (v) { ForwardMode |= FwdModeBit_SystemMessages; } else { ForwardMode &= ~FwdModeBit_SystemMessages; }
2916 }
2917
2918 /*********************************************************************/
2937 if (v) { ForwardMode |= FwdModeBit_OnlyKnownMessages; } else { ForwardMode &= ~FwdModeBit_OnlyKnownMessages; }
2938 }
2939
2940 /*********************************************************************/
2948 void SetForwardOwnMessages(bool v=true) {
2949 if (v) { ForwardMode |= FwdModeBit_OwnMessages; } else { ForwardMode &= ~FwdModeBit_OwnMessages; }
2950 }
2951
2952 /*********************************************************************/
2966 void SetHandleOnlyKnownMessages(bool v=true) {
2967 if (v) { ForwardMode |= HandleModeBit_OnlyKnownMessages; } else { ForwardMode &= ~HandleModeBit_OnlyKnownMessages; }
2968 }
2969
2970 /*********************************************************************/
2981 void SetDebugMode(tDebugMode _dbMode);
2982
2983 /*********************************************************************/
2990 static bool IsBroadcast(unsigned char Source) { return Source==0xff; }
2991
2992};
2993
2994/************************************************************************/
3008void SetN2kPGN59392(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN);
3009
3010/************************************************************************/
3016inline void SetN2kPGNISOAcknowledgement(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN) {
3017 SetN2kPGN59392(N2kMsg,Control,GroupFunction,PGN);
3018}
3019
3020/************************************************************************/
3039void SetN2kPGN60928(tN2kMsg &N2kMsg, unsigned long UniqueNumber, int ManufacturerCode,
3040 unsigned char DeviceFunction, unsigned char DeviceClass,
3041 unsigned char DeviceInstance=0, unsigned char SystemInstance=0, unsigned char IndustryGroup=4
3042 );
3043/************************************************************************/
3055void SetN2kPGN60928(tN2kMsg &N2kMsg, uint64_t Name);
3056
3057/************************************************************************/
3063inline void SetN2kISOAddressClaim(tN2kMsg &N2kMsg, unsigned long UniqueNumber, int ManufacturerCode,
3064 unsigned char DeviceFunction, unsigned char DeviceClass,
3065 unsigned char DeviceInstance=0, unsigned char SystemInstance=0, unsigned char IndustryGroup=4
3066 ) {
3067 SetN2kPGN60928(N2kMsg, UniqueNumber, ManufacturerCode, DeviceFunction, DeviceClass,
3068 DeviceInstance, SystemInstance, IndustryGroup);
3069}
3070/************************************************************************/
3076inline void SetN2kISOAddressClaim(tN2kMsg &N2kMsg, uint64_t Name) {
3077 SetN2kPGN60928(N2kMsg, Name);
3078}
3079
3080/************************************************************************/
3096void SetN2kPGN126996(tN2kMsg &N2kMsg, unsigned int N2kVersion, unsigned int ProductCode,
3097 const char *ModelID, const char *SwCode,
3098 const char *ModelVersion, const char *ModelSerialCode,
3099 unsigned char CertificationLevel=1, unsigned char LoadEquivalency=1);
3100
3101/************************************************************************/
3107inline void SetN2kProductInformation(tN2kMsg &N2kMsg, unsigned int N2kVersion, unsigned int ProductCode,
3108 const char *ModelID, const char *SwCode,
3109 const char *ModelVersion, const char *ModelSerialCode,
3110 unsigned char CertificationLevel=1, unsigned char LoadEquivalency=1) {
3111 SetN2kPGN126996(N2kMsg,N2kVersion,ProductCode,
3112 ModelID,SwCode,ModelVersion,ModelSerialCode,
3113 CertificationLevel,LoadEquivalency);
3114}
3115
3116/************************************************************************/
3139bool ParseN2kPGN126996(const tN2kMsg& N2kMsg, unsigned short &N2kVersion, unsigned short &ProductCode,
3140 int ModelIDSize, char *ModelID, int SwCodeSize, char *SwCode,
3141 int ModelVersionSize, char * ModelVersion, int ModelSerialCodeSize, char *ModelSerialCode,
3142 unsigned char &CertificationLevel, unsigned char &LoadEquivalency);
3143
3144/************************************************************************/
3157void SetN2kPGN126998(tN2kMsg &N2kMsg,
3158 const char *ManufacturerInformation,
3159 const char *InstallationDescription1=0,
3160 const char *InstallationDescription2=0,
3161 bool UsePgm=false);
3162
3163/************************************************************************/
3170 const char *ManufacturerInformation,
3171 const char *InstallationDescription1=0,
3172 const char *InstallationDescription2=0,
3173 bool UsePgm=false) {
3174 SetN2kPGN126998(N2kMsg,
3175 ManufacturerInformation,
3176 InstallationDescription1,
3177 InstallationDescription2,
3178 UsePgm);
3179}
3180
3181/************************************************************************/
3201bool ParseN2kPGN126998(const tN2kMsg& N2kMsg,
3202 size_t &ManufacturerInformationSize, char *ManufacturerInformation,
3203 size_t &InstallationDescription1Size, char *InstallationDescription1,
3204 size_t &InstallationDescription2Size, char *InstallationDescription2);
3205
3206/************************************************************************/
3218void SetN2kPGN59904(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN);
3219
3220/************************************************************************/
3226inline void SetN2kPGNISORequest(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN) {
3227 SetN2kPGN59904(N2kMsg,Destination,RequestedPGN);
3228}
3229
3230/************************************************************************/
3244bool ParseN2kPGN59904(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN);
3245
3246/************************************************************************/
3253inline bool ParseN2kPGNISORequest(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN) {
3254 return ParseN2kPGN59904(N2kMsg, RequestedPGN);
3255}
3256
3257/************************************************************************/
3263
3264/************************************************************************/
3280void SetN2kPGN126464(tN2kMsg &N2kMsg, uint8_t Destination, tN2kPGNList tr, const unsigned long *PGNs);
3281
3282/************************************************************************/
3289inline void SetN2kPGNTransmitList(tN2kMsg &N2kMsg, uint8_t Destination, const unsigned long *PGNs) {
3290 SetN2kPGN126464(N2kMsg,Destination,N2kpgnl_transmit,PGNs);
3291}
3292
3293/************************************************************************/
3305void SetN2kPGN126993(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter);
3306
3307/************************************************************************/
3313inline void SetHeartbeat(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter) {
3314 SetN2kPGN126993(N2kMsg, timeInterval_ms, sequenceCounter);
3315}
3316
3317#endif
File declares tN2kCANMsg class used internally on tNMEA2000.
Base and default group function PGN 126208 message handler class.
tN2kGroupFunctionCode
FunctionCode for the group function.
This File contains the class tN2kMsg and all necessary functions to handle a NMEA2000 Message.
#define BIT(n)
Definition: N2kMsg.h:70
This File contains an I/O stream used in the NMEA2000 libraries.
uint32_t N2kMillis()
Definition: N2kTimer.cpp:48
The file contains function and classes for best timing performance.
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.
Definition: NMEA2000.h:3107
#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
void SetN2kPGNTransmitList(tN2kMsg &N2kMsg, uint8_t Destination, const unsigned long *PGNs)
Setting up Message "PGN List - Transmit PGNs group function" - PGN 126464.
Definition: NMEA2000.h:3289
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".
Definition: NMEA2000.cpp:2788
void SetN2kPGN126993(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter)
Setting up PGN 126993 Message "Heartbeat".
Definition: NMEA2000.cpp:2923
void SetN2kPGN126998(tN2kMsg &N2kMsg, const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0, bool UsePgm=false)
Setting up PGN 126998 Message "Configuration information".
Definition: NMEA2000.cpp:2823
void SetN2kPGN60928(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 PGN 60928 Message "ISO Address Claim".
Definition: NMEA2000.cpp:2746
#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
void SetN2kPGN126464(tN2kMsg &N2kMsg, uint8_t Destination, tN2kPGNList tr, const unsigned long *PGNs)
Setting up PGN 126464 Message "PGN List - Transmit PGNs group function".
Definition: NMEA2000.cpp:2907
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.
Definition: NMEA2000.h:3169
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".
Definition: NMEA2000.cpp:2873
#define N2kMessageGroups
Number of message groups.
Definition: NMEA2000.h:104
#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
void SetN2kPGN59904(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN)
Setting up PGN 59904 Message "ISO request".
Definition: NMEA2000.cpp:2887
void SetN2kPGN59392(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN)
Setting up PGN 59392 Message "ISO Acknowledgement".
Definition: NMEA2000.cpp:2732
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.
Definition: NMEA2000.h:3063
#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
void SetHeartbeat(tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter)
Setting up Message "Heartbeat" - PGN 126993.
Definition: NMEA2000.h:3313
bool ParseN2kPGN59904(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN)
Parsing the content of message PGN 59904 "ISO request".
Definition: NMEA2000.cpp:2894
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=1, unsigned char LoadEquivalency=1)
Setting up PGN 126996 Message "Product information".
Definition: NMEA2000.cpp:2771
void SetN2kPGNISOAcknowledgement(tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN)
Setting up Message "ISO Acknowledgement" - PGN 59392.
Definition: NMEA2000.h:3016
#define N2kMaxCanBusAddress
Max CAN Bus Address given by the library.
Definition: NMEA2000.h:106
bool ParseN2kPGNISORequest(const tN2kMsg &N2kMsg, unsigned long &RequestedPGN)
Parsing the content of a "ISO request" message - PGN 59904.
Definition: NMEA2000.h:3253
void SetN2kPGNISORequest(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN)
Setting up Message "ISO request" - PGN 59904.
Definition: NMEA2000.h:3226
tN2kPGNList
Enumeration of types for PGN lists according to PGN 126464.
Definition: NMEA2000.h:3262
@ N2kpgnl_receive
Definition: NMEA2000.h:3262
@ N2kpgnl_transmit
Definition: NMEA2000.h:3262
Specific compiler definition to adapt the library to your needs.
Streaming Class to handle all Streams generated by the Library.
Definition: N2kStream.h:60
Class used internally on tNMEA2000 to handle incoming NMEA2000 messages.
Definition: N2kCANMsg.h:42
Base handler class for Group Functions.
This class contains all the data of an NMEA2000 message.
Definition: N2kMsg.h:656
Un synchronized Scheduler which can roll over.
Definition: N2kTimer.h:286
void Disable()
Disable the Scheduler.
Definition: N2kTimer.h:306
bool IsEnabled() const
Check if the scheduler is enabled.
Definition: N2kTimer.h:324
void FromNow(uint32_t _Add)
Set Timestamp for next event relative to now.
Definition: N2kTimer.h:345
bool IsTime() const
Is it time for the next event.
Definition: N2kTimer.h:332
Synchronized Scheduler for timed message sending.
Definition: N2kTimer.h:124
uint32_t GetOffset() const
Get the Offset of the Scheduler.
Definition: N2kTimer.h:222
uint32_t GetPeriod() const
Get the Period of the Scheduler.
Definition: N2kTimer.h:229
Structure holds all the data needed for a valid CAN-Message.
Definition: NMEA2000.h:993
unsigned char buf[8]
Data payload for the CAN Message.
Definition: NMEA2000.h:1000
unsigned char len
Length of carried data of the CAN Message.
Definition: NMEA2000.h:998
bool wait_sent
Has the CAN Message to wait before sending.
Definition: NMEA2000.h:1002
unsigned long id
ID of the CAN Message.
Definition: NMEA2000.h:996
This class represents a N2k device.
Definition: NMEA2000.h:481
unsigned long GetCreateTime() const
Returns the Time of Creation of this device.
Definition: NMEA2000.h:507
uint8_t GetSource() const
Returns the Source Address of this device.
Definition: NMEA2000.h:505
virtual unsigned short GetProductCode() const =0
Get the product code from the product information of this device.
unsigned char GetIndustryGroup() const
Get the Industry Group from the Device Information.
Definition: NMEA2000.h:563
virtual const unsigned long * GetTransmitPGNs() const
Get the list of transmitted PGNs from this device.
Definition: NMEA2000.h:607
virtual const unsigned long * GetReceivePGNs() const
Get the list of received PGNs from this device.
Definition: NMEA2000.h:609
virtual const char * GetManufacturerInformation() const
Get the manufacturer information from the configuration information of this device.
Definition: NMEA2000.h:598
unsigned char GetSystemInstance() const
Get the System Instance from the Device Information.
Definition: NMEA2000.h:568
uint64_t GetName() const
Get the Name of this device.
Definition: NMEA2000.h:513
unsigned char GetDeviceInstanceUpper() const
Get the Device Instance (upper bits) from the Device Information.
Definition: NMEA2000.h:546
unsigned char GetDeviceInstanceLower() const
Get the Device Instance (lower bits) from the Device Information.
Definition: NMEA2000.h:541
uint8_t Source
Source address on bus for this device.
Definition: NMEA2000.h:488
virtual unsigned short GetCertificationLevel() const =0
Get the certification level from the product information of this device.
virtual const char * GetModelVersion() const =0
Get the model version from the product information of this device.
uint32_t GetUniqueNumber() const
Get the unique Number from the Device Information.
Definition: NMEA2000.h:525
uint16_t GetManufacturerCode() const
Get the Manufacturer Code from the Device Information.
Definition: NMEA2000.h:530
unsigned long CreateTime
Timestamp when this device was created.
Definition: NMEA2000.h:486
unsigned char GetDeviceInstance() const
Get the Device Instance from the Device Information.
Definition: NMEA2000.h:536
virtual const char * GetSwCode() const =0
Get the Software version code from the product information of this device.
virtual const char * GetModelID() const =0
Get the model ID from the product information of this device.
virtual unsigned short GetN2kVersion() const =0
Get N2k Standard version from the product information of this device.
virtual ~tDevice()
Destroy the Device object.
Definition: NMEA2000.h:502
tDeviceInformation DevI
This object holds all necessary device informations.
Definition: NMEA2000.h:484
virtual const char * GetModelSerialCode() const =0
Get the model serial code from the product information of this device.
virtual unsigned short GetLoadEquivalency() const =0
Get the load equivalency from the product information of this device.
unsigned char GetDeviceFunction() const
Get the Device Function from the Device Information.
Definition: NMEA2000.h:552
virtual const char * GetInstallationDescription2() const
Get the installation description 2 from the configuration information of this device.
Definition: NMEA2000.h:604
unsigned char GetDeviceClass() const
Get the Device Class from the Device Information.
Definition: NMEA2000.h:558
bool IsSame(uint64_t Other)
Check if two devices are the same, by comparing the device name.
Definition: NMEA2000.h:520
virtual const char * GetInstallationDescription1() const
Get the installation description 1 from the configuration information of this device.
Definition: NMEA2000.h:601
tDevice(uint64_t _Name, uint8_t _Source=255)
Construct a new Device object.
Definition: NMEA2000.h:499
Class that holds all the device informations and several helper functions to that.
Definition: NMEA2000.h:297
void SetDeviceInstance(unsigned char _DeviceInstance)
Set the Device Instance to the Device Information.
Definition: NMEA2000.h:388
uint16_t GetManufacturerCode() const
Get the Manufacturer Code from the Device Information.
Definition: NMEA2000.h:382
uint64_t GetName() const
Get the Name from the Device Information.
Definition: NMEA2000.h:462
void SetName(uint64_t _Name)
Set the Name to the Device Information.
Definition: NMEA2000.h:467
void SetIndustryGroup(unsigned char _IndustryGroup)
Set the Industry Group to the Device Information.
Definition: NMEA2000.h:439
unsigned char GetDeviceInstance() const
Get the Device Instance from the Device Information.
Definition: NMEA2000.h:394
bool IsSame(uint64_t Other)
Check if two devices are the same, by comparing the device NAME.
Definition: NMEA2000.h:474
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
void SetUniqueNumber(uint32_t _UniqueNumber)
Set a unique Number to the Device Information.
Definition: NMEA2000.h:364
tUnionDeviceInformation DeviceInformation
Union that contains all the Device Information
Definition: NMEA2000.h:352
void SetDeviceClass(unsigned char _DeviceClass)
Set the Device Class to the Device Information.
Definition: NMEA2000.h:426
void SetDeviceFunction(unsigned char _DeviceFunction)
Set the Device Function to the Device Information.
Definition: NMEA2000.h:412
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 SetManufacturerCode(uint16_t _ManufacturerCode)
Set the Manufacturer Code to the Device Information.
Definition: NMEA2000.h:376
void SetSystemInstance(unsigned char _SystemInstance)
Set the System Instance to the Device Information.
Definition: NMEA2000.h:451
tDeviceInformation()
Construct a new empty Device Information object.
Definition: NMEA2000.h:358
This class represents an internal device.
Definition: NMEA2000.h:771
void UpdateAddressClaimEndSource()
Updates AddressClaimEndSource.
Definition: NMEA2000.h:918
bool QueryPendingIsoAddressClaim()
Check if enough time has passed.
Definition: NMEA2000.h:868
bool HasPendingInformation
internal device has pending information
Definition: NMEA2000.h:812
const unsigned long * ReceiveMessages
Pointer to a buffer that holds all supported receive PGNs for this device.
Definition: NMEA2000.h:804
tN2kScheduler PendingIsoAddressClaim
Timestamp set while last tNMEA2000::SendIsoAddressClaim was executed.
Definition: NMEA2000.h:789
void ClearPendingConfigurationInformation()
Resets PendingConfigurationInformation to zero.
Definition: NMEA2000.h:903
void SetPendingProductInformation()
Set the timestamp for Pending a ProductInformation message.
Definition: NMEA2000.h:879
void SetPendingConfigurationInformation()
Set the timestamp for Pending a ConfigurationInformation message.
Definition: NMEA2000.h:901
uint8_t NextDTSequence
Next Sequence.
Definition: NMEA2000.h:820
uint8_t HeartbeatSequence
Heartbeat Sequence.
Definition: NMEA2000.h:828
tN2kScheduler NextDTSendTime
Timestamp, when next data packet can be send on TP broadcast.
Definition: NMEA2000.h:818
uint8_t AddressClaimEndSource
Holds the highest source address for Address Claim process.
Definition: NMEA2000.h:810
tProductInformation * LocalProductInformation
This holds all the local (???) Product Informations for this specific device.
Definition: NMEA2000.h:783
char * ManufacturerSerialCode
This holds the Manufacturer Code for this specific device.
Definition: NMEA2000.h:786
tN2kSyncScheduler HeartbeatScheduler
Scheduler for the heartbeat message.
Definition: NMEA2000.h:826
uint8_t N2kSource
Source address of this device on the NMEA2000 bus.
Definition: NMEA2000.h:774
size_t MaxPGNSequenceCounters
Fast packet PGNs sequence counters.
Definition: NMEA2000.h:808
bool QueryPendingProductInformation()
Check if enough time has passed.
Definition: NMEA2000.h:892
const tProductInformation * ProductInformation
This holds all the Product Informations for this specific device.
Definition: NMEA2000.h:780
tN2kScheduler AddressClaimTimer
Timer value for AddressClaim.
Definition: NMEA2000.h:798
void UpdateHasPendingInformation()
Definition: NMEA2000.h:922
bool QueryPendingConfigurationInformation()
Check if enough time has passed.
Definition: NMEA2000.h:914
tN2kMsg PendingTPMsg
Pending N2k message.
Definition: NMEA2000.h:816
tN2kScheduler PendingConfigurationInformation
Timestamp set while last tNMEA2000::SendConfigurationInformation was executed.
Definition: NMEA2000.h:795
tN2kScheduler PendingProductInformation
Timestamp set while last tNMEA2000::SendProductInformation was executed.
Definition: NMEA2000.h:792
tDeviceInformation DeviceInformation
This holds all the Device Informations for this specific device.
Definition: NMEA2000.h:776
const unsigned long * TransmitMessages
Pointer to a buffer that holds all supported transmit PGNs for this device.
Definition: NMEA2000.h:801
void SetPendingIsoAddressClaim(unsigned long FromNow=2)
Set the timestamp for Pending an ISO Address Claim message.
Definition: NMEA2000.h:857
void ClearPendingIsoAddressClaim()
Resets PendingIsoAddressClaim to zero.
Definition: NMEA2000.h:870
unsigned long * PGNSequenceCounters
Fast packet PGNs sequence counters.
Definition: NMEA2000.h:806
void ClearPendingProductInformation()
Resets PendingProductInformation to zero.
Definition: NMEA2000.h:881
tInternalDevice()
Construct a new Internal Device object.
Definition: NMEA2000.h:837
Message handler class.
Definition: NMEA2000.h:616
unsigned long GetPGN() const
Return the PGN that is handled by this message handler.
Definition: NMEA2000.h:656
unsigned long PGN
Definition: NMEA2000.h:625
virtual ~tMsgHandler()
Destroys the Message Handler object.
Definition: NMEA2000.h:651
tMsgHandler(unsigned long _PGN=0, tNMEA2000 *_pNMEA2000=0)
Construct a new Message Handler object.
Definition: NMEA2000.h:644
tNMEA2000 * GetNMEA2000()
Returns the tNMEA2000 object of this handler.
Definition: NMEA2000.h:633
virtual void HandleMsg(const tN2kMsg &N2kMsg)=0
Handles a given message *.
tNMEA2000 device class definition.
Definition: NMEA2000.h:138
bool SendTPCM_RTS(int iDev)
Send ISO Transport Protocol message RTS.
Definition: NMEA2000.cpp:1687
bool IsMySource(unsigned char Source)
Checks if the source belongs to a device on Devices.
Definition: NMEA2000.cpp:2073
void SetFastPacketMessages(const unsigned long *_FastPacketMessages)
Set the list of known Fast Packet Messages.
Definition: NMEA2000.cpp:1148
bool IsReadyToSend() const
Checks if the device is ready to start address claiming.
Definition: NMEA2000.h:1601
void SendHeartbeat(int iDev)
Send heartbeat for specific device.
Definition: NMEA2000.cpp:1388
void SendPendingInformation()
Send ISO AddressClaim, Product Information and Config Information.
Definition: NMEA2000.cpp:1431
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.
Definition: NMEA2000.cpp:745
bool(* ISORqstHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex)
Handler callbacks for 'ISORequest' messages.
Definition: NMEA2000.h:1079
static void ClearSetCharBuf(const char *str, size_t MaxLen, char *buf)
Setting up a clean Char Buffer.
Definition: NMEA2000.cpp:654
bool IsTxPGN(unsigned long PGN, int iDev=0)
Check if this message is a Transmit message of this device.
Definition: NMEA2000.cpp:875
size_t GetFastPacketTxPGNCount(int iDev)
Get the Fast Packet Tx PGN Count.
Definition: NMEA2000.cpp:813
int DeviceCount
Number of devices.
Definition: NMEA2000.h:977
static void ClearCharBuf(size_t MaxLen, char *buf)
Clears a char array buffer with 0s.
Definition: NMEA2000.cpp:637
void InitDevices()
Initialize all devices.
Definition: NMEA2000.cpp:710
tN2kCANMsg * N2kCANMsgBuf
Buffer for receiving messages.
Definition: NMEA2000.h:1015
void ExtendSingleFrameMessages(const unsigned long *_SingleFrameMessages)
Set the list of known Extended Single Frame Messages.
Definition: NMEA2000.cpp:1153
void EnableForward(bool v=true)
Enable message forwarding to stream.
Definition: NMEA2000.h:2900
void ParseMessages()
Parse all incoming Messages.
Definition: NMEA2000.cpp:2577
void SetISORqstHandler(bool(*ISORequestHandler)(unsigned long RequestedPGN, unsigned char Requester, int DeviceIndex))
Set the message handler for incoming ISO Requests.
Definition: NMEA2000.cpp:2684
tDebugMode dbMode
Attribute that holds the actual Debug Mode (default = md_none)
Definition: NMEA2000.h:950
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.
Definition: NMEA2000.cpp:1093
bool HasAllTPDTSent(int iDev)
Check if all data bytes of the multi packet message has been send successful.
Definition: NMEA2000.cpp:1781
void RemoveGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler)
Remove a message handler for incoming Group Function messages.
Definition: NMEA2000.cpp:2690
void SetForwardSystemMessages(bool v=true)
Enable System Messages for forwarding.
Definition: NMEA2000.h:2914
unsigned int ForwardMode
Actual message forward operation mode (default = all messages - also system and own)
Definition: NMEA2000.h:959
void SetSingleFrameMessages(const unsigned long *_SingleFrameMessages)
Set the list of known Single Frame Messages.
Definition: NMEA2000.cpp:1143
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
void HandleISORequest(const tN2kMsg &N2kMsg)
Handles an ISO Request.
Definition: NMEA2000.cpp:2333
N2kStream * ForwardStream
Actual stream to be used for forward messaging.
Definition: NMEA2000.h:961
void SetMsgHandler(void(*_MsgHandler)(const tN2kMsg &N2kMsg))
Set the message handler for incoming NMEA2000 messages.
Definition: NMEA2000.cpp:2638
static T N2kMax(T a, T b)
Delivers Max out of A an B.
Definition: NMEA2000.h:193
tN2kGroupFunctionHandler * pGroupFunctionHandlers
Pointer to Buffer for GRoup Function Handlers.
Definition: NMEA2000.h:1083
void SetForwardStream(N2kStream *_stream)
Set the Forward Stream object.
Definition: NMEA2000.h:2603
bool SendFrame(unsigned long id, unsigned char len, const unsigned char *buf, bool wait_sent=true)
Sends a single CAN frame.
Definition: NMEA2000.cpp:1335
bool StartSendTPMessage(const tN2kMsg &msg, int iDev)
Start sending an ISO-TP message.
Definition: NMEA2000.cpp:1926
void HandleGroupFunction(const tN2kMsg &N2kMsg)
Handles a Group Function.
Definition: NMEA2000.cpp:2375
bool SendConfigurationInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Config Information message.
Definition: NMEA2000.cpp:2264
bool ReadResetInstallationDescriptionChanged()
Check if this device has changed its Install Description.
Definition: NMEA2000.cpp:1083
void SetForwardOnlyKnownMessages(bool v=true)
Enable Only Known Messages for forwarding.
Definition: NMEA2000.h:2936
void SetForwardOwnMessages(bool v=true)
Enable Own Messages for forwarding.
Definition: NMEA2000.h:2948
bool IsInitialized()
Determines if the CAN BUS is already initialized.
Definition: NMEA2000.h:1234
void SetN2kCANMsgBufSize(const uint8_t _MaxN2kCANMsgs)
Set incoming CAN message (tNMEA2000::N2kCANMsgBuf) buffer size.
Definition: NMEA2000.h:1816
unsigned char GetCertificationLevel(int iDev=0) const
Get the Certification Level of the device.
Definition: NMEA2000.cpp:994
void AttachMsgHandler(tMsgHandler *_MsgHandler)
Attach a message handler for incoming N2kMessages.
Definition: NMEA2000.cpp:2643
bool AddressChanged
Flag that the address has changed.
Definition: NMEA2000.h:970
bool CheckKnownMessage(unsigned long PGN, bool &SystemMessage, bool &FastPacket)
Check if this Message is known to the system.
Definition: NMEA2000.cpp:1579
void SetDebugMode(tDebugMode _dbMode)
Set the Debug Mode of the system.
Definition: NMEA2000.cpp:1547
bool IsValidDevice(int iDev) const
Checks if the device index on Devices is valid.
Definition: NMEA2000.h:1593
void ExtendReceiveMessages(const unsigned long *_ReceiveMessages, int iDev=0)
Extend the list of Received Messages.
Definition: NMEA2000.cpp:1170
uint8_t MaxN2kCANMsgs
Size of N2kCANMsgBuf receiving message buffer.
Definition: NMEA2000.h:1021
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.
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
N2kStream * GetForwardStream() const
Read current Forward Stream object.
Definition: NMEA2000.h:2610
bool ForwardEnabled() const
Is message forwarding enabled.
Definition: NMEA2000.h:1520
static const int HandleModeBit_OnlyKnownMessages
Forward mode bit: -> Only known messages will be handled.
Definition: NMEA2000.h:946
bool Open()
Open the CAN device.
Definition: NMEA2000.cpp:1200
tN2kMode
System mode defines how the device will behave on the NMEA2000 bus.
Definition: NMEA2000.h:683
@ N2km_ListenOnly
Definition: NMEA2000.h:689
@ N2km_NodeOnly
Definition: NMEA2000.h:695
@ N2km_SendOnly
Definition: NMEA2000.h:705
@ N2km_ListenAndNode
Definition: NMEA2000.h:699
@ N2km_ListenAndSend
Definition: NMEA2000.h:711
void GetManufacturerInformation(char *buf, size_t max_len)
Get the Manufacturer Information of this device.
Definition: NMEA2000.cpp:1074
void SetHeartbeatInterval(unsigned long interval, bool SetAsDefault=true, int iDev=-1) __attribute__((deprecated))
Deprecated. Use function SetHeartbeatIntervalAndOffset.
Definition: NMEA2000.cpp:1383
virtual void SetN2kCANSendFrameBufSize(const uint16_t _MaxCANSendFrames)
Set CAN send frame buffer size.
Definition: NMEA2000.h:1853
bool ForwardSystemMessages() const
Is forwarding enabled for system messages.
Definition: NMEA2000.h:1528
tForwardType
Type how to forward messages in listen mode.
Definition: NMEA2000.h:664
@ fwdt_Text
Definition: NMEA2000.h:671
@ fwdt_Actisense
Definition: NMEA2000.h:667
void SendPendingTPMessage(int iDev)
Send pending ISO-TP Messages.
Definition: NMEA2000.cpp:1956
void SendTPCM_EndAck(unsigned long PGN, unsigned char Destination, int iDev, uint16_t nBytes, unsigned char nPackets)
Send ISO Transport Protocol message End Acknowledge.
Definition: NMEA2000.cpp:1725
tN2kScheduler OpenScheduler
Definition: NMEA2000.h:966
bool IsFastPacketPGN(unsigned long PGN)
Check if this PNG is a fast packet message.
Definition: NMEA2000.cpp:1552
void AddGroupFunctionHandler(tN2kGroupFunctionHandler *pGroupFunctionHandler)
Add a message handler for incoming Group Function messages.
Definition: NMEA2000.cpp:2708
void Restart()
Restart the device.
Definition: NMEA2000.cpp:1264
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.
Definition: NMEA2000.cpp:1450
void ExtendTransmitMessages(const unsigned long *_TransmitMessages, int iDev=0)
Extend the list of Transmitted Messages.
Definition: NMEA2000.cpp:1163
uint32_t GetHeartbeatInterval(int iDev=0)
Get the Heartbeat Interval of a device.
Definition: NMEA2000.h:2513
bool SendTPDT(int iDev)
Send ISO Transport Protocol data packet.
Definition: NMEA2000.cpp:1762
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.
Definition: NMEA2000.cpp:583
void HandleISOAddressClaim(const tN2kMsg &N2kMsg)
Handles an IsoAddressClaim.
Definition: NMEA2000.cpp:2430
tNMEA2000()
Construct a new NMEA2000 object.
Definition: NMEA2000.cpp:660
uint16_t MaxCANSendFrames
Size of CANSendFrameBuf or before initialization requested total frame buffering size.
Definition: NMEA2000.h:1049
static const int FwdModeBit_OnlyKnownMessages
Forward mode bit: -> Only known messages will be forwarded. System messages will be forwarded accordi...
Definition: NMEA2000.h:941
void GetInstallationDescription1(char *buf, size_t max_len)
Get the Install Description 1 of this device.
Definition: NMEA2000.cpp:1056
static const int FwdModeBit_SystemMessages
Forward mode bit: -> System messages will be forwarded.
Definition: NMEA2000.h:938
unsigned char GetN2kSource(int DeviceIndex=0) const
Read address for current device.
Definition: NMEA2000.h:2827
tOpenState
Library open state.
Definition: NMEA2000.h:751
@ os_Open
State Open.
Definition: NMEA2000.h:763
@ os_None
State none.
Definition: NMEA2000.h:754
@ os_OpenCAN
State Open CAN.
Definition: NMEA2000.h:757
@ os_WaitOpen
State Wait Open.
Definition: NMEA2000.h:760
uint16_t CANSendFrameBufferRead
Next write index for the library CAN send frame buffer.
Definition: NMEA2000.h:1055
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
uint16_t CANSendFrameBufferWrite
Next read index for the library CAN send frame buffer.
Definition: NMEA2000.h:1052
bool SendFrames()
Sends pending all frames.
Definition: NMEA2000.cpp:1318
void SetOnOpen(void(*_OnOpen)())
Set OnOpen callback function.
Definition: NMEA2000.cpp:2633
bool IsAddressClaimStarted(int iDev)
Checks if the IsoAddressClaim is already started.
Definition: NMEA2000.cpp:2414
bool IsOpen() const
Test is NMEA2000 open and running.
Definition: NMEA2000.h:2634
virtual void SetN2kCANReceiveFrameBufSize(const uint16_t _MaxCANReceiveFrames)
Set CAN receive frame buffer size.
Definition: NMEA2000.h:1870
void ExtendFastPacketMessages(const unsigned long *_FastPacketMessages)
Set the list of known Extended Fast Packet Messages.
Definition: NMEA2000.cpp:1158
void RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev)
Respond to an ISO request.
Definition: NMEA2000.cpp:2297
void SendRxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Receive messages.
Definition: NMEA2000.cpp:2161
tMsgHandler * MsgHandlers
Pointer to a buffer for Message Handlers.
Definition: NMEA2000.h:963
uint8_t SetN2kCANBufMsg(unsigned long canId, unsigned char len, unsigned char *buf)
Function handles received CAN frame and adds it to tN2kCANMsg.
Definition: NMEA2000.cpp:1977
void SendTxPGNList(unsigned char Destination, int DeviceIndex, bool UseTP=false)
Send a list with all supported Transmit messages.
Definition: NMEA2000.cpp:2128
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.
Definition: NMEA2000.cpp:1634
static T N2kMin(T a, T b)
Delivers Min out of A an B.
Definition: NMEA2000.h:205
void StartAddressClaim()
Starting the ISO Address Claim for all devices.
Definition: NMEA2000.cpp:2406
tCANSendFrame * GetNextFreeCANSendFrame()
Get the Next Free CAN Frame from CANSendFrameBuf.
Definition: NMEA2000.cpp:1417
tConfigurationInformation ConfigurationInformation
Configuration Information of the device.
Definition: NMEA2000.h:983
void SetProgmemConfigurationInformation(const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0)
Set the Configuration Information located on PROGMEM.
Definition: NMEA2000.cpp:802
void GetModelVersion(char *buf, size_t max_len, int iDev=0) const
Get the Model Version of the device.
Definition: NMEA2000.cpp:962
int GetSequenceCounter(unsigned long PGN, int iDev)
Get the Sequence Counter for the PGN.
Definition: NMEA2000.cpp:831
const tNMEA2000::tProductInformation * GetProductInformation(int iDev, bool &IsProgMem) const
Get the Product Information of the device.
Definition: NMEA2000.cpp:891
void SendTPCM_Abort(unsigned long PGN, unsigned char Destination, int iDev, unsigned char AbortCode)
Send ISO Transport Protocol message Abort.
Definition: NMEA2000.cpp:1742
void EndSendTPMessage(int iDev)
Ends sending of ISO-TP message.
Definition: NMEA2000.cpp:1949
tForwardType ForwardType
Actual message forward type (default = fwdt_Actisense)
Definition: NMEA2000.h:956
const unsigned long * SingleFrameMessages[N2kMessageGroups]
Definition: NMEA2000.h:985
bool HandleReceivedSystemMessage(int MsgIndex)
Handles a received system message.
Definition: NMEA2000.cpp:2543
tN2kMode N2kMode
Actual operation mode of this device (default = N2km_ListenOnly)
Definition: NMEA2000.h:954
tOpenState OpenState
Definition: NMEA2000.h:968
const unsigned long * FastPacketMessages[N2kMessageGroups]
Definition: NMEA2000.h:986
void(* MsgHandler)(const tN2kMsg &N2kMsg)
Handler callbacks for normal messages.
Definition: NMEA2000.h:1077
bool HandleOnlyKnownMessages() const
Is handle only known messages enabled.
Definition: NMEA2000.h:1552
char * LocalConfigurationInformationData
Pointer to a buffer for local Configuration Information.
Definition: NMEA2000.h:981
static void SetCharBuf(const char *str, size_t MaxLen, char *buf)
Setting up a Char Buffer.
Definition: NMEA2000.cpp:644
unsigned short GetN2kVersion(int iDev=0) const
Get the N2k standard version of the device.
Definition: NMEA2000.cpp:902
uint16_t MaxCANReceiveFrames
Max number received CAN messages that can go to the buffer.
Definition: NMEA2000.h:1061
int FindSourceDeviceIndex(unsigned char Source) const
Finds a device on Devices by its source address.
Definition: NMEA2000.cpp:2062
bool SendProductInformation(unsigned char Destination, int DeviceIndex, bool UseTP)
Send a Product Information message.
Definition: NMEA2000.cpp:2222
virtual void InitCANFrameBuffers()
Initialize CAN Frame buffers.
Definition: NMEA2000.cpp:1188
bool DeviceInformationChanged
Flag that the device information has changed.
Definition: NMEA2000.h:972
void SendTPCM_CTS(unsigned long PGN, unsigned char Destination, int iDev, unsigned char nPackets, unsigned char NextPacketNumber)
Send ISO Transport Protocol message CTS.
Definition: NMEA2000.cpp:1707
bool SendTPCM_BAM(int iDev)
Send ISO Transport Protocol message BAM.
Definition: NMEA2000.cpp:1668
bool IsActiveNode()
Returns if this node is active on the bus.
Definition: NMEA2000.h:1584
void GetModelSerialCode(char *buf, size_t max_len, int iDev=0) const
Get the Model Serial of the device.
Definition: NMEA2000.cpp:978
bool ReadResetAddressChanged()
Check if this device has changed its address.
Definition: NMEA2000.cpp:2496
void SetHandleOnlyKnownMessages(bool v=true)
Set the Handle Only Known Messages.
Definition: NMEA2000.h:2966
void SetMode(tN2kMode _N2kMode, uint8_t _N2kSource=15)
Set the library mode and start source address.
Definition: NMEA2000.cpp:1177
void ForwardMessage(const tN2kMsg &N2kMsg)
Forwards a N2k message.
Definition: NMEA2000.cpp:2078
uint32_t GetHeartbeatOffset(int iDev=0)
Get the Heartbeat Offset of a device.
Definition: NMEA2000.h:2524
bool ForwardOnlyKnownMessages() const
Is forwarding enabled for known messages only.
Definition: NMEA2000.h:1536
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.
Definition: NMEA2000.cpp:1047
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.
Definition: NMEA2000.cpp:1786
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 HandleCommandedAddress(uint64_t CommandedName, unsigned char NewAddress, int iDev)
Handles if we get commanded to set a new address.
Definition: NMEA2000.cpp:2455
bool IsFastPacket(const tN2kMsg &N2kMsg)
Check if this PNG is a fast packet message.
Definition: NMEA2000.cpp:1572
static const int FwdModeBit_EnableForward
Forward mode bit: -> If set, forward is enabled.
Definition: NMEA2000.h:936
void GetInstallationDescription2(char *buf, size_t max_len)
Get the Install Description 2 of this device.
Definition: NMEA2000.cpp:1065
bool ForwardOwnMessages() const
Is forwarding enabled for own messages.
Definition: NMEA2000.h:1544
unsigned short GetProductCode(int iDev=0) const
Get the Product Code of the device.
Definition: NMEA2000.cpp:916
tDebugMode
For debugging we have some cases for SendMsg.
Definition: NMEA2000.h:718
@ dm_ClearText
Definition: NMEA2000.h:724
@ dm_Actisense
Definition: NMEA2000.h:727
bool ReadResetDeviceInformationChanged()
Check if this device has changed its DeviceInstances or SystemInstance.
Definition: NMEA2000.cpp:2504
void GetSwCode(char *buf, size_t max_len, int iDev=0) const
Get the Sw Code of the device.
Definition: NMEA2000.cpp:946
void SetN2kSource(unsigned char _iAddr, int _iDev=0)
Set source for the given device.
Definition: NMEA2000.cpp:2488
void GetModelID(char *buf, size_t max_len, int iDev=0) const
Get the ModelID of the device.
Definition: NMEA2000.cpp:930
void DetachMsgHandler(tMsgHandler *_MsgHandler)
Detach a message handler for incoming N2kMessages.
Definition: NMEA2000.cpp:2668
bool HandleReceivedMessage(unsigned char Destination)
Should received message be handled depending on the destination of the received message.
Definition: NMEA2000.h:1572
void CopyProgmemConfigurationInformationToLocal()
Copy Configuration Information to local memory.
Definition: NMEA2000.cpp:1022
void(* OnOpen)()
Callback function, which will be called when library start bus communication.
Definition: NMEA2000.h:1074
unsigned char GetLoadEquivalency(int iDev=0) const
Get the Load Equivalency of this device.
Definition: NMEA2000.cpp:1008
void GetNextAddress(int DeviceIndex, bool RestartAtEnd=false)
Get the next free address for the device.
Definition: NMEA2000.cpp:2512
void RespondGroupFunction(const tN2kMsg &N2kMsg, tN2kGroupFunctionCode GroupFunctionCode, unsigned long PGNForGroupFunction, int iDev)
Respond to an Group Function.
Definition: NMEA2000.cpp:2353
static const int FwdModeBit_OwnMessages
Forward mode bit: -> Forward also all messages, what this device will send.
Definition: NMEA2000.h:944
void SetForwardType(tForwardType fwdType)
Set the Forward Streaming Type.
Definition: NMEA2000.h:2591
bool InstallationDescriptionChanged
Flag the Installation description has changed.
Definition: NMEA2000.h:1746
void SetConfigurationInformation(const char *ManufacturerInformation, const char *InstallationDescription1=0, const char *InstallationDescription2=0)
Set the Configuration Information of this device.
Definition: NMEA2000.cpp:764
tInternalDevice * Devices
Pointer to a buffer for all internal devices.
Definition: NMEA2000.h:975
void SetDeviceCount(const uint8_t _DeviceCount)
Set the count of devices library shows on bus.
Definition: NMEA2000.cpp:704
tCANSendFrame * CANSendFrameBuf
Buffer for library send out CAN frames.
Definition: NMEA2000.h:1035
void RunMessageHandlers(const tN2kMsg &N2kMsg)
Run all message handlers.
Definition: NMEA2000.cpp:2620
Structure that holds the Configuration Information of this device.
Definition: NMEA2000.h:734
const char * InstallationDescription2
pointer to char array holding the installation description 2
Definition: NMEA2000.h:740
const char * InstallationDescription1
pointer to char array holding the installation description 1
Definition: NMEA2000.h:738
const char * ManufacturerInformation
pointer to char array holding the manufacturer information
Definition: NMEA2000.h:736
Structure that holds all the product information.
Definition: NMEA2000.h:216
unsigned short N2kVersion
Version of NMEA2000 Standard that is supported.
Definition: NMEA2000.h:219
unsigned short ProductCode
Product Code of the device.
Definition: NMEA2000.h:221
char N2kModelID[Max_N2kModelID_len+1]
Max length of ModelID Note that we reserve one extra char for null termination
Definition: NMEA2000.h:225
unsigned char LoadEquivalency
Load Equivalency of the device A Load Equivalence Number express the amount of current that is drawn ...
Definition: NMEA2000.h:243
unsigned char CertificationLevel
Certification level of the device.
Definition: NMEA2000.h:236
char N2kModelVersion[Max_N2kModelVersion_len+1]
Max length of Model Version Note that we reserve one extra char for null termination.
Definition: NMEA2000.h:231
bool IsSame(const tProductInformation &Other)
Compares two product information structures.
Definition: NMEA2000.cpp:632
void Clear()
Clears out all data
Definition: NMEA2000.cpp:627
char N2kSwCode[Max_N2kSwCode_len+1]
Max length of Software Code Note that we reserve one extra char for null termination
Definition: NMEA2000.h:228
char N2kModelSerialCode[Max_N2kModelSerialCode_len+1]
Max length of Serial Code Note that we reserve one extra char for null termination.
Definition: NMEA2000.h:234
void Set(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)
Set all the product information data of the structure.
Definition: NMEA2000.h:262
Union that holds the device informations.
Definition: NMEA2000.h:304
unsigned char DeviceInstance
Device instance number.
Definition: NMEA2000.h:319
uint32_t UnicNumberAndManCode
32 bit number carrying Unique Number and Manufacturer Code
Definition: NMEA2000.h:317
unsigned char DeviceFunction
Device function code.
Definition: NMEA2000.h:325
unsigned char IndustryGroupAndSystemInstance
Industry Group and System Instance (each 4bits)
Definition: NMEA2000.h:347