Merge pull request #35 from DurandA/json-exporter

software/dump: add JSON dump
This commit is contained in:
enjoy-digital 2021-08-25 13:05:20 +02:00 committed by GitHub
commit 9437f52233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -168,6 +168,8 @@ class LiteScopeAnalyzerDriver:
dump = CSVDump()
elif ext == ".py":
dump = PythonDump()
elif ext == ".json":
dump = JSONDump()
elif ext == ".sr":
dump = SigrokDump(samplerate=samplerate)
else:

View File

@ -1,5 +1,6 @@
from litescope.software.dump.common import DumpData, DumpVariable, Dump
from litescope.software.dump.csv import CSVDump
from litescope.software.dump.python import PythonDump
from litescope.software.dump.json import JSONDump
from litescope.software.dump.sigrok import SigrokDump
from litescope.software.dump.vcd import VCDDump

View File

@ -0,0 +1,25 @@
#
# This file is part of LiteScope.
#
# Copyright (c) 2021 Arnaud Durand <arnaud.durand@unifr.ch>
# SPDX-License-Identifier: BSD-2-Clause
import json
from litescope.software.dump.common import Dump
class JSONDump(Dump):
def __init__(self, dump=None):
Dump.__init__(self)
self.variables = [] if dump is None else dump.variables
def generate_data(self):
return {v.name: v.values for v in self.variables}
def write(self, filename):
with open(filename, "w") as f:
json.dump(self.generate_data(), f)
def read(self, filename):
raise NotImplementedError("Python files can not (yet) be read, please contribute!")