summaryrefslogtreecommitdiff
path: root/n/avr/proto
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr/proto')
-rwxr-xr-xn/avr/proto/protodec39
1 files changed, 17 insertions, 22 deletions
diff --git a/n/avr/proto/protodec b/n/avr/proto/protodec
index 0ee929b..7a29004 100755
--- a/n/avr/proto/protodec
+++ b/n/avr/proto/protodec
@@ -6,9 +6,11 @@ sub syntax
print <<EOF;
$0 - Décodeur de protocol série pour le robot.
Syntaxe : $0 code [colonnes] [code [colonnes] ...
-Exemple : $0 l 1 2u 3-4 m 2
+Exemple : $0 l 1 2u 3-4 m 1-2.8
décode pour les codes l et m. Pour l, décode la première colonne en 8 bits, la
-deuxième en 8 bits non signés, les troisième et quatrième en 16 bits.
+deuxième en 8 bits non signés, les troisième et quatrième en 16 bits. Pour m,
+décode la première et deuxième en 16 bits, virgule fixe à 8 bits derrière la
+virgule.
EOF
exit 1;
}
@@ -37,11 +39,13 @@ sub prcmd
print $c;
for (@{$$cmd{$c}})
{
- /^(\d)-(\d)(u?)$/;
- if ($3 eq 'u') {
- print ' ', cvhexu @v[$1 - 1 .. $2 - 1];
+ /^(\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];
+ print ' ', (cvhex @v[$1 - 1 .. $2 - 1]) / (1 << $fp);
}
}
print "\n";
@@ -58,12 +62,12 @@ while ($_ = shift)
$acmd = $_;
next;
};
- /^([0-8])(u?)$/ and do {
+ /^(\d+)(\.\d+)?(u?)$/ and do {
syntax if !defined $acmd;
push @acmdl, "$1-$1$2";
next;
};
- /^([0-8])-([0-8])(u?)$/ and do {
+ /^(\d+)-(\d+)(\.\d+)?(u?)$/ and do {
syntax if !defined $acmd;
syntax if $2 <= $1;
push @acmdl, $_;
@@ -75,23 +79,14 @@ $cmd{$acmd} = [ @acmdl ] if defined $acmd;
syntax if !scalar %cmd;
-#print $_, ' ', join (' ', @{$cmd{$_}}), "\n" for keys %cmd;
-
while (<>)
{
chomp;
- if (/^!([a-zA-Z])(\w\w)?(\w\w)?(\w\w)?(\w\w)?(\w\w)?(\w\w)?(\w\w)?(\w\w)?(\w\w)?$/o)
+ if (/^!([a-zA-Z])(?:[a-f0-9]{2})*$/o)
{
- my @m;
- push @m, $1 if defined $1;
- push @m, $2 if defined $2;
- push @m, $3 if defined $3;
- push @m, $4 if defined $4;
- push @m, $5 if defined $5;
- push @m, $6 if defined $6;
- push @m, $7 if defined $7;
- push @m, $8 if defined $8;
- push @m, $9 if defined $9;
- prcmd \%cmd, @m;
+ my $c = $1;
+ s/^!([a-zA-Z])//;
+ my @args = /[a-f0-9]{2}/og;
+ prcmd \%cmd, $c, @args;
}
}