NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
tN2kDeviceList Class Reference

Helper class to keep track of all devices on the bus. More...

#include <N2kDeviceList.h>

Inheritance diagram for tN2kDeviceList:
Collaboration diagram for tN2kDeviceList:

Classes

class  tInternalDevice
 This class represents an internal device. More...
 

Public Member Functions

 tN2kDeviceList (tNMEA2000 *_pNMEA2000)
 Constructor for the class. More...
 
uint8_t Count () const
 Return number of known devices in Sources. More...
 
const tNMEA2000::tDeviceFindDeviceByIDs (uint16_t ManufacturerCode, uint32_t UniqueNumber) const
 Find a device in Sources by the manufacturer code and unique ID. More...
 
const tNMEA2000::tDeviceFindDeviceByName (uint64_t NAME) const
 Find a device in Sources by the NAME of the device. More...
 
const tNMEA2000::tDeviceFindDeviceByProduct (uint16_t ManufacturerCode, uint16_t ProductCode, uint8_t Source=0xff) const
 Find a device in Sources by the manufacturer and product code. More...
 
const tNMEA2000::tDeviceFindDeviceBySource (uint8_t Source) const
 Return device by it's bus source address. More...
 
unsigned long GetDeviceLastMessageTime (uint8_t Source) const
 
void HandleMsg (const tN2kMsg &N2kMsg)
 Handle NMEA2000 messages. More...
 
bool ReadResetIsListUpdated ()
 Check if device list has updated. More...
 
- Public Member Functions inherited from tNMEA2000::tMsgHandler
 tMsgHandler (unsigned long _PGN=0, tNMEA2000 *_pNMEA2000=0)
 Construct a new Message Handler object. More...
 
virtual ~tMsgHandler ()
 Destroys the Message Handler object. More...
 
unsigned long GetPGN () const
 Return the PGN that is handled by this message handler. More...
 

Protected Member Functions

void AddDevice (uint8_t Source)
 Adds a device to Sources. More...
 
void HandleConfigurationInformation (const tN2kMsg &N2kMsg)
 Handle a Configuration Information message - PGN 126998. More...
 
void HandleIsoAddressClaim (const tN2kMsg &N2kMsg)
 Handle ISO Address Claim Message - PGN 60928. More...
 
void HandleOther (const tN2kMsg &N2kMsg)
 Handles all Other messages. More...
 
void HandleProductInformation (const tN2kMsg &N2kMsg)
 Handle a Product Information message - PGN 126996. More...
 
void HandleSupportedPGNList (const tN2kMsg &N2kMsg)
 Handle a Product Information message - PGN 126464. More...
 
tN2kDeviceList::tInternalDeviceLocalFindDeviceByIDs (uint16_t ManufacturerCode, uint32_t UniqueNumber) const
 Find a device in Sources by the manufacturer code and unique ID. More...
 
tN2kDeviceList::tInternalDeviceLocalFindDeviceByName (uint64_t Name) const
 Find a device in Sources by the name of the device. More...
 
tN2kDeviceList::tInternalDeviceLocalFindDeviceByProduct (uint16_t ManufacturerCode, uint16_t ProductCode, uint8_t Source=0xff) const
 Find a device in Sources by the manufacturer and product code. More...
 
tN2kDeviceList::tInternalDeviceLocalFindDeviceBySource (uint8_t Source) const
 Find a device in Sources by the source address. More...
 
bool RequestConfigurationInformation (uint8_t Source)
 Request the configuration information of a specific device on the bus. More...
 
bool RequestIsoAddressClaim (uint8_t Source)
 Request the ISO AddressClaim for a specific device on the bus. More...
 
bool RequestProductInformation (uint8_t Source)
 Request the product information of a specific device on the bus. More...
 
bool RequestSupportedPGNList (uint8_t Source)
 Request the supported PGNs of a specific device on the bus. More...
 
void SaveDevice (tInternalDevice *pDevice, uint8_t Source)
 Saves a device to Sources. More...
 
