From 0acde34abf331454989bd1fa5088d6c749ad8935 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Wed, 1 May 2024 23:28:58 -0400 Subject: [PATCH] Cleaning up ISM and PAGE parsers. --- csdr/module/toolbox.py | 3 ++- htdocs/lib/MessagePanel.js | 4 ++-- owrx/toolbox.py | 14 +++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/csdr/module/toolbox.py b/csdr/module/toolbox.py index 391a5b27..1af5c504 100644 --- a/csdr/module/toolbox.py +++ b/csdr/module/toolbox.py @@ -8,7 +8,8 @@ class Rtl433Module(ExecModule): def __init__(self, sampleRate: int = 250000, jsonOutput: bool = False): cmd = [ "rtl_433", "-r", "cs16:-", "-s", str(sampleRate), - "-M", "time:utc", "-F", "json" if jsonOutput else "kv", + "-M", "time:unix" if jsonOutput else "time:utc", + "-F", "json" if jsonOutput else "kv", "-A", ] super().__init__(Format.COMPLEX_SHORT, Format.CHAR, cmd) diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js index b552dbd4..a80d3021 100644 --- a/htdocs/lib/MessagePanel.js +++ b/htdocs/lib/MessagePanel.js @@ -630,7 +630,7 @@ IsmMessagePanel = function(el) { MessagePanel.call(this, el); this.initClearTimer(); // These are basic message attributes - this.basicInfo = ['mode', 'id', 'model', 'time', 'color']; + this.basicInfo = ['mode', 'id', 'model', 'timestamp', 'freq', 'color']; } IsmMessagePanel.prototype = Object.create(MessagePanel.prototype); @@ -665,7 +665,7 @@ IsmMessagePanel.prototype.pushMessage = function(msg) { // Get basic information, assume white color if missing var address = msg.hasOwnProperty('id')? msg.id : '???'; var device = msg.hasOwnProperty('model')? msg.model : ''; - var tstamp = msg.hasOwnProperty('time')? msg.time : ''; + var tstamp = msg.hasOwnProperty('timestamp')? Utils.HHMMSS(msg.timestamp) : ''; var color = msg.hasOwnProperty('color')? msg.color : '#FFF'; // Append message header (address, time, etc) diff --git a/owrx/toolbox.py b/owrx/toolbox.py index eebe6423..45f61b78 100644 --- a/owrx/toolbox.py +++ b/owrx/toolbox.py @@ -106,7 +106,6 @@ class TextParser(LineBasedModule): try: #logger.debug("%s: %s" % (self.myName(), str(line))) - # If running as a service with a log file... # Let parse() function do its thing out = self.parse(line) # If running as a service and writing to a log file... @@ -173,6 +172,10 @@ class IsmParser(TextParser): out = json.loads(msg) # Add mode name out["mode"] = "ISM" + # Convert Unix timestamps to milliseconds + if "time" in out: + out["timestamp"] = int(out["time"]) * 1000 + del out["time"] # Add frequency, if known if self.frequency: out["freq"] = self.frequency @@ -191,7 +194,7 @@ class PageParser(TextParser): pm = Config.get() self.filtering = "paging_filter" in pm and pm["paging_filter"] # POCSAG: Address: Function: (Certainty: )?(Numeric|Alpha|Skyper): - self.rePocsag = re.compile(r"POCSAG(\d+):\s*Address:\s*(\S+)\s+Function:\s*(\S+)(\s+Certainty:.*(\d+))?(\s+(\S+):\s*(.*))?") + self.rePocsag = re.compile(r"POCSAG(\d+):\s*Address:\s*(\S+)\s+Function:\s*(-?\d+)(\s+Certainty:\s*(-?\d+))?(\s+(\S+):\s*(.*))?") # FLEX|NNNN-NN-NN NN:NN:NN|//C/C|NN.NNN|NNNNNNNNN|| # FLEX|NNNN-NN-NN NN:NN:NN|//C/C|NN.NNN|NNNNNNNNN NNNNNNNNN|| self.reFlex1 = re.compile(r"FLEX\|(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d:\d\d)\|(\d+/\d+/\S/\S)\|(\d\d\.\d\d\d)\|(\d+(?:\s+\d+)?)\|(\S+)\|(.*)") @@ -266,16 +269,17 @@ class PageParser(TextParser): "baud": baud, "timestamp": round(datetime.now().timestamp() * 1000), "address": capcode, - "function": function, - "certainty": certainty, + "function": int(function), "type": msgtype, "message": msg } - # Output type and message + # Output type, message, and certainty if len(msgtype)>0: out["type"] = msgtype if len(msg)>0: out["message"] = msg + if certainty is not None: + out["certainty"] = int(certainty) # Done return out