1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-21 23:55:17 -05:00

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.
This commit is contained in:
Hemna 2022-12-16 12:35:54 -05:00
parent 98c426d61a
commit 4af94fb2e4
2 changed files with 26 additions and 18 deletions

View File

@ -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()

View File

@ -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()