diff options
author | Christian Pointner <equinox@mur.at> | 2011-07-23 12:51:16 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2011-07-23 12:51:16 +0000 |
commit | 7663b63f3bf356b66ebadc320aede0c54d756a51 (patch) | |
tree | 2e574f1cc09e9444d7516f7777dbc280e46b63b2 /software/tests/beacon/decode.pl | |
parent | beaconcnt should be working now (diff) |
added beacon decoder script
git-svn-id: https://svn.spreadspace.org/mur.sat@43 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/tests/beacon/decode.pl')
-rwxr-xr-x | software/tests/beacon/decode.pl | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/software/tests/beacon/decode.pl b/software/tests/beacon/decode.pl new file mode 100755 index 0000000..2dc19e8 --- /dev/null +++ b/software/tests/beacon/decode.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w + +use strict; +use MIME::Base32 qw( RFC ); + +my @beacons; +if(!$ARGV[0] || $ARGV[0] eq "-") { + @beacons = <STDIN>; +} else { + open(my $fh, "<", $ARGV[0]) or die "Unable to open file " . $ARGV[0]; + @beacons = <$fh>; + close($fh) +} + +foreach(@beacons) { + chomp; + my $beacon = $_; + + if($beacon =~ /([^ ]+) ([A-Z2-7]{3}) ([A-Z2-7])/) { + my $preamble = $1; + my $cnt = $2; + my $checksum = $3; + + my $cntval = unpack("n", MIME::Base32::decode($cnt . "=")) >> 1; + my $csval_recv = unpack("C", MIME::Base32::decode($checksum . "=")) >> 3; + + my $csval_calc = 0; + my @values = unpack("C*", $preamble); + @values = (@values, unpack("C*", $cnt)); + foreach(@values) { $csval_calc ^= $_ - ord(' '); } + $csval_calc = ($csval_calc & 0x1F) ^ (($csval_calc & 0x20) >> 5); + + print $beacon . " -> (cnt: " . sprintf("%04X", $cntval) . ") "; + if($csval_calc != $csval_recv) { + print " checksom wrong! (" . sprintf("%02X", $csval_recv) . " vs. " . sprintf("%02X", $csval_calc) . ")\n"; + } else { + print " checksom ok! (" . sprintf("%02X", $csval_recv) . ")\n"; + } + + + } else { + print "Beacon format wrong '" . $beacon . "'\n"; + } + + +} + |