53 , m_received_packet_callback(received_packet_callback)
54 , m_packets_transmitted(0)
70 new Serial(dev_name.c_str(),
SerialFlags(SerialFlags::BR_921600, SerialFlags::DB_8)));
78 "Could not open serial device: " << dev_name.c_str());
85 "Could not create serial device handle: " << dev_name.c_str());
90 std::make_unique<SVHReceiveThread>(std::chrono::microseconds(500),
94 std::placeholders::_1,
95 std::placeholders::_2));
104 <<
" opened and receive thread started. Communication can now begin.");
139 packet.
data.resize(64, 0);
141 uint8_t check_sum1 = 0;
142 uint8_t check_sum2 = 0;
145 for (
size_t i = 0; i < packet.
data.size(); i++)
147 check_sum1 += packet.
data[i];
148 check_sum2 ^= packet.
data[i];
163 ssize_t bytes_send = 0;
164 while (bytes_send < size)
174 std::this_thread::sleep_for(std::chrono::microseconds(782));
181 "sendPacket failed, serial device was not properly initialized.");
200 uint8_t check_sum1 = 0;
201 uint8_t check_sum2 = 0;
204 for (
size_t i = 0; i < packet.
data.size(); i++)
206 check_sum1 += packet.
data[i];
207 check_sum2 ^= packet.
data[i];
220 std::cout << send_array << std::endl;
226 unsigned int packet_count)
std::unique_ptr< SVHReceiveThread > m_svh_receiver
handle to manage the actual receiving of data
const uint8_t PACKET_HEADER1
Header sync byte 1.
ReceivedPacketCallback m_received_packet_callback
Callback function for received packets.
const uint8_t PACKET_HEADER2
Header sync byte 2.
void printPacketOnConsole(SVHSerialPacket &packet)
printPacketOnConsole is a pure helper function to show what raw data is actually sent. This is not meant for any productive use other than understand whats going on.
std::shared_ptr< Serial > m_serial_device
pointer to serial interface object
~SVHSerialInterface()
Default DTOR.
void receivedPacketCallback(const SVHSerialPacket &packet, unsigned int packet_count)
void close()
canceling receive thread and closing connection to serial port
std::vector< uint8_t > array
array of template type TArray
unsigned int m_dummy_packets_printed
packet counter simulation for pure showing purposes
std::function< void(const SVHSerialPacket &packet, unsigned int packet_count)> ReceivedPacketCallback
definition of function callback for received packages
bool sendPacket(SVHSerialPacket &packet)
function for sending packets via serial device to the SVH
std::vector< uint8_t > data
Payload of the package.
bool connect(const std::string &dev_name)
connecting to serial device and starting receive thread
const size_t C_PACKET_APPENDIX_SIZE
The packet overhead size in bytes.
#define SVH_LOG_DEBUG_STREAM(NAME, M)
#define SVH_LOG_ERROR_STREAM(NAME, M)
uint8_t index
Continuosly incremented counter per package.
unsigned int m_packets_transmitted
packet counters
bool m_connected
serial device connected state
SVHSerialInterface(const ReceivedPacketCallback &received_packet_callback)
Constructs a serial interface class for basic communication with the SCHUNK five finger hand...
std::thread m_receive_thread
thread for receiving serial packets
Enables acces to serial devices.
void resetTransmitPackageCount()
resetTransmitPackageCount Resets the transmitpackage count to zero
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.
Short description of tSerialFlags.