33 #include <icl_comm/ByteOrderConversion.h> 34 #include <boost/bind/bind.hpp> 37 using icl_comm::serial::SerialFlags;
43 m_received_packet_callback(received_packet_callback),
44 m_packets_transmitted(0)
59 m_serial_device.reset(
new Serial(dev_name.c_str(), SerialFlags(SerialFlags::eBR_921600, SerialFlags::eDB_8)));
130 packet.
data.resize(64,0);
135 for (
size_t i = 0; i < packet.
data.size(); i++)
137 check_sum1 += packet.
data[i];
138 check_sum2 ^= packet.
data[i];
148 icl_comm::ArrayBuilder send_array(size);
153 size_t bytes_send = 0;
154 while (bytes_send < size)
156 bytes_send +=
m_serial_device->Write(send_array.array.data() + bytes_send, size - bytes_send);
201 for (
size_t i = 0; i < packet.
data.size(); i++)
203 check_sum1 += packet.
data[i];
204 check_sum2 ^= packet.
data[i];
213 icl_comm::ArrayBuilder send_array(size);
217 std::cout << send_array << std::endl;
const uint8_t PACKET_HEADER1
Header sync byte 1.
ReceivedPacketCallback m_received_packet_callback
Callback function for received packets.
boost::function< void(const SVHSerialPacket &packet, unsigned int packet_count)> ReceivedPacketCallback
definition of boost function callback for received packages
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.
~SVHSerialInterface()
Default DTOR.
void receivedPacketCallback(const SVHSerialPacket &packet, unsigned int packet_count)
called on received packets, calls m_received_packet_callback
void close()
canceling receive thread and closing connection to serial port
unsigned int m_dummy_packets_printed
packet counter simulation for pure showing purposes
int usleep(unsigned long useconds)
bool sendPacket(SVHSerialPacket &packet)
function for sending packets via serial device to the SVH
std::vector< uint8_t > data
Payload of the package.
Thread for receiving messages from the serial device.
bool connect(const std::string &dev_name)
connecting to serial device and starting receive thread
ThreadStream & endl(ThreadStream &stream)
const size_t cPACKET_APPENDIX_SIZE
The packet overhead size in bytes.
uint8_t index
Continuosly incremented counter per package.
unsigned int m_packets_transmitted
packet counters
boost::shared_ptr< SVHReceiveThread > m_receive_thread
thread for receiving serial packets
bool m_connected
serial device connected state
boost::shared_ptr< Serial > m_serial_device
pointer to serial interface object
SVHSerialInterface(const ReceivedPacketCallback &received_packet_callback)
Constructs a serial interface class for basic communication with the SCHUNK five finger hand...
uint8_t last_index
used to wait to the response of the sending packet
Basic communication handler for the SCHUNK five finger hand.
void resetTransmitPackageCount()
resetTransmitPackageCount Resets the transmitpackage count to zero
#define LOGGING_TRACE_C(streamname, classname, arg)
#define LOGGING_ERROR_C(streamname, classname, arg)
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.