diff --git a/tools/findbits.py b/tools/findbits.py index 501d23019..fb088d739 100755 --- a/tools/findbits.py +++ b/tools/findbits.py @@ -25,77 +25,77 @@ import os # invert binary string def invert(data): - return ''.join('0' if c == '1' else '1' for c in data) + return ''.join('0' if c == '1' else '1' for c in data) # do the actual search def search(target,data): - location = data.find(target) - if location >= 0: - print '*** Match at bit %d:' % location, - print '%s<%s>%s' % (data[:location],target,data[location+len(target):]) - else: - print 'Not found' + location = data.find(target) + if location >= 0: + print '*** Match at bit %d:' % location, + print '%s<%s>%s' % (data[:location],target,data[location+len(target):]) + else: + print 'Not found' # convert integer to binary string def binstring(number): - return bin(number)[2:] if number > 0 else '' + return bin(number)[2:] if number > 0 else '' # reverse string order def stringreverse(data): - return data[::-1] + return data[::-1] # match forward, backward and inverted def domatch(binary,number): - reversed= stringreverse(number) - inverted= invert(binary) + reversed= stringreverse(number) + inverted= invert(binary) - print ' Forward: (%s)' % number, - search(binary,number) - print ' Reverse: (%s)' % reversed, - search(binary,reversed) - print ' Inverse: (%s)' % inverted - print ' Forward: (%s)' % number, - search(inverted,number) - print ' Reverse: (%s)' % reversed, - search(inverted,reversed) + print ' Forward: (%s)' % number, + search(binary,number) + print ' Reverse: (%s)' % reversed, + search(binary,reversed) + print ' Inverse: (%s)' % inverted + print ' Forward: (%s)' % number, + search(inverted,number) + print ' Reverse: (%s)' % reversed, + search(inverted,reversed) def main(): - if(len(sys.argv) < 3): - print - print '\t'+sys.argv[0] + ' - Search bitstream for a known number' - print - print 'Usage: ' + sys.argv[0] + ' ' - print - print '\tNUMBER will be converted to it\'s BINARY equivalent for all valid' - print '\tinstances of BINARY, OCTAL, DECIMAL and HEX, and the bitstream' - print '\tand it\'s inverse will be searched for a pattern match. Note that' - print '\tNUMBER must be specified in BINARY to match leading zeros.' - print - print 'Example:' - print - print '\tfindbits.py 73 0110010101110011' - print - os._exit(True) + if(len(sys.argv) < 3): + print + print '\t'+sys.argv[0] + ' - Search bitstream for a known number' + print + print 'Usage: ' + sys.argv[0] + ' ' + print + print '\tNUMBER will be converted to it\'s BINARY equivalent for all valid' + print '\tinstances of BINARY, OCTAL, DECIMAL and HEX, and the bitstream' + print '\tand it\'s inverse will be searched for a pattern match. Note that' + print '\tNUMBER must be specified in BINARY to match leading zeros.' + print + print 'Example:' + print + print '\tfindbits.py 73 0110010101110011' + print + os._exit(True) - bases= { - 2:'BINARY', - 8:'OCTAL', - 10:'DECIMAL', - 16:'HEX', - } + bases= { + 2:'BINARY', + 8:'OCTAL', + 10:'DECIMAL', + 16:'HEX', + } - for base, base_name in sorted(bases.iteritems()): - try: - number= int(sys.argv[1],base) - print - print 'Trying', base_name - # do BINARY as specified to preserve leading zeros - if base == 2: - domatch(sys.argv[1],sys.argv[2]) - else: - domatch(binstring(number),sys.argv[2]) - except: - continue + for base, base_name in sorted(bases.iteritems()): + try: + number= int(sys.argv[1],base) + print + print 'Trying', base_name + # do BINARY as specified to preserve leading zeros + if base == 2: + domatch(sys.argv[1],sys.argv[2]) + else: + domatch(binstring(number),sys.argv[2]) + except: + continue if __name__ == '__main__': - main() + main() diff --git a/tools/findbits_test.py b/tools/findbits_test.py index 3288cb35b..4415ce726 100644 --- a/tools/findbits_test.py +++ b/tools/findbits_test.py @@ -4,65 +4,65 @@ from itertools import imap import unittest, sys, findbits class TestFindBits(unittest.TestCase): - def setUp(self): - self.old_stdout = sys.stdout - sys.stdout = OutputBuffer() + def setUp(self): + self.old_stdout = sys.stdout + sys.stdout = OutputBuffer() - def tearDown(self): - sys.stdout = self.old_stdout + def tearDown(self): + sys.stdout = self.old_stdout - INVERT_CASES = [ - ('10', '01'), - ('', ''), - ] - def test_invert(self): - self.commutative_test(findbits.invert, self.INVERT_CASES) + INVERT_CASES = [ + ('10', '01'), + ('', ''), + ] + def test_invert(self): + self.commutative_test(findbits.invert, self.INVERT_CASES) - SEARCH_CASES = [ - ('1111', '10111101', ['Match at bit 2', '0<1111>0']), - ('00', '10111101', ['Not found']), - ] - def test_search(self): - for target, data, expected_fragments in self.SEARCH_CASES: - sys.stdout.clear_buffer() - findbits.search(target, data) - for fragment in expected_fragments: - self.assertIn(fragment, sys.stdout.content) + SEARCH_CASES = [ + ('1111', '10111101', ['Match at bit 2', '0<1111>0']), + ('00', '10111101', ['Not found']), + ] + def test_search(self): + for target, data, expected_fragments in self.SEARCH_CASES: + sys.stdout.clear_buffer() + findbits.search(target, data) + for fragment in expected_fragments: + self.assertIn(fragment, sys.stdout.content) - BINSTRING_CASES = [ - (42, '101010'), - (1, '1'), - (0, ''), - ] - def test_binstring(self): - self.unary_operation_test(findbits.binstring, self.BINSTRING_CASES) + BINSTRING_CASES = [ + (42, '101010'), + (1, '1'), + (0, ''), + ] + def test_binstring(self): + self.unary_operation_test(findbits.binstring, self.BINSTRING_CASES) - REVERSE_CASES = [ - ('abc', 'cba'), - ('', ''), - ] - def test_stringreverse(self): - self.commutative_test(findbits.stringreverse, self.REVERSE_CASES) + REVERSE_CASES = [ + ('abc', 'cba'), + ('', ''), + ] + def test_stringreverse(self): + self.commutative_test(findbits.stringreverse, self.REVERSE_CASES) - def commutative_test(self, operation, cases): - self.unary_operation_test(operation, cases) - self.unary_operation_test(operation, imap(reversed, cases)) + def commutative_test(self, operation, cases): + self.unary_operation_test(operation, cases) + self.unary_operation_test(operation, imap(reversed, cases)) - def unary_operation_test(self, operation, cases): - for case_in, case_out in cases: - self.assertEqual(operation(case_in), case_out) + def unary_operation_test(self, operation, cases): + for case_in, case_out in cases: + self.assertEqual(operation(case_in), case_out) class OutputBuffer(object): - def __init__(self): - self.clear_buffer() + def __init__(self): + self.clear_buffer() - def clear_buffer(self): - self.content = '' + def clear_buffer(self): + self.content = '' - def write(self, data): - self.content += data + def write(self, data): + self.content += data if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() \ No newline at end of file diff --git a/tools/install-gnuarm4.sh b/tools/install-gnuarm4.sh index 793bdbf5d..a5d92c5d5 100755 --- a/tools/install-gnuarm4.sh +++ b/tools/install-gnuarm4.sh @@ -14,16 +14,16 @@ if [ "${1}" = "" ]; then echo "Syntax: ${0} [download & build directory (default ${PWD})]" exit 1 else - DESTDIR="${1}" + DESTDIR="${1}" fi # Where do you want to build the tools. This is where the log files # will be written (which you can monitor with 'tail' during compilation). # You can delete this directory after everything is done. if [ ! "${2}" = "" ]; then - SRCDIR="${2}" + SRCDIR="${2}" else - SRCDIR="${PWD}" + SRCDIR="${PWD}" fi BUILDDIR=${SRCDIR}/build-gnuarm4 diff --git a/tools/mkversion.pl b/tools/mkversion.pl index 674c44177..023c84c8b 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -32,28 +32,28 @@ my $commandGIT = "env which git"; if ( defined($commandGIT) ) { - my $githistory = `git fetch --all`; - # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case - my $gitversion = `git describe --dirty --always`; - my $gitbranch = `git rev-parse --abbrev-ref HEAD`; - $clean = $gitversion =~ '-dirty' ? 0 : 1; + my $githistory = `git fetch --all`; + # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case + my $gitversion = `git describe --dirty --always`; + my $gitbranch = `git rev-parse --abbrev-ref HEAD`; + $clean = $gitversion =~ '-dirty' ? 0 : 1; - if ( defined($gitbranch) and defined($gitversion) ) { - $fullgitinfo = $fullgitinfo.'/'. $gitbranch . '/' . $gitversion; + if ( defined($gitbranch) and defined($gitversion) ) { + $fullgitinfo = $fullgitinfo.'/'. $gitbranch . '/' . $gitversion; - my @compiletime = localtime(); - $compiletime[4] += 1; - $compiletime[5] += 1900; - $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @compiletime); - } else { - $fullgitinfo = $fullgitinfo.'/master/release (git)'; - } + my @compiletime = localtime(); + $compiletime[4] += 1; + $compiletime[5] += 1900; + $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @compiletime); + } else { + $fullgitinfo = $fullgitinfo.'/master/release (git)'; + } } else { - $fullgitinfo = $fullgitinfo.'/master/release (no_git)'; - my @dl_time = localtime( (stat('../README.md'))[10] ); - $dl_time[4] += 1; - $dl_time[5] += 1900; - $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @dl_time); + $fullgitinfo = $fullgitinfo.'/master/release (no_git)'; + my @dl_time = localtime( (stat('../README.md'))[10] ); + $dl_time[4] += 1; + $dl_time[5] += 1900; + $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @dl_time); } $fullgitinfo =~ s/(\s)//g; @@ -66,11 +66,11 @@ print < out.s19\n"; + die "usage: $0 file-to-endian-swap.s19 > out.s19\n"; } while(<>) { - chomp; + chomp; - if(/^S0/) { - next; - } - if(/^S7/) { - print "$_\n"; - next; - } + if(/^S0/) { + next; + } + if(/^S7/) { + print "$_\n"; + next; + } - if(not /^S3(..)(........)(.*)(..)$/) { - die "bad S record at line $.\n"; - } + if(not /^S3(..)(........)(.*)(..)$/) { + die "bad S record at line $.\n"; + } - $data = $3; - $checksum = $4; + $data = $3; + $checksum = $4; - print "S3$1$2"; - while($data =~ m#(..)(..)(..)(..)#g) { - print "$4$3$2$1"; - } - print "$checksum\n"; + print "S3$1$2"; + while($data =~ m#(..)(..)(..)(..)#g) { + print "$4$3$2$1"; + } + print "$checksum\n"; } diff --git a/tools/xorcheck.py b/tools/xorcheck.py index 73eeb4a7f..091998a31 100755 --- a/tools/xorcheck.py +++ b/tools/xorcheck.py @@ -24,29 +24,29 @@ import sys import os if(len(sys.argv) < 3): - print - print '\t'+sys.argv[0] + ' - Generate final byte for XOR LRC' - print - print 'Usage: ' + sys.argv[0] + ' ... ' - print - print '\tSpecifying the bytes of a UID with a known LRC will find the last byte value' - print '\tneeded to generate that LRC with a rolling XOR. All bytes should be specified in HEX.' - print - print 'Example:' - print - print '\txorcheck.py 04 00 80 64 ba' - print - print 'Should produce the output:' - print - print '\tTarget (BA) requires final LRC XOR byte value: 5A' - print - os._exit(True) + print + print '\t'+sys.argv[0] + ' - Generate final byte for XOR LRC' + print + print 'Usage: ' + sys.argv[0] + ' ... ' + print + print '\tSpecifying the bytes of a UID with a known LRC will find the last byte value' + print '\tneeded to generate that LRC with a rolling XOR. All bytes should be specified in HEX.' + print + print 'Example:' + print + print '\txorcheck.py 04 00 80 64 ba' + print + print 'Should produce the output:' + print + print '\tTarget (BA) requires final LRC XOR byte value: 5A' + print + os._exit(True) target= int(sys.argv[len(sys.argv) - 1],16) lrc= 0x00 for i in range(len(sys.argv) - 1): - lrc ^= int(sys.argv[i + 1],16) + lrc ^= int(sys.argv[i + 1],16) print print 'Target (%02X) requires final LRC XOR byte value: %02X' % (target,lrc) print