Created
February 10, 2022 23:23
-
-
Save szpajder/89846e95c749fb071db617ca0fe27064 to your computer and use it in GitHub Desktop.
This scripts parses dumphfdl log file and builds an array of frequencies that have been advertised in HFDL squitters found in the log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use Getopt::Std; | |
my $freqs = {}; | |
sub add_freqs { | |
my $gs = shift; | |
my @freqs_list = @_; | |
for(@freqs_list) { | |
#print "Adding freq $_\n"; | |
$freqs->{int($_)} = 1; | |
} | |
} | |
sub print_bands_sh { | |
my $bands = {}; | |
my $band; | |
for(sort { $a <=> $b } keys %$freqs) { | |
$band = int($_ / 1000); # kHz to Hz | |
$bands->{$band} ||= []; | |
push @{$bands->{$band}}, $_; | |
} | |
print "declare -A bands\nbands=(\n"; | |
for(sort { $a <=> $b } keys %$bands) { | |
print "\t[$_]=\"" . join(' ', @{$bands->{$_}}) . "\"\n"; | |
} | |
print ")\n"; | |
} | |
my %opts; | |
getopts('e:i:', \%opts); | |
my $exclude_gs = qr/$opts{'e'}/ if defined $opts{'e'}; | |
my $ignore_squitters_from_gs = qr/$opts{'i'}/ if defined $opts{'i'}; | |
my ($date, $gs, $reporting_gs); | |
use constant { | |
GET_UPLINK => 1, | |
GET_GS_ID => 2, | |
GET_FREQS => 3 | |
}; | |
my $state = GET_UPLINK; | |
while(<STDIN>) { | |
if($state == GET_UPLINK) { | |
if(/Src GS: (.*)/) { | |
$reporting_gs = $1; | |
#print "reporting gs: $reporting_gs\n"; | |
if(!defined $ignore_squitters_from_gs || $reporting_gs !~ $ignore_squitters_from_gs) { | |
#print "GET_GS_ID\n"; | |
$state = GET_GS_ID; | |
} | |
} | |
} elsif($state == GET_GS_ID) { | |
if(/^\s+ID: (.*)/) { | |
$gs = $1; | |
#print "GS ID: $gs\n"; | |
if(!defined $exclude_gs || $gs !~ /$exclude_gs/) { | |
$state = GET_FREQS; | |
#print "GET_FREQS\n"; | |
} | |
} elsif(/^$/) { | |
#print "GET_UPLINK\n"; | |
$state = GET_UPLINK; | |
} | |
} elsif($state == GET_FREQS) { | |
if(/in use: (.*)/) { | |
my @freqs = split(/, /, $1); | |
add_freqs($gs, @freqs); | |
$state = GET_GS_ID; | |
} | |
} | |
} | |
print_bands_sh(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment