Added generic parser for unknown protocol

pull/65/head
Konstantin Gründger 2019-06-03 22:17:55 +02:00
rodzic dab3ca3ddb
commit 7a577ab9ef
3 zmienionych plików z 21 dodań i 7 usunięć

Wyświetl plik

@ -0,0 +1,12 @@
from .base import BaseParser
class GenericParser(BaseParser):
def __init__(self):
self.beacon_type = 'generic'
def parse_position(self, aprs_comment):
return {'comment': aprs_comment}
def parse_status(self, aprs_comment):
return {'comment': aprs_comment}

Wyświetl plik

@ -3,7 +3,7 @@ from datetime import datetime
from ogn.parser.utils import createTimestamp, parseAngle, KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER
from ogn.parser.pattern import PATTERN_APRS, PATTERN_APRS_POSITION, PATTERN_APRS_STATUS, PATTERN_SERVER
from ogn.parser.exceptions import AprsParseError, OgnParseError
from ogn.parser.exceptions import AprsParseError
from ogn.parser.aprs_comment.ogn_parser import OgnParser
from ogn.parser.aprs_comment.fanet_parser import FanetParser
@ -15,6 +15,7 @@ from ogn.parser.aprs_comment.receiver_parser import ReceiverParser
from ogn.parser.aprs_comment.skylines_parser import SkylinesParser
from ogn.parser.aprs_comment.spider_parser import SpiderParser
from ogn.parser.aprs_comment.spot_parser import SpotParser
from ogn.parser.aprs_comment.generic_parser import GenericParser
def parse(aprs_message, reference_timestamp=None):
@ -105,6 +106,7 @@ dstcall_parser_mapping = {'APRS': OgnParser(),
'OGSKYL': SkylinesParser(),
'OGSPID': SpiderParser(),
'OGSPOT': SpotParser(),
'GENERIC': GenericParser(),
}
@ -113,4 +115,4 @@ def parse_comment(aprs_comment, dstcall='APRS', aprs_type="position"):
if parser:
return parser.parse(aprs_comment, aprs_type)
else:
raise OgnParseError("No parser for dstcall {} found. APRS comment: {}".format(dstcall, aprs_comment))
return dstcall_parser_mapping.get('GENERIC').parse(aprs_comment, aprs_type)

Wyświetl plik

@ -6,7 +6,7 @@ from datetime import datetime
from time import sleep
from ogn.parser.parse import parse
from ogn.parser.exceptions import AprsParseError, OgnParseError
from ogn.parser.exceptions import AprsParseError
class TestStringMethods(unittest.TestCase):
@ -54,6 +54,10 @@ class TestStringMethods(unittest.TestCase):
def test_spot_beacons(self):
self.parse_valid_beacon_data_file(filename='spot.txt', beacon_type='spot')
def test_generic_beacons(self):
message = parse("EPZR>WTFDSTCALL,TCPIP*,qAC,GLIDERN1:>093456h this is a comment")
self.assertEqual(message['beacon_type'], 'generic')
def test_fail_parse_aprs_none(self):
with self.assertRaises(TypeError):
parse(None)
@ -66,10 +70,6 @@ class TestStringMethods(unittest.TestCase):
with self.assertRaises(AprsParseError):
parse("Lachens>APRS,TCPIwontbeavalidstring")
def test_fail_bad_dstcall(self):
with self.assertRaises(OgnParseError):
parse("EPZR>WTFDSTCALL,TCPIP*,qAC,GLIDERN1:>093456h this is a comment")
def test_v026_chile(self):
# receiver beacons from chile have a APRS position message with a pure user comment
message = parse("VITACURA1>APRS,TCPIP*,qAC,GLIDERN4:/201146h3322.79SI07034.80W&/A=002329 Vitacura Municipal Aerodrome, Club de Planeadores Vitacura")