Created
March 6, 2016 12:22
-
-
Save onitake/5b5e4f1d46c28931b92c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use IO::File; | |
sub usage() { | |
print STDERR "Usage: scantscf GSL_TS_CFG.h\n"; | |
print STDERR "Dumps the configuration block of Silead firmware in header format.\n"; | |
-1; | |
} | |
my $tscffile = $ARGV[0] or exit usage; | |
my $in = IO::File->new($tscffile, 'r') or die "Can't open $tscffile: $!"; | |
my $cfg = 0; | |
while (my $line = <$in>) { | |
if ($cfg and $line =~ /};/) { | |
$cfg = 0; | |
} elsif ($line =~ /gsl_config_data_id/) { | |
$cfg = 1; | |
} elsif ($cfg) { | |
$line =~ s/\s//g; | |
for my $code (split(/,/, $line)) { | |
my $value; | |
if ($code =~ /0[xX]([0-9a-f]+)/) { | |
$value = hex($1) & 0xffffffff; | |
} elsif ($code =~ /([0-9]+)/) { | |
$value = int($1) & 0xffffffff; | |
} else { | |
$value = 0; | |
} | |
my @bytes; | |
my $ascii = ''; | |
for my $i (0, 8, 16, 24) { | |
my $byte = ($value >> $i) & 0xff; | |
if ($byte >= 0x20 && $byte <= 0x7e) { | |
$ascii .= chr($byte); | |
} else { | |
$ascii .= '.'; | |
} | |
push(@bytes, $byte); | |
} | |
my @shorts = ($value & 0xffff, ($value >> 16) & 0xffff); | |
printf("%10d %5d %5d %3d %3d %3d %3d 0x%08x 0x%04x 0x%04x 0x%02x 0x%02x 0x%02x 0x%02x %s\n", $value, @shorts, @bytes, $value, @shorts, @bytes, $ascii); | |
} | |
} | |
} | |
$in->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment