summaryrefslogtreecommitdiffstats
path: root/libtoprammer/bitfile.py
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2011-01-19 21:17:46 +0100
committerMichael Buesch <mb@bu3sch.de>2011-01-19 21:17:46 +0100
commit05aba2e57eec1b6cdaf5bae62fb396402088b0ae (patch)
tree3f893530d82e018c10cd51ed87b27078aea0349b /libtoprammer/bitfile.py
parent20f6e4324b0e65c9dd3ce89dacb3cd3eb77b2da3 (diff)
downloadtoprammer-05aba2e57eec1b6cdaf5bae62fb396402088b0ae.tar.xz
toprammer-05aba2e57eec1b6cdaf5bae62fb396402088b0ae.zip
Rewrite byte handling.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'libtoprammer/bitfile.py')
-rw-r--r--libtoprammer/bitfile.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/libtoprammer/bitfile.py b/libtoprammer/bitfile.py
index e141602..263c24d 100644
--- a/libtoprammer/bitfile.py
+++ b/libtoprammer/bitfile.py
@@ -1,7 +1,7 @@
"""
# *.BIT file parser
#
-# Copyright (c) 2009 Michael Buesch <mb@bu3sch.de>
+# Copyright (c) 2009-2011 Michael Buesch <mb@bu3sch.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,6 +27,9 @@ except ImportError:
print "On Debian Linux run: apt-get install python-pkg-resources"
sys.exit(1)
+from util import *
+
+
class BitfileException(Exception): pass
class Bitfile:
@@ -89,22 +92,22 @@ class Bitfile:
raise BitfileException("No payload found")
def __parseNextField(self, data, i):
- fieldId = ord(data[i + 0])
+ fieldId = byte2int(data[i + 0])
if (fieldId == self.FIELD_SRCFILE):
data = self.__parse16bitField(data, i + 1)
- self.srcfile = data.strip().strip("\x00")
+ self.srcfile = data.decode("ASCII").strip().strip("\x00")
return len(data) + 3
if (fieldId == self.FIELD_FPGA):
data = self.__parse16bitField(data, i + 1)
- self.fpga = data.strip().strip("\x00")
+ self.fpga = data.decode("ASCII").strip().strip("\x00")
return len(data) + 3
if (fieldId == self.FIELD_DATE):
data = self.__parse16bitField(data, i + 1)
- self.date = data.strip().strip("\x00")
+ self.date = data.decode("ASCII").strip().strip("\x00")
return len(data) + 3
if (fieldId == self.FIELD_TIME):
data = self.__parse16bitField(data, i + 1)
- self.time = data.strip().strip("\x00")
+ self.time = data.decode("ASCII").strip().strip("\x00")
return len(data) + 3
if (fieldId == self.FIELD_PAYLOAD):
self.payload = self.__parse32bitField(data, i + 1)
@@ -112,12 +115,12 @@ class Bitfile:
raise BitfileException("Found unknown data field 0x%02X" % fieldId)
def __parse16bitField(self, data, i):
- fieldLen = (ord(data[i + 0]) << 8) | ord(data[i + 1])
+ fieldLen = (byte2int(data[i + 0]) << 8) | byte2int(data[i + 1])
return data[i + 2 : i + 2 + fieldLen]
def __parse32bitField(self, data, i):
- fieldLen = (ord(data[i + 0]) << 24) | (ord(data[i + 1]) << 16) |\
- (ord(data[i + 2]) << 8) | ord(data[i + 3])
+ fieldLen = (byte2int(data[i + 0]) << 24) | (byte2int(data[i + 1]) << 16) |\
+ (byte2int(data[i + 2]) << 8) | byte2int(data[i + 3])
return data[i + 4 : i + 4 + fieldLen]
def __probeFile(fullpath):
bues.ch cgit interface