continue sigrok export (should almost work)

This commit is contained in:
Florent Kermarrec 2015-02-18 11:59:35 +01:00
parent cd43163d9d
commit 130212039e
1 changed files with 30 additions and 15 deletions

View File

@ -1,5 +1,6 @@
import sys import sys
import os import os
import math
import shutil import shutil
import datetime import datetime
import zipfile import zipfile
@ -320,31 +321,44 @@ total probes = {}
samplerate = {} MHz samplerate = {} MHz
""".format( """.format(
name, name,
8, # XXX add parameter len(self.dump.vars),
50, # XXX add parameter 50, # XXX add parameter
) )
# XXX add probe names for i, var in enumerate(self.dump.vars):
r += "probe{} = {}\n".format(i, var.name)
f.write(r) f.write(r)
f.close() f.close()
def create_data(self, name): def create_data(self, name):
# XXX are probes limited to 1 bit?
data_bits = math.ceil(len(self.dump.vars)/8)*8
data_len = 0
for var in self.dump.vars:
data_len = max(data_len, len(var))
datas = []
for i in range(data_len):
data = 0
for j, var in enumerate(reversed(self.dump.vars)):
data = data << 1
try:
data |= var.values[i] %2
except:
pass
datas.append(data)
f = open(name, "wb") f = open(name, "wb")
# XXX for data in datas:
for i in range(16): f.write(data.to_bytes(data_bits//8, "big"))
f.write(bytes(i))
f.close() f.close()
def zip(self, name): def zip(self, name):
def zipdir(path, zip): f = zipfile.ZipFile(name + ".sr", "w")
for root, dirs, files in os.walk(path): os.chdir(name)
for file in files: f.write("version")
# XXX f.write("metadata")
os.chdir(root) f.write(name)
zip.write(file)
os.chdir("..") os.chdir("..")
zipf = zipfile.ZipFile(name + ".sr", 'w') f.close()
zipdir(name, zipf)
zipf.close()
def write(self, filename): def write(self, filename):
name, ext = os.path.splitext(filename) name, ext = os.path.splitext(filename)
@ -357,6 +371,7 @@ samplerate = {} MHz
self.create_data(name) self.create_data(name)
os.chdir("..") os.chdir("..")
self.zip(name) self.zip(name)
shutil.rmtree(name)
def main(): def main():
dump = Dump() dump = Dump()