habitat.parser_modules.simple_binary_parser

This module contains a parser for a generic and simple binary protocol. The protocol does not specify callsigns or checksums, so the assumption is that both are provided in an outer protocol layer or out of band. Any binary data that python’s struct.unpack may interpret is usable.

Any fields may be submitted but it is recommended that a GPS-provided latitude, longitude and time are submitted.

The configuration document should specify the format string, a name and optionally a sensor for each field in the data. The format strings will be concatenated to unpack the data. A format string prefix may be provided as the format_prefix key in the configuration, to specify byte order, size and alignment. Note that at present each field must map to precisely one format string argument, so while variable length strings are OK, a field cannot have, for instance, two integers.

Example payload_configuration.sentences[0]:

{
    "protocol": "simple_binary",
    "callsign": "1234567890",
    "format_prefix": "<",
    "fields": [
        {
            "format": "i",
            "name": "latitude"
        }, {
            "format": "i",
            "name": "longitude"
        }, {
            "format": "I",
            "name": "date",
            "sensor": "std_telem.binary_timestamp"
        }, {
            "format": "b",
            "name": "temperature"
        }
    ],
    "filters": {
        "post": [
            {
                "type": "normal",
                "filter": "common.numeric_scale",
                "source": "latitude",
                "scale": 1E-7
            },
            {
                "type": "normal",
                "filter": "common.numeric_scale",
                "source": "longitude",
                "scale": 1E-7
            }
        ]
    }
}

For the list of format string specifiers, please see: http://docs.python.org/2/library/struct.html.

The filter common.numeric_scale may be useful for fixed-point data rather than sending floats, and the various std_telem.binary* sensors may be applicable.

Classes

ParserModule(parser) Base class for real ParserModules to inherit from.
SimpleBinaryParser(parser) The Simple Binary Parser Module

Exceptions

CantExtractCallsign Parser submodule cannot find a callsign, though in theory might be able to parse the sentence if one were provided.
class habitat.parser_modules.simple_binary_parser.SimpleBinaryParser(parser)[source]

The Simple Binary Parser Module

pre_parse(string)[source]

As no callsign is provided by the protocol, assume any string we are given is potentially parseable binary data.

parse(data, config)[source]

Parse string, extracting processed field data.

config is the relevant sentence dictionary from the payload’s configuration document, containing the required binary format and field details.

Returns a dictionary of the parsed data.

ValueError is raised on invalid messages.