Skip to content

Commit

Permalink
Fix in for aprslib issue #80
Browse files Browse the repository at this point in the history
aprslib incorrectly decodes weather packets and doesn't provide
wind_speed or wind_direction from the CSE/SPD 7 bytes in the APRS
packet.  This patch puts a temporary fix in place until the
aprslib pull request lands and is released.

rossengeorgiev/aprs-python#80

rossengeorgiev/aprs-python#81
  • Loading branch information
hemna committed Jul 13, 2023
1 parent bba7b68 commit 5c15d9d
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions aprsd/packets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,34 @@ def factory(raw_packet):
if packet_type == PACKET_TYPE_WX:
# the weather information is in a dict
# this brings those values out to the outer dict

for key in raw["weather"]:
raw[key] = raw["weather"][key]

# If we have the broken aprslib, then we need to
# Convert the course and speed to wind_speed and wind_direction
# aprslib issue #80
# https://github.com/rossengeorgiev/aprs-python/issues/80
# Wind speed and course is option in the SPEC.
# For some reason aprslib multiplies the speed by 1.852.
if "wind_speed" not in raw and "wind_direction" not in raw:
# Most likely this is the broken aprslib
# So we need to convert the wind_gust speed
raw["wind_gust"] = raw.get("wind_gust", 0)/0.44704
if "wind_speed" not in raw:
wind_speed = raw.get("speed")
if wind_speed:
raw["wind_speed"] = wind_speed/1.852
if "speed" in raw:
del[raw["speed"]]
if "wind_direction" not in raw:
wind_direction = raw.get("course")
if wind_direction:
raw["wind_direction"] = wind_direction
if "course" in raw:
del[raw["course"]]


return dacite.from_dict(data_class=class_name, data=raw)

def log(self, header=None):
Expand Down Expand Up @@ -281,10 +306,6 @@ class GPSPacket(PathPacket):
comment: str = None
symbol: str = field(default="l")
symbol_table: str = field(default="/")
# in MPH
speed: float = 0.00
# 0 to 360
course: int = 0

def decdeg2dms(self, degrees_decimal):
is_positive = degrees_decimal >= 0
Expand Down Expand Up @@ -387,6 +408,10 @@ class MicEPacket(GPSPacket):
messagecapable: bool = False
mbits: str = None
mtype: str = None
# in MPH
speed: float = 0.00
# 0 to 360
course: int = 0

def _build_raw(self):
raise NotImplementedError
Expand All @@ -397,6 +422,10 @@ class ObjectPacket(GPSPacket):
alive: bool = True
raw_timestamp: str = None
symbol: str = field(default="r")
# in MPH
speed: float = 0.00
# 0 to 360
course: int = 0

def _build_raw(self):
"""
Expand Down Expand Up @@ -424,6 +453,8 @@ def _build_raw(self):
@dataclass()
class WeatherPacket(GPSPacket):
symbol: str = "_"
wind_speed: float = 0.00
wind_direction: int = 0
wind_gust: float = 0.00
temperature: float = 0.00
# in inches. 1.04 means 1.04 inches
Expand Down

0 comments on commit 5c15d9d

Please sign in to comment.