70#define BIT(n) (1 << n)
174void SetBufFloat(
float v,
int &index,
unsigned char *buf);
184void SetBufDouble(
double v,
int &index,
unsigned char *buf);
203void SetBuf8ByteDouble(
double v,
double precision,
int &index,
unsigned char *buf);
221void SetBuf4ByteDouble(
double v,
double precision,
int &index,
unsigned char *buf);
257void SetBuf3ByteDouble(
double v,
double precision,
int &index,
unsigned char *buf);
275void SetBuf2ByteDouble(
double v,
double precision,
int &index,
unsigned char *buf);
311void SetBuf1ByteDouble(
double v,
double precision,
int &index,
unsigned char *buf);
403void SetBufUInt64(uint64_t v,
int &index,
unsigned char *buf);
415void SetBufStr(
const char *str,
int len,
int &index,
unsigned char *buf,
bool UsePgm=
false,
unsigned char fillChar=0x0);
492double GetBuf1ByteDouble(
double precision,
int &index,
const unsigned char *buf,
double def=0);
509double GetBuf1ByteUDouble(
double precision,
int &index,
const unsigned char *buf,
double def=-1);
526double GetBuf2ByteDouble(
double precision,
int &index,
const unsigned char *buf,
double def=0);
543double GetBuf2ByteUDouble(
double precision,
int &index,
const unsigned char *buf,
double def=-1);
560double GetBuf3ByteDouble(
double precision,
int &index,
const unsigned char *buf,
double def=0);
577double GetBuf4ByteDouble(
double precision,
int &index,
const unsigned char *buf,
double def=0);
594double GetBuf4ByteUDouble(
double precision,
int &index,
const unsigned char *buf,
double def=-1);
611double GetBuf8ByteDouble(
double precision,
int &index,
const unsigned char *buf,
double def=0);
627double GetBufDouble(
int &index,
const unsigned char *buf,
double def=0);
641float GetBufFloat(
int &index,
const unsigned char *buf,
float def=0);
682#if !defined(N2K_NO_ISO_MULTI_PACKET_SUPPORT)
712 tN2kMsg(
unsigned char _Source=15,
unsigned char _Priority=6,
unsigned long _PGN=0,
int _DataLen=0);
718 void SetPGN(
unsigned long _PGN);
746 void Init(
unsigned char _Priority,
unsigned long _PGN,
unsigned char _Source,
unsigned char _Destination=0xff);
752 virtual void Clear();
951 void AddStr(
const char *str,
int len,
bool UsePgm=
false,
unsigned char fillChar=0xff);
960 void AddAISStr(
const char *str,
int len);
971 void AddVarStr(
const char *str,
bool UsePgm=
false);
982 void AddBuf(
const void *buf,
size_t bufLen);
992 unsigned char GetByte(
int &Index)
const;
1003 int16_t
Get2ByteInt(
int &Index, int16_t def=0x7fff)
const;
1014 uint16_t
Get2ByteUInt(
int &Index, uint16_t def=0xffff)
const;
1025 uint32_t
Get3ByteUInt(
int &Index, uint32_t def=0xffffffff)
const;
1036 uint32_t
Get4ByteUInt(
int &Index, uint32_t def=0xffffffff)
const;
1047 uint64_t
GetUInt64(
int &Index, uint64_t def=0xffffffffffffffffULL)
const;
1176 bool GetStr(
char *StrBuf,
size_t Length,
int &Index)
const;
1192 bool GetStr(
size_t StrBufSize,
char *StrBuf,
size_t Length,
unsigned char nulChar,
int &Index)
const;
1208 bool GetVarStr(
size_t &StrBufSize,
char *StrBuf,
int &Index)
const;
1221 bool GetBuf(
void *buf,
size_t Length,
int &Index)
const;
1233 bool SetByte(uint8_t v,
int &Index);
1272void PrintBuf(
N2kStream *port,
unsigned char len,
const unsigned char *pData,
bool AddLF=
false);
Type definitions and utility macros used in the NMEA2000 libraries.
const uint32_t N2kUInt32NA
Constant "Not Available" for a unsigned 32bit int value.
void SetBufDouble(double v, int &index, unsigned char *buf)
Writes a double value into a byte array buffer
uint16_t GetBuf2ByteUInt(int &index, const unsigned char *buf)
Extracts 2 bytes out of the given buffer and converts it to an integer value.
double GetBuf1ByteDouble(double precision, int &index, const unsigned char *buf, double def=0)
Extracts the specified numbers of bytes out of the given buffer and converts it to a double value.
void PrintBuf(N2kStream *port, unsigned char len, const unsigned char *pData, bool AddLF=false)
Print out a buffer (byte array)
int16_t GetBuf2ByteInt(int &index, const unsigned char *buf)
Extracts 2 bytes out of the given buffer and converts it to an integer value.
void SetBuf2ByteInt(int16_t v, int &index, unsigned char *buf)
Writes an integer value into a byte array buffer using 2 bytes To write a integer value into a certai...
const double N2kDoubleNA
Constant "Not Available" for a double value.
double GetBuf3ByteDouble(double precision, int &index, const unsigned char *buf, double def=0)
Extracts 3 bytes out of the given buffer and converts it to a double value.
void SetBuf2ByteUDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double unsigned value into a byte array buffer using 2 bytes.
const uint64_t N2kUInt64NA
Constant "Not Available" for a unsigned 64bit int value.
const int8_t N2kInt8NA
Constant "Not Available" for a signed 8bit value.
double GetBuf8ByteDouble(double precision, int &index, const unsigned char *buf, double def=0)
Extracts 8 bytes out of the given buffer and converts it to a double value.
double GetBuf4ByteDouble(double precision, int &index, const unsigned char *buf, double def=0)
Extracts 4 bytes out of the given buffer and converts it to a double value.
double GetBufDouble(int &index, const unsigned char *buf, double def=0)
Extracts bytes out of the given buffer and converts it to a double value.
void SetBuf3ByteDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double signed value into a byte array buffer using 3 bytes.
void SetBufStr(const char *str, int len, int &index, unsigned char *buf, bool UsePgm=false, unsigned char fillChar=0x0)
Writes a string into a byte array buffer.
float GetBufFloat(int &index, const unsigned char *buf, float def=0)
Extracts the specified numbers of bytes out of the given buffer and converts it to an float value.
const int16_t N2kInt16NA
Constant "Not Available" for a signed 16bit int value.
void SetBuf2ByteDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double signed value into a byte array buffer using 2 bytes.
double GetBuf1ByteUDouble(double precision, int &index, const unsigned char *buf, double def=-1)
Extracts 1 byte out of the given buffer and converts it to a double value.
const int64_t N2kInt64NA
Constant "Not Available" for a signed 64bit int value.
double GetBuf4ByteUDouble(double precision, int &index, const unsigned char *buf, double def=-1)
Extracts 4 bytes out of the given buffer and converts it to a double value.
void SetBufFloat(float v, int &index, unsigned char *buf)
Writes a float value into a byte array buffer.
uint64_t GetBuf8ByteUInt(int &index, const unsigned char *buf)
Extracts 8 bytes out of the given buffer and converts it to an integer value.
void SetBuf4ByteDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double signed value into a byte array buffer using 4 bytes.
double GetBuf2ByteUDouble(double precision, int &index, const unsigned char *buf, double def=-1)
Extracts 2 bytes out of the given buffer and converts it to a double value.
void SetBufUInt64(uint64_t v, int &index, unsigned char *buf)
Writes an unsigned integer 64bit value into a byte array buffer using 8 bytes To write a integer valu...
const int32_t N2kInt32NA
Constant "Not Available" for a signed 32bit int value.
const float N2kFloatNA
Constant "Not Available" for a float value.
void SetBuf4ByteUDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double unsigned value into a byte array buffer using 4 bytes.
void SetBuf3ByteInt(int32_t v, int &index, unsigned char *buf)
Writes an integer value into a byte array buffer using 3 bytes To write a integer value into a certai...
const uint16_t N2kUInt16NA
Constant "Not Available" for a unsigned 16bit int value.
const uint8_t N2kUInt8NA
Constant "Not Available" for a unsigned 8bit int value.
void SetBuf2ByteUInt(uint16_t v, int &index, unsigned char *buf)
Writes an unsigned integer value into a byte array buffer using 2 bytes.
void SetBuf8ByteDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double signed value into a byte array buffer using 8 bytes.
void SetBuf1ByteUDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double unsigned value into a byte array buffer using 1 byte.
uint32_t GetBuf4ByteUInt(int &index, const unsigned char *buf)
Extracts 4 bytes out of the given buffer and converts it to an integer value.
bool N2kIsNA(double v)
Verify that the specified value is equal to "Not available".
void SetBuf4ByteUInt(uint32_t v, int &index, unsigned char *buf)
Writes an unsigned integer value into a byte array buffer u ing 4 bytes To write a integer value into...
void SetBuf1ByteDouble(double v, double precision, int &index, unsigned char *buf)
Writes a double signed value into a byte array buffer using 1 byte.
uint32_t GetBuf3ByteUInt(int &index, const unsigned char *buf)
Extracts 3 bytes out of the given buffer and converts it to an integer value.
double GetBuf2ByteDouble(double precision, int &index, const unsigned char *buf, double def=0)
Extracts 2 bytes out of the given buffer and converts it to a double value.
This File contains an I/O stream used in the NMEA2000 libraries.
Streaming Class to handle all Streams generated by the Library.
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.
void Add2ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 2 bytes.
void AddFloat(float v, float UndefVal=N2kFloatNA)
Add float value to the buffer This method adds a float value to the message buffer using SetBufFloat ...
void AddStr(const char *str, int len, bool UsePgm=false, unsigned char fillChar=0xff)
Add string value to the buffer The string will be added to the end (indicated by DataLen) of the byte...
void Add2ByteUInt(uint16_t v)
Add unsigned integer value to the buffer using 2 bytes The value will be added to the end (indicated ...
double Get3ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 3 bytes out of Data The fixed point integer mechanism is used.
double Get4ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 4 bytes out of Data The fixed point integer mechanism is used.
double Get1ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 1 bytes out of Data The fixed point integer mechanism is used.
bool GetVarStr(size_t &StrBufSize, char *StrBuf, int &Index) const
Get a string out of Data This method determines the length of the string by it self,...
void Add4ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 4 bytes.
void Add2ByteInt(int16_t v)
Add integer value to the buffer using 2 bytes The value will be added to the end (indicated by DataLe...
int GetRemainingDataLength(int Index) const
Get the Remaining Data Length.
void Add4ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 4 bytes.
void Add3ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 3 bytes.
bool IsTPMessage() const
Determine if the message is flagged as MultiPacket Message.
bool IsValid() const
Checks if the Message Meta Content is valid Basic check if the message object is valid,...
void AddByte(unsigned char v)
Add byte value to the buffer The byte will be added to the end (indicated by DataLen) of the byte arr...
void ResetData()
Fills the whole data buffer with 0xff.
void Add2ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 2 bytes.
void Add1ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 1 byte.
bool Set2ByteUInt(uint16_t v, int &Index)
Set a 2byte unsigned integer in Data.
void Add1ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 1 byte.
void ForceSource(unsigned char _Source) const
Set the Source of the message.
void Print(N2kStream *port, bool NoData=false) const
Print out the whole content of the N2kMsg Object.
void AddUInt64(uint64_t v)
Add unsigned integer value to the buffer using 8 bytes The value will be added to the end (indicated ...
void AddBuf(const void *buf, size_t bufLen)
Add byte array to the buffer.
uint16_t Get2ByteUInt(int &Index, uint16_t def=0xffff) const
Get an unsigned integer from 2 bytes out of Data.
double Get2ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 2 bytes out of Data The fixed point integer mechanism is used.
unsigned char Source
Source of the NMEA2000 message.
void Add8ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 8 bytes.
static const int MaxDataLen
Maximum number of bytes that can be stored in the data buffer With fast packet the first frame can ha...
float GetFloat(int &Index, float def=N2kFloatNA) const
Get a float out of Data.
double Get2ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 2 bytes out of Data The fixed point integer mechanism is used.
void AddVarStr(const char *str, bool UsePgm=false)
Add string value to the buffer This method determines the length of the string by it self using strle...
unsigned char Priority
Priority of the NMEA2000 message.
bool SetByte(uint8_t v, int &Index)
Set a byte in Data.
uint32_t Get3ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 3 bytes out of Data.
double Get1ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 1 bytes out of Data The fixed point integer mechanism is used.
void Add3ByteInt(int32_t v)
Add integer value to the buffer using 3 bytes The value will be added to the end (indicated by DataLe...
virtual void Clear()
Clears the content of the N2kMsg object The method sets the PGN, DataLen and MsgTime to zero.
unsigned long MsgTime
timestamp (ms since start [max 49days]) of the NMEA2000 message
void Add4ByteUInt(uint32_t v)
Add unsigned integer value to the buffer using 4 bytes The value will be added to the end (indicated ...
void CheckDestination() const
Validation check for the message destination We can send to specified destination only for PGN:s low ...
bool TPMessage
Message is a MultiPacket Message.
void SetPGN(unsigned long _PGN)
Set the Parameter Group Number of the message *.
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.
int16_t Get2ByteInt(int &Index, int16_t def=0x7fff) const
Get an integer from 2 bytes out of Data.
bool GetBuf(void *buf, size_t Length, int &Index) const
Get a byte array out of Data.
int GetAvailableDataLength() const
Get the Available Data Length The method calculates the available data length with MaxDataLen - DataL...
bool GetStr(char *StrBuf, size_t Length, int &Index) const
Get a string out of Data.
void AddAISStr(const char *str, int len)
Add string value to the buffer after filtering characters as defined in ITU-R M.1371-1 The string wil...
double Get4ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 4 bytes out of Data The fixed point integer mechanism is used.
void Init(unsigned char _Priority, unsigned long _PGN, unsigned char _Source, unsigned char _Destination=0xff)
Initialisation of the N2kMsg object.
void SetIsTPMessage(bool tp=true)
Set the MultiPacket Message status.
tN2kMsg(unsigned char _Source=15, unsigned char _Priority=6, unsigned long _PGN=0, int _DataLen=0)
Construct a new t N2k Msg object.
void SendInActisenseFormat(N2kStream *port) const
Print out the whole content of the N2kMsg Object using the Actisense Format.
double Get8ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 8 bytes out of Data The fixed point integer mechanism is used.
uint32_t Get4ByteUInt(int &Index, uint32_t def=0xffffffff) const
Get an unsigned integer from 4 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.
unsigned char Destination
Destination of the NMEA2000 message.