def _parse_protocol_specific(comment): """ Parses the comment string from Fanet's APRS messages. :param str comment: comment string :return: parsed comment :rtype: dict """ fields = comment.split(' ') if len(fields) != 3: raise exceptions.ParseError('Fanet comment incorrectly formatted:' ' received {}'.format(comment)) lat_dig = int(fields[0][2]) lon_dig = int(fields[0][3]) update_position = [{ 'target': 'latitude', 'function': Parser._get_location_update_func(lat_dig) }, { 'target': 'longitude', 'function': Parser._get_location_update_func(lon_dig) }] return { '_update': update_position, 'id': fields[1], 'vertical_speed': Parser._convert_fpm_to_ms(fields[2]) }
def _parse_protocol_specific(comment): """ Parses the comment string from Spot's APRS messages. :param str comment: comment string :return: parsed comment :rtype: dict """ fields = comment.split(' ', maxsplit=2) if len(fields) < 3: raise exceptions.ParseError('SPOT comment incorrectly formatted: ' 'received {}'.format(comment)) return {'id': fields[0], 'model': fields[1], 'status': fields[2]}
def parse_message(cls, raw_message): """ Parses the fields of a raw APRS message to a dictionary. Returns none if message could not be parsed. :param str raw_message: raw APRS message :return: parsed message or None if the message failed to parse :rtype: dict or None :raises ogn_lib.exceptions.ParseError: if message cannot be parsed using Parser.PATTERN_ALL """ raw_message = cls._preprocess_message(raw_message) match = cls.PATTERN_ALL.match(raw_message) if not match: raise exceptions.ParseError('Message {} did not match {}'.format( raw_message, cls.PATTERN_ALL)) data = { 'from': match.group('source'), 'destto': match.group('destination'), 'beacon_type': constants.BeaconType.aircraft_beacon, 'timestamp': Parser._parse_timestamp(match.group('time')), 'latitude': Parser._parse_location(match.group('latitude')), 'longitude': Parser._parse_location(match.group('longitude')), 'altitude': Parser._parse_altitude(match.group('altitude')) } data.update(Parser._parse_digipeaters(match.group('digipeaters'))) data.update( Parser._parse_heading_speed(match.group('heading'), match.group('speed'))) protocol_specific = match.group('protocol_specific') if protocol_specific: comment_data = cls._parse_protocol_specific(protocol_specific) try: cls._update_data(data, comment_data['_update']) del comment_data['_update'] except KeyError: logger.debug('comment_data[\'_update\'] not set') data.update(comment_data) data['raw'] = raw_message return data
def _parse_protocol_specific(comment): """ Parses the comment string from LiveTrack24's APRS messages. :param str comment: comment string :return: parsed comment :rtype: dict """ fields = comment.split(' ', maxsplit=2) if len(fields) < 3: raise exceptions.ParseError('LT24 comment incorrectly formatted:' ' received {}'.format(comment)) return { 'id': fields[0], 'vertical_speed': Parser._convert_fpm_to_ms(fields[1]), 'source': fields[2] }
def __call__(cls, raw_message): """ Parses the fields of a raw APRS message to a dictionary by calling the underlying method ParserBase._parse_message. :param str raw_message: raw APRS message :return: parsed message :rtype: dict :raises ogn_lib.exceptions.ParserNotFoundError: if parser for this message's callsign was not found """ try: _, body = raw_message.split('>', 1) destto, *_ = body.split(',', 1) if 'TCPIP*' in body: return ServerParser.parse_message(raw_message) try: parser = cls.parsers[destto] logger.debug('Using %s parser for %s', parser, raw_message) except KeyError: logger.warn('Parser for a destto name %s not found; found: %s', destto, list(cls.parsers.keys())) if cls.default: parser = cls.default else: raise exceptions.ParserNotFoundError( 'Parser for a destto name {} not found; found: {}'. format(destto, list(cls.parsers.keys()))) return parser.parse_message(raw_message) except exceptions.ParserNotFoundError: raise except Exception as e: msg = 'Failed to parse message: {}'.format(raw_message) logger.error(msg) logger.exception(e) raise exceptions.ParseError(msg)
def _parse_protocol_specific(comment): """ Parses the comment string from Spider's APRS messages. :param str comment: comment string :return: parsed comment :rtype: dict """ fields = comment.split(' ', maxsplit=3) if len(fields) < 4: raise exceptions.ParseError('Spider comment incorrectly formatted:' ' received {}'.format(comment)) return { 'id': fields[0], 'signal_strength': fields[1], 'spider_id': fields[2], 'gps_status': fields[3] }