2011-08-18 23:10:49 +02:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
2016-11-03 05:10:34 +01:00
|
|
|
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
|
2013-05-29 18:43:35 +02:00
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-11-03 14:52:33 +01:00
|
|
|
*
|
|
|
|
***********************************************************************
|
|
|
|
*
|
2012-02-06 16:44:09 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2013-06-04 02:28:13 +02:00
|
|
|
* This program must be linked against libowlps-resultreader and
|
|
|
|
* libowlps.
|
2011-08-18 23:10:49 +02:00
|
|
|
*/
|
|
|
|
|
2012-02-06 16:44:09 +01:00
|
|
|
|
2011-08-22 21:51:30 +02:00
|
|
|
#include "owlps-resultreader.h"
|
2013-06-04 02:28:13 +02:00
|
|
|
#include <owlps.h>
|
2011-08-18 23:10:49 +02:00
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
#include <signal.h>
|
2011-08-18 23:10:49 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2011-08-20 11:10:12 +02:00
|
|
|
struct sigaction action ; // Signal handler structure
|
2011-08-18 23:10:49 +02:00
|
|
|
owl_result *result ;
|
|
|
|
int sockfd ;
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* 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 */
|
2011-08-20 19:28:31 +02:00
|
|
|
sockfd = owl_create_udp_listening_socket(OWL_DEFAULT_RESULT_PORT) ;
|
2011-08-18 23:10:49 +02:00
|
|
|
if (sockfd < 0)
|
|
|
|
return 1 ;
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* Read loop */
|
2013-05-15 21:46:13 +02:00
|
|
|
owl_run = true ;
|
2011-08-20 11:10:12 +02:00
|
|
|
while (owl_run)
|
2011-08-18 23:10:49 +02:00
|
|
|
{
|
2011-08-20 08:57:29 +02:00
|
|
|
if (! (result = owl_receive_position(sockfd)))
|
2011-08-18 23:10:49 +02:00
|
|
|
return 1 ;
|
|
|
|
owl_print_result(result) ;
|
|
|
|
owl_free_result(result) ;
|
|
|
|
printf("--------------\n") ;
|
|
|
|
}
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* Cleaning */
|
2011-08-18 23:10:49 +02:00
|
|
|
close(sockfd) ;
|
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
}
|