get dump1090 on STDOUT instead of a tcp socket

This commit is contained in:
Jakob Ketterl 2023-09-15 20:44:17 +02:00
parent 1a8d1dcb8b
commit e201ca07e3

View file

@ -1,8 +1,6 @@
from pycsdr.modules import ExecModule, Writer, TcpSource from pycsdr.modules import ExecModule
from pycsdr.types import Format from pycsdr.types import Format
from csdr.module import LogWriter, LineBasedModule from csdr.module import LineBasedModule
from owrx.socket import getAvailablePort
import time
import logging import logging
@ -11,43 +9,15 @@ logger = logging.getLogger(__name__)
class Dump1090Module(ExecModule): class Dump1090Module(ExecModule):
def __init__(self): def __init__(self):
self.tcpSource = None
self.writer = None
self.port = getAvailablePort()
super().__init__( super().__init__(
Format.COMPLEX_SHORT, Format.COMPLEX_SHORT,
Format.CHAR, Format.CHAR,
["dump1090", "--ifile", "-", "--iformat", "SC16", "--quiet", "--net-ro-port", str(self.port)], ["dump1090", "--ifile", "-", "--iformat", "SC16", "--raw"],
# send some data on decoder shutdown since the dump1090 internal reader locks up otherwise # send some data on decoder shutdown since the dump1090 internal reader locks up otherwise
# dump1090 reads chunks of 100ms, which equals to 240k samples at 2.4MS/s # dump1090 reads chunks of 100ms, which equals to 240k samples at 2.4MS/s
# some extra should not hurt # some extra should not hurt
flushSize=300000 flushSize=300000
) )
super().setWriter(LogWriter(__name__))
self.start()
def start(self):
delay = 0.5
retries = 0
while True:
try:
self.tcpSource = TcpSource(self.port, Format.CHAR)
if self.writer:
self.tcpSource.setWriter(self.writer)
break
except ConnectionError:
if retries > 20:
logger.error("maximum number of connection attempts reached. did dump1090 start up correctly?")
raise
retries += 1
time.sleep(delay)
def setWriter(self, writer: Writer) -> None:
self.writer = writer
if self.tcpSource is not None:
self.tcpSource.setWriter(writer)
class RawDeframer(LineBasedModule): class RawDeframer(LineBasedModule):