154 lines
4.9 KiB
C
154 lines
4.9 KiB
C
/*
|
|
* 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
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
* 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.
|
|
*
|
|
***********************************************************************
|
|
*
|
|
* This is the header file of OwlPS Aggregator.
|
|
*/
|
|
|
|
|
|
#ifndef _OWLPS_AGGREGATOR_H_
|
|
#define _OWLPS_AGGREGATOR_H_
|
|
|
|
#include <owlps-config.h>
|
|
|
|
#include <owlps.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
/* Arguments & program configuration */
|
|
#define OPTIONS "Ac:C:Df:FGhH:i:k:K:l:o:O:p:qt:vV" // getopt string
|
|
#define DEFAULT_CONFIG_FILE OWL_CONFIG_PREFIX "/owlps-aggregator.conf"
|
|
#define DEFAULT_AGGREGATE_TIMEOUT 600 // milliseconds
|
|
#define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds
|
|
#define DEFAULT_CHECK_INTERVAL 300 // milliseconds
|
|
#define DEFAULT_CP_KEEP_TIMEOUT 35 // seconds
|
|
#define DEFAULT_AC_ORDER_INTERVAL 1000 // milliseconds
|
|
#define POSITIONER_DEFAULT_HOST "localhost"
|
|
|
|
|
|
/* Verbosity levels */
|
|
#define VERBOSE_QUIET cfg_getint(cfg, "verbose") == 0
|
|
#define VERBOSE_WARNING cfg_getint(cfg, "verbose") >= 1
|
|
#define VERBOSE_INFO cfg_getint(cfg, "verbose") >= 2
|
|
#define VERBOSE_CHATTERBOX cfg_getint(cfg, "verbose") >= 3
|
|
#define VERBOSE_REQUESTS cfg_getint(cfg, "verbose") >= 4
|
|
|
|
|
|
/* Linked list storing data of each request */
|
|
typedef struct _request_info_list
|
|
{
|
|
// Number of the current packet:
|
|
uint16_t packet_id ;
|
|
// MAC address of the transmitter CP (in bytes):
|
|
uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ;
|
|
// Timestamp of arrival on the listener:
|
|
owl_timestamp capture_time ;
|
|
// Signal strength received by the CP from the mobile:
|
|
int8_t ss_dbm ;
|
|
struct _request_info_list *next ;
|
|
} request_info_list ;
|
|
|
|
|
|
/* Linked list of the requests */
|
|
typedef struct _request_list
|
|
{
|
|
uint8_t type ;
|
|
|
|
// Number of packets sent by the mobile for this request:
|
|
uint16_t nb_packets ;
|
|
|
|
/* Request identifier */
|
|
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // Mobile MAC address
|
|
owl_timestamp request_time ; // Request time on the mobile
|
|
|
|
/* Calibration data */
|
|
float x_position ;
|
|
float y_position ;
|
|
float z_position ;
|
|
owl_direction direction ; // Request orientation
|
|
|
|
/* Other data */
|
|
uint8_t mobile_ip_addr_bytes[4] ; // Mobile IP address
|
|
// Arrival time of the first packet of the request on the aggregator:
|
|
owl_timestamp start_time ;
|
|
request_info_list *info ; // Data for this request
|
|
|
|
struct _request_list *next ;
|
|
} request_list ;
|
|
|
|
|
|
/* Linked list of the known CPs */
|
|
typedef struct _cp_list
|
|
{
|
|
uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
|
|
char ip_addr[INET_ADDRSTRLEN] ;
|
|
|
|
owl_timestamp last_seen ;
|
|
|
|
struct _cp_list *previous ;
|
|
struct _cp_list *next ;
|
|
} cp_list ;
|
|
|
|
|
|
/* Function headers */
|
|
int initialise_configuration(int argc, char **argv) ;
|
|
int parse_config_file(int argc, char **argv) ;
|
|
int parse_command_line(int argc, char **argv) ;
|
|
int check_configuration(void) ;
|
|
|
|
int read_loop(int sockfd) ;
|
|
void print_captured_request(const owl_captured_request *const request) ;
|
|
void got_request(const owl_captured_request *const request) ;
|
|
void add_captured_request(const owl_timestamp *const reception_time,
|
|
const owl_captured_request *const request,
|
|
request_info_list *const request_info) ;
|
|
|
|
void* monitor_requests(void *NULL_value) ;
|
|
void scan_request_list(FILE *const stream,
|
|
const int sockfd,
|
|
const struct sockaddr *const serv) ;
|
|
void flush_request_list(FILE *const stream,
|
|
const int sockfd,
|
|
const struct sockaddr *const serv) ;
|
|
void output_request(request_list *const request_ptr,
|
|
FILE *const stream,
|
|
const int sockfd,
|
|
const struct sockaddr *const serv) ;
|
|
|
|
#ifndef NDEBUG
|
|
void print_request_list(void) ;
|
|
void print_request_info(request_info_list *info) ;
|
|
#endif // NDEBUG
|
|
|
|
void* listen_for_cps(void *NULL_value) ;
|
|
void update_cp(uint8_t mac_addr_bytes[ETHER_ADDR_LEN],
|
|
char ip_addr[INET_ADDRSTRLEN]) ;
|
|
cp_list* find_cp(uint8_t mac_addr_bytes[ETHER_ADDR_LEN]) ;
|
|
cp_list* add_cp_front(uint8_t mac_addr_bytes[ETHER_ADDR_LEN]) ;
|
|
void update_cp_ip_addr(cp_list *cp, char ip_addr[INET_ADDRSTRLEN]) ;
|
|
void update_cp_seen(cp_list *cp) ;
|
|
void push_cp(cp_list *cp) ;
|
|
|
|
void* monitor_cps(void *NULL_value) ;
|
|
void delete_old_cps(void) ;
|
|
void delete_cp(cp_list *cp) ;
|
|
void unlink_cp(cp_list *cp) ;
|
|
void order_send(cp_list *cp) ;
|
|
void free_cp_list(void) ;
|
|
|
|
void print_usage(void) ;
|
|
void print_version(void) ;
|
|
|
|
#endif // _OWLPS_AGGREGATOR_H_
|