Fixed ddhhmm vs. hhmmss problem

pull/32/head
Konstantin Gründger 2017-09-30 14:17:35 +02:00
rodzic 33a7690f7d
commit 054c9eeed0
5 zmienionych plików z 75 dodań i 2 usunięć

Wyświetl plik

@ -25,11 +25,18 @@ def parse_aprs(message, reference_date=None, reference_time=None):
match_position = re.search(PATTERN_APRS_POSITION, message)
if match_position:
if match_position.group('time_hhmmss'):
timestamp = createTimestamp(match_position.group('time_hhmmss'), reference_date, reference_time)
else:
timestamp_ddmmhh = match_position.group('time_ddmmhh')
reference_date = reference_date.replace(day=int(timestamp_ddmmhh[:2]))
timestamp = createTimestamp(timestamp_ddmmhh[2:] + '00', reference_date)
return {'name': match_position.group('callsign'),
'dstcall': match_position.group('dstcall'),
'relay': match_position.group('relay') if match_position.group('relay') else None,
'receiver_name': match_position.group('receiver'),
'timestamp': createTimestamp(match_position.group('time'), reference_date, reference_time),
'timestamp': timestamp,
'latitude': parseAngle('0' + match_position.group('latitude') + (match_position.group('latitude_enhancement') or '0')) *
(-1 if match_position.group('latitude_sign') == 'S' else 1),
'symboltable': match_position.group('symbol_table'),

Wyświetl plik

@ -0,0 +1,32 @@
import re
from ogn.parser.pattern import PATTERN_RECEIVER_POSITION, PATTERN_RECEIVER_STATUS
def parse_position(aprs_comment):
match = re.search(PATTERN_RECEIVER_POSITION, aprs_comment)
return {'user_comment': match.group('user_comment') if match.group('user_comment') else None}
def parse_status(aprs_comment):
match = re.search(PATTERN_RECEIVER_STATUS, aprs_comment)
return {'version': match.group('version'),
'platform': match.group('platform'),
'cpu_load': float(match.group('cpu_load')),
'free_ram': float(match.group('ram_free')),
'total_ram': float(match.group('ram_total')),
'ntp_error': float(match.group('ntp_offset')),
'rt_crystal_correction': float(match.group('ntp_correction')),
'voltage': float(match.group('voltage')) if match.group('voltage') else None,
'amperage': float(match.group('amperage')) if match.group('amperage') else None,
'cpu_temp': float(match.group('cpu_temperature')) if match.group('cpu_temperature') else None,
'senders_visible': int(match.group('visible_senders')) if match.group('visible_senders') else None,
'senders_total': int(match.group('senders')) if match.group('senders') else None,
'rec_crystal_correction': int(match.group('rf_correction_manual')) if match.group('rf_correction_manual') else None,
'rec_crystal_correction_fine': float(match.group('rf_correction_automatic')) if match.group('rf_correction_automatic') else None,
'rec_input_noise': float(match.group('signal_quality')) if match.group('signal_quality') else None,
'senders_signal': float(match.group('senders_signal_quality')) if match.group('senders_signal_quality') else None,
'senders_messages': float(match.group('senders_messages')) if match.group('senders_messages') else None,
'good_senders_signal': float(match.group('good_senders_signal_quality')) if match.group('good_senders_signal_quality') else None,
'good_senders': float(match.group('good_senders')) if match.group('good_senders') else None,
'good_and_bad_senders': float(match.group('good_and_bad_senders')) if match.group('good_and_bad_senders') else None}

Wyświetl plik

@ -0,0 +1,27 @@
import re
from ogn.parser.utils import fpm2ms
from ogn.parser.pattern import PATTERN_TRACKER_BEACON_POSITION, PATTERN_TRACKER_BEACON_STATUS
def parse_position(aprs_comment):
match = re.search(PATTERN_TRACKER_BEACON_POSITION, aprs_comment)
return {'address_type': int(match.group('details'), 16) & 0b00000011,
'aircraft_type': (int(match.group('details'), 16) & 0b01111100) >> 2,
'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1,
'address': match.group('id'),
'climb_rate': int(match.group('climb_rate')) * fpm2ms if match.group('climb_rate') else None,
'turn_rate': float(match.group('turn_rate')) if match.group('turn_rate') else None,
'flightlevel': float(match.group('flight_level')) if match.group('flight_level') else None,
'signal_quality': float(match.group('signal_quality')) if match.group('signal_quality') else None,
'error_count': int(match.group('errors')) if match.group('errors') else None,
'frequency_offset': float(match.group('frequency_offset')) if match.group('frequency_offset') else None,
'gps_status': match.group('gps_accuracy') if match.group('gps_accuracy') else None,
'software_version': float(match.group('flarm_software_version')) if match.group('flarm_software_version') else None,
'hardware_version': int(match.group('flarm_hardware_version'), 16) if match.group('flarm_hardware_version') else None}
def parse_status(aprs_comment):
match = re.search(PATTERN_TRACKER_BEACON_STATUS, aprs_comment)
return {'voltage': float(match.group('voltage')) if match.group('voltage') else None,
'temperature': float(match.group('temperature')) if match.group('temperature') else None}

Wyświetl plik

@ -1,7 +1,7 @@
import re
PATTERN_APRS_POSITION = re.compile(r"^(?P<callsign>.+?)>(?P<dstcall>[A-Z0-9]+),((?P<relay>[A-Za-z0-9]+)\*)?.*,(?P<receiver>.+?):/(?P<time>\d{6})+(h|z)(?P<latitude>\d{4}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>\d{5}\.\d{2})(?P<longitude_sign>E|W)(?P<symbol>.)(?P<course_extension>(?P<course>\d{3})/(?P<ground_speed>\d{3}))?/A=(?P<altitude>\d{6})(?P<pos_extension>\s!W((?P<latitude_enhancement>\d)(?P<longitude_enhancement>\d))!)?(?:\s(?P<comment>.*))?$")
PATTERN_APRS_POSITION = re.compile(r"^(?P<callsign>.+?)>(?P<dstcall>[A-Z0-9]+),((?P<relay>[A-Za-z0-9]+)\*)?.*,(?P<receiver>.+?):/((?P<time_hhmmss>\d{6})h|(?P<time_ddmmhh>\d{6})z)(?P<latitude>\d{4}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>\d{5}\.\d{2})(?P<longitude_sign>E|W)(?P<symbol>.)(?P<course_extension>(?P<course>\d{3})/(?P<ground_speed>\d{3}))?/A=(?P<altitude>\d{6})(?P<pos_extension>\s!W((?P<latitude_enhancement>\d)(?P<longitude_enhancement>\d))!)?(?:\s(?P<comment>.*))?$")
PATTERN_APRS_STATUS = re.compile(r"^(?P<callsign>.+?)>(?P<dstcall>[A-Z0-9]+),.+,(?P<receiver>.+?):>(?P<time>\d{6})+h\s(?P<comment>.*)$")
PATTERN_NAVITER_BEACON = re.compile("""

Wyświetl plik

@ -64,6 +64,13 @@ class TestStringMethods(unittest.TestCase):
self.assertEqual(message['relay'], "NAV07220E")
def test_v027_ddhhmm(self):
# beacons can have hhmmss or ddhhmm timestamp
raw_message = "ICA4B0678>APRS,qAS,LSZF:/301046z4729.50N/00812.89E'227/091/A=002854 !W01! id054B0678 +040fpm +0.0rot 19.0dB 0e +1.5kHz gps1x1"
message = parse_aprs(raw_message, reference_date=datetime(2015, 1, 1, 9, 35, 29))
self.assertEqual(message['timestamp'].strftime('%d %H:%M'), "30 10:46")
if __name__ == '__main__':
unittest.main()