[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.
This commit is contained in:
Matteo Cypriani 2011-08-26 16:00:22 +02:00
parent b22a42a524
commit 91609a40fe
2 changed files with 31 additions and 13 deletions

View File

@ -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")

View File

@ -3,6 +3,7 @@
*/
#include <owlps-client.h>
#include <owlps-resultreader.h>
#include <stdio.h>
#include <stdlib.h>
@ -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 ;
}