Send number of packets at the beginning of request

The packet number and number of packets are now sent right after the
packet type, instead of at the end of the request.
This commit is contained in:
Matteo Cypriani 2012-05-09 21:13:52 +02:00
parent f0e23521c3
commit 96d1c54e54
3 changed files with 25 additions and 25 deletions

View File

@ -104,8 +104,8 @@ void owl_send_request(const int sockfd,
owl_msleep(delay) ; // Wait during the wanted delay
if (! owl_run)
break ;
memcpy(&((char*) packet)[packet_size - sizeof(uint16_t)],
&current_pkt, sizeof(uint16_t)) ;
// Update the packet number:
memcpy(&((char*) packet)[1], &current_pkt, sizeof(uint16_t)) ;
owl_send_packet(sockfd, server, packet, packet_size) ;
}

View File

@ -460,6 +460,14 @@ void make_packet()
// Packet type:
memset(&packet[offset++], OWL_REQUEST_CALIBRATION, 1) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of packets:
npkt = htons(options.nb_pkt) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Request time:
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ;
@ -479,19 +487,11 @@ void make_packet()
memcpy(&packet[offset], &options.y, sizeof(float)) ;
offset += sizeof(float) ;
memcpy(&packet[offset], &options.z, sizeof(float)) ;
offset += sizeof(float) ;
// Convert the coordinates back to the host endianess (mandatory
// in flood mode):
options.x = owl_ntohf(options.x) ;
options.y = owl_ntohf(options.y) ;
options.z = owl_ntohf(options.z) ;
// Number of packets:
npkt = htons(options.nb_pkt) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
}
else // Standard packet
@ -505,16 +505,16 @@ void make_packet()
// Packet type:
memset(&packet[offset++], OWL_REQUEST_NORMAL, 1) ;
// Request time:
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of packets:
npkt = htons(options.nb_pkt) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&packet[offset], &npkt, sizeof(uint16_t)) ;
// Request time:
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
}
printf("Packet timestamp: %s\n", request_time_str) ;

View File

@ -1494,6 +1494,14 @@ uint_fast16_t make_packet(uint8_t **packet)
// Request type:
memset(&pkt[offset++], OWL_REQUEST_AUTOCALIBRATION, 1) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of packets:
npkt = htons(GET_AUTOCALIBRATION_NBPKT()) ;
memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Timestamp:
memcpy(&pkt[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ;
@ -1504,16 +1512,8 @@ uint_fast16_t make_packet(uint8_t **packet)
memcpy(&pkt[offset], &my_position_y, sizeof(float)) ;
offset += sizeof(float) ;
memcpy(&pkt[offset], &my_position_z, sizeof(float)) ;
offset += sizeof(float) ;
// Number of packets:
npkt = htons(GET_AUTOCALIBRATION_NBPKT()) ;
memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ;
offset += sizeof(uint16_t) ;
// Number of the current packet (1 for the first):
npkt = htons(1u) ;
memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ;
#ifndef NDEBUG
offset += sizeof(uint16_t) ;
offset += sizeof(float) ;
assert(offset == size) ;
#endif // NDEBUG