4 inline void printHex(
char * data,
int length) {
5 for(
int i = 0; i < length; ++i) {
6 printf(
"0x%.2X ", (
unsigned)(
unsigned char)data[i]);
22 unsigned char usb_packet[18];
23 bool packet_complete =
false;
26 while(!packet_complete && !this->
canceled) {
39 if(packet_index == 0 && this->
data_buffer[0] == 0xF0) {
46 }
else if(packet_index == 0) {
52 if(packet_index == 1 && this->
data_buffer[0] == 0x55) {
59 }
else if(packet_index == 1) {
72 }
else if(packet_index == 2) {
80 if(packet_index >= 3) {
90 if(packet_index == 18)
91 packet_complete =
true;
100 packet.
channel = usb_packet[2];
101 packet.
id = ((usb_packet[4] << 3) | ((usb_packet[5] >> 5) & 7)) & 0x0fff;
102 for (
int i = 0; i < 8; i++) {
103 packet.
data[i] = usb_packet[i + 9];
110 unsigned char usb_packet[18] = {0xF0, 0x55, 0x00, 0x00, 0x00, 0x00, 0x04,
111 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00};
114 usb_packet[6] = (packet.
id & 0xFF00) >> 8;
115 usb_packet[7] = packet.
id & 0x00FF;
117 usb_packet[2] = packet.
channel;
119 for(
int i = 0; i < 8; ++i) {
120 usb_packet[9+i] = packet.
data[i];
126 this->
write(usb_packet, 18);
139 unsigned short checksum = 0;
140 unsigned short checksum_hi = 0;
142 for(
int i = 0; i < 17; i++) {
143 checksum += (short)usb_packet[i];
146 checksum_hi = (
unsigned short)(checksum >> 8);
148 checksum += checksum_hi;
149 checksum_hi = (
unsigned short)(checksum >> 8);
151 checksum += checksum_hi;
152 checksum = (~checksum + 1) & 0xff;
153 return (
unsigned char)checksum;
unsigned char computeChecksum(unsigned char *usb_packet)
void sendPacket(Packet &packet)
std::vector< unsigned char > data_buffer
void printHex(char *data, int length)
static unsigned int BUFFER_SIZE
void getPacket(Packet &packet)
virtual int read(unsigned char *buffer, int size)=0
#define RMP_THROW_MSG_AND_ID(ExceptionClass, Message, Id)
virtual int write(unsigned char *buffer, int size)=0