2018-03-10 08:35:51 +00:00
|
|
|
from ogn.parser.pattern import PATTERN_TRACKER_POSITION_COMMENT, PATTERN_TRACKER_STATUS_COMMENT
|
2018-04-30 19:45:28 +00:00
|
|
|
from ogn.parser.utils import FPM_TO_MS, HPM_TO_DEGS
|
2017-09-30 12:17:35 +00:00
|
|
|
|
2017-10-05 08:36:53 +00:00
|
|
|
from .base import BaseParser
|
2017-09-30 12:17:35 +00:00
|
|
|
|
2017-10-05 08:36:53 +00:00
|
|
|
|
|
|
|
class TrackerParser(BaseParser):
|
|
|
|
def __init__(self):
|
2018-03-10 07:58:32 +00:00
|
|
|
self.beacon_type = 'tracker'
|
2020-05-21 21:14:31 +00:00
|
|
|
self.position_pattern = PATTERN_TRACKER_POSITION_COMMENT
|
|
|
|
self.status_pattern = PATTERN_TRACKER_STATUS_COMMENT
|
2017-09-30 12:17:35 +00:00
|
|
|
|
2019-06-03 19:09:57 +00:00
|
|
|
def parse_position(self, aprs_comment):
|
|
|
|
match = self.position_pattern.match(aprs_comment)
|
2020-10-04 09:06:28 +00:00
|
|
|
|
|
|
|
result = {}
|
|
|
|
if match.group('details'):
|
|
|
|
result.update({
|
|
|
|
'address_type': int(match.group('details'), 16) & 0b00000011,
|
2017-10-04 21:23:41 +00:00
|
|
|
'aircraft_type': (int(match.group('details'), 16) & 0b01111100) >> 2,
|
|
|
|
'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1,
|
2018-04-28 11:44:01 +00:00
|
|
|
'address': match.group('address'),
|
2020-10-04 09:06:28 +00:00
|
|
|
})
|
|
|
|
if match.group('climb_rate'): result['climb_rate'] = int(match.group('climb_rate')) * FPM_TO_MS
|
|
|
|
if match.group('turn_rate'): result['turn_rate'] = float(match.group('turn_rate')) * HPM_TO_DEGS
|
|
|
|
if match.group('flight_level'): result['flightlevel'] = float(match.group('flight_level'))
|
|
|
|
if match.group('signal_quality'): result['signal_quality'] = float(match.group('signal_quality'))
|
|
|
|
if match.group('error_count'): result['error_count'] = int(match.group('error_count'))
|
|
|
|
if match.group('frequency_offset'): result['frequency_offset'] = float(match.group('frequency_offset'))
|
|
|
|
if match.group('gps_quality'):
|
|
|
|
result.update({
|
|
|
|
'gps_quality': {
|
|
|
|
'horizontal': int(match.group('gps_quality_horizontal')),
|
|
|
|
'vertical': int(match.group('gps_quality_vertical'))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if match.group('signal_power'): result['signal_power'] = float(match.group('signal_power'))
|
|
|
|
return result
|
2017-09-30 12:17:35 +00:00
|
|
|
|
2019-06-03 19:09:57 +00:00
|
|
|
def parse_status(self, aprs_comment):
|
|
|
|
match = self.status_pattern.match(aprs_comment)
|
2019-05-07 13:22:53 +00:00
|
|
|
if match:
|
2020-10-04 09:06:28 +00:00
|
|
|
result = {}
|
|
|
|
|
|
|
|
if match.group('hardware_version'): result['hardware_version'] = int(match.group('hardware_version'))
|
|
|
|
if match.group('software_version'): result['software_version'] = int(match.group('software_version'))
|
|
|
|
if match.group('gps_satellites'): result['gps_satellites'] = int(match.group('gps_satellites'))
|
|
|
|
if match.group('gps_quality'): result['gps_quality'] = int(match.group('gps_quality'))
|
|
|
|
if match.group('gps_altitude'): result['gps_altitude'] = int(match.group('gps_altitude'))
|
|
|
|
if match.group('pressure'): result['pressure'] = float(match.group('pressure'))
|
|
|
|
if match.group('temperature'): result['temperature'] = float(match.group('temperature'))
|
|
|
|
if match.group('humidity'): result['humidity'] = int(match.group('humidity'))
|
|
|
|
if match.group('voltage'): result['voltage'] = float(match.group('voltage'))
|
|
|
|
if match.group('transmitter_power'): result['transmitter_power'] = int(match.group('transmitter_power'))
|
|
|
|
if match.group('noise_level'): result['noise_level'] = float(match.group('noise_level'))
|
|
|
|
if match.group('relays'): result['relays'] = int(match.group('relays'))
|
|
|
|
return result
|
2019-05-07 13:22:53 +00:00
|
|
|
else:
|
2019-06-08 06:02:31 +00:00
|
|
|
return {'comment': aprs_comment}
|