NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
This file contains the class tNMEA2000, which consists the main functionality of the library. More...
#include "NMEA2000_CompilerDefns.h"
#include "N2kStream.h"
#include "N2kMsg.h"
#include "N2kCANMsg.h"
#include "N2kTimer.h"
#include "N2kGroupFunction.h"
Go to the source code of this file.
Classes | |
class | tNMEA2000 |
tNMEA2000 device class definition. More... | |
struct | tNMEA2000::tCANSendFrame |
Structure holds all the data needed for a valid CAN-Message. More... | |
struct | tNMEA2000::tConfigurationInformation |
Structure that holds the Configuration Information of this device. More... | |
class | tNMEA2000::tDevice |
This class represents a N2k device. More... | |
class | tNMEA2000::tDeviceInformation |
Class that holds all the device informations and several helper functions to that. More... | |
union | tNMEA2000::tDeviceInformation::tUnionDeviceInformation |
Union that holds the device informations. More... | |
class | tNMEA2000::tInternalDevice |
This class represents an internal device. More... | |
class | tNMEA2000::tMsgHandler |
Message handler class. More... | |
struct | tNMEA2000::tProductInformation |
Structure that holds all the product information. More... | |
Macros | |
#define | DefaultHeartbeatInterval 60000 |
Interval for Heartbeat. More... | |
#define | Max_N2kConfigurationInfoField_len 71 |
Max length of Configuration Info Fields. More... | |
#define | Max_N2kModelID_len 32 |
Max length of ModelID Document says for length 33 but then values has not been translated right on devices. More... | |
#define | Max_N2kModelSerialCode_len 32 |
Max length of SerialCode Document says for length 32 but then values has not been translated right on devices. More... | |
#define | Max_N2kModelVersion_len 32 |
Max length of Model Version Document says for length 24 but then values has not been translated right on devices. More... | |
#define | Max_N2kMsgBuf_Time 100 |
Message buffer time. More... | |
#define | Max_N2kProductInfoStrLen 33 |
Define length of longest info string Define length of longest info string (from Max_N2kModelID_len, Max_N2kSwCode_len, Max_N2kModelVersion_len, Max_N2kModelSerialCode_len) More... | |
#define | Max_N2kSwCode_len 32 |
Max length of Software Code Document says for length 40 but then values has not been translated right on devices. More... | |
#define | N2kMaxCanBusAddress 251 |
Max CAN Bus Address given by the library. More... | |
#define | N2kMessageGroups 2 |
Number of message groups. More... | |
#define | N2kNullCanBusAddress 254 |
Null Address (???) More... | |
#define | N2kPGNConfigurationInformation 126998L |
PGN for an Configuration Information message. More... | |
#define | N2kPGNIsoAddressClaim 60928L |
PGN for an ISO Address Claim message. More... | |
#define | N2kPGNProductInformation 126996L |
PGN for a Production Information message. More... | |
Enumerations | |
enum | tN2kPGNList { N2kpgnl_transmit =0 , N2kpgnl_receive =1 } |
Enumeration of types for PGN lists according to PGN 126464. More... | |
Functions | |
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". More... | |
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". More... | |
bool | ParseN2kPGN59904 (const tN2kMsg &N2kMsg, unsigned long &RequestedPGN) |
Parsing the content of message PGN 59904 "ISO request". More... | |
bool | ParseN2kPGNISORequest (const tN2kMsg &N2kMsg, unsigned long &RequestedPGN) |
Parsing the content of a "ISO request" message - PGN 59904. More... | |
void | SetHeartbeat (tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter) |
Setting up Message "Heartbeat" - PGN 126993. More... | |
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. More... | |
void | SetN2kISOAddressClaim (tN2kMsg &N2kMsg, uint64_t Name) |
Setting up Message "ISO Address Claim" - PGN 60928. More... | |
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. More... | |
void | SetN2kPGN126464 (tN2kMsg &N2kMsg, uint8_t Destination, tN2kPGNList tr, const unsigned long *PGNs) |
Setting up PGN 126464 Message "PGN List - Transmit PGNs group
function". More... | |
void | SetN2kPGN126993 (tN2kMsg &N2kMsg, uint32_t timeInterval_ms, uint8_t sequenceCounter) |
Setting up PGN 126993 Message "Heartbeat". More... | |
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". More... | |
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". More... | |
void | SetN2kPGN59392 (tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN) |
Setting up PGN 59392 Message "ISO Acknowledgement". More... | |
void | SetN2kPGN59904 (tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN) |
Setting up PGN 59904 Message "ISO request". More... | |
void | SetN2kPGN60928 (tN2kMsg &N2kMsg, uint64_t Name) |
Setting up PGN 60928 Message "ISO Address Claim". More... | |
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". More... | |
void | SetN2kPGNISOAcknowledgement (tN2kMsg &N2kMsg, unsigned char Control, unsigned char GroupFunction, unsigned long PGN) |
Setting up Message "ISO Acknowledgement" - PGN 59392. More... | |
void | SetN2kPGNISORequest (tN2kMsg &N2kMsg, uint8_t Destination, unsigned long RequestedPGN) |
Setting up Message "ISO request" - PGN 59904. More... | |
void | SetN2kPGNTransmitList (tN2kMsg &N2kMsg, uint8_t Destination, const unsigned long *PGNs) |
Setting up Message "PGN List - Transmit PGNs group
function" - PGN 126464. More... | |
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. More... | |
This file contains the class tNMEA2000, which consists the main functionality of the library.
With tNMEA2000 class you can easily communicate with NMEA2000 bus. Library can be used for any kind of NMEA2000 bus device needs from bus traffic listener to complex MFD system.
As default library simply reads all messages from bus and forwards them to defined forward stream (e.g., Serial) in Actisense format. Using N2km_ListenAndNode mode, one can make NMEA2000 compatible devices and even NMEA2000 certified devices by implementing all NMEA2000 certification requirements. Simple example is bus device, which provides some sensor like temperature, battery or engine information to the bus to be shown or MFD.
For detailed description see tNMEA2000.
Definition in file NMEA2000.h.
#define DefaultHeartbeatInterval 60000 |
Interval for Heartbeat.
Definition at line 824 of file NMEA2000.h.
#define Max_N2kConfigurationInfoField_len 71 |
Max length of Configuration Info Fields.
I do not know what standard says about max field length, but according to tests NMEAReader crashed with length >=90. Some device was reported not to work string length over 70.
Definition at line 99 of file NMEA2000.h.
#define Max_N2kModelID_len 32 |
Max length of ModelID Document says for length 33 but then values has not been translated right on devices.
Definition at line 70 of file NMEA2000.h.
#define Max_N2kModelSerialCode_len 32 |
Max length of SerialCode Document says for length 32 but then values has not been translated right on devices.
Definition at line 82 of file NMEA2000.h.
#define Max_N2kModelVersion_len 32 |
Max length of Model Version Document says for length 24 but then values has not been translated right on devices.
Definition at line 78 of file NMEA2000.h.
#define Max_N2kMsgBuf_Time 100 |
Message buffer time.
Definition at line 102 of file NMEA2000.h.
#define Max_N2kProductInfoStrLen 33 |
Define length of longest info string Define length of longest info string (from Max_N2kModelID_len, Max_N2kSwCode_len, Max_N2kModelVersion_len, Max_N2kModelSerialCode_len)
Definition at line 90 of file NMEA2000.h.
#define Max_N2kSwCode_len 32 |
Max length of Software Code Document says for length 40 but then values has not been translated right on devices.
Definition at line 74 of file NMEA2000.h.
#define N2kMaxCanBusAddress 251 |
Max CAN Bus Address given by the library.
Definition at line 106 of file NMEA2000.h.
#define N2kMessageGroups 2 |
Number of message groups.
Definition at line 104 of file NMEA2000.h.
#define N2kNullCanBusAddress 254 |
Null Address (???)
Definition at line 108 of file NMEA2000.h.
#define N2kPGNConfigurationInformation 126998L |
PGN for an Configuration Information message.
Definition at line 63 of file NMEA2000.h.
#define N2kPGNIsoAddressClaim 60928L |
PGN for an ISO Address Claim message.
Definition at line 59 of file NMEA2000.h.
#define N2kPGNProductInformation 126996L |
PGN for a Production Information message.
Definition at line 61 of file NMEA2000.h.
enum tN2kPGNList |
Enumeration of types for PGN lists according to PGN 126464.
Enumerator | |
---|---|
N2kpgnl_transmit | |
N2kpgnl_receive |
Definition at line 3262 of file NMEA2000.h.
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".
Provides product information onto the network that could be important for determining quality of data coming from this product.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
N2kVersion | NMEA Network Message Database Version |
ProductCode | NMEA Manufacturer's Product Code |
ModelIDSize | Size of ModelID |
ModelID | Manufacturer's Model ID |
SwCodeSize | Size of Software Version Code |
SwCode | Manufacturer's Software Version Code |
ModelVersionSize | Size of Model Version |
ModelVersion | Manufacturer's Model Version |
ModelSerialCodeSize | Size of Model Serial Code |
ModelSerialCode | Manufacturer's Model Serial Code |
CertificationLevel | NMEA 2000 Certification Level |
LoadEquivalency | Load Equivalency |
true | Parsing of PGN Message successful |
false | Parsing of PGN Message aborted |
Definition at line 2788 of file NMEA2000.cpp.
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".
Free-form alphanumeric fields describing the installation (e.g., starboard engine room location) of the device and installation notes (e.g., calibration data).
N2kMsg | Reference to a N2kMsg Object |
ManufacturerInformationSize | Size off Manufacturer Information |
ManufacturerInformation | Manufacturer Information |
InstallationDescription1Size | Size off Installation Description |
InstallationDescription1 | Installation Description, Field 1 |
InstallationDescription2Size | Size off Installation Description |
InstallationDescription2 | Installation Description, Field 2 |
true | Parsing of PGN Message successful |
false | Parsing of PGN Message aborted |
Definition at line 2873 of file NMEA2000.cpp.
bool ParseN2kPGN59904 | ( | const tN2kMsg & | N2kMsg, |
unsigned long & | RequestedPGN | ||
) |
Parsing the content of message PGN 59904 "ISO request".
As defined by ISO, this message has a data length of 3 bytes with no padding added to complete the single frame. The appropriate response to this message is based on the PGN being requested, and whether the receiver supports the requested PGN.
N2kMsg | Reference to a N2kMsg Object |
RequestedPGN | PGN being requested |
true | Parsing of PGN Message successful |
false | Parsing of PGN Message aborted |
Definition at line 2894 of file NMEA2000.cpp.
|
inline |
Parsing the content of a "ISO request" message - PGN 59904.
Alias of PGN 59904. This alias was introduced to improve the readability of the source code. See parameter details on ParseN2kPGN59904
Definition at line 3253 of file NMEA2000.h.
|
inline |
Setting up Message "Heartbeat" - PGN 126993.
Alias of PGN 126993. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN126993
Definition at line 3313 of file NMEA2000.h.
|
inline |
Setting up Message "Configuration information" - PGN 126998.
Alias of PGN 126998. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN126998
Definition at line 3169 of file NMEA2000.h.
|
inline |
Setting up Message "ISO Address Claim" - PGN 60928.
Alias of PGN 60928. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN60928
Definition at line 3076 of file NMEA2000.h.
|
inline |
Setting up Message "ISO Address Claim" - PGN 60928.
Alias of PGN 60928. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN60928
Definition at line 3063 of file NMEA2000.h.
void SetN2kPGN126464 | ( | tN2kMsg & | N2kMsg, |
uint8_t | Destination, | ||
tN2kPGNList | tr, | ||
const unsigned long * | PGNs | ||
) |
Setting up PGN 126464 Message "PGN List - Transmit PGNs group function".
The PGN List group function type is 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.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
Destination | Address of the destination |
tr | Transmit or Receive, see tN2kPGNList |
PGNs | List of PGNs |
Definition at line 2907 of file NMEA2000.cpp.
void SetN2kPGN126993 | ( | tN2kMsg & | N2kMsg, |
uint32_t | timeInterval_ms, | ||
uint8_t | sequenceCounter | ||
) |
Setting up PGN 126993 Message "Heartbeat".
This PGN shall be transmitted by all NMEA devices. Reception of this PGN confirms that a device is still present on the network. Reception of this PGN may also be used to maintain an address to NAME association table within the receiving device.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
timeInterval_ms | time interval in msec (0.01 - 655.32s ) |
sequenceCounter | Sequence counter |
Definition at line 2923 of file NMEA2000.cpp.
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".
Provides product information onto the network that could be important for determining quality of data coming from this product.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
N2kVersion | NMEA Network Message Database Version |
ProductCode | NMEA Manufacturer's Product Code |
ModelID | Manufacturer's Model ID |
SwCode | Manufacturer's Software Version Code |
ModelVersion | Manufacturer's Model Version |
ModelSerialCode | Manufacturer's Model Serial Code |
CertificationLevel | NMEA 2000 Certification Level |
LoadEquivalency | Load Equivalency |
Definition at line 2771 of file NMEA2000.cpp.
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".
Free-form alphanumeric fields describing the installation (e.g., starboard engine room location) of the device and installation notes (e.g., calibration data).
N2kMsg | Reference to a N2kMsg Object, ready to be send |
ManufacturerInformation | Manufacturer Information |
InstallationDescription1 | Installation Description, Field 1 |
InstallationDescription2 | Installation Description, Field 2 |
UsePgm | Use program memory, default = false |
Definition at line 2823 of file NMEA2000.cpp.
void SetN2kPGN59392 | ( | tN2kMsg & | N2kMsg, |
unsigned char | Control, | ||
unsigned char | GroupFunction, | ||
unsigned long | PGN | ||
) |
Setting up PGN 59392 Message "ISO Acknowledgement".
This message is provided by ISO 11783 for a handshake mechanism between transmitting and receiving devices. This message is the possible response to acknowledge the reception of a “normal broadcast” message or the response to a specific command to indicate compliance or failure.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
Control | Control Byte |
GroupFunction | Group Function value |
PGN | PGN of requested Information |
Setting up PGN 59392 Message "ISO Acknowledgement".
Definition at line 2732 of file NMEA2000.cpp.
void SetN2kPGN59904 | ( | tN2kMsg & | N2kMsg, |
uint8_t | Destination, | ||
unsigned long | RequestedPGN | ||
) |
Setting up PGN 59904 Message "ISO request".
As defined by ISO, this message has a data length of 3 bytes with no padding added to complete the single frame. The appropriate response to this message is based on the PGN being requested, and whether the receiver supports the requested PGN.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
Destination | Address of the destination |
RequestedPGN | PGN being requested |
Definition at line 2887 of file NMEA2000.cpp.
void SetN2kPGN60928 | ( | tN2kMsg & | N2kMsg, |
uint64_t | Name | ||
) |
Setting up PGN 60928 Message "ISO Address Claim".
This network management message is used to claim a network address and to respond with device information (NAME) requested by the ISO Request or Complex Request Group Function. This PGN contains several fields that are Request Parameters that can be used to control the expected response to requests for this PGN.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
Name | Name of the device |
Definition at line 2762 of file NMEA2000.cpp.
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".
This network management message is used to claim a network address and to respond with device information (NAME) requested by the ISO Request or Complex Request Group Function. This PGN contains several fields that are Request Parameters that can be used to control the expected response to requests for this PGN.
N2kMsg | Reference to a N2kMsg Object, ready to be send |
UniqueNumber | Unique Number (ISO Identity Number) |
ManufacturerCode | Manufacturer Code |
DeviceFunction | Device Function (ISO Function) |
DeviceClass | Device Class |
DeviceInstance | Device Instance |
SystemInstance | System Instance (ISO Device Class Instance) |
IndustryGroup | Industry Group |
Definition at line 2746 of file NMEA2000.cpp.
|
inline |
Setting up Message "ISO Acknowledgement" - PGN 59392.
Alias of PGN 59392. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN59392
Definition at line 3016 of file NMEA2000.h.
|
inline |
Setting up Message "ISO request" - PGN 59904.
Alias of PGN 59904. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN59904
Definition at line 3226 of file NMEA2000.h.
|
inline |
Setting up Message "PGN List - Transmit PGNs group function" - PGN 126464.
Alias of PGN 126464. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN126464
Definition at line 3289 of file NMEA2000.h.
|
inline |
Setting up Message "Product information" - PGN 126996.
Alias of PGN 126996. This alias was introduced to improve the readability of the source code. See parameter details on SetN2kPGN126996
Definition at line 3107 of file NMEA2000.h.