- Protected Member Functions inherited from tNMEA2000::tMsgHandler
tNMEA2000GetNMEA2000 ()
 Returns the tNMEA2000 object of this handler. More...
 
virtual void HandleMsg (const tN2kMsg &N2kMsg)=0
 Handles a given message *. More...
 

Protected Attributes

bool HasPendingRequests
 There are still requests pending. More...
 
bool ListUpdated
 The list of devices has been updated. More...
 
uint8_t MaxDevices
 Number of NMEA2000 devices stored in Sources. More...
 
tInternalDeviceSources [N2kMaxBusDevices]
 List of NMEA2000 devices found on the bus. More...
 
- Protected Attributes inherited from tNMEA2000::tMsgHandler
unsigned long PGN
 

Detailed Description

Helper class to keep track of all devices on the bus.

On bus each message contains sender source address. Device source address may be changed due to address claiming on power up or when new device will be added to the bus. For this reason source address can not be used as only filter for similar messages like position data. By using tN2kDeviceList source address related to NAME can be easily found at any time with FindDeviceByName(). With ReadResetIsListUpdated() can be easily checked is there any changes on device list and then request interesting source address with FindDeviceByName().

Check all search methods:

Definition at line 72 of file N2kDeviceList.h.

Constructor & Destructor Documentation

◆ tN2kDeviceList()

tN2kDeviceList::tN2kDeviceList ( tNMEA2000 _pNMEA2000)

Constructor for the class.

Initialize all the attributes of the class

Parameters
_pNMEA2000Pointer to an NMEA2000 object

Definition at line 40 of file N2kDeviceList.cpp.

Member Function Documentation

◆ AddDevice()

void tN2kDeviceList::AddDevice ( uint8_t  Source)
protected

Adds a device to Sources.

Parameters
SourceSource address of the device

Definition at line 235 of file N2kDeviceList.cpp.

◆ Count()

uint8_t tN2kDeviceList::Count ( ) const

Return number of known devices in Sources.

Returns
Number of devices

Definition at line 401 of file N2kDeviceList.cpp.

◆ FindDeviceByIDs()

const tNMEA2000::tDevice * tN2kDeviceList::FindDeviceByIDs ( uint16_t  ManufacturerCode,
uint32_t  UniqueNumber 
) const
inline

Find a device in Sources by the manufacturer code and unique ID.

Return device by manufacturer identification. Each device should have manufacturer id and unique ID.

Parameters
ManufacturerCodeManufacturer code of the device to be searched for
UniqueNumberUnique ID of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 675 of file N2kDeviceList.h.

◆ FindDeviceByName()

const tNMEA2000::tDevice * tN2kDeviceList::FindDeviceByName ( uint64_t  NAME) const
inline

Find a device in Sources by the NAME of the device.

Return device by it's NAME. Device NAME is complete device information data, which is unique for all registered devices and should be unique for own made devices on own bus. NAME will be matched according to matching parameter. If there is no device with given NAME, function returns null.

Parameters
NAMENAME of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 661 of file N2kDeviceList.h.

◆ FindDeviceByProduct()

const tNMEA2000::tDevice * tN2kDeviceList::FindDeviceByProduct ( uint16_t  ManufacturerCode,
uint16_t  ProductCode,
uint8_t  Source = 0xff 
) const
inline

Find a device in Sources by the manufacturer and product code.

Return device by manufacturer product code. Each device should have product code given by NMEA2000 organization. Search with source = 0xff finds first device. To find all devices with given manufacturer product code, repeat search with found device source until device will not be found.

Parameters
ManufacturerCodeManufacturer code of the device to be searched for
ProductCodeProduct code of the device to be searched for
SourceSource address of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 694 of file N2kDeviceList.h.

◆ FindDeviceBySource()

const tNMEA2000::tDevice * tN2kDeviceList::FindDeviceBySource ( uint8_t  Source) const
inline

Return device by it's bus source address.

Return device by it's bus source address. If there is no device with given source, function returns null

Parameters
SourceSource address of the device to be searched for
Returns
const tNMEA2000::tDevice*

