diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h index b0d8c6c..0bcf13c 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h @@ -15,11 +15,13 @@ /* Arguments & program configuration */ -#define OPTIONS "Aa:c:f:hi:k:l:o:p:t:" // getopt string +#define OPTIONS "Aa:c:C:f:hi:k:K:l:o:p:t:" // 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" diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c index aa59748..43a2b51 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c @@ -103,8 +103,12 @@ void parse_config_file(int argc, char **argv) // Autocalibration activated? CFG_BOOL("autocalibration", cfg_false, CFGF_NONE), // Port on which autocalibration data are exchanged: - CFG_INT("autocalbration_port", AUTOCALIBRATION_DEFAULT_PORT, + CFG_INT("autocalbration_port", DEFAULT_AUTOCALIBRATION_PORT, CFGF_NONE), + // Time we keep APs in the list (in seconds): + CFG_INT("ap_keep_timeout", DEFAULT_AP_KEEP_TIMEOUT, CFGF_NONE), + // Time between two checks of the AP list (in milliseconds): + CFG_INT("ap_check_interval", DEFAULT_AP_CHECK_INTERVAL, CFGF_NONE), CFG_END() } ; @@ -168,6 +172,9 @@ void parse_command_line(int argc, char **argv) case 'c' : cfg_setint(cfg, "check_interval", strtol(optarg, NULL, 0)) ; break ; + case 'C' : + cfg_setint(cfg, "ap_check_interval", strtol(optarg, NULL, 0)) ; + break ; case 'f' : // Config file break ; // (already parsed) case 'h' : @@ -179,6 +186,9 @@ void parse_command_line(int argc, char **argv) case 'k' : cfg_setint(cfg, "keep_timeout", strtol(optarg, NULL, 0)) ; break ; + case 'K' : + cfg_setint(cfg, "ap_keep_timeout", strtol(optarg, NULL, 0)) ; + break ; case 'l' : cfg_setint(cfg, "listening_port", strtol(optarg, NULL, 0)) ; break ; @@ -247,6 +257,26 @@ void check_configuration() #endif // DEBUG cfg_setint(cfg, "check_interval", DEFAULT_CHECK_INTERVAL) ; } + + // ap_keep_timeout // + if (cfg_getint(cfg, "ap_keep_timeout") < 0) + { +#ifdef DEBUG + fprintf(stderr, "Warning! ap_keep_timeout cannot be negative:" + " failing back to default value.\n") ; +#endif // DEBUG + cfg_setint(cfg, "ap_keep_timeout", DEFAULT_AP_KEEP_TIMEOUT) ; + } + + // ap_check_interval // + if (cfg_getint(cfg, "ap_check_interval") < 0) + { +#ifdef DEBUG + fprintf(stderr, "Warning! ap_check_interval cannot be negative:" + " failing back to default value.\n") ; +#endif // DEBUG + cfg_setint(cfg, "ap_check_interval", DEFAULT_AP_CHECK_INTERVAL) ; + } } @@ -763,7 +793,7 @@ void monitor_aps() if (nb_aps > 1) order_send(aps) ; - usleep(cfg_getint(cfg, "ap_check_interval")) ; + usleep(cfg_getint(cfg, "ap_check_interval") * 1000) ; } } @@ -779,7 +809,7 @@ void delete_old_aps() while (aps != NULL) if (sub_date(aps->last_seen, now) > - (unsigned long) cfg_getint(cfg, "keep_ap_timeout")) + (unsigned long) cfg_getint(cfg, "ap_keep_timeout") * 1000) delete_ap(aps) ; else return ; @@ -819,9 +849,25 @@ void unlink_ap(ap_list *ap) } +/* + * Sends a send order to the given AP. + */ void order_send(ap_list *ap) { + autocalibration_order message ; + struct sockaddr_in serv; + struct sockaddr_in client ; + socklen_t serv_len = sizeof(serv); + int sockfd = + create_udp_sending_socket(ap->ip_addr, + cfg_getint(cfg, "autocalibration_port"), + &serv, &client) ; + message.order = AUTOCALIBRATION_ORDER_SEND ; + sendto(sockfd, (void *)&message, sizeof(message), 0, + (struct sockaddr *)&serv, serv_len) ; + + (void) close(sockfd) ; } @@ -970,8 +1016,8 @@ void print_usage() "Aggregation options:\n" "\t-t aggregate_timeout\tRequests are stored during" - " 'aggregate_timeout' before to be grouped (default:" - " %d millisecondes).\n" + " 'aggregate_timeout' milliseconds before to be grouped" + " (default: %d ms).\n" "\t-k keep_timeout\t\tAggregated requests are kept during" " 'keep_timeout' milliseconds (default: %d milliseconds).\n" "\t-c check_interval\tTime between two checks of the stored" @@ -981,6 +1027,10 @@ void print_usage() "\t-A\tEnable autocalibration (default: disabled).\n" "\t-a port\tPort on which autocalibration data" " are exchanged with the listeners (default: %d).\n" + "\t-K ap_keep_timeout\tInactive APs are kept during" + " 'ap_keep_timeout' seconds (default: %d s).\n" + "\t-C ap_check_interval\tTime (in milliseconds) between two" + " checks of the stored APs (default: %d ms).\n" , program_name, AGGREGATE_DEFAULT_PORT, @@ -989,6 +1039,8 @@ void print_usage() DEFAULT_AGGREGATE_TIMEOUT, DEFAULT_KEEP_TIMEOUT, DEFAULT_CHECK_INTERVAL, - AUTOCALIBRATION_DEFAULT_PORT + DEFAULT_AUTOCALIBRATION_PORT, + DEFAULT_AP_KEEP_TIMEOUT, + DEFAULT_AP_CHECK_INTERVAL ) ; } diff --git a/infrastructure-centred/owlps-listener/owlps-listener.h b/infrastructure-centred/owlps-listener/owlps-listener.h index ef14216..79fef70 100644 --- a/infrastructure-centred/owlps-listener/owlps-listener.h +++ b/infrastructure-centred/owlps-listener/owlps-listener.h @@ -51,9 +51,9 @@ #define OPTIONS "Aa:d:f:hH:kl:m:n:p:qr:t:vw:" // getopt string #define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf" enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ; -#define AUTOCALIBRATION_DEFAULT_HELLO_DELAY 120 // seconds -#define AUTOCALIBRATION_DEFAULT_DELAY 25000 // ms -#define AUTOCALIBRATION_DEFAULT_NBPKT 20 +#define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds +#define DEFAULT_AUTOCALIBRATION_DELAY 25000 // ms +#define DEFAULT_AUTOCALIBRATION_NBPKT 20 /* Error codes */ diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index bb79a7b..c580d29 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -53,10 +53,10 @@ struct { "", #ifdef USE_PTHREAD FALSE, - AUTOCALIBRATION_DEFAULT_PORT, - AUTOCALIBRATION_DEFAULT_HELLO_DELAY, - AUTOCALIBRATION_DEFAULT_DELAY, - AUTOCALIBRATION_DEFAULT_NBPKT, + DEFAULT_AUTOCALIBRATION_PORT, + DEFAULT_AUTOCALIBRATION_HELLO_DELAY, + DEFAULT_AUTOCALIBRATION_DELAY, + DEFAULT_AUTOCALIBRATION_NBPKT, #endif // USE_PTHREAD FALSE } ; @@ -163,18 +163,18 @@ void parse_config_file(int argc, char **argv) // Autocalibration activated? CFG_BOOL("autocalibration", cfg_false, CFGF_NONE), // Port on which autocalibration data are exchanged: - CFG_INT("autocalibration_port", AUTOCALIBRATION_DEFAULT_PORT, + CFG_INT("autocalibration_port", DEFAULT_AUTOCALIBRATION_PORT, CFGF_NONE), // Delay between two hello messages: CFG_INT("autocalibration_hello_delay", - AUTOCALIBRATION_DEFAULT_HELLO_DELAY, + DEFAULT_AUTOCALIBRATION_HELLO_DELAY, CFGF_NONE), // Delay between two calibration packet transmission: - CFG_INT("autocalibration_delay", AUTOCALIBRATION_DEFAULT_DELAY, + CFG_INT("autocalibration_delay", DEFAULT_AUTOCALIBRATION_DELAY, CFGF_NONE), // Number of packets for a calibration request: CFG_INT("autocalibration_nb_packets", - AUTOCALIBRATION_DEFAULT_NBPKT, CFGF_NONE), + DEFAULT_AUTOCALIBRATION_NBPKT, CFGF_NONE), #endif // USE_PTHREAD // Display capture packets, or not: CFG_BOOL("verbose", cfg_false, CFGF_NONE), @@ -1005,9 +1005,9 @@ void print_usage() DEFAULT_CONFIG_FILE, LOC_REQUEST_DEFAULT_PORT, AGGREGATE_DEFAULT_PORT, - AUTOCALIBRATION_DEFAULT_PORT, - AUTOCALIBRATION_DEFAULT_HELLO_DELAY, - AUTOCALIBRATION_DEFAULT_DELAY, - AUTOCALIBRATION_DEFAULT_NBPKT + DEFAULT_AUTOCALIBRATION_PORT, + DEFAULT_AUTOCALIBRATION_HELLO_DELAY, + DEFAULT_AUTOCALIBRATION_DELAY, + DEFAULT_AUTOCALIBRATION_NBPKT ) ; } diff --git a/libowlps/owlps.h b/libowlps/owlps.h index f9fe4d1..8c65de9 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -44,7 +44,7 @@ #define POSITIONER_DEFAULT_PORT 9902 // Port on which listener listens for order from aggregator: #define LISTENER_DEFAULT_PORT 9903 -#define AUTOCALIBRATION_DEFAULT_PORT 9904 +#define DEFAULT_AUTOCALIBRATION_PORT 9904 // Port on which the mobile listens for its position: #define MOBILE_DEFAULT_PORT 9910