habitat.parser: interpretation of incoming strings

The parser interprets incoming telemetry strings into useful telemetry data.

class habitat.parser.ParserSink(server)[source]

The Parser Sink

The parser sink is the interface between the message server and the parser modules. It is responsible for receiving raw telemetry from the message server, giving it to modules which turn it into beautiful telemetry data, and then sending that back to the message server.

setup()[source]

Initialises the sink, adding the types of telemetry we care about to our types list and setting up lists of modules

Scans the certs/ca directory to find CA certificates and loads them.

message(message)[source]

Handles a new message from the server, hopefully turning it into parsed telemetry data.

This function attempts to determine which of the loaded parser modules should be used to parse the message, and which config file it should be given to do so.

For the priority ordered list self.modules, resolution proceeds as:

for module in modules:
    module.pre_parse to find a callsign
    if a callsign is found:
        look up the configuration document for that callsign
        if a configuration document is found:
            check it specifies that this module should be used
            if it does:
                module.parse to get the data
                return
if all modules were attempted but no config docs were found:
    for module in modules:
        if this module has a default configuration:
            module.pre_parse to find a callsign
            if a callsign is found:
                use this module's default configuration
                module.parse to get the data
                return
if we still can't get any data:
    error

Note that in the loops below, the pre_parse, _find_config_doc and parse methods will all raise a ValueError if failure occurs, continuing the loop.

The output is a new message of type Message.TELEM, with message.data being the parsed data as well as any special fields, identified by a leading underscore in the key.

These fields may include:

  • _protocol which gives the parser module name that was used to decode this message
  • _used_default_config is a boolean value set to True if a default configuration was used for the module as no specific configuration could be found
  • _raw gives the original submitted data
  • _sentence gives the ASCII sentence from the UKHAS parser
  • _extra_data from the UKHAS parser, where the sentence contained more data than the UKHAS parser was configured for

Parser modules should be wary when outputting field names with leading underscores.

class habitat.parser.ParserModule(parser)[source]

ParserModules are classes which turn radio strings into useful data.

ParserModules

  • can be given various configuration parameters.
  • should probably inherit from ParserModule.

Store the parser reference for later use.

pre_parse(string)[source]

Go though a string and attempt to extract a callsign, returning it as a string. If no callsign could be extracted, a ValueError is raised.

parse(string, config)[source]

Go through a string which has been identified as the format this parser module should be able to parse, extracting the data as per the information in the config parameter, which is the sentence dictionary extracted from the payload’s configuration document.

Previous topic

habitat.message_server: the Server and its Sinks

Next topic

habitat.sensor_manager: Sensor function management

This Page