diff --git a/set_record.py b/set_record.py index 6fa8617..73ce96e 100644 --- a/set_record.py +++ b/set_record.py @@ -340,7 +340,7 @@ class Retagger: self.packets_dropped += 1 class VcdSink: - def __init__(self, fs, signals, timescale='1 us'): + def __init__(self, fs, signals, timescale='1 us', verbose_trace=False): self.writer = VCDWriter(fs, timescale=timescale, date=datetime.datetime.now().isoformat(), version=f"PET v1.0") self.skalars = {} self.arrays = {} @@ -348,6 +348,7 @@ class VcdSink: self.varnames = {} self.timestamp = 0 self.packets_dropped = 0 + self.verbose_trace = verbose_trace for v in signals: hvar, vtype = v.split(":") hier, _, name = hvar.rpartition(".") @@ -397,16 +398,17 @@ class VcdSink: elif datatag[0] == 'A': timestamp = self.timestamp try: - #print(f"### {timestamp:012X} : {self.varnames[tag]}[{sub}] <= {value} [OK] ", flush=True) + if self.verbose_trace: + print(f"### {timestamp:012} : {self.varnames[tag]}[{sub}] <= {value} [OK] ", flush=True) self.writer.change(self.arrays[tag][sub], timestamp, value) except ValueError: - print(f"### {timestamp:012X} : {self.varnames[tag]}[{sub}] <= {value} [VAL_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]}[{sub}] <= {value} [VAL_ERR] ", flush=True) self.packets_dropped += 1 except writer.VCDPhaseError: - print(f"### {timestamp:012X} : {self.varnames[tag]}[{sub}] <= {value} [PHA_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]}[{sub}] <= {value} [PHA_ERR] ", flush=True) self.packets_dropped += 1 except: - print(f"### {timestamp:012X} : {self.varnames[tag]}[{sub}] <= {value} [ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]}[{sub}] <= {value} [ERR] ", flush=True) self.packets_dropped += 1 elif datatag == 'S4': timestamp = self.timestamp @@ -419,16 +421,17 @@ class VcdSink: if sub == 1: try: string = self.strings[tag][1] - #print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\"", flush=True) - self.writer.change(self.strings[tag][0], timestamp, self.strings[tag][1]) + if self.verbose_trace: + print(f"### {timestamp:012} : {self.varnames[tag]} <= \"{string}\"", flush=True) + self.writer.change(self.strings[tag][0], timestamp, string) except ValueError: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [VAL_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [VAL_ERR] ", flush=True) self.packets_dropped += 1 except writer.VCDPhaseError: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [PHA_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [PHA_ERR] ", flush=True) self.packets_dropped += 1 except: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\" [ERR] ", flush=True) self.packets_dropped += 1 self.strings[tag][1] = "" @@ -440,16 +443,17 @@ class VcdSink: value = True elif datatag == 'F4': value = struct.unpack(">f", struct.pack(">L", value))[0] - #print(f"### {timestamp:012X} : {self.varnames[tag]} <= {value:08X}", flush=True) + if self.verbose_trace: + print(f"### {timestamp:012} : {self.varnames[tag]} <= {value:08X}", flush=True) self.writer.change(self.skalars[tag], timestamp, value) except ValueError: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= {value} [VAL_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= {value} [VAL_ERR] ", flush=True) self.packets_dropped += 1 except writer.VCDPhaseError: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= {value} [PHA_ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= {value} [PHA_ERR] ", flush=True) self.packets_dropped += 1 except: - print(f"### {timestamp:012X} : {self.varnames[tag]} <= {value} [ERR] ", flush=True) + print(f"### {timestamp:012} : {self.varnames[tag]} <= {value} [ERR] ", flush=True) self.packets_dropped += 1 def process_noise(noisefile, b): @@ -469,6 +473,8 @@ def main(): help='source tree to scan for trace marks') parser.add_argument('--diagnostics', action=argparse.BooleanOptionalAction, help='add additional signals tracing internal state of PET') + parser.add_argument('--trace', action=argparse.BooleanOptionalAction, + help='write out every trace that arrives') args = parser.parse_args() print(header) @@ -478,6 +484,7 @@ def main(): source_tree = args.source timescale = args.timescale enable_diag = args.diagnostics + enable_verbose_trace = args.trace predefined_signals = [] if enable_diag: @@ -506,7 +513,7 @@ def main(): nfile = open(noisefile, 'wb') process_noise_p = partial(process_noise, nfile) - vcd_sink = VcdSink(dfile, signals, timescale) + vcd_sink = VcdSink(dfile, signals, timescale, enable_verbose_trace) retagger = Retagger(vcd_sink.process, tags) packet_filter = Filter(retagger.process, process_noise_p) print("Signals:")