[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:
parent
b22a42a524
commit
91609a40fe
|
@ -27,8 +27,10 @@ HEADER=
|
||||||
# Flags
|
# Flags
|
||||||
LIBOWLPS_DIR = ../libowlps
|
LIBOWLPS_DIR = ../libowlps
|
||||||
LIBOWLPSCLIENT_DIR = ../libowlps-client
|
LIBOWLPSCLIENT_DIR = ../libowlps-client
|
||||||
|
LIBOWLPSRESULTREADER_DIR = ../libowlps-resultreader
|
||||||
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes \
|
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes \
|
||||||
-I$(LIBOWLPS_DIR) -I$(LIBOWLPSCLIENT_DIR)
|
-I$(LIBOWLPS_DIR) -I$(LIBOWLPSCLIENT_DIR) \
|
||||||
|
-I$(LIBOWLPSRESULTREADER_DIR)
|
||||||
#CFLAGS += -g -O0
|
#CFLAGS += -g -O0
|
||||||
DEPFLAGS = -MMD
|
DEPFLAGS = -MMD
|
||||||
XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
|
XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
|
||||||
|
@ -36,7 +38,8 @@ PICFLAG = -fPIC
|
||||||
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
|
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
|
||||||
OWLPSFLAGS += -D DEBUG
|
OWLPSFLAGS += -D DEBUG
|
||||||
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
|
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
|
||||||
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client
|
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client \
|
||||||
|
-L$(LIBOWLPSRESULTREADER_DIR) -lowlps-resultreader
|
||||||
|
|
||||||
OS := $(shell uname)
|
OS := $(shell uname)
|
||||||
ifeq ("$(OS)", "Linux")
|
ifeq ("$(OS)", "Linux")
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <owlps-client.h>
|
#include <owlps-client.h>
|
||||||
|
#include <owlps-resultreader.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -41,7 +42,7 @@ void print_configuration(void) ;
|
||||||
void create_socket(void) ;
|
void create_socket(void) ;
|
||||||
void make_packet(void) ;
|
void make_packet(void) ;
|
||||||
void send_request(void) ;
|
void send_request(void) ;
|
||||||
void receive_position(void) ;
|
int receive_position(void) ;
|
||||||
void print_usage(void) ;
|
void print_usage(void) ;
|
||||||
void print_version(void) ;
|
void print_version(void) ;
|
||||||
|
|
||||||
|
@ -87,6 +88,7 @@ uint_fast16_t packet_size ; // Packet size
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct sigaction action ; // Signal handler structure
|
struct sigaction action ; // Signal handler structure
|
||||||
|
int ret = 0 ;
|
||||||
|
|
||||||
program_name = argv[0] ;
|
program_name = argv[0] ;
|
||||||
parse_command_line(argc, argv) ;
|
parse_command_line(argc, argv) ;
|
||||||
|
@ -112,9 +114,9 @@ int main(int argc, char *argv[])
|
||||||
close(sockfd) ;
|
close(sockfd) ;
|
||||||
|
|
||||||
if (options.listening_port > 0)
|
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:
|
owl_result *result ;
|
||||||
float x, y, z ;
|
|
||||||
|
printf("Waiting for the result from the infrastructure...\n") ;
|
||||||
|
|
||||||
sockfd = owl_create_udp_listening_socket(options.listening_port) ;
|
sockfd = owl_create_udp_listening_socket(options.listening_port) ;
|
||||||
recvfrom(sockfd, &x, sizeof(float), 0, NULL, NULL) ;
|
if (sockfd < 0)
|
||||||
recvfrom(sockfd, &y, sizeof(float), 0, NULL, NULL) ;
|
return OWL_ERR_SOCKET_CREATE ;
|
||||||
recvfrom(sockfd, &z, sizeof(float), 0, NULL, NULL) ;
|
|
||||||
close(sockfd) ;
|
|
||||||
|
|
||||||
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 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue