diff --git a/scripts/owlps-aggsetcoord.pl b/scripts/owlps-aggsetcoord.pl index 860fe26..5ca8888 100755 --- a/scripts/owlps-aggsetcoord.pl +++ b/scripts/owlps-aggsetcoord.pl @@ -7,7 +7,11 @@ owlps-aggsetcoord - set the coordinates in an aggregation CSV file =head1 SYNOPSIS -B [ B<-h> | B<-V> ] [ B<-v> ] [ > ] +B +[ B<-h> | B<-V> ] +[ B<-v> ] +[ B<-m> > ] +[ > ] =head1 DESCRIPTION @@ -33,10 +37,6 @@ standard input is read. =over 3 -=item * -The mobile terminal's MAC address is not taken into account, so if the input -file includes several mobiles the results won't make any sense. - =item * It is not yet possible to choose an interval of lines to work on: the whole file is treated. @@ -60,6 +60,10 @@ Print version message and exit. Turn on verbose mode (displays a trace on the standard error). +=item B<-m> > + +Work only on positioning requests transmitted by MAC address I. + =back @@ -91,6 +95,7 @@ use OwlPS::CSV; use constant FORMAT_VERSION => 1; # Indexes of the fields in the CSV lines (first field is #0) +use constant MAC_FIELD_INDEX => 1; use constant TYPE_FIELD_INDEX => 2; use constant TIMESTAMP_FIELD_INDEX => 4; use constant X_FIELD_INDEX => 5; @@ -109,6 +114,9 @@ use constant BASE_COORD => "0.00"; # Verbose mode my $verbose; +# Selected transmitter's MAC address (will stay undefined if -m was not used) +my $selected_mac; + # Current line my $cur_line; @@ -161,6 +169,15 @@ sub print_warning(@) { } +# Returns true if $mac is the transmitter's MAC address selected by the user, or +# if the user didn't select any particular MAC address. +# Parameters: $mac +sub is_selected_mac($) { + if (!defined($selected_mac)) { return 1 } + return $selected_mac eq $_[0]; +} + + # Returns true if all $x, $y and $z are ready to be printed. # Arguments: $x, $y, $z sub is_complete($$$) { @@ -203,9 +220,12 @@ sub check_oldest_lines() { $end_line ) = split(';', $prev_lines[0], 9); - # Display and delete the line if it is not a positioning request or if - # it is complete - if ($type != REQUEST_TYPE_NORMAL + # Display and delete the line if either of the following is true: + # - it is not a positioning request + # - it is not the selected transmitter's MAC address + # - it is complete + if ( $type != REQUEST_TYPE_NORMAL + || !is_selected_mac($mac) || is_complete($x, $y, $z)) { print shift @prev_lines; @@ -244,6 +264,15 @@ sub apply_interpolation($$$$$$) { next; } + # Skip requests sent by other devices than the selected one + if (defined($selected_mac)) { + my $mac = get_field($prev_lines[-$i], MAC_FIELD_INDEX); + if ($selected_mac ne $mac) { + $nb_lines++; + next; + } + } + my $time = get_field($prev_lines[-$i], TIMESTAMP_FIELD_INDEX); my $newvalue = interpolate_1d($start, $start_time, $stop, $stop_time, $time); @@ -261,7 +290,7 @@ sub apply_interpolation($$$$$$) { ## Option parsing ## $Getopt::Std::STANDARD_HELP_VERSION = 1; -use constant OPTIONS => 'hvV'; +use constant OPTIONS => 'hm:vV'; my %options; if (!getopts(OPTIONS, \%options)) { HELP_MESSAGE(*STDERR); @@ -279,7 +308,8 @@ if ($options{'V'}) { exit 0; } -$verbose = $options{'v'}; +$verbose = $options{'v'}; +$selected_mac = $options{'m'}; ## Main loop: read lines ## @@ -291,10 +321,9 @@ while ($cur_line = <>) { # The current line is empty if ($cur_line eq "\n") { - # If we don't have previous lines, we print it - if (@prev_lines == 0) { print "\n" } - # If we have previous lines, we store it - else { push @prev_lines, "\n" } + # If we don't have previous lines, we print it; if we do, we store it + if (@prev_lines == 0) { print "\n" } + else { push @prev_lines, "\n" } next; } @@ -324,16 +353,22 @@ while ($cur_line = <>) { # Check the request type: we work only on positioning requests but must take # into account other request types if ($type != REQUEST_TYPE_NORMAL) { + trace("Non-positioning request: line skipped.\n"); # If we have no lines in memory, we can just print the line and jump to - # the next one - if (@prev_lines == 0) { - print $cur_line; - next; - } + # the next one, otherwise we have to store the line + if (@prev_lines == 0) { print $cur_line } + else { push @prev_lines, $cur_line } + next; + } - # Otherwise, we have to store the line - trace("Non-positioning request line stored.\n"); - push @prev_lines, $cur_line; + + # Check the transmitter's MAC address + if (!is_selected_mac($mac)) { + trace( "Transmitter's MAC address ($mac) doesn't match the selected" + . " transmiter's MAC address ($selected_mac): line skipped.\n"); + # Print or store the line + if (@prev_lines == 0) { print $cur_line } + else { push @prev_lines, $cur_line } next; }