30#if defined(N2kDeviceList_HANDLE_IN_DEBUG)
31#define DebugStream Serial
32# define N2kHandleInDbg(fmt, args...) DebugStream.print (fmt , ## args)
33# define N2kHandleInDbgln(fmt, args...) DebugStream.println (fmt , ## args)
35# define N2kHandleInDbg(fmt, args...)
36# define N2kHandleInDbgln(fmt, args...)
58 for (uint8_t i=0; i<
MaxDevices && result==0; i++) {
71 for (uint8_t i=0; i<
MaxDevices && result==0; i++) {
73 (ManufacturerCode==
N2kUInt16NA ||
Sources[i]->GetManufacturerCode()==ManufacturerCode) &&
84 if ( Source<
MaxDevices ) { Source++; }
else { Source=0; }
88 for (uint8_t i=Source; i<
MaxDevices && result==0; i++) {
90 Sources[i]->GetManufacturerCode()==ManufacturerCode &&
134 switch ( N2kMsg.
PGN ) {
143 switch ( N2kMsg.
PGN ) {
184 if (
Sources[i]->ReadyForRequestProductInformation() ) {
202 if (
Sources[i]->ReadyForRequestConfigurationInformation() ) {
220 if (
Sources[i]->ReadyForRequestPGNList() ) {
256 uint64_t CallerName=N2kMsg.
GetUInt64(Index);
275 }
else if (!pDevice->
IsSame(CallerName) ) {
348 size_t InstDesc1Size;
349 size_t InstDesc2Size;
357 int TotalSize=ManISize+InstDesc1Size+InstDesc2Size;
379 uint8_t PGNCount=(N2kMsg.
DataLen-Index)/3;
381 unsigned long * PGNList=0;
384 switch (N2kPGNList) {
393 for (iPGN=0; iPGN<PGNCount; iPGN++) { PGNList[iPGN]=N2kMsg.
Get3ByteUInt(Index); }
424 if ( ConfI!=0 ) free(ConfI);
425 if ( TransmitPGNs!=0 ) free(TransmitPGNs);
426 if ( ReceivePGNs!=0 ) free(ReceivePGNs);
431 if ( _ManISize>0 ) _ManISize++;
432 if ( _InstDesc1Size>0 ) _InstDesc1Size++;
433 if ( _InstDesc2Size>0 ) _InstDesc2Size++;
434 uint16_t _ConfISize=_ManISize+_InstDesc1Size+_InstDesc2Size;
435 if ( ConfI!=0 && ConfISize<_ConfISize ) {
436 free(ConfI); ConfI=0; ConfISize=0;
439 ConfISize=_ConfISize;
440 ConfI=(
char*)(ConfISize>0?malloc(ConfISize):0);
442 ManufacturerInformation=ConfI;
443 ManufacturerInformation[0]=
'\0';
444 }
else ManufacturerInformation=0;
445 if ( _InstDesc1Size>0 ) {
446 InstallationDescription1=ConfI+_ManISize;
447 InstallationDescription1[0]=
'\0';
448 }
else InstallationDescription1=0;
449 if ( _InstDesc2Size>0 ) {
450 InstallationDescription2=ConfI+_ManISize+_InstDesc1Size;
451 InstallationDescription2[0]=
'\0';
452 }
else InstallationDescription2=0;
460 if (TransmitPGNs!=0 && TransmitPGNsSize<count ) { free(TransmitPGNs); TransmitPGNs=0; TransmitPGNsSize=0; }
461 if (TransmitPGNs==0) { TransmitPGNs=(
unsigned long *)malloc((count+1)*
sizeof(
unsigned long)); TransmitPGNsSize=count; }
462 if (TransmitPGNs!=0) TransmitPGNs[0]=0;
468 if (ReceivePGNs!=0 && ReceivePGNsSize<count ) { free(ReceivePGNs); ReceivePGNs=0; ReceivePGNsSize=0; }
469 if (ReceivePGNs==0) { ReceivePGNs=(
unsigned long *)malloc((count+1)*
sizeof(
unsigned long)); ReceivePGNsSize=count; }
470 if (ReceivePGNs!=0) ReceivePGNs[0]=0;
#define N2kHandleInDbg(fmt, args...)
#define N2kHandleInDbgln(fmt, args...)
#define N2kMaxBusDevices
Maximum allowed number of devices on the CAN BUS bus system is 254.
const uint32_t N2kUInt32NA
Constant "Not Available" for a unsigned 32bit int value.
const uint16_t N2kUInt16NA
Constant "Not Available" for a unsigned 16bit int value.
bool N2kHasElapsed(uint32_t Start, uint32_t Elapsed, uint32_t Now=N2kMillis())
Has time elapsed since start.
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".
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 N2kPGNIsoAddressClaim
PGN for an ISO Address Claim message.
#define N2kPGNProductInformation
PGN for a Production Information message.
#define N2kPGNConfigurationInformation
PGN for an Configuration Information message.
void SetN2kPGNISORequest(tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN)
Setting up Message "ISO request" - PGN 59904.
tN2kPGNList
Enumeration of types for PGN lists according to PGN 126464.
This class represents an internal device.
char * InstallationDescription1
Pointer to the Installation Description 1.
void ClearConfigurationInformationLoaded()
Resets the Configuration Information Loaded values of the device.
unsigned long * InitReceivePGNs(uint8_t count)
Initialize an array for received PGNs This functions frees if needed old reservation and reserves new...
bool ShouldRequestProductInformation()
Should the Device Product Information be requested As long as the device Product Information is not s...
const char * GetInstallationDescription1() const
Get the Installation Description 1 of this device.
bool ProdILoaded
Product Information has been loaded.
const char * GetInstallationDescription2() const
Get the Installation Description 2 of this device.
void SetDeviceInformation(uint64_t _Name)
Set the Device Information.
void SetConfigurationInformationRequested()
Increments the Number of how often the Configuration Information has already been requested and store...
const char * GetManufacturerInformation() const
Get the Manufacturer Information of this device.
char * ManufacturerInformation
Pointer to the Manufacturer Information.
bool ShouldRequestName()
Should the Device Name be requested As long as the device name is not set yet and the number of reque...
unsigned long * TransmitPGNs
Transmitted PGNs.
bool HasProductInformation() const
Has the Product Information for the device already been loaded.
char * InitConfigurationInformation(size_t &_ManISize, size_t &_InstDesc1Size, size_t &_InstDesc2Size)
Initialize the Configuration Information of this device.
bool ShouldRequestPGNList()
Should the Device PGN List be requested As long as the device PGN List is not set yet and the number ...
uint8_t TransmitPGNsSize
Size of the transmitted PGN (number of bytes)
unsigned long * InitTransmitPGNs(uint8_t count)
Initialize an array for transmitted PGNs This functions frees if needed old reservation and reserves ...
uint16_t ConfISize
Size of the Config Information (number of bytes)
bool ShouldRequestConfigurationInformation()
Should the Device Configuration Information be requested As long as the device Configuration Informat...
void ClearPGNListLoaded()
Resets the PGN List Loaded values of the device.
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)
Set the Product Information of the device.
tInternalDevice(uint64_t _Name, uint8_t _Source=255)
Construct a new Internal Device object.
uint8_t ReceivePGNsSize
Size of the received PGN (number of bytes)
unsigned long LastMessageTime
Time of the last message.
~tInternalDevice()
Destroy the Internal Device object Clean up all the memory.
uint8_t nNameRequested
How many times we have requested the name.
void SetProductInformationRequested()
Increments the Number of how often the Product Information has already been requested and stores the ...
void SetSource(uint8_t _Source)
Set the Source address of the device.
bool IsSameProductInformation(tNMEA2000::tProductInformation &Other)
Compares two Product Informations.
tNMEA2000::tProductInformation ProdI
Product Information of this device.
void ClearProductInformationLoaded()
Resets the Product Information Loaded values of the device.
char * ConfI
Pointer to the Config Information.
bool ConfILoaded
Product Information has been loaded.
void SetPGNListRequested()
Increments the Number of how often the PGN List has already been requested and stores the timestamp.
unsigned long * ReceivePGNs
Received PGNs.
void SetNameRequested()
Increments the Number of how often the name has already been requested.
char * InstallationDescription2
Pointer to the Installation Description 2.
void HandleProductInformation(const tN2kMsg &N2kMsg)
Handle a Product Information message - PGN 126996.
void SaveDevice(tInternalDevice *pDevice, uint8_t Source)
Saves a device to Sources.
void HandleOther(const tN2kMsg &N2kMsg)
Handles all Other messages.
void HandleSupportedPGNList(const tN2kMsg &N2kMsg)
Handle a Product Information message - PGN 126464.
uint8_t MaxDevices
Number of NMEA2000 devices stored in Sources.
bool RequestIsoAddressClaim(uint8_t Source)
Request the ISO AddressClaim for a specific device on the bus.
tN2kDeviceList::tInternalDevice * LocalFindDeviceBySource(uint8_t Source) const
Find a device in Sources by the source address.
void HandleConfigurationInformation(const tN2kMsg &N2kMsg)
Handle a Configuration Information message - PGN 126998.
bool RequestSupportedPGNList(uint8_t Source)
Request the supported PGNs of a specific device on the bus.
bool RequestProductInformation(uint8_t Source)
Request the product information of a specific device on the bus.
tInternalDevice * Sources[N2kMaxBusDevices]
List of NMEA2000 devices found on the bus.
void HandleIsoAddressClaim(const tN2kMsg &N2kMsg)
Handle ISO Address Claim Message - PGN 60928.
bool RequestConfigurationInformation(uint8_t Source)
Request the configuration information of a specific device on the bus.
uint8_t Count() const
Return number of known devices in Sources.
tN2kDeviceList::tInternalDevice * LocalFindDeviceByName(uint64_t Name) const
Find a device in Sources by the name of the device.
tN2kDeviceList::tInternalDevice * LocalFindDeviceByProduct(uint16_t ManufacturerCode, uint16_t ProductCode, uint8_t Source=0xff) const
Find a device in Sources by the manufacturer and product code.
tN2kDeviceList(tNMEA2000 *_pNMEA2000)
Constructor for the class.
tN2kDeviceList::tInternalDevice * LocalFindDeviceByIDs(uint16_t ManufacturerCode, uint32_t UniqueNumber) const
Find a device in Sources by the manufacturer code and unique ID.
void AddDevice(uint8_t Source)
Adds a device to Sources.
void HandleMsg(const tN2kMsg &N2kMsg)
Handle NMEA2000 messages.
bool HasPendingRequests
There are still requests pending.
bool ListUpdated
The list of devices has been updated.
This class contains all the data of an NMEA2000 message.
unsigned char Source
Source of the NMEA2000 message.
uint32_t Get3ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 3 bytes out of Data.
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.
int DataLen
Number of bytes already stored in tN2kMsg::Data of this message.
unsigned long PGN
Parameter Group Number (PGN) of the NMEA2000 message.
uint8_t GetSource() const
Returns the Source Address of this device.
uint64_t GetName() const
Get the Name of this device.
uint32_t GetUniqueNumber() const
Get the unique Number from the Device Information.
bool IsSame(uint64_t Other)
Check if two devices are the same, by comparing the device name.
tNMEA2000 * GetNMEA2000()
Returns the tNMEA2000 object of this handler.
tNMEA2000 device class definition.
bool SendMsg(const tN2kMsg &N2kMsg, int DeviceIndex=0)
Send message to the NMEA2000 bus.