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

21 wiersze
1000 B
Python
Czysty Zwykły widok Historia

2018-04-10 16:54:30 +00:00
import re
2018-04-30 19:00:08 +00:00
from ogn.parser.utils import FPM_TO_MS
2018-04-10 16:54:30 +00:00
from ogn.parser.pattern import PATTERN_FANET_POSITION_COMMENT
from .base import BaseParser
class FanetParser(BaseParser):
def __init__(self):
self.beacon_type = 'fanet'
2019-06-03 19:09:57 +00:00
self.position_parser = re.compile(PATTERN_FANET_POSITION_COMMENT)
2018-04-10 16:54:30 +00:00
2019-06-03 19:09:57 +00:00
def parse_position(self, aprs_comment):
ac_match = self.position_parser.match(aprs_comment)
2018-04-28 11:44:01 +00:00
return {'address_type': int(ac_match.group('details'), 16) & 0b00000011 if ac_match.group('details') else None,
'aircraft_type': (int(ac_match.group('details'), 16) & 0b01111100) >> 2 if ac_match.group('details') else None,
'stealth': (int(ac_match.group('details'), 16) & 0b10000000) >> 7 == 1 if ac_match.group('details') else None,
'address': ac_match.group('address') if ac_match.group('address') else None,
2018-04-30 19:00:08 +00:00
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS if ac_match.group('climb_rate') else None}