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