From 490cf1e542d2df7a35344cbb7bf7284fd871416d Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Wed, 20 Mar 2024 21:36:26 -0400 Subject: [PATCH] Improving service output, DSC decoder. --- owrx/aircraft.py | 4 ++-- owrx/config/defaults.py | 3 ++- owrx/controllers/settings/decoding.py | 4 ++++ owrx/dsc.py | 22 +++++++++++++--------- owrx/toolbox.py | 23 ++++++++++++++++------- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/owrx/aircraft.py b/owrx/aircraft.py index 3a0870c8..fcb6b0c6 100644 --- a/owrx/aircraft.py +++ b/owrx/aircraft.py @@ -325,8 +325,8 @@ class AircraftParser(TextParser): out[key] = self.reDots.sub("\\1", out[key]) # Update aircraft database with the new data AircraftManager.getSharedInstance().update(out) - # Done - return out + # Do not return anything when in service mode + return None if self.service else out # Mode-specific parse function def parseAircraft(self, msg: bytes): diff --git a/owrx/config/defaults.py b/owrx/config/defaults.py index 58a02c90..12026f00 100644 --- a/owrx/config/defaults.py +++ b/owrx/config/defaults.py @@ -210,5 +210,6 @@ defaultConfig = PropertyLayer( fax_postprocess=True, fax_color=False, fax_am=False, - cw_showcw=False + cw_showcw=False, + dsc_show_errors=True ).readonly() diff --git a/owrx/controllers/settings/decoding.py b/owrx/controllers/settings/decoding.py index 8703b7c4..c1f732cc 100644 --- a/owrx/controllers/settings/decoding.py +++ b/owrx/controllers/settings/decoding.py @@ -51,6 +51,10 @@ class DecodingSettingsController(SettingsFormController): "cw_showcw", "Show CW codes (dits / dahs) when decoding CW", ), + CheckboxInput( + "dsc_show_errors", + "Show partial messages when decoding DSC", + ), ), Section( "Digital voice", diff --git a/owrx/dsc.py b/owrx/dsc.py index d18d224e..1742933d 100644 --- a/owrx/dsc.py +++ b/owrx/dsc.py @@ -1,5 +1,6 @@ from owrx.toolbox import TextParser from owrx.color import ColorCache +from owrx.config import Config import json import logging @@ -25,16 +26,19 @@ class DscParser(TextParser): # return None # Expect JSON data in text form out = json.loads(msg) - # Add mode name, time stamp, frequency, and color to identify sender - out["mode"] = "DSC" + # Filter out errors + pm = Config.get() + if "data" in out and not pm["dsc_show_errors"]: + return {} + # Add frequency if self.frequency != 0: out["frequency"] = self.frequency - if "src" in out: - out["color"] = self.colors.getColor(out["src"]) - # Log received messages, showing errors in debug mode only - if "data" in out: - logger.debug("{0}".format(out)) - else: - logger.info("{0}".format(out)) + # When in interactive mode, add mode name and color to identify sender + if not self.service: + out["mode"] = "DSC" + if "src" in out: + out["color"] = self.colors.getColor(out["src"]) + # Log received messages for debugging + logger.debug("{0}".format(out)) # Done return out diff --git a/owrx/toolbox.py b/owrx/toolbox.py index 46173a3e..85b62c87 100644 --- a/owrx/toolbox.py +++ b/owrx/toolbox.py @@ -62,8 +62,8 @@ class TextParser(LineBasedModule): # Write new line into the file try: self.file.write(data) - except Exception: - pass + except Exception as exptn: + logger.debug("Exception writing file: %s" % str(exptn)) # No more than maxLines per file self.cntLines = self.cntLines + 1 if self.cntLines >= self.maxLines: @@ -106,18 +106,24 @@ class TextParser(LineBasedModule): try: #logger.debug("%s: %s" % (self.myName(), str(line))) # If running as a service with a log file... - if self.service and self.filePfx is not None: - # Write message into open log file, including end-of-line - self.writeFile(line) - self.writeFile(b"\n") # Let parse() function do its thing out = self.parse(line) + # If running as a service and writing to a log file... + if self.service and self.filePfx is not None: + if out and len(out) > 0: + # If parser returned output, write it into log file + self.writeFile(str(out).encode("utf-8")) + self.writeFile(b"\n") + elif out is None and len(line) > 0: + # Write input into log file, including end-of-line + self.writeFile(line) + self.writeFile(b"\n") except Exception as exptn: logger.debug("%s: Exception parsing: %s" % (self.myName(), str(exptn))) # Return parsed result, ignore result in service mode - return out if not self.service else None + return out if not self.service and len(out) > 0 else None class RdsParser(TextParser): @@ -128,6 +134,9 @@ class RdsParser(TextParser): super().__init__(filePrefix="WFM", service=service) def parse(self, msg: bytes): + # Do not parse in service mode + if self.service: + return None # Expect JSON data in text form data = json.loads(msg) # Delete constantly changing group ID