diff --git a/owlps-ardrone/Makefile b/owlps-ardrone/Makefile index 6ac4292..a7cfff8 100644 --- a/owlps-ardrone/Makefile +++ b/owlps-ardrone/Makefile @@ -27,8 +27,10 @@ DEPS = oc.o # Flags LIBOWLPS_DIR = ../libowlps LIBOWLPSCLIENT_DIR = ../libowlps-client +LIBOWLPSRESULTREADER_DIR = ../libowlps-resultreader CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes \ - -I$(LIBOWLPS_DIR) -I$(LIBOWLPSCLIENT_DIR) + -I$(LIBOWLPS_DIR) -I$(LIBOWLPSCLIENT_DIR) \ + -I$(LIBOWLPSRESULTREADER_DIR) #CFLAGS += -g -O0 DEPFLAGS = -MMD XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) @@ -37,9 +39,17 @@ OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" OWLPSFLAGS += -D DEBUG LIBS = -L$(LIBOWLPS_DIR) -lowlps \ -L$(LIBOWLPSCLIENT_DIR) -lowlps-client \ - -lrt -lm -pthread + -L$(LIBOWLPSRESULTREADER_DIR) -lowlps-resultreader \ + -lm -pthread + +OS := $(shell uname) +ifeq ("$(OS)", "Linux") + LIBS += -lrt +endif + STATIC_LIBS = + ## Cibles de compilation standard ## .PHONY : all dynamic static install uninstall clean purge help diff --git a/owlps-ardrone/owlps-drone.c b/owlps-ardrone/owlps-drone.c index 6dcd7a9..b20a116 100644 --- a/owlps-ardrone/owlps-drone.c +++ b/owlps-ardrone/owlps-drone.c @@ -5,6 +5,7 @@ #include "owlps-drone.h" #include +#include #include #include @@ -785,209 +786,24 @@ void send_request() void* receive_position(void* NULL_value) { // Position of the mobile as computed by the infrastructure: - char timestampXYZ[128] ; - char *data_cpy ; - while(run) - { - recvfrom(sockreceivefd, ×tampXYZ, 128, 0, NULL, NULL) ; - data_cpy = strdup(timestampXYZ) ; - string2data(data_cpy) ; - usleep(100000); - } - pthread_exit(NULL_value); -} - - -/* Split the string received from OwlPS Positioning and store the fields - * in a result structure. - * - * Handled CSV format: - * Mobile_MAC;Request_type;Request_timestamp;Algorithm;X;Y;Z;Error;Area - * The Request_timestamp format is: seconds.nanoseconds - */ -void string2data(char* string_data) -{ - char *mac = NULL ; - char *ptr = NULL ; - - const char delims[] = ";" ; - - int type_req = 0 ; - int count_algo= 0 ; - int count_print = 0 ; - int onetime = 0 ; - owl_bool error_present = owl_false ; - - while(onetime<1) - { - // Mobile MAC address - ptr = strtok(string_data, delims) ; - if(ptr==NULL) - { - print_error("mac") ; - break ; - } - mac = ptr ; - - // Request type - ptr = strtok(NULL, delims) ; - if (ptr==NULL) - { - print_error("request") ; - break ; - } - type_req = atoi(ptr) ; - - // Timestamp (seconds) - ptr = strtok(NULL, ".") ; - if (ptr==NULL) - { - print_error("timestamp") ; - break ; - } - sscanf(ptr, "%ld", ×tamp.tv_sec) ; - - // Timestamp (nanoseconds) - ptr = strtok(NULL, ";") ; - if (ptr==NULL) - { - print_error("timestamp") ; - break ; - } - sscanf(ptr, "%ld", ×tamp.tv_nsec) ; - ++onetime ; - } - result results[10]; + owl_result *result ; while(run) { - // Algorithm name - ptr = strtok(NULL, delims) ; - if (ptr == NULL) - break ; - strncpy(results[count_algo].algo, ptr, ALGO_STRLEN) ; - if(!strcmp(results[count_algo].algo,"Real")) - error_present = owl_true ; - - // X coordinate - ptr = strtok(NULL, delims) ; - if(ptr==NULL) + result = owl_receive_position(sockreceivefd) ; + if (result) { - if(count_algo==0) - { - print_error ("trame"); - break ; - } - else - { - print_error ("algo"); - count_algo-- ; - break ; - } + owl_print_result(result) ; + owl_free_result(result) ; } - results[count_algo].x = atof(ptr) ; - - // Y coordinate - ptr = strtok(NULL, delims) ; - if(ptr==NULL) - { - if(count_algo==0) - { - print_error ("trame"); - break ; - } - else - { - print_error ("algo"); - count_algo--; - break ; - } - } - results[count_algo].y = atof(ptr) ; - - // Z coordinate - ptr = strtok(NULL, delims) ; - if(ptr==NULL) - { - if(count_algo==0) - { - print_error ("trame"); - break ; - } - else - { - print_error("algo") ; - count_algo--; - break ; - } - } - results[count_algo].z = atof(ptr) ; - - // Distance error - if (error_present) - { - ptr = strtok(NULL, delims) ; - if(ptr==NULL) - { - if(count_algo==0) - { - print_error ("trame"); - break ; - } - else - { - print_error ("algo"); - count_algo--; - break ; - } - } - results[count_algo].error = atof(ptr) ; - } - ++count_algo ; - - // Area name - ptr = strtok(NULL, delims) ; - if (ptr == NULL) - { - if (count_algo == 0) - { - print_error("trame") ; - break ; - } - else - { - print_error("algo") ; - count_algo-- ; - break ; - } - } - strncpy(results[count_algo].area, ptr, AREA_STRLEN) ; + usleep(100000) ; } - for (count_print = 0 ; count_print < count_algo ; ++count_print) - printf("\n----------------\n" - " Mobile's MAC address: %s\n" - " Request type: %d\n" - " Timestamp: %ld.%ld\n" - " Algorithm: %s\n" - " X: %f\n" - " Y: %f\n" - " Z: %f\n" - " Distance error: %f\n" - " Area: %s\n" - "------------------\n", - mac, - type_req, - timestamp.tv_sec, timestamp.tv_nsec, - results[count_print].algo, - results[count_print].x, - results[count_print].y, - results[count_print].z, - results[count_print].error, - results[count_print].area) ; + pthread_exit(NULL_value) ; } + void print_error(char* merror) { if (! strcmp(merror,"trame")) diff --git a/owlps-ardrone/owlps-drone.h b/owlps-ardrone/owlps-drone.h index bae6da7..221de2d 100644 --- a/owlps-ardrone/owlps-drone.h +++ b/owlps-ardrone/owlps-drone.h @@ -39,17 +39,6 @@ #define ERR_BAD_USAGE 1 // Bad program call (bad number of arguments) -/* Result from OwlPS Positioning (parsed string structure) */ -typedef struct _result -{ - char algo[ALGO_STRLEN]; - float x; - float y; - float z; - float error ; - char area[AREA_STRLEN] ; -} result ; - typedef struct _gps { float time;