diff --git a/csdr/__init__.py b/csdr/__init__.py index a22be7f..1737c11 100644 --- a/csdr/__init__.py +++ b/csdr/__init__.py @@ -30,7 +30,8 @@ from functools import partial from csdr.output import Output -from owrx.kiss import KissClient, DirewolfConfig, DirewolfConfigSubscriber +from owrx.aprs.kiss import KissClient +from owrx.aprs.direwolf import DirewolfConfig, DirewolfConfigSubscriber from owrx.audio.chopper import AudioChopper from csdr.pipe import Pipe diff --git a/owrx/aprs.py b/owrx/aprs/__init__.py similarity index 99% rename from owrx/aprs.py rename to owrx/aprs/__init__.py index 1ce7278..a4c55ae 100644 --- a/owrx/aprs.py +++ b/owrx/aprs/__init__.py @@ -1,6 +1,5 @@ -from owrx.kiss import KissDeframer +from owrx.aprs.kiss import KissDeframer from owrx.map import Map, LatLngLocation -from owrx.bands import Bandplan from owrx.metrics import Metrics, CounterMetric from owrx.parser import Parser from datetime import datetime, timezone diff --git a/owrx/kiss.py b/owrx/aprs/direwolf.py similarity index 74% rename from owrx/kiss.py rename to owrx/aprs/direwolf.py index bd0d354..5cb5853 100644 --- a/owrx/kiss.py +++ b/owrx/aprs/direwolf.py @@ -1,17 +1,12 @@ -import socket -import time -import logging import random from owrx.config import Config from abc import ABC, abstractmethod +import socket + +import logging logger = logging.getLogger(__name__) -FEND = 0xC0 -FESC = 0xDB -TFEND = 0xDC -TFESC = 0xDD - FEET_PER_METER = 3.28084 @@ -141,51 +136,3 @@ IGLOGIN {callsign} {password} ) return config - - -class KissClient(object): - def __init__(self, port): - delay = 0.5 - retries = 0 - while True: - try: - self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.socket.connect(("localhost", port)) - break - except ConnectionError: - if retries > 20: - logger.error("maximum number of connection attempts reached. did direwolf start up correctly?") - raise - retries += 1 - time.sleep(delay) - - def read(self): - return self.socket.recv(1) - - -class KissDeframer(object): - def __init__(self): - self.escaped = False - self.buf = bytearray() - - def parse(self, input): - frames = [] - for b in input: - if b == FESC: - self.escaped = True - elif self.escaped: - if b == TFEND: - self.buf.append(FEND) - elif b == TFESC: - self.buf.append(FESC) - else: - logger.warning("invalid escape char: %s", str(input[0])) - self.escaped = False - elif input[0] == FEND: - # data frames start with 0x00 - if len(self.buf) > 1 and self.buf[0] == 0x00: - frames += [self.buf[1:]] - self.buf = bytearray() - else: - self.buf.append(b) - return frames diff --git a/owrx/aprs/kiss.py b/owrx/aprs/kiss.py new file mode 100644 index 0000000..b26c1fb --- /dev/null +++ b/owrx/aprs/kiss.py @@ -0,0 +1,59 @@ +import socket +import time + +import logging + +logger = logging.getLogger(__name__) + +FEND = 0xC0 +FESC = 0xDB +TFEND = 0xDC +TFESC = 0xDD + + +class KissClient(object): + def __init__(self, port): + delay = 0.5 + retries = 0 + while True: + try: + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket.connect(("localhost", port)) + break + except ConnectionError: + if retries > 20: + logger.error("maximum number of connection attempts reached. did direwolf start up correctly?") + raise + retries += 1 + time.sleep(delay) + + def read(self): + return self.socket.recv(1) + + +class KissDeframer(object): + def __init__(self): + self.escaped = False + self.buf = bytearray() + + def parse(self, input): + frames = [] + for b in input: + if b == FESC: + self.escaped = True + elif self.escaped: + if b == TFEND: + self.buf.append(FEND) + elif b == TFESC: + self.buf.append(FESC) + else: + logger.warning("invalid escape char: %s", str(input[0])) + self.escaped = False + elif input[0] == FEND: + # data frames start with 0x00 + if len(self.buf) > 1 and self.buf[0] == 0x00: + frames += [self.buf[1:]] + self.buf = bytearray() + else: + self.buf.append(b) + return frames diff --git a/setup.py b/setup.py index 9c11425..17c4539 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ setup( "owrx.reporting", "owrx.audio", "owrx.admin", + "owrx.aprs", "csdr", "htdocs", ]