mirror of
https://github.com/ha7ilm/openwebrx.git
synced 2026-01-21 15:50:17 +01:00
add message parsing
This commit is contained in:
parent
476e4ebc5b
commit
10337f7db8
|
|
@ -1,14 +1,16 @@
|
|||
from pycsdr.modules import Convert
|
||||
from pycsdr.types import Format
|
||||
from csdr.chain.demodulator import ServiceDemodulator
|
||||
from owrx.adsb.dump1090 import Dump1090Module
|
||||
from owrx.adsb.dump1090 import Dump1090Module, RawDeframer, ModeSParser
|
||||
|
||||
|
||||
class Dump1090(ServiceDemodulator):
|
||||
def __init__(self):
|
||||
workers = [
|
||||
Convert(Format.COMPLEX_FLOAT, Format.COMPLEX_SHORT),
|
||||
Dump1090Module()
|
||||
Dump1090Module(),
|
||||
RawDeframer(),
|
||||
ModeSParser(),
|
||||
]
|
||||
|
||||
super().__init__(workers)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from pycsdr.modules import ExecModule, Writer, TcpSource
|
||||
from pycsdr.types import Format
|
||||
from csdr.module import LogWriter
|
||||
from csdr.module import LogWriter, ThreadModule, PickleModule
|
||||
from owrx.socket import getAvailablePort
|
||||
import time
|
||||
import pickle
|
||||
|
||||
import logging
|
||||
|
||||
|
|
@ -44,3 +45,47 @@ class Dump1090Module(ExecModule):
|
|||
self.writer = writer
|
||||
if self.tcpSource is not None:
|
||||
self.tcpSource.setWriter(writer)
|
||||
|
||||
|
||||
class RawDeframer(ThreadModule):
|
||||
def __init__(self):
|
||||
self.retained = bytes()
|
||||
super().__init__()
|
||||
|
||||
def getInputFormat(self) -> Format:
|
||||
return Format.CHAR
|
||||
|
||||
def getOutputFormat(self) -> Format:
|
||||
return Format.CHAR
|
||||
|
||||
def run(self):
|
||||
while self.doRun:
|
||||
data = self.reader.read()
|
||||
if data is None:
|
||||
self.doRun = False
|
||||
else:
|
||||
self.retained += data
|
||||
lines = self.retained.split(b"\n")
|
||||
|
||||
# keep the last line
|
||||
# this should either be empty if the last char was \n
|
||||
# or an incomplete line if the read returned early
|
||||
self.retained = lines[-1]
|
||||
|
||||
# log all completed lines
|
||||
for line in lines[0:-1]:
|
||||
self.writer.write(pickle.dumps(self.parse(line)))
|
||||
|
||||
def parse(self, line):
|
||||
if line.startswith(b'*') and line.endswith(b';') and len(line) in [16, 30]:
|
||||
return bytes.fromhex(line[1:-1].decode())
|
||||
else:
|
||||
logger.warning("invalid raw message: %s", line)
|
||||
|
||||
|
||||
class ModeSParser(PickleModule):
|
||||
def process(self, input):
|
||||
return {
|
||||
"mode": "ADSB",
|
||||
"df": (input[0] & 0b11111000) >> 3
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue