NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
Class for reading Actisense format messages. More...
#include <ActisenseReader.h>
Public Member Functions | |
tActisenseReader () | |
Constructor for the class Initialize all class attributes and clear the buffer. More... | |
bool | GetMessageFromStream (tN2kMsg &N2kMsg, bool ReadOut=true) |
Read Actisense formatted NMEA2000 message from stream. More... | |
bool | Handling () const |
Indicates if still message handling is needed. More... | |
bool | IsStart (char ch) |
Checks if character is start of Actisense format. More... | |
void | ParseMessages () |
Parse messages from stream. More... | |
void | SetDefaultSource (unsigned char source) |
Set the default source address for the messages. More... | |
void | SetMsgHandler (void(*_MsgHandler)(const tN2kMsg &N2kMsg)) |
Set the Msg Handler object. More... | |
void | SetReadStream (N2kStream *_stream) |
Set the Read Stream object. More... | |
Protected Member Functions | |
bool | AddByteToBuffer (char NewByte) |
Adds a new Byte to the buffer. More... | |
bool | CheckMessage (tN2kMsg &N2kMsg) |
Checks is Actisense message read from stream valid and builds tN2kMsg message from it. More... | |
void | ClearBuffer () |
Clears the buffer. More... | |
Protected Attributes | |
int | byteSum |
Sum of all bytes is used as kind of check sum. More... | |
unsigned char | DefaultSource |
Default source of the N2k message. More... | |
bool | EscapeReceived |
Escape character has been received. More... | |
unsigned char | MsgBuf [MAX_STREAM_MSG_BUF_LEN] |
Buffer for incoming messages from stream. More... | |
void(* | MsgHandler )(const tN2kMsg &N2kMsg) |
bool | MsgIsComing |
A Message is coming. More... | |
int | MsgWritePos |
Current write position inside the buffer. More... | |
N2kStream * | ReadStream |
Stream to read from. More... | |
bool | StartOfTextReceived |
Start of text has been received. More... | |
Class for reading Actisense format messages.
This is class for reading Actisense format messages from given stream and convert it to tN2kMsg. Converted tN2kMsg message can be then sent to the NMEA2000 bus with tNMEA2000::SendMsg();
Definition at line 57 of file ActisenseReader.h.
tActisenseReader::tActisenseReader | ( | ) |
Constructor for the class Initialize all class attributes and clear the buffer.
Definition at line 31 of file ActisenseReader.cpp.
|
protected |
Adds a new Byte to the buffer.
NewByte | new Byte to be added |
true | Success |
false | Buffer is full |
Definition at line 47 of file ActisenseReader.cpp.
|
protected |
Checks is Actisense message read from stream valid and builds tN2kMsg message from it.
N2kMsg | Reference to a destination tN2kMsg Object |
true | Message is valid. Message has been copied to N2kMsg |
false | Length does not match, checksum does not match or data length greater than tN2kMsg::MaxDataLen |
Definition at line 63 of file ActisenseReader.cpp.
|
protected |
Clears the buffer.
Definition at line 38 of file ActisenseReader.cpp.
bool tActisenseReader::GetMessageFromStream | ( | tN2kMsg & | N2kMsg, |
bool | ReadOut = true |
||
) |
Read Actisense formatted NMEA2000 message from stream.
GetMessageFromStream is nonblocking function and returns false, if there is no message available. You can either call this or ParseMessages() periodically.
Function reads Actisense formatted NMEA2000 message from stream Actisense Format: <10><02><93><length (1)><priority (1)><PGN (3)><destination (1)><source (1)><time (4)><len (1)><data (len)><CRC (1)><10><03> or <10><02><94><length (1)><priority (1)><PGN (3)><destination (1)><len (1)><data (len)><CRC (1)><10><03>
N2kMsg | Reference to a N2kMsg Object |
ReadOut | Parameter is designed to be used if stream has multiprotocol data. |
true | for new message received. |
false | if (ReadStream==0) |
Definition at line 110 of file ActisenseReader.cpp.
|
inline |
Indicates if still message handling is needed.
Function is designed to be used if stream has multiprotocol data.
true | |
false |
Definition at line 196 of file ActisenseReader.h.
bool tActisenseReader::IsStart | ( | char | ch | ) |
Checks if character is start of Actisense format.
Function is designed to be used if stream has multiprotocol data.
ch | character |
true | if (ch==Escape) |
false |
Definition at line 100 of file ActisenseReader.cpp.
void tActisenseReader::ParseMessages | ( | ) |
Parse messages from stream.
Call this periodically on loop as fast as possible. Function is nonblocking and reads data from stream as it is available.
To handle received messages set message handler with SetMsgHandler(). On message handler call GetMessageFromStream() to read arrived message.
Definition at line 183 of file ActisenseReader.cpp.
|
inline |
Set the default source address for the messages.
If you use an application, which sends data by using Actisense data request type, the source set by this function will be set as source. Default=65;
source | Source address to be used |
Definition at line 134 of file ActisenseReader.h.
|
inline |
Set the Msg Handler object.
Set message handler to be used as callback within ParseMessages, when new message has been received. On message handler call GetMessageFromStream() to read arrived message.
_MsgHandler | {type} |
Definition at line 186 of file ActisenseReader.h.
|
inline |
Set the Read Stream object.
Set stream, which would be used for reading messages. You have to open stream first, so e.g. for SerialUSB call begin first.
_stream | Stream to read from |
Definition at line 123 of file ActisenseReader.h.
|
protected |
Sum of all bytes is used as kind of check sum.
Definition at line 69 of file ActisenseReader.h.
|
protected |
Default source of the N2k message.
Definition at line 75 of file ActisenseReader.h.
|
protected |
Escape character has been received.
Definition at line 67 of file ActisenseReader.h.
|
protected |
Buffer for incoming messages from stream.
Definition at line 71 of file ActisenseReader.h.
|
protected |
Definition at line 81 of file ActisenseReader.h.
|
protected |
A Message is coming.
Definition at line 65 of file ActisenseReader.h.
|
protected |
Current write position inside the buffer.
Definition at line 73 of file ActisenseReader.h.
|
protected |
Stream to read from.
Definition at line 79 of file ActisenseReader.h.
|
protected |
Start of text has been received.
Definition at line 63 of file ActisenseReader.h.