Documentation added.

This commit is contained in:
Kai Lauterbach 2011-12-29 22:50:22 +01:00
parent c1fcb4135e
commit 14c16cd9e9

View file

@ -1,42 +1,77 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
#
# usage:
#
# ./param2HexFrame.pl "frame 1 data" "frame 2 data" ... "frame N data"
#
# frame X data = delay; layer 1; layer 2; layer 3
#
# delay = 0 to 31 (multiplied by 8 in firmware and equals to the ISR calls (delay/300 seconds)
# 0 equals to a delay of 255/300 seconds.
#
# layer Y = layer no(1,2,3), bit0, bit1, bit2, ..., bit n (1 to 9)
#
# Sample usage which generates 5 frames:
#
# ./param2HexFrame.pl "25;3,2,5,8;" "14;3,3,5,7" "3;3,4,5,6;2,6,5,4" "23;3,1,5,9" "0;2,1,2,3,4,5,6,7,8,9;1,5"
# Frame 0 = 0xca480000 = hi:0xca48 = lo:0x0000 = 0b11001010010010000000000000000000
# Frame 1 = 0x71500000 = hi:0x7150 = lo:0x0000 = 0b01110001010100000000000000000000
# Frame 2 = 0x18e07000 = hi:0x18e0 = lo:0x7000 = 0b00011000111000000111000000000000
# Frame 3 = 0xbc440000 = hi:0xbc44 = lo:0x0000 = 0b10111100010001000000000000000000
# Frame 4 = 0x0003fe10 = hi:0x0003 = lo:0xfe10 = 0b00000000000000111111111000010000
#
use strict; use strict;
for (my $i=0; $i<=$#ARGV; $i++) for (my $i=0; $i<=$#ARGV; $i++)
{ {
print "Frame $i = "; printf("Frame %02d = ", $i);
my @list = split(",", $ARGV[$i]);
my $frame = 0; my @list = split(";", $ARGV[$i]);
my $first = 1; my $frame = 0;
my $ebene = 0; my $status = 1;
my $bit = 0; foreach my $ele (@list)
if ($#list >= 0 && $#list <= 9)
{ {
my $ele = 0; my @list2 = split(",", $ele);
foreach my $ele (@list)
{
if ($first == 1)
{
$ebene = ($ele - 1) * 9;
$first = 2;
} elsif ($first == 2) { my $status2 = 1;
$first = 0; my $layer = 0;
if ($ele < 32) my $bit = 0;
if ($status == 1) { # read the delay
$status = 0;
# minimum delay is 0 (equals to a delay of 255 ISR calls)
# maximum delay is 31 (equals to a delay of 31*8 ISR calls)
if ($ele > -1 && $ele < 32)
{
$frame |= $ele << 27;
}
} else {
if ($#list >= 0 && $#list <= 9)
{
my $ele = 0;
foreach my $ele2 (@list2)
{ {
$frame |= $ele << 27; if ($status2 == 1) # read the layer
} {
} else { # the layer has to be in range of 1 to 3
if ($ele < 10) if ($ele2 > 0 && $ele2 < 4)
{ {
$bit = $ebene + $ele-1; $layer = ($ele2 - 1) * 9;
$frame |= (1 << $bit); $status2 = 0;
}
} else {
if ($ele2 > 0 && $ele2 < 10) # bit 1 to 9 allowed
{
$bit = $layer + $ele2-1;
$frame |= (1 << $bit);
}
}
} }
} }
} }
printf("0x%08x = ", $frame);
printf("0b%032b\n", $frame);
} }
printf("0x%08x = ", $frame);
printf("hi:0x%04x = ", $frame >> 16);
printf("lo:0x%04x = ", $frame & 0xffff);
printf("0b%032b\n", $frame);
} }