From 91609a40fe7f23521627b71cd231e7cb6849627a Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 26 Aug 2011 16:00:22 +0200 Subject: [PATCH] [Client] Use libowlps-resultreader Use functions from libowlps-resultreader in receive_position(). By the way, this function is still not really useful, as we do not verify that the received result correspond to the set request. --- owlps-client/Makefile | 7 +++++-- owlps-client/owlps-client.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/owlps-client/Makefile b/owlps-client/Makefile index a81b1da..859a08d 100644 --- a/owlps-client/Makefile +++ b/owlps-client/Makefile @@ -27,8 +27,10 @@ HEADER= # 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) @@ -36,7 +38,8 @@ PICFLAG = -fPIC OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" OWLPSFLAGS += -D DEBUG LIBS = -L$(LIBOWLPS_DIR) -lowlps \ - -L$(LIBOWLPSCLIENT_DIR) -lowlps-client + -L$(LIBOWLPSCLIENT_DIR) -lowlps-client \ + -L$(LIBOWLPSRESULTREADER_DIR) -lowlps-resultreader OS := $(shell uname) ifeq ("$(OS)", "Linux") diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index 2103a8b..e3a5718 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -3,6 +3,7 @@ */ #include +#include #include #include @@ -41,7 +42,7 @@ void print_configuration(void) ; void create_socket(void) ; void make_packet(void) ; void send_request(void) ; -void receive_position(void) ; +int receive_position(void) ; void print_usage(void) ; void print_version(void) ; @@ -87,6 +88,7 @@ uint_fast16_t packet_size ; // Packet size int main(int argc, char *argv[]) { struct sigaction action ; // Signal handler structure + int ret = 0 ; program_name = argv[0] ; parse_command_line(argc, argv) ; @@ -112,9 +114,9 @@ int main(int argc, char *argv[]) close(sockfd) ; if (options.listening_port > 0) - receive_position() ; + ret = receive_position() ; - return 0 ; + return ret ; } @@ -450,18 +452,31 @@ void make_packet() -void receive_position() +/* + * Receives a position computed by the infrastructure. + * Note that it is currently not guaranteed that the received result + * correspond to the request sent. + * Returns 0, or a non-zero value in case of error. + */ +int receive_position() { - // Position of the mobile as computed by the infrastructure: - float x, y, z ; + owl_result *result ; + + printf("Waiting for the result from the infrastructure...\n") ; sockfd = owl_create_udp_listening_socket(options.listening_port) ; - recvfrom(sockfd, &x, sizeof(float), 0, NULL, NULL) ; - recvfrom(sockfd, &y, sizeof(float), 0, NULL, NULL) ; - recvfrom(sockfd, &z, sizeof(float), 0, NULL, NULL) ; - close(sockfd) ; + if (sockfd < 0) + return OWL_ERR_SOCKET_CREATE ; - printf("Computed position: (%.4f;%.4f;%.4f)\n", x, y, z) ; + result = owl_receive_position(sockfd) ; + if (result == NULL) + return OWL_ERR_SOCKET_RECV ; + + close(sockfd) ; + owl_print_result(result) ; + owl_free_result(result) ; + + return 0 ; }