Skip to content

Commit

Permalink
Fix Weather Packet Parsing
Browse files Browse the repository at this point in the history
Unroll proposed weather packet parsing fixes for PR#81 (Issue rossengeorgiev#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.
  • Loading branch information
shackrat committed Sep 17, 2023
1 parent e8afe4b commit 6fb7c52
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions aprslib/parsing/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6fb7c52

Please sign in to comment.