From 96d1c54e540cd805d1ff96087e4a9b9aff73473f Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 9 May 2012 21:13:52 +0200 Subject: [PATCH] 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. --- libowlps-client/libowlps-client.c | 4 ++-- owlps-client/owlps-client.c | 28 ++++++++++++++-------------- owlps-listener/owlps-listenerd.c | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libowlps-client/libowlps-client.c b/libowlps-client/libowlps-client.c index 6def3f0..29b2d59 100644 --- a/libowlps-client/libowlps-client.c +++ b/libowlps-client/libowlps-client.c @@ -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)], - ¤t_pkt, sizeof(uint16_t)) ; + // Update the packet number: + memcpy(&((char*) packet)[1], ¤t_pkt, sizeof(uint16_t)) ; owl_send_packet(sockfd, server, packet, packet_size) ; } diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index 6d4dd81..70d15c8 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -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) ; diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index f75fd53..3e5bc94 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -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