Skip to content

Instantly share code, notes, and snippets.

@szpajder
Created February 10, 2022 23:29
Show Gist options
  • Save szpajder/804303d39946943774c9d67bcb526dc1 to your computer and use it in GitHub Desktop.
Save szpajder/804303d39946943774c9d67bcb526dc1 to your computer and use it in GitHub Desktop.
This script analyzes a log file produced by dumphfdl and list HFDL frequency changes as a timestamped event list
#!/usr/bin/perl -w
use Getopt::Std;
my $freqs = {};
sub check_freqs {
my($date, $gs, $frequency, $reporting_freq, $reporting_gs) = (shift, shift, shift, shift, shift);
my @new_freqs_list = @_;
$freqs->{$gs} ||= {};
my $new_freqs = {};
for(@new_freqs_list) {
$new_freqs->{$_} = 1;
}
for(keys %{$freqs->{$gs}}) {
unless(exists($new_freqs->{$_})) {
if($frequency < 0 || $frequency == $_) {
print("[$date] [$gs] channel down: $_ (reported by $reporting_gs on $reporting_freq - channels now in use: @new_freqs_list) \n");
}
delete $freqs->{$gs}->{$_};
}
}
for(@new_freqs_list) {
unless(exists($freqs->{$gs}->{$_})) {
if($frequency < 0 || $frequency == $_) {
print("[$date] [$gs] channel up: $_ (reported by $reporting_gs on $reporting_freq - channels now in use: @new_freqs_list)\n");
}
$freqs->{$gs}->{$_} = 1;
}
}
}
my %opts;
getopts('s:f:i:', \%opts);
my $station_name = defined $opts{'s'} ? qr/$opts{'s'}/ : qr/./;
my $frequency = $opts{'f'} || -1;
my $ignore_gs = qr/$opts{'i'}/ if defined $opts{'i'};
my ($date, $gs, $reporting_freq, $reporting_gs);
my ($gs_tmp);
my $grab_freqs = 0;
while(<STDIN>) {
if($grab_freqs) {
if(/in use: (.*)/) {
if(!defined $ignore_gs || $reporting_gs !~ $ignore_gs) {
my @freqs = split(/, /, $1);
check_freqs($date, $gs, $frequency, $reporting_freq, $reporting_gs, @freqs);
}
$grab_freqs = 0;
}
} else {
if(/^\[(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d \S+)\] \[(\S+ kHz)/) {
($date, $reporting_freq) = ($1, $2);
} elsif(/Src GS: (.*)/) {
$reporting_gs = $1;
} elsif(/^\s+ID: (.*)/) {
$gs_tmp = $1;
if($gs_tmp =~ /$station_name/) {
$gs = $gs_tmp;
$grab_freqs = 1;
} else {
$grab_freqs = 0;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment