python-ogn-client/ogn/parser/aprs_comment/flarm_parser.py

32 wiersze
2.1 KiB
Python
Czysty Zwykły widok Historia

from ogn.parser.pattern import PATTERN_FLARM_POSITION_COMMENT
from ogn.parser.utils import FPM_TO_MS, HPM_TO_DEGS
2017-10-05 08:36:53 +00:00
from .base import BaseParser
class FlarmParser(BaseParser):
def __init__(self):
self.beacon_type = 'flarm'
2020-05-21 21:14:31 +00:00
self.position_pattern = PATTERN_FLARM_POSITION_COMMENT
2017-10-05 08:36:53 +00:00
2019-06-03 19:09:57 +00:00
def parse_position(self, aprs_comment):
2020-05-21 21:14:31 +00:00
match = self.position_pattern.match(aprs_comment)
2020-08-30 12:23:23 +00:00
return {k: v for (k, v) in
{'address_type': int(match.group('details'), 16) & 0b00000011 if match.group('details') else None,
'aircraft_type': (int(match.group('details'), 16) & 0b01111100) >> 2 if match.group('details') else None,
'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1 if match.group('details') else None,
'address': match.group('address') or None,
'climb_rate': int(match.group('climb_rate')) * FPM_TO_MS if match.group('climb_rate') else None,
'turn_rate': float(match.group('turn_rate')) * HPM_TO_DEGS if match.group('turn_rate') else None,
'signal_quality': float(match.group('signal_quality')) if match.group('signal_quality') else None,
'error_count': int(match.group('error_count')) if match.group('error_count') else None,
'frequency_offset': float(match.group('frequency_offset')) if match.group('frequency_offset') else None,
'gps_quality': {
'horizontal': int(match.group('gps_quality_horizontal')),
'vertical': int(match.group('gps_quality_vertical'))} if match.group('gps_quality') else None,
'software_version': float(match.group('software_version')) if match.group('software_version') else None,
'hardware_version': int(match.group('hardware_version'), 16) if match.group('hardware_version') else None,
'real_address': match.group('real_address') or None,
'signal_power': float(match.group('signal_power')) if match.group('signal_power') else None}.items() if v is not None}