Definition at line 640 of file N2kDeviceList.h.

◆ GetDeviceLastMessageTime()

unsigned long tN2kDeviceList::GetDeviceLastMessageTime ( uint8_t  Source) const
inline

Definition at line 643 of file N2kDeviceList.h.

◆ HandleConfigurationInformation()

void tN2kDeviceList::HandleConfigurationInformation ( const tN2kMsg N2kMsg)
protected

Handle a Configuration Information message - PGN 126998.

The message contains free-form alphanumeric fields describing the installation (e.g., starboard engine room location) of the device and installation notes (e.g., calibration data). It is parsed and all data is stored in the internal device

Parameters
N2kMsgReference to a N2kMsg Object,

Definition at line 342 of file N2kDeviceList.cpp.

◆ HandleIsoAddressClaim()

void tN2kDeviceList::HandleIsoAddressClaim ( const tN2kMsg N2kMsg)
protected

Handle ISO Address Claim Message - PGN 60928.

This function handle an ISO address claim message. It checks whether the caller device is already listed at Sources or not. If it is already listed, it checks also if the name at this source position still matches. When the name doesn't match, it moves the "old" device to a free spot in Sources.

If the caller is completely unknown, a new device will be placed in Sources.

Parameters
N2kMsgReference to a N2kMsg Object,

Definition at line 252 of file N2kDeviceList.cpp.

◆ HandleMsg()

void tN2kDeviceList::HandleMsg ( const tN2kMsg N2kMsg)
virtual

Handle NMEA2000 messages.

Depending on the message PGN the correct handler (see HandleIsoAddressClaim, HandleProductInformation, HandleConfigurationInformation, HandleSupportedPGNList, HandleOther) is chosen. If there is now device with this source address is listed in Sources, a new device is added ( AddDevice).

Parameters
N2kMsgReference to a N2kMsg Object,

Implements tNMEA2000::tMsgHandler.

Definition at line 130 of file N2kDeviceList.cpp.

◆ HandleOther()

void tN2kDeviceList::HandleOther ( const tN2kMsg N2kMsg)
protected

Handles all Other messages.

If request is pending ( HasPendingRequests == true) it requires a name for every device, then loads product + config informations and supported PGN lists as needed.

Parameters
N2kMsgReference to a N2kMsg Object,

Definition at line 165 of file N2kDeviceList.cpp.

◆ HandleProductInformation()

void tN2kDeviceList::HandleProductInformation ( const tN2kMsg N2kMsg)
protected

Handle a Product Information message - PGN 126996.

The message provides product information onto the network that could be important for determining quality of data coming from this product. The message is parsed and all data is stored in tInternalDevice::ProdI

Parameters
N2kMsgReference to a N2kMsg Object,

Definition at line 314 of file N2kDeviceList.cpp.

◆ HandleSupportedPGNList()

void tN2kDeviceList::HandleSupportedPGNList ( const tN2kMsg N2kMsg)
protected

Handle a Product Information message - PGN 126464.

The PGN 126464 message consists the group function type defined by the first field. The message will be either a Transmit PGNs or a Receive PGNs group function that identifies the PGNs transmitted from or received by a node. This function determines if the PGNs are receive or transmit PGN (see tN2kPGNList) an the stores the PGNs to the corresponding internal device in Sources.

Parameters
N2kMsgReference to a N2kMsg Object,

Definition at line 373 of file N2kDeviceList.cpp.

◆ LocalFindDeviceByIDs()

tN2kDeviceList::tInternalDevice * tN2kDeviceList::LocalFindDeviceByIDs ( uint16_t  ManufacturerCode,
uint32_t  UniqueNumber 
) const
protected

Find a device in Sources by the manufacturer code and unique ID.

Parameters
ManufacturerCodeManufacturer code of the device to be searched for
UniqueNumberUnique ID of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 66 of file N2kDeviceList.cpp.

◆ LocalFindDeviceByName()

tN2kDeviceList::tInternalDevice * tN2kDeviceList::LocalFindDeviceByName ( uint64_t  Name) const
protected

