31static const char *
hex =
"0123456789ABCDEF";
34 s[0] =
hex[
byte >> 4];
35 s[1] =
hex[
byte & 0xf];
60 while (sentence[i] !=
'*') {
61 checksum ^= sentence[i];
68 size_t pcdin_sentence_length = 6+1+6+1+8+1+2+1+msg.
DataLen*2+1+2 + 1;
70 if (size < pcdin_sentence_length) {
86 for (
int i = 0; i < msg.
DataLen; i++) {
94 return (
size_t)(s - buffer);
102static bool readNHexByte(
const char *s,
unsigned int n, uint32_t &value) {
103 value=(uint32_t)(-1);
104 if (strlen(s) < 2*n) {
107 for (
unsigned int i = 0; i < 2*n; i++) {
108 if (!isxdigit(s[i])) {
113 char sNumber[2*n + 1];
114 strncpy(sNumber, s,
sizeof(sNumber));
115 sNumber[
sizeof(sNumber) - 1] = 0;
117 value = strtol(sNumber, 0, 16);
124 const char *s = buffer;
125 if (strncmp(
"$PCDIN,", s, 6) != 0) {
140 msg.
PGN = (pgnHigh << 16) + pgnLow;
155 while (s[dataLen] != 0 && s[dataLen] !=
'*') {
158 if (dataLen % 2 != 0) {
167 for (
int i = 0; i < dataLen; i++) {
bool SeasmartToN2k(const char *buffer, uint32_t ×tamp, tN2kMsg &msg)
Converts a null terminated $PCDIN NMEA sentence into a tN2kMsg.
size_t N2kToSeasmart(const tN2kMsg &msg, uint32_t timestamp, char *buffer, size_t size)
Converts a tN2kMsg into a $PCDIN NMEA sentence.
static int append2Bytes(char *s, uint16_t i)
static bool readNHexByte(const char *s, unsigned int n, uint32_t &value)
static int appendWord(char *s, uint32_t i)
static uint8_t nmea_compute_checksum(const char *sentence)
static int appendByte(char *s, uint8_t byte)
Conversion functions between N2k and Seasmart.
This class contains all the data of an NMEA2000 message.
unsigned char Data[MaxDataLen]
Byte array which carries all the data of the NMEA2000 message.
unsigned char Source
Source of the NMEA2000 message.
static const int MaxDataLen
Maximum number of bytes that can be stored in the data buffer With fast packet the first frame can ha...
virtual void Clear()
Clears the content of the N2kMsg object The method sets the PGN, DataLen and MsgTime to zero.
int DataLen
Number of bytes already stored in tN2kMsg::Data of this message.
unsigned long PGN
Parameter Group Number (PGN) of the NMEA2000 message.