From 583f00e0b8efe2832f63efb478a51d3ad35e92ed Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 7 Oct 2007 22:16:03 +0200 Subject: Included SI2E avr modules. Well, this need more works... --- digital/avr/modules/proto/utils/protodec | 107 +++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 digital/avr/modules/proto/utils/protodec (limited to 'digital/avr/modules/proto/utils/protodec') diff --git a/digital/avr/modules/proto/utils/protodec b/digital/avr/modules/proto/utils/protodec new file mode 100755 index 00000000..014d119e --- /dev/null +++ b/digital/avr/modules/proto/utils/protodec @@ -0,0 +1,107 @@ +#!/usr/bin/perl -w +use strict; + +sub syntax +{ + print <= 2 ** ($b - 1)) { + return -(2 ** $b - $h); + } else { + return $h; + } +} + +# Process one proto packet. +sub prcmd +{ + my ($cmd, $c, @v) = @_; + # Return if not wanted. + return unless exists $$cmd{$c}; + print $c; + # Print each args. + for (@{$$cmd{$c}}) + { + /^(\d+)-(\d+)(?:\.(\d+))?(u?)$/o; + my $fp = 0; + $fp = $3 if $3; + if ($4 eq 'u') { + print ' ', (cvhexu @v[$1 - 1 .. $2 - 1]) / (1 << $fp); + } else { + print ' ', (cvhex @v[$1 - 1 .. $2 - 1]) / (1 << $fp); + } + } + print "\n"; +}; + +# Read command line. +my %cmd; +my ($acmd, @acmdl); + +while ($_ = shift) +{ + # Command char. + /^[a-zA-Z]$/ and do { + $cmd{$acmd} = [ @acmdl ] if defined $acmd; + @acmdl = (); + $acmd = $_; + next; + }; + # Single arg. + /^(\d+)(\.\d+)?(u?)$/ and do { + syntax if !defined $acmd; + push @acmdl, "$1-$1$2"; + next; + }; + # Range arg. + /^(\d+)-(\d+)(\.\d+)?(u?)$/ and do { + syntax if !defined $acmd; + syntax if $2 <= $1; + push @acmdl, $_; + next; + }; + syntax; +} +$cmd{$acmd} = [ @acmdl ] if defined $acmd; + +syntax if !scalar %cmd; + +# For each line. +while (<>) +{ + chomp; + # Match a proto packet. + if (/^!([a-zA-Z])(?:[a-f0-9]{2})*$/o) + { + my $c = $1; + s/^!([a-zA-Z])//; + my @args = /[a-f0-9]{2}/og; + prcmd \%cmd, $c, @args; + } + if (/^#.*$/o) + { + print "$_\n"; + } +} -- cgit v1.2.3