litescope/software/dump/sigrok: remove 8 bits limitation and some cleanup

This commit is contained in:
Florent Kermarrec 2017-06-23 11:40:44 +02:00
parent d8649fca5f
commit 8d87992b95
1 changed files with 16 additions and 17 deletions

View File

@ -20,19 +20,20 @@ class SigrokDump(Dump):
f.close()
def write_metadata(self, name):
probe_bits = math.ceil(len(self.variables)/8)*8
f = open("metadata", "w")
r = """
[global]
sigrok version = 0.2.0
sigrok version=0.3.0
[device 1]
driver = litescope
capturefile = dump
unitsize = 1
capturefile=logic-1-1
total probes={}
samplerate = {} KHz
samplerate={} MHz
unitsize={}
""".format(
len(self.variables),
self.samplerate//1000*2,
probe_bits,
self.samplerate//1e6*2,
probe_bits//8
)
for i, variable in enumerate(self.variables):
r += "probe{}={}\n".format(i + 1, variable.name)
@ -40,8 +41,6 @@ samplerate = {} KHz
f.close()
def write_data(self):
# TODO: study bytes/bits ordering to remove limitation
assert len(self.variables) < 8
data_bits = math.ceil(len(self.variables)/8)*8
data_len = 0
for variable in self.variables:
@ -56,9 +55,9 @@ samplerate = {} KHz
except:
pass
datas.append(data)
f = open("dump", "wb")
f = open("logic-1-1", "wb")
for data in datas:
f.write(data.to_bytes(data_bits//8, "big"))
f.write(data.to_bytes(data_bits//8, "little"))
f.close()
def zip(self, name):
@ -66,7 +65,7 @@ samplerate = {} KHz
os.chdir(name)
f.write("version")
f.write("metadata")
f.write("dump")
f.write("logic-1-1")
os.chdir("..")
f.close()
@ -105,7 +104,7 @@ samplerate = {} KHz
m = re.search("samplerate = ([0-9]+) kHz", l, re.I)
if m is not None:
self.samplerate = int(m.group(1))*1000
m = re.search("samplerate = ([0-9]+) mHz", l, re.I)
m = re.search("samplerate = ([0-9]+) MHz", l, re.I)
if m is not None:
self.samplerate = int(m.group(1))*1000000
f.close()
@ -113,12 +112,12 @@ samplerate = {} KHz
def read_data(self, name, nprobes):
datas = []
f = open("dump", "rb")
f = open("logic-1-1", "rb")
while True:
data = f.read(math.ceil(nprobes/8))
if data == bytes('', "utf-8"):
break
data = int.from_bytes(data, "big")
data = int.from_bytes(data, "little")
datas.append(data)
f.close()
return datas