From b91f7a4d075cae8d9423533283af89f8abef54bb Mon Sep 17 00:00:00 2001 From: regehr Date: Tue, 24 Jun 2008 04:41:37 +0000 Subject: [PATCH] put FLID decoding tool where it'll get installed with the rest of the scripts --- tools/tinyos/Makefile.am | 2 +- tools/tinyos/safe/Makefile.am | 3 ++ tools/tinyos/safe/tos-decode-flid | 69 +++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tools/tinyos/safe/Makefile.am create mode 100755 tools/tinyos/safe/tos-decode-flid diff --git a/tools/tinyos/Makefile.am b/tools/tinyos/Makefile.am index 63d29962..875fca72 100644 --- a/tools/tinyos/Makefile.am +++ b/tools/tinyos/Makefile.am @@ -1,4 +1,4 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = java misc ncc tosthreads +SUBDIRS = java misc ncc tosthreads safe diff --git a/tools/tinyos/safe/Makefile.am b/tools/tinyos/safe/Makefile.am new file mode 100644 index 00000000..9f58895e --- /dev/null +++ b/tools/tinyos/safe/Makefile.am @@ -0,0 +1,3 @@ +AUTOMAKE_OPTIONS = foreign + +bin_SCRIPTS = tos-decode-flid diff --git a/tools/tinyos/safe/tos-decode-flid b/tools/tinyos/safe/tos-decode-flid new file mode 100755 index 00000000..62893cb2 --- /dev/null +++ b/tools/tinyos/safe/tos-decode-flid @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w + +use strict; + +sub decode ($$) { + my $a = shift; + my $b = shift; + die if ($a<0 || $a>3); + die if ($b<0 || $b>3); + my $c = ($a << 2) + $b; + my $h = sprintf "%X", $c; + return $h; +} + +sub make_flid () { + + my $flid = $ARGV[0]; + die "expected 8 characters" if (length($flid) != 8); + + my $flidstr = + "0x" . + decode(substr($flid,0,1),substr($flid,1,1)) . + decode(substr($flid,2,1),substr($flid,3,1)) . + decode(substr($flid,4,1),substr($flid,5,1)) . + decode(substr($flid,6,1),substr($flid,7,1)); +} + +my $flidstr = make_flid(); + +my $fn = $ARGV[1]; +my $found = 0; + +if (defined ($fn)) { + open INF, "<$fn" or die; + while (my $line = ) { + chomp $line; + + my @fields = split /\#\#\#/, $line; + foreach (@fields) { + (s/^\s*//g); + (s/\s*$//g); + (s/^\"//g); + (s/\"$//g); + } + if (hex($fields[0]) == hex($flidstr)) { + my $check = $fields[1]; + my $text = $fields[2]; + my $loc = $fields[3]; + my $func = $fields[4]; + + + $found = 1; + + print "Deputy error message for flid $flidstr:\n\n"; + + printf "%s: %s: Assertion failed in %s:\n %s\n", + $loc, $func, $check, $text; + } + } + close INF; +} +else { + print "Usage: tos-decode-flid flid flid-file\n"; + exit 2; +} + +if (!$found) { + print "oops -- flid $flidstr not found in file\n"; +} -- 2.39.2