owlps/libowlps-resultreader/owlps-resultreader-udp.c

55 lines
1.3 KiB
C

/*
* This file is part of the Owl Positioning System (OwlPS).
* OwlPS is a project of the University of Franche-Comté
* (Université de Franche-Comté), France.
*
* This is the main source file of OwlPS ResultReader-UDP, a simple
* program demonstrating the use of libowlps-resultreader-udp.
* The received results are printed on the standard output.
*
* This program must be linked against libowlps and its dependencies
* (see the Makefile).
*/
#include "owlps-resultreader.h"
#include <signal.h>
#include <unistd.h>
int main(void)
{
struct sigaction action ; // Signal handler structure
owl_result *result ;
int sockfd ;
/* Set up signal handlers */
action.sa_flags = 0 ;
sigemptyset(&action.sa_mask) ;
action.sa_handler = owl_sigint_handler ;
sigaction(SIGINT, &action, NULL) ;
action.sa_handler = owl_sigterm_handler ;
sigaction(SIGTERM, &action, NULL) ;
/* Open the socket */
sockfd = owl_create_udp_listening_socket(OWL_DEFAULT_RESULT_PORT) ;
if (sockfd < 0)
return 1 ;
/* Read loop */
owl_run = owl_true ;
while (owl_run)
{
if (! (result = owl_receive_position(sockfd)))
return 1 ;
owl_print_result(result) ;
owl_free_result(result) ;
printf("--------------\n") ;
}
/* Cleaning */
close(sockfd) ;
return 0 ;
}