Improving service output, DSC decoder.

This commit is contained in:
Marat Fayzullin 2024-03-20 21:36:26 -04:00
parent 83d3f25488
commit 490cf1e542
5 changed files with 37 additions and 19 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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",

View File

@ -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

View File

@ -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