2020-04-12 11:10:23 +00:00
|
|
|
from .wsjt import WsjtChopper
|
|
|
|
from .parser import Parser
|
|
|
|
import re
|
2020-04-13 14:35:31 +00:00
|
|
|
from js8py import Js8
|
2020-04-17 21:50:23 +00:00
|
|
|
from js8py.frames import Js8FrameHeartbeat, Js8FrameCompound
|
2020-04-14 19:10:35 +00:00
|
|
|
from owrx.map import Map, LocatorLocation
|
|
|
|
from owrx.pskreporter import PskReporter
|
2020-04-14 20:31:30 +00:00
|
|
|
from owrx.metrics import Metrics, CounterMetric
|
2020-04-12 11:10:23 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Js8Chopper(WsjtChopper):
|
|
|
|
def getInterval(self):
|
|
|
|
return 15
|
|
|
|
|
|
|
|
def getFileTimestampFormat(self):
|
|
|
|
return "%y%m%d_%H%M%S"
|
|
|
|
|
|
|
|
def decoder_commandline(self, file):
|
|
|
|
return ["js8", "--js8", "-d", str(self.decoding_depth("js8")), file]
|
|
|
|
|
|
|
|
|
|
|
|
class Js8Parser(Parser):
|
|
|
|
decoderRegex = re.compile(" ?<Decode(Started|Debug|Finished)>")
|
|
|
|
|
|
|
|
def parse(self, raw):
|
2020-04-13 14:35:31 +00:00
|
|
|
try:
|
|
|
|
freq, raw_msg = raw
|
|
|
|
self.setDialFrequency(freq)
|
|
|
|
msg = raw_msg.decode().rstrip()
|
|
|
|
if Js8Parser.decoderRegex.match(msg):
|
|
|
|
return
|
|
|
|
if msg.startswith(" EOF on input file"):
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.debug(msg)
|
|
|
|
|
|
|
|
frame = Js8().parse_message(msg)
|
2020-04-14 19:10:35 +00:00
|
|
|
self.handler.write_js8_message(frame, self.dial_freq)
|
|
|
|
logger.debug(frame)
|
|
|
|
|
2020-04-14 20:31:30 +00:00
|
|
|
self.pushDecode()
|
|
|
|
|
2020-04-17 21:50:23 +00:00
|
|
|
if (isinstance(frame, Js8FrameHeartbeat) or isinstance(frame, Js8FrameCompound)) and frame.grid:
|
2020-04-14 19:10:35 +00:00
|
|
|
Map.getSharedInstance().updateLocation(
|
|
|
|
frame.callsign, LocatorLocation(frame.grid), "JS8", self.band
|
|
|
|
)
|
|
|
|
PskReporter.getSharedInstance().spot({
|
|
|
|
"callsign": frame.callsign,
|
|
|
|
"mode": "JS8",
|
|
|
|
"locator": frame.grid,
|
|
|
|
"freq": self.dial_freq + frame.freq,
|
|
|
|
"db": frame.db,
|
|
|
|
"timestamp": frame.timestamp,
|
|
|
|
"msg": str(frame)
|
|
|
|
})
|
2020-04-13 14:35:31 +00:00
|
|
|
|
|
|
|
except Exception:
|
|
|
|
logger.exception("error while parsing js8 message")
|
2020-04-14 20:31:30 +00:00
|
|
|
|
|
|
|
def pushDecode(self):
|
|
|
|
metrics = Metrics.getSharedInstance()
|
|
|
|
band = "unknown"
|
|
|
|
if self.band is not None:
|
|
|
|
band = self.band.getName()
|
|
|
|
if band is None:
|
|
|
|
band = "unknown"
|
|
|
|
|
2020-04-14 21:16:45 +00:00
|
|
|
name = "js8call.decodes.{band}.JS8".format(band=band)
|
2020-04-14 20:31:30 +00:00
|
|
|
metric = metrics.getMetric(name)
|
|
|
|
if metric is None:
|
|
|
|
metric = CounterMetric()
|
|
|
|
metrics.addMetric(name, metric)
|
|
|
|
|
|
|
|
metric.inc()
|