kopia lustrzana https://github.com/glidernet/python-ogn-client
rodzic
58e44e7530
commit
48d0faf374
|
@ -8,7 +8,7 @@ from .base import BaseParser
|
|||
|
||||
class FlarmParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'aircraft_beacon'
|
||||
self.beacon_type = 'flarm'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.pattern import PATTERN_LT24_BEACON
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
||||
class LT24Parser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'lt24_beacon'
|
||||
self.beacon_type = 'lt24'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
ac_match = re.search(PATTERN_LT24_BEACON, aprs_comment)
|
||||
return {'id': ac_match.group('id'),
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None,
|
||||
'source': ac_match.group('source') if ac_match.group('source') else None}
|
||||
|
|
|
@ -8,7 +8,7 @@ from .base import BaseParser
|
|||
|
||||
class NaviterParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'naviter_beacon'
|
||||
self.beacon_type = 'naviter'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
|
|
|
@ -8,24 +8,24 @@ from .base import BaseParser
|
|||
|
||||
class OgnParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'depends...'
|
||||
self.beacon_type = None
|
||||
|
||||
def parse(self, aprs_comment, aprs_type):
|
||||
if not aprs_comment:
|
||||
return {'beacon_type': 'receiver_beacon'}
|
||||
return {'beacon_type': 'receiver'}
|
||||
|
||||
ac_data = self.parse_aircraft_beacon(aprs_comment)
|
||||
if ac_data:
|
||||
ac_data.update({'beacon_type': 'aircraft_beacon'})
|
||||
ac_data.update({'beacon_type': 'aircraft'})
|
||||
return ac_data
|
||||
|
||||
rc_data = self.parse_receiver_beacon(aprs_comment)
|
||||
if rc_data:
|
||||
rc_data.update({'beacon_type': 'receiver_beacon'})
|
||||
rc_data.update({'beacon_type': 'receiver'})
|
||||
return rc_data
|
||||
else:
|
||||
return {'user_comment': aprs_comment,
|
||||
'beacon_type': 'receiver_beacon'}
|
||||
'beacon_type': 'receiver'}
|
||||
|
||||
@staticmethod
|
||||
def parse_aircraft_beacon(aprs_comment):
|
||||
|
|
|
@ -7,7 +7,7 @@ from .base import BaseParser
|
|||
|
||||
class ReceiverParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'receiver_beacon'
|
||||
self.beacon_type = 'receiver'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
|
|
|
@ -3,4 +3,4 @@ from .base import BaseParser
|
|||
|
||||
class SkylinesParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'skylines_beacon'
|
||||
self.beacon_type = 'skylines'
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.pattern import PATTERN_SPIDER_BEACON
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
||||
class SpiderParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'spider_beacon'
|
||||
self.beacon_type = 'spider'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
ac_match = re.search(PATTERN_SPIDER_BEACON, aprs_comment)
|
||||
return {'id': ac_match.group('id'),
|
||||
'signal_strength': int(ac_match.group('signal_strength')) if ac_match.group('signal_strength') else None,
|
||||
'spider_id': ac_match.group('spider_id') if ac_match.group('spider_id') else None,
|
||||
'gps_status': ac_match.group('gps_status') if ac_match.group('gps_status') else None}
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.pattern import PATTERN_SPOT_BEACON
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
||||
class SpotParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = 'spot_beacon'
|
||||
self.beacon_type = 'spot'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
ac_match = re.search(PATTERN_SPOT_BEACON, aprs_comment)
|
||||
return {'id': ac_match.group('id'),
|
||||
'model': int(ac_match.group('model')) if ac_match.group('model') else None,
|
||||
'status': ac_match.group('status') if ac_match.group('status') else None}
|
||||
|
|
|
@ -8,7 +8,7 @@ from .base import BaseParser
|
|||
|
||||
class TrackerParser(BaseParser):
|
||||
def __init__(self):
|
||||
self.beacon_type = "aircraft_beacon"
|
||||
self.beacon_type = 'tracker'
|
||||
|
||||
@staticmethod
|
||||
def parse_position(aprs_comment):
|
||||
|
|
|
@ -4,12 +4,31 @@ 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>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))(?P<latitude>9000\.00|[0-8]\d{3}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>18000\.00|1[0-7]\d{3}\.\d{2}|0\d{4}\.\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{5}|\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|z))\s(?P<comment>.*)$")
|
||||
|
||||
PATTERN_LT24_BEACON = re.compile("""
|
||||
id(?P<id>\d+)\s
|
||||
(?P<climb_rate>[+-]\d+)fpm\s
|
||||
(?P<source>.+)
|
||||
""", re.VERBOSE | re.MULTILINE)
|
||||
|
||||
PATTERN_NAVITER_BEACON = re.compile("""
|
||||
id(?P<details>[\dA-F]{4})(?P<id>[\dA-F]{6})\s
|
||||
(?P<climb_rate>[+-]\d+)fpm\s
|
||||
(?P<turn_rate>[+-][\d.]+)rot
|
||||
""", re.VERBOSE | re.MULTILINE)
|
||||
|
||||
PATTERN_SPIDER_BEACON = re.compile("""
|
||||
id(?P<id>[\d-]+)\s
|
||||
(?P<signal_strength>[+-]\d+)dB\s
|
||||
(?P<spider_id>[A-Z]+)\s
|
||||
(?P<gps_status>.+)
|
||||
""", re.VERBOSE | re.MULTILINE)
|
||||
|
||||
PATTERN_SPOT_BEACON = re.compile("""
|
||||
id(?P<id>[\d-]+)\s
|
||||
SPOT(?P<model>\d)\s
|
||||
(?P<status>[A-Z]+)
|
||||
""", re.VERBOSE | re.MULTILINE)
|
||||
|
||||
PATTERN_TRACKER_BEACON_POSITION = re.compile("""
|
||||
id(?P<details>[\dA-F]{2})(?P<id>[\dA-F]{6}?)\s?
|
||||
(?:(?P<climb_rate>[+-]\d+?)fpm\s)?
|
||||
|
|
|
@ -22,34 +22,34 @@ class TestStringMethods(unittest.TestCase):
|
|||
print(e)
|
||||
|
||||
def test_aprs_aircraft_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='aprs_aircraft.txt', beacon_type='aircraft_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='aprs_aircraft.txt', beacon_type='aircraft')
|
||||
|
||||
def test_aprs_receiver_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='aprs_receiver.txt', beacon_type='receiver_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='aprs_receiver.txt', beacon_type='receiver')
|
||||
|
||||
def test_ogn_flarm_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='ogn_flarm.txt', beacon_type='aircraft_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='ogn_flarm.txt', beacon_type='flarm')
|
||||
|
||||
def test_ogn_receiver_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='ogn_receiver.txt', beacon_type='receiver_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='ogn_receiver.txt', beacon_type='receiver')
|
||||
|
||||
def test_ogn_tracker_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='ogn_tracker.txt', beacon_type='aircraft_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='ogn_tracker.txt', beacon_type='tracker')
|
||||
|
||||
def test_lt24_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='lt24.txt', beacon_type='lt24_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='lt24.txt', beacon_type='lt24')
|
||||
|
||||
def test_naviter_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='naviter.txt', beacon_type='naviter_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='naviter.txt', beacon_type='naviter')
|
||||
|
||||
def test_skylines_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='skylines.txt', beacon_type='skylines_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='skylines.txt', beacon_type='skylines')
|
||||
|
||||
def test_spider_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='spider.txt', beacon_type='spider_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='spider.txt', beacon_type='spider')
|
||||
|
||||
def test_spot_beacons(self):
|
||||
self.parse_valid_beacon_data_file(filename='spot.txt', beacon_type='spot_beacon')
|
||||
self.parse_valid_beacon_data_file(filename='spot.txt', beacon_type='spot')
|
||||
|
||||
def test_fail_parse_aprs_none(self):
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
|
@ -5,13 +5,12 @@ from ogn.parser.aprs_comment.lt24_parser import LT24Parser
|
|||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
@unittest.skip("Not yet implemented")
|
||||
def test(self):
|
||||
message = LT24Parser.parse_position("id25387 +000fpm GPS")
|
||||
|
||||
self.assertEqual(message['id'], 25387)
|
||||
self.assertEqual(message['id'], "25387")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, 0, 2)
|
||||
self.assertEqual(message['wtf'], 'GPS')
|
||||
self.assertEqual(message['source'], 'GPS')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.aprs_comment.spider_parser import SpiderParser
|
||||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
def test(self):
|
||||
message = SpiderParser.parse_position("id300234010617040 +19dB LWE 3D")
|
||||
|
||||
self.assertEqual(message['id'], "300234010617040")
|
||||
self.assertEqual(message['signal_strength'], 19)
|
||||
self.assertEqual(message['spider_id'], "LWE")
|
||||
self.assertEqual(message['gps_status'], "3D")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -4,13 +4,12 @@ from ogn.parser.aprs_comment.spot_parser import SpotParser
|
|||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
@unittest.skip("Not yet implemented")
|
||||
def test(self):
|
||||
message = SpotParser.parse_position("id0-2860357 SPOT3 GOOD")
|
||||
|
||||
self.assertEqual(message['id'], "0-2860357")
|
||||
self.assertEqual(message['hw_version'], 3)
|
||||
self.assertEqual(message['wtf'], "GOOD")
|
||||
self.assertEqual(message['model'], 3)
|
||||
self.assertEqual(message['status'], "GOOD")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Ładowanie…
Reference in New Issue