Class for receiving messages from the serial device. More...
#include <SVHReceiveThread.h>
Public Member Functions | |
unsigned int | receivedPacketCount () |
return the count of received packets More... | |
void | resetReceivedPackageCount () |
resetReceivedPackageCount Resets the received package count to zero. This can be usefull to set all communication variables to the initial state More... | |
void | run () |
run method of the thread, executes the main program in an infinite loop More... | |
void | stop () |
stop the run() method More... | |
SVHReceiveThread (const std::chrono::microseconds &idle_sleep, std::shared_ptr< Serial > device, ReceivedPacketCallback const &received_callback) | |
SVHReceiveThread Constructs a new Receivethread. More... | |
~SVHReceiveThread () | |
Default DTOR. More... | |
Private Types | |
enum | tState { RS_HEADE_R1, RS_HEADE_R2, RS_INDEX, RS_ADDRESS, RS_LENGT_H1, RS_LENGT_H2, RS_DATA, RS_CHECKSU_M1, RS_CHECKSU_M2 } |
enum for receive packet state machine states More... | |
Private Member Functions | |
bool | receiveData () |
state machine processing received data More... | |
Private Attributes | |
driver_svh::ArrayBuilder | m_ab |
pointer to array builder object for packet receive More... | |
uint8_t | m_checksum1 |
Checksum of packet. More... | |
uint8_t | m_checksum2 |
std::atomic< bool > | m_continue {true} |
Flag to end the run() method from external callers. More... | |
std::vector< uint8_t > | m_data |
length of received serial data More... | |
std::chrono::microseconds | m_idle_sleep |
sleep time during run() if idle More... | |
uint16_t | m_length |
length of received serial data More... | |
std::atomic< unsigned int > | m_packets_received |
packets counter More... | |
ReceivedPacketCallback | m_received_callback |
function callback for received packages More... | |
tState | m_received_state |
current state of the state machine More... | |
std::shared_ptr< Serial > | m_serial_device |
pointer to serial device object More... | |
unsigned int | m_skipped_bytes |
counter for skipped bytes in case no packet is detected More... | |
Class for receiving messages from the serial device.
Instantiate this class in client code and call its run() method in a separate thread. Data is passed to the caller via the provided callback.
Definition at line 67 of file SVHReceiveThread.h.
|
private |
enum for receive packet state machine states
Enumerator | |
---|---|
RS_HEADE_R1 | |
RS_HEADE_R2 | |
RS_INDEX | |
RS_ADDRESS | |
RS_LENGT_H1 | |
RS_LENGT_H2 | |
RS_DATA | |
RS_CHECKSU_M1 | |
RS_CHECKSU_M2 |
Definition at line 109 of file SVHReceiveThread.h.
driver_svh::SVHReceiveThread::SVHReceiveThread | ( | const std::chrono::microseconds & | idle_sleep, |
std::shared_ptr< Serial > | device, | ||
ReceivedPacketCallback const & | received_callback | ||
) |
SVHReceiveThread Constructs a new Receivethread.
idle_sleep | sleep time during run() if no data is available |
device | handle of the serial device |
received_callback | function to call uppon finished packet |
Definition at line 47 of file SVHReceiveThread.cpp.
|
inline |
Default DTOR.
Definition at line 81 of file SVHReceiveThread.h.
|
private |
state machine processing received data
Definition at line 102 of file SVHReceiveThread.cpp.
|
inline |
return the count of received packets
Definition at line 90 of file SVHReceiveThread.h.
|
inline |
resetReceivedPackageCount Resets the received package count to zero. This can be usefull to set all communication variables to the initial state
Definition at line 96 of file SVHReceiveThread.h.
void driver_svh::SVHReceiveThread::run | ( | ) |
run method of the thread, executes the main program in an infinite loop
Definition at line 62 of file SVHReceiveThread.cpp.
|
inline |
stop the run() method
Definition at line 87 of file SVHReceiveThread.h.
|
private |
pointer to array builder object for packet receive
Definition at line 136 of file SVHReceiveThread.h.
|
private |
Checksum of packet.
Definition at line 129 of file SVHReceiveThread.h.
|
private |
Definition at line 130 of file SVHReceiveThread.h.
|
private |
Flag to end the run() method from external callers.
Definition at line 100 of file SVHReceiveThread.h.
|
private |
length of received serial data
Definition at line 133 of file SVHReceiveThread.h.
|
private |
sleep time during run() if idle
Definition at line 103 of file SVHReceiveThread.h.
|
private |
length of received serial data
Definition at line 126 of file SVHReceiveThread.h.
|
private |
packets counter
Definition at line 139 of file SVHReceiveThread.h.
|
private |
function callback for received packages
Definition at line 148 of file SVHReceiveThread.h.
|
private |
current state of the state machine
Definition at line 123 of file SVHReceiveThread.h.
|
private |
pointer to serial device object
Definition at line 106 of file SVHReceiveThread.h.
|
private |
counter for skipped bytes in case no packet is detected
Definition at line 142 of file SVHReceiveThread.h.