From 59e5af8ee59bfeac4c72662c42bcf0663162e3ef Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 16 Dec 2022 12:35:54 -0500 Subject: [PATCH] Added contructing a GPSPacket for sending This patch adds the needed code to construct the raw output string for sending a GPSPacket. TODO: Need to incorporate speed, course, rng, position ambiguity ? TODO: Need to add option to 'compress' the output location data. --- aprsd/cmds/webchat.py | 14 +------------- aprsd/packets/core.py | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/aprsd/cmds/webchat.py b/aprsd/cmds/webchat.py index e79763c..58a8eba 100644 --- a/aprsd/cmds/webchat.py +++ b/aprsd/cmds/webchat.py @@ -365,24 +365,12 @@ class SendMessageNamespace(Namespace): LOG.debug(f"Lat DDM {lat}") LOG.debug(f"Long DDM {long}") - local_datetime = datetime.datetime.now() - utc_offset_timedelta = datetime.datetime.utcnow() - local_datetime - result_utc_datetime = local_datetime + utc_offset_timedelta - time_zulu = result_utc_datetime.strftime("%d%H%M") - - # now construct a beacon to send over the client connection - txt = ( - f"{self._config['aprs']['login']}>APZ100,WIDE2-1" - f":@{time_zulu}z{lat}/{long}l APRSD WebChat Beacon" - ) - - LOG.debug(f"Sending {txt}") beacon = packets.GPSPacket( from_call=self._config["aprs"]["login"], to_call="APDW16", - raw=txt, latitude=lat, longitude=long, + comment="APRSD WebChat Beacon", ) beacon.send_direct() diff --git a/aprsd/packets/core.py b/aprsd/packets/core.py index b9d9736..2623c0f 100644 --- a/aprsd/packets/core.py +++ b/aprsd/packets/core.py @@ -1,5 +1,6 @@ import abc from dataclasses import asdict, dataclass, field +import datetime import logging import re import time @@ -220,7 +221,6 @@ class MessagePacket(PathPacket): @dataclass() class StatusPacket(PathPacket): status: str = None - timestamp: int = 0 messagecapable: bool = False comment: str = None @@ -235,15 +235,35 @@ class GPSPacket(PathPacket): altitude: float = 0.00 rng: float = 0.00 posambiguity: int = 0 - timestamp: int = 0 comment: str = None - symbol: str = None - symbol_table: str = None + symbol: str = field(default="l") + symbol_table: str = field(default="/") speed: float = 0.00 course: int = 0 + def _build_time_zulu(self): + """Build the timestamp in UTC/zulu.""" + if self.timestamp: + local_dt = datetime.datetime.fromtimestamp(self.timestamp) + else: + local_dt = datetime.datetime.now() + self.timestamp = datetime.datetime.timestamp(local_dt) + + utc_offset_timedelta = datetime.datetime.utcnow() - local_dt + result_utc_datetime = local_dt + utc_offset_timedelta + time_zulu = result_utc_datetime.strftime("%d%H%M") + return time_zulu + def _build_raw(self): - raise NotImplementedError + time_zulu = self._build_time_zulu() + + self.raw = ( + f"{self.from_call}>{self.to_call},WIDE2-1:" + f"@{time_zulu}z{self.latitude}{self.symbol_table}" + f"{self.longitude}{self.symbol}" + ) + if self.comment: + self.raw = f"{self.raw}{self.comment}" @dataclass()