[Client] make_packet(): include the packet number

The prepared packet now includes the number of packets of the request
and the current packet ID. The packet ID is initialised to 1 for the
first packet.
This commit is contained in:
Matteo Cypriani 2011-10-24 15:16:45 +02:00
parent 5939bdbd04
commit 8e7aac1e6e
1 changed files with 36 additions and 10 deletions

View File

@ -440,6 +440,7 @@ void make_packet()
uint_fast16_t offset ; // Index used to create the packet
owl_timestamp request_time ;
char request_time_str[OWL_TIMESTAMP_STRLEN] ;
uint16_t npkt ;
// Get the current time and copy it as a string before to switch it to
// network endianess:
@ -453,42 +454,67 @@ void make_packet()
offset = 0 ;
packet_size =
sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 ;
sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 +
sizeof(uint16_t) * 2 ;
packet = malloc(packet_size) ;
memset(&packet[offset], OWL_REQUEST_CALIBRATION, 1) ; // Packet type
++offset ;
// Packet type:
memset(&packet[offset++], OWL_REQUEST_CALIBRATION, 1) ;
// Request time:
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ;
packet[offset++] = options.direction ; // Direction
// Direction:
packet[offset++] = options.direction ;
#ifdef DEBUG
printf("Direction = %d, X = %f, Y = %f, Z = %f\n",
packet[offset - 1], options.x, options.y, options.z) ;
#endif // DEBUG
// Convert the coordinates to the network endianess
// Convert the coordinates to the network endianess:
options.x = owl_htonf(options.x) ;
options.y = owl_htonf(options.y) ;
options.z = owl_htonf(options.z) ;
// Copy the coordinates to the packet
// Copy the coordinates to the packet:
memcpy(&packet[offset], &options.x, sizeof(float)) ;
offset += sizeof(float) ;
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)
// 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
{
printf("Preparing request packet...\n") ;
packet_size = sizeof(uint8_t) + sizeof(owl_timestamp) ;
offset = 0 ;
packet_size =
sizeof(uint8_t) + sizeof(owl_timestamp) + sizeof(uint16_t) * 2 ;
packet = malloc(packet_size) ;
memset(&packet[0], OWL_REQUEST_NORMAL, 1) ; // Packet type
memcpy(&packet[1], &request_time, sizeof(request_time)) ;
// 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 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)) ;
}
printf("Packet timestamp: %s\n", request_time_str) ;