118 lines
3.2 KiB
C
118 lines
3.2 KiB
C
/*
|
|
* This file is part of the rtap localisation project.
|
|
*/
|
|
|
|
#ifndef _OWLPS_AGGREGATOR_H_
|
|
#define _OWLPS_AGGREGATOR_H_
|
|
|
|
#include <owlps.h>
|
|
|
|
#include <confuse.h>
|
|
|
|
#define DEBUG
|
|
|
|
// Uncomment to output the timestamp on each line of the output file:
|
|
//#define USE_TIMESTAMP
|
|
|
|
|
|
/* Arguments & program configuration */
|
|
#define OPTIONS "Aa:c:C:f:hi:k:K:l:o:p:t:v" // getopt string
|
|
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-aggregator.conf"
|
|
#define DEFAULT_AGGREGATE_TIMEOUT 1500 // milliseconds
|
|
#define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds
|
|
#define DEFAULT_CHECK_INTERVAL 500000 // microseconds
|
|
#define DEFAULT_AP_KEEP_TIMEOUT 600 // s
|
|
#define DEFAULT_AP_CHECK_INTERVAL 1000 // ms
|
|
#define POSITIONER_DEFAULT_IP "127.0.0.1"
|
|
|
|
|
|
/* Error codes */
|
|
#define ERR_NO_MESSAGE_RECEIVED 1 // Error when reading the socket
|
|
#define ERR_CREATING_SOCKET 2 // Erreur when creating listening socket
|
|
#define ERR_BAD_USAGE 3 // Bad program call
|
|
#define ERR_PARSING_CONFIG_FILE 4 // Error reading the configuration file
|
|
#define ERR_SENDING_INFO 5 // Error sending a message on a socket
|
|
#define ERR_CREATING_THREAD 6 // Error creating a thread
|
|
|
|
|
|
/* Linked list storing data of each request */
|
|
typedef struct _request_info_list
|
|
{
|
|
// MAC address of the data sender (in bytes):
|
|
uint8_t ap_mac_addr_bytes[6] ;
|
|
// Signal strength received by the AP from the mobile:
|
|
uint8_t antenna_signal_dbm ;
|
|
struct _request_info_list *next ;
|
|
} request_info_list ;
|
|
|
|
|
|
/* Linked list of the requests */
|
|
typedef struct _request_list
|
|
{
|
|
/* Request identifier */
|
|
uint8_t mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
|
|
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 */
|
|
// 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 APs */
|
|
typedef struct _ap_list
|
|
{
|
|
uint8_t mac_addr_bytes[6] ;
|
|
char ip_addr[INET_ADDRSTRLEN] ;
|
|
|
|
owl_timestamp last_seen ;
|
|
|
|
struct _ap_list *previous ;
|
|
struct _ap_list *next ;
|
|
} ap_list ;
|
|
|
|
|
|
/* Function headers */
|
|
void initialise_configuration(int argc, char **argv) ;
|
|
void parse_config_file(int argc, char **argv) ;
|
|
void parse_command_line(int argc, char **argv) ;
|
|
void check_configuration(void) ;
|
|
|
|
int read_loop(int sockfd) ;
|
|
void got_request(owl_captured_request request) ;
|
|
|
|
void* monitor_requests(void *NULL_value) ;
|
|
void free_request_list(void) ;
|
|
#ifdef DEBUG
|
|
void print_request_list(void) ;
|
|
void print_request_info(request_info_list *info) ;
|
|
#endif // DEBUG
|
|
|
|
void* listen_for_aps(void *NULL_value) ;
|
|
void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN]) ;
|
|
ap_list* find_ap(uint8_t mac_addr_bytes[6]) ;
|
|
ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) ;
|
|
void update_ap_ip_addr(ap_list *ap, char ip_addr[INET_ADDRSTRLEN]) ;
|
|
void update_ap_seen(ap_list *ap) ;
|
|
void push_ap(ap_list *ap) ;
|
|
|
|
void* monitor_aps(void *NULL_value) ;
|
|
void delete_old_aps(void) ;
|
|
void delete_ap(ap_list *ap) ;
|
|
void unlink_ap(ap_list *ap) ;
|
|
void order_send(ap_list *ap) ;
|
|
void free_ap_list(void) ;
|
|
|
|
void print_usage(void) ;
|
|
|
|
#endif // _OWLPS_AGGREGATOR_H_
|