NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
tActisenseReader Class Reference

Class for reading Actisense format messages. More...

#include <ActisenseReader.h>

Collaboration diagram for tActisenseReader:

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...
 
N2kStreamReadStream
 Stream to read from. More...
 
bool StartOfTextReceived
 Start of text has been received. More...
 

Detailed Description

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();

Note
There is an unresolved problem to use programming port with reading data. Read works fine for a while, but then stops. With e.g. Arduino Due USB port there is no problem.

Definition at line 57 of file ActisenseReader.h.

Constructor & Destructor Documentation

◆ tActisenseReader()

tActisenseReader::tActisenseReader ( )

Constructor for the class Initialize all class attributes and clear the buffer.

Definition at line 31 of file ActisenseReader.cpp.

Member Function Documentation

◆ AddByteToBuffer()

bool tActisenseReader::AddByteToBuffer ( char  NewByte)
protected

Adds a new Byte to the buffer.

Parameters
NewBytenew Byte to be added
Return values
trueSuccess
falseBuffer is full

Definition at line 47 of file ActisenseReader.cpp.

◆ CheckMessage()

bool tActisenseReader::CheckMessage ( tN2kMsg N2kMsg)
protected

Checks is Actisense message read from stream valid and builds tN2kMsg message from it.

Parameters
N2kMsgReference to a destination tN2kMsg Object
Return values
trueMessage is valid. Message has been copied to N2kMsg
falseLength does not match, checksum does not match or data length greater than tN2kMsg::MaxDataLen

Definition at line 63 of file ActisenseReader.cpp.

◆ ClearBuffer()

void tActisenseReader::ClearBuffer ( )
protected

Clears the buffer.

Definition at line 38 of file ActisenseReader.cpp.

◆ GetMessageFromStream()

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>

Parameters
N2kMsgReference to a N2kMsg Object
ReadOutParameter is designed to be used if stream has multiprotocol data.
Return values
truefor new message received.
falseif (ReadStream==0)

Definition at line 110 of file ActisenseReader.cpp.

◆ Handling()

bool tActisenseReader::Handling ( ) const
inline

Indicates if still message handling is needed.

Function is designed to be used if stream has multiprotocol data.

Return values
true
false

Definition at line 196 of file ActisenseReader.h.

◆ IsStart()

bool tActisenseReader::IsStart ( char  ch)

Checks if character is start of Actisense format.

Function is designed to be used if stream has multiprotocol data.

Parameters
chcharacter
Return values
trueif (ch==Escape)
false

Definition at line 100 of file ActisenseReader.cpp.

◆ ParseMessages()

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.

◆ SetDefaultSource()

void tActisenseReader::SetDefaultSource ( unsigned char  source)
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;

Parameters
sourceSource address to be used

Definition at line 134 of file ActisenseReader.h.

◆ SetMsgHandler()

void tActisenseReader::SetMsgHandler ( void(*)(const tN2kMsg &N2kMsg)  _MsgHandler)
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.

Parameters
_MsgHandler{type}

Definition at line 186 of file ActisenseReader.h.

◆ SetReadStream()

void tActisenseReader::SetReadStream ( N2kStream _stream)
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.

Parameters
_streamStream to read from

Definition at line 123 of file ActisenseReader.h.

Member Data Documentation

◆ byteSum

int tActisenseReader::byteSum
protected

Sum of all bytes is used as kind of check sum.

Definition at line 69 of file ActisenseReader.h.

◆ DefaultSource

unsigned char tActisenseReader::DefaultSource
protected

Default source of the N2k message.

Definition at line 75 of file ActisenseReader.h.

◆ EscapeReceived

bool tActisenseReader::EscapeReceived
protected

Escape character has been received.

Definition at line 67 of file ActisenseReader.h.

◆ MsgBuf

unsigned char tActisenseReader::MsgBuf[MAX_STREAM_MSG_BUF_LEN]
protected

Buffer for incoming messages from stream.

Definition at line 71 of file ActisenseReader.h.

◆ MsgHandler

void(* tActisenseReader::MsgHandler) (const tN2kMsg &N2kMsg)
protected

Definition at line 81 of file ActisenseReader.h.

◆ MsgIsComing

bool tActisenseReader::MsgIsComing
protected

A Message is coming.

Definition at line 65 of file ActisenseReader.h.

◆ MsgWritePos

int tActisenseReader::MsgWritePos
protected

Current write position inside the buffer.

Definition at line 73 of file ActisenseReader.h.

◆ ReadStream

N2kStream* tActisenseReader::ReadStream
protected

Stream to read from.

Definition at line 79 of file ActisenseReader.h.

◆ StartOfTextReceived

bool tActisenseReader::StartOfTextReceived
protected

Start of text has been received.

Definition at line 63 of file ActisenseReader.h.


The documentation for this class was generated from the following files: