NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
Helper class to keep track of all devices on the bus. More...
#include <N2kDeviceList.h>
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::tDevice * | FindDeviceByIDs (uint16_t ManufacturerCode, uint32_t UniqueNumber) const |
Find a device in Sources by the manufacturer code and unique ID. More... | |
const tNMEA2000::tDevice * | FindDeviceByName (uint64_t NAME) const |
Find a device in Sources by the NAME of the device. More... | |
const tNMEA2000::tDevice * | FindDeviceByProduct (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::tDevice * | FindDeviceBySource (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::tInternalDevice * | LocalFindDeviceByIDs (uint16_t ManufacturerCode, uint32_t UniqueNumber) const |
Find a device in Sources by the manufacturer code and unique ID. More... | |
tN2kDeviceList::tInternalDevice * | LocalFindDeviceByName (uint64_t Name) const |
Find a device in Sources by the name of the device. More... | |
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. More... | |
tN2kDeviceList::tInternalDevice * | LocalFindDeviceBySource (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 | |
tNMEA2000 * | GetNMEA2000 () |
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... | |
tInternalDevice * | Sources [N2kMaxBusDevices] |
List of NMEA2000 devices found on the bus. More... | |
Protected Attributes inherited from tNMEA2000::tMsgHandler | |
unsigned long | PGN |
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:
This class is derived from tNMEA2000::tMsgHandler.
Definition at line 72 of file N2kDeviceList.h.
tN2kDeviceList::tN2kDeviceList | ( | tNMEA2000 * | _pNMEA2000 | ) |
Constructor for the class.
Initialize all the attributes of the class
_pNMEA2000 | Pointer to an NMEA2000 object |
Definition at line 40 of file N2kDeviceList.cpp.
|
protected |
Adds a device to Sources.
Source | Source address of the device |
Definition at line 235 of file N2kDeviceList.cpp.
uint8_t tN2kDeviceList::Count | ( | ) | const |
Return number of known devices in Sources.
Definition at line 401 of file N2kDeviceList.cpp.
|
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.
ManufacturerCode | Manufacturer code of the device to be searched for |
UniqueNumber | Unique ID of the device to be searched for |
Definition at line 675 of file N2kDeviceList.h.
|
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.
NAME | NAME of the device to be searched for |
Definition at line 661 of file N2kDeviceList.h.
|
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.
ManufacturerCode | Manufacturer code of the device to be searched for |
ProductCode | Product code of the device to be searched for |
Source | Source address of the device to be searched for |
Definition at line 694 of file N2kDeviceList.h.
|
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
Source | Source address of the device to be searched for |
Definition at line 640 of file N2kDeviceList.h.
|
inline |
Definition at line 643 of file N2kDeviceList.h.
|
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
N2kMsg | Reference to a N2kMsg Object, |
Definition at line 342 of file N2kDeviceList.cpp.
|
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.
N2kMsg | Reference to a N2kMsg Object, |
Definition at line 252 of file N2kDeviceList.cpp.
|
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).
N2kMsg | Reference to a N2kMsg Object, |
Implements tNMEA2000::tMsgHandler.
Definition at line 130 of file N2kDeviceList.cpp.
|
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.
N2kMsg | Reference to a N2kMsg Object, |
Definition at line 165 of file N2kDeviceList.cpp.
|
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
N2kMsg | Reference to a N2kMsg Object, |
Definition at line 314 of file N2kDeviceList.cpp.
|
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.
N2kMsg | Reference to a N2kMsg Object, |
Definition at line 373 of file N2kDeviceList.cpp.
|
protected |
Find a device in Sources by the manufacturer code and unique ID.
ManufacturerCode | Manufacturer code of the device to be searched for |
UniqueNumber | Unique ID of the device to be searched for |
Definition at line 66 of file N2kDeviceList.cpp.
|
protected |
Find a device in Sources by the name of the device.
Name | Name of the device to be searched for |
Definition at line 55 of file N2kDeviceList.cpp.
|
protected |
Find a device in Sources by the manufacturer and product code.
ManufacturerCode | Manufacturer code of the device to be searched for |
ProductCode | Product code of the device to be searched for |
Source | Source address of the device to be searched for |
Definition at line 81 of file N2kDeviceList.cpp.
|
protected |
Find a device in Sources by the source address.
Source | Source address of the device to be searched for |
Definition at line 48 of file N2kDeviceList.cpp.
|
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.
Definition at line 706 of file N2kDeviceList.h.
|
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.
Source | Destination address of the target device |
Definition at line 106 of file N2kDeviceList.cpp.
|
protected |
Request the ISO AddressClaim for a specific device on the bus.
Source | Destination address of the target device |
Definition at line 122 of file N2kDeviceList.cpp.
|
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.
Source | Destination address of the target device |
Definition at line 98 of file N2kDeviceList.cpp.
|
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.
Source | Destination address of the target device |
Definition at line 114 of file N2kDeviceList.cpp.
|
protected |
Saves a device to Sources.
pDevice | Pointer to a device |
Source | Source address of the device |
Definition at line 243 of file N2kDeviceList.cpp.
|
protected |
There are still requests pending.
Definition at line 451 of file N2kDeviceList.h.
|
protected |
The list of devices has been updated.
Definition at line 449 of file N2kDeviceList.h.
|
protected |
Number of NMEA2000 devices stored in Sources.
Definition at line 447 of file N2kDeviceList.h.
|
protected |
List of NMEA2000 devices found on the bus.
Definition at line 445 of file N2kDeviceList.h.