From 6fb7c52502c4a1552748ec1b0ccc4d0e8cb7074c Mon Sep 17 00:00:00 2001 From: shackrat Date: Sun, 17 Sep 2023 00:29:46 -0400 Subject: [PATCH] Fix Weather Packet Parsing Unroll proposed weather packet parsing fixes for PR#81 (Issue #80). Course and Speed are ignored by parse_data_extentions() by when either value is '000'. I.e. 000/000 is considered not relevent an is ignored. When either value is 000, course or speed is set to None. It is possible for a weather report to have a speed of 0, meaning no wind. This should still be captured as it's relevent for a weather report. Course can also be 0, since some weather stations will report 0 for direction when speed is also 0. The core of the issue is that parse_data_extentions() ignores course and speed as noted above, AND it trims the course/speed from the body string. parse_weather_data() still looks to parse course/speed, but cannot when it's been removed by parse_data_extentions(). This change duplicates the contents of "body" so both parse_data_extentions() and parse_weather_data(body) have the appropriate body to parse. --- aprslib/parsing/position.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/aprslib/parsing/position.py b/aprslib/parsing/position.py index ccd270d..c99145e 100644 --- a/aprslib/parsing/position.py +++ b/aprslib/parsing/position.py @@ -62,27 +62,18 @@ def parse_position(packet_type, body): if parsed['symbol'] == '_': # attempt to parse winddir/speed # Page 92 of the spec + + # Duplicate body since parse_data_extentions() trims it and chops off + # part of the weather packet that parse_weather_data() expects + weather_body = body + + # Parse extensions body, result = parse_data_extentions(body) - wind_speed = result.get("speed") - wind_direction = result.get("course") + parsed.update(result) logger.debug("Attempting to parse weather report from comment") - body, result = parse_weather_data(body) - if wind_speed: - result.update({ - 'wind_speed': wind_speed * 0.44704, - }) - elif wind_direction: - # Since result.get("speed") now returns None if speed is 0, - # set wind speed as zero if wind direction has also been reported - # This is consistent with the behavior in 0.7.1 and earlier. - result.update({ - 'wind_speed': 0, - }) - if wind_direction: - result.update({ - 'wind_direction': wind_direction, - }) + body, result = parse_weather_data(weather_body) + parsed.update({ 'comment': body.strip(' '), 'weather': result,