-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinput-interpreter.pl
executable file
·70 lines (58 loc) · 1.92 KB
/
input-interpreter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
use strict;
use warnings;
use profiles;
#Could take a while.
print "Starting profile import...\n";
my @profiles = @{import_profile_data("rt2860")};
print "Done with profile import.\n";
my $xml = new XML::Simple;
open(my $XML_INPUT, "./iwlist ra0 scan |");
my $data = $xml->parse_fh($XML_INPUT);
my @cells;
#Populate array of cells
foreach my $cell (@{$data->{cell}}){
my %current_cell = xml_cell_to_hash_cell($cell);
push(@cells,\%current_cell);
}
my @deltas;
my ($best_delta,$best_x,$best_y) = (-99999,0,0);
#Generate change value.
#Somewhat verbose in order to prevent the array of pointers to hashes with pointers
#to arrays of pointers to hashes from being a total goat screw.
foreach my $profile_ptr (@profiles){
my %profile = %{$profile_ptr};
my @profile_cells = @{$profile{'cells'}};
my $delta_sum=0;
foreach my $profile_cell (@profile_cells){
foreach my $cell_ptr (@cells){
my %cell = %{$cell_ptr};
if(${$profile_cell}{'address'} eq $cell{'address'}){
#This algorithm is kind of dumb but should work fine until I whip up something sexier.
${$profile_cell}{'delta'} = abs($cell{'signal'}-${$profile_cell}{'signal'}) +
abs($cell{'noise'}-${$profile_cell}{'noise'})-90;
$delta_sum-=${$profile_cell}{'delta'};
# print "updated inbetween dsum to:$delta_sum\n";
}
}
}
my %entry = ();
$entry{'x'}=$profile{'x'};
$entry{'y'}=$profile{'y'};
$entry{'delta'}=$delta_sum;
print "My delta sum is $delta_sum\n";
$profile{'delta_sum'}=$delta_sum;
push(@deltas,\%entry);
if($profile{'delta_sum'}>$best_delta && $profile{'delta_sum'}!=0){
$best_x = $profile{'x'};
$best_y = $profile{'y'};
$best_delta = $profile{'delta_sum'};
}
}
#my @sorted_deltas = sort { ${$a}{'delta_sum'} <=> ${$b}{'delta_sum'} } @deltas;
foreach my $d (@deltas){
# print ${$d}{'delta_sum'},"\n";
}
print "Best delta value: $best_delta\nClosest x: $best_x\nClosest y: $best_y\n";