Find a device in Sources by the name of the device.

Parameters
NameName of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 55 of file N2kDeviceList.cpp.

◆ LocalFindDeviceByProduct()

tN2kDeviceList::tInternalDevice * tN2kDeviceList::LocalFindDeviceByProduct ( uint16_t  ManufacturerCode,
uint16_t  ProductCode,
uint8_t  Source = 0xff 
) const
protected

Find a device in Sources by the manufacturer and product code.

Parameters
ManufacturerCodeManufacturer code of the device to be searched for
ProductCodeProduct code of the device to be searched for
SourceSource address of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 81 of file N2kDeviceList.cpp.

◆ LocalFindDeviceBySource()

tN2kDeviceList::tInternalDevice * tN2kDeviceList::LocalFindDeviceBySource ( uint8_t  Source) const
protected

Find a device in Sources by the source address.

Parameters
SourceSource address of the device to be searched for
Returns
tN2kDeviceList::tInternalDevice*

Definition at line 48 of file N2kDeviceList.cpp.

◆ ReadResetIsListUpdated()

bool tN2kDeviceList::ReadResetIsListUpdated ( )
inline

Check if device list has updated.

Device list will be automatically updated. In stable system list should be ready and stable in few seconds. If you add device on the fly, list will be updated as soon as it start to send data to the bus.

Returns
true
false

Definition at line 706 of file N2kDeviceList.h.

◆ RequestConfigurationInformation()

bool tN2kDeviceList::RequestConfigurationInformation ( uint8_t  Source)
protected

Request the configuration information of a specific device on the bus.

This function sends out an ISO Request message in order to obtain more information about a specific device on the bus.

Parameters
SourceDestination address of the target device
Returns
true -> Message was sent successfully
false

Definition at line 106 of file N2kDeviceList.cpp.

◆ RequestIsoAddressClaim()

bool tN2kDeviceList::RequestIsoAddressClaim ( uint8_t  Source)
protected

Request the ISO AddressClaim for a specific device on the bus.

Parameters
SourceDestination address of the target device
Returns
true -> Message was sent successfully
false

Definition at line 122 of file N2kDeviceList.cpp.

◆ RequestProductInformation()

bool tN2kDeviceList::RequestProductInformation ( uint8_t  Source)
protected

Request the product information of a specific device on the bus.

This function sends out an ISO Request message in order to obtain more information about a specific device on the bus.

Parameters
SourceDestination address of the target device
Returns
true -> Message was sent successfully
false

Definition at line 98 of file N2kDeviceList.cpp.

◆ RequestSupportedPGNList()

bool tN2kDeviceList::RequestSupportedPGNList ( uint8_t  Source)
protected

Request the supported PGNs of a specific device on the bus.

This function sends out an ISO Request message in order to obtain more information about a specific device on the bus.

Parameters
SourceDestination address of the target device
Returns
true -> Message was sent successfully
false

Definition at line 114 of file N2kDeviceList.cpp.

◆ SaveDevice()

void tN2kDeviceList::SaveDevice ( tInternalDevice pDevice,
uint8_t  Source 
)
protected

Saves a device to Sources.

Parameters
pDevicePointer to a device
SourceSource address of the device

Definition at line 243 of file N2kDeviceList.cpp.

Member Data Documentation

◆ HasPendingRequests

bool tN2kDeviceList::HasPendingRequests
protected

There are still requests pending.

Definition at line 451 of file N2kDeviceList.h.

◆ ListUpdated

bool tN2kDeviceList::ListUpdated
protected

The list of devices has been updated.

Definition at line 449 of file N2kDeviceList.h.

◆ MaxDevices

uint8_t tN2kDeviceList::MaxDevices
protected

Number of NMEA2000 devices stored in Sources.

Definition at line 447 of file N2kDeviceList.h.

◆ Sources

tInternalDevice* tN2kDeviceList::Sources[N2kMaxBusDevices]
protected

List of NMEA2000 devices found on the bus.

Definition at line 445 of file N2kDeviceList.h.


The documentation for this class was generated from the following files: