48 std::shared_ptr<Serial> device,
50 : m_idle_sleep(idle_sleep)
51 , m_serial_device(device)
52 , m_received_state(RS_HEADE_R1)
56 , m_packets_received(0)
58 , m_received_callback(received_callback)
70 auto start = std::chrono::high_resolution_clock::now();
75 auto elapsed_time = std::chrono::high_resolution_clock::now() - start;
79 std::this_thread::sleep_for(
m_idle_sleep - elapsed_time);
83 std::this_thread::sleep_for(elapsed_time %
m_idle_sleep);
90 "Cannot read data from serial device. It is not opened!");
191 m_data.push_back(data_byte);
210 for (
size_t i = 0; i <
m_data.size(); ++i)
216 if ((checksum1 == 0) && (checksum2 == 0))
222 m_ab >> received_packet;
229 "Received packet index:" << received_packet.index
230 <<
", address:" << received_packet.address
231 <<
", size:" << received_packet.data.size());
247 m_ab >> received_packet;
252 "Checksum error: " << (
int)checksum1 <<
"," << (
int)checksum2
254 <<
"bytes, packet index:" << received_packet.index
255 <<
", address:" << received_packet.address
256 <<
", size:" << received_packet.data.size());
std::vector< uint8_t > m_data
length of received serial data
const uint8_t PACKET_HEADER1
Header sync byte 1.
tState m_received_state
current state of the state machine
unsigned int m_skipped_bytes
counter for skipped bytes in case no packet is detected
const uint8_t PACKET_HEADER2
Header sync byte 2.
ReceivedPacketCallback m_received_callback
function callback for received packages
bool receiveData()
state machine processing received data
void run()
run method of the thread, executes the main program in an infinite loop
uint16_t m_length
length of received serial data
std::function< void(const SVHSerialPacket &packet, unsigned int packet_count)> ReceivedPacketCallback
definition of function callback for received packages
std::shared_ptr< Serial > m_serial_device
pointer to serial device object
#define SVH_LOG_DEBUG_STREAM(NAME, M)
driver_svh::ArrayBuilder m_ab
pointer to array builder object for packet receive
void appendWithoutConversion(const T &data)
add data without any byte conversion
std::chrono::microseconds m_idle_sleep
sleep time during run() if idle
std::atomic< bool > m_continue
Flag to end the run() method from external callers.
void reset(size_t array_size=1)
Resets the Arraybuilder to initial state, all values will be deleted.
uint8_t m_checksum1
Checksum of packet.
SVHReceiveThread(const std::chrono::microseconds &idle_sleep, std::shared_ptr< Serial > device, ReceivedPacketCallback const &received_callback)
SVHReceiveThread Constructs a new Receivethread.
#define SVH_LOG_WARN_STREAM(NAME, M)
std::atomic< unsigned int > m_packets_received
packets counter
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.