29 lines
839 B
Python
29 lines
839 B
Python
from owrx.toolbox import TextParser
|
|
from owrx.color import ColorCache
|
|
import json
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class DscParser(TextParser):
|
|
def __init__(self, service: bool = False):
|
|
# Colors will be assigned via this cache
|
|
self.colors = ColorCache()
|
|
# Construct parent object
|
|
super().__init__(filePrefix="DSC", service=service)
|
|
|
|
def parse(self, msg: bytes):
|
|
# Do not parse in service mode
|
|
if self.service:
|
|
return None
|
|
# Expect JSON data in text form
|
|
logger.debug("TEXT: {0}".format(msg))
|
|
out = json.loads(msg)
|
|
# Add mode name and a color to identify the sender
|
|
out["mode"] = "DSC"
|
|
out["color"] = self.colors.getColor(out["src"])
|
|
logger.debug("JSON: {0}".format(out))
|
|
return out
|