35 for (
int i = 0; i <
size; i++) {
46 for (
int i = 0; i <
size; i++) {
62 unsigned char * buffer = &
packet[3];
66 for (n =
size - 5; n > 1; ) {
67 c += (*(buffer) << 8) | *(buffer + 1);
73 c ^=
static_cast<int>(*(buffer++));
81 unsigned char prefix[3];
87 ::memset(prefix, 0,
sizeof(prefix));
92 if ((cnt += read(fd, &prefix[2], 1)) < 0) {
94 "Error reading packet.hppeader from robot connection: P2OSPacket():Receive():read():");
99 if (prefix[0] == 0xFA && prefix[1] == 0xFB) {
107 prefix[0] = prefix[1];
108 prefix[1] = prefix[2];
113 size = prefix[2] + 3;
114 memcpy(
packet, prefix, 3);
117 while (cnt != prefix[2]) {
118 if ((cnt += read(fd, &
packet[3 + cnt], prefix[2] - cnt)) < 0) {
120 "Error reading packet body from robot connection: P2OSPacket():Receive():read():");
139 ROS_ERROR(
"Packet to P2OS can't be larger than 200 bytes");
144 memcpy(&
packet[3], data, datasize);
147 packet[3 + datasize] = chksum >> 8;
148 packet[3 + datasize + 1] = chksum & 0xFF;
161 while (cnt !=
size) {
unsigned char packet[packet_len]
int Build(unsigned char *data, unsigned char datasize)