Skip to content

Commit fb95db6

Browse files
committed
Fix telemetry packet with leading 0
sometimes the analog values in telemetry packets don't contain a leading zero. this patch fixes and tests for that.
1 parent a336be2 commit fb95db6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

aprslib/parsing/telemetry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def parse_telemetry_report(body):
199199
continue
200200

201201
# Allow integers, decimals, and negative numbers
202-
if not re.match(r'^-?\d+\.?\d*$', val_str):
202+
# Also allow values starting with decimal point (e.g., .10 = 0.10)
203+
if not re.match(r'^-?(\d+\.?\d*|\.\d+)$', val_str):
203204
raise ParseError("telemetry analog value %d has invalid format" % (i+1))
204205
try:
205206
val = float(val_str)

tests/test_parse_telemetry.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ def test_valid_telemetry_digital_bits_with_non_binary_suffix(self):
263263
self.assertEqual(result['telemetry']['bits'], '01100101')
264264
self.assertEqual(result.get('comment', ''), '2')
265265

266+
def test_valid_telemetry_leading_decimal_analog_value(self):
267+
"""Test telemetry packet with leading decimal in analog value (e.g., .10 = 0.10)"""
268+
packet = "IT9FDP-15>APRTLM,TCPIP*,qAC,T2CZECH:T#720,.10,12.83,12.19,14.0,14.8,00000000"
269+
result = parse(packet)
270+
271+
self.assertEqual(result['format'], 'telemetry')
272+
self.assertEqual(result['telemetry']['seq'], 720)
273+
# .10 should be parsed as 0.1
274+
self.assertEqual(result['telemetry']['vals'], [0.1, 12.83, 12.19, 14.0, 14.8])
275+
self.assertEqual(result['telemetry']['bits'], '00000000')
276+
266277
def test_parse_telemetry_report_function_direct(self):
267278
"""Test parse_telemetry_report function directly"""
268279
body = "#123,456,789,012,345,678,11001010,Test"

0 commit comments

Comments
 (0)