Skip to content

Commit

Permalink
Implement
Browse files Browse the repository at this point in the history
Implements: Fix issue 80: Weather packet decoding. rossengeorgiev#81
  • Loading branch information
shackrat committed Sep 14, 2023
1 parent 09ac002 commit d915878
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
3 changes: 2 additions & 1 deletion aprslib/parsing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ def parse_data_extentions(body):
# course speed bearing nrq
# Page 27 of the spec
# format: 111/222/333/444text
# Speed is in mph
match = re.findall(r"^([0-9 \.]{3})/([0-9 \.]{3})", body)
if match:
cse, spd = match[0]
body = body[7:]
if cse.isdigit() and cse != "000":
parsed.update({'course': int(cse) if 1 <= int(cse) <= 360 else 0})
if spd.isdigit() and spd != "000":
parsed.update({'speed': int(spd)*1.852})
parsed.update({'speed': int(spd)})

# DF Report format
# Page 29 of teh spec
Expand Down
13 changes: 10 additions & 3 deletions aprslib/parsing/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ def parse_position(packet_type, body):
# attempt to parse winddir/speed
# Page 92 of the spec
body, result = parse_data_extentions(body)
parsed.update(result)
wind_speed = result.get("speed")
wind_direction = result.get("course")

logger.debug("Attempting to parse weather report from comment")
body, result = parse_weather_data(body)
if wind_speed:
result.update({
'wind_speed': wind_speed,
})
if wind_direction:
result.update({
'wind_direction': wind_direction,
})
parsed.update({
'comment': body.strip(' '),
'weather': result,
Expand Down Expand Up @@ -204,5 +213,3 @@ def parse_normal(body):
})

return (body, parsed)


6 changes: 4 additions & 2 deletions aprslib/parsing/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
]

# constants
wind_multiplier = 0.44704
rain_multiplier = 0.254
# wind is in miles per hour
wind_multiplier = 1
# Spec 1.1 Rain is in hundredths of an inch.
rain_multiplier = 0.01

key_map = {
'g': 'wind_gust',
Expand Down
8 changes: 4 additions & 4 deletions tests/test_parse_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_course_speed(self):
self.assertEqual(remaining, '/text')
self.assertEqual(parsed, {
'course': 123,
'speed': 100*1.852,
'speed': 100,
})

def test_course_speed_spaces(self):
Expand Down Expand Up @@ -305,7 +305,7 @@ def test_empty_bearing_nrq(self):
self.assertEqual(remaining, 'text')
self.assertEqual(parsed, {
'course': 111,
'speed': 100*1.852,
'speed': 100,
})

body = "111/100/2 /33.text"
Expand All @@ -314,7 +314,7 @@ def test_empty_bearing_nrq(self):
self.assertEqual(remaining, 'text')
self.assertEqual(parsed, {
'course': 111,
'speed': 100*1.852,
'speed': 100,
})

def test_course_speed_bearing_nrq_empty_cse_speed(self):
Expand All @@ -335,7 +335,7 @@ def test_course_speed_bearing_nrq(self):
self.assertEqual(remaining, 'text')
self.assertEqual(parsed, {
'course': 123,
'speed': 100*1.852,
'speed': 100,
'bearing': 234,
'nrq': 345,
})
Expand Down
20 changes: 10 additions & 10 deletions tests/test_parse_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_position_packet_only_weather_valid(self):
'wind_gust': 0.0,
'temperature': 18.88888888888889,
'rain_1h': 0.0,
'rain_24h': 0.0
'rain_24h': 0.0,
}
}

Expand All @@ -50,14 +50,14 @@ def test_position_packet_data_ext_and_weather_valid(self):
'symbol_table': '/',
'latitude': 49.05833333333333,
'longitude': -72.02916666666667,
'course': 90,
'speed': 1*1.852,
'comment': '...dUII',
'weather': {
'wind_gust': 0.0,
'temperature': 18.88888888888889,
'rain_1h': 0.0,
'rain_24h': 0.0
'rain_24h': 0.0,
'wind_direction': 90,
'wind_speed': 1,
}
}

Expand All @@ -77,13 +77,13 @@ def test_position_packet_optional_speed(self):
'symbol_table': '/',
'latitude': 49.05833333333333,
'longitude': -72.02916666666667,
'course': 90,
'comment': '...dUII',
'weather': {
'wind_gust': 0.0,
'temperature': 18.88888888888889,
'rain_1h': 0.0,
'rain_24h': 0.0
'rain_24h': 0.0,
'wind_direction': 90
}
}

Expand All @@ -103,13 +103,13 @@ def test_position_packet_optional_course(self):
'symbol_table': '/',
'latitude': 49.05833333333333,
'longitude': -72.02916666666667,
'speed': 1*1.852,
'comment': '...dUII',
'weather': {
'wind_gust': 0.0,
'temperature': 18.88888888888889,
'rain_1h': 0.0,
'rain_24h': 0.0
'rain_24h': 0.0,
'wind_speed': 1,
}
}

Expand Down Expand Up @@ -153,13 +153,13 @@ def test_position_packet_optional_course(self):
'symbol_table': '/',
'latitude': 49.05833333333333,
'longitude': -72.02916666666667,
'speed': 1*1.852,
'comment': '...dUII',
'weather': {
'wind_gust': 0.0,
'temperature': 18.88888888888889,
'rain_1h': 0.0,
'rain_24h': 0.0
'rain_24h': 0.0,
'wind_speed': 1,
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse_weather_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from aprslib.parsing import parse_weather_data
from aprslib.parsing import parse

wind_multiplier = 0.44704
mm_multiplier = 0.254
wind_multiplier = 1
mm_multiplier = 0.010

class ParseCommentWeather(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit d915878

Please sign in to comment.