# Path: habitat/parser.py
# class ParserModule(object):
#     """
#     Base class for real ParserModules to inherit from.
# 
#     **ParserModules** are classes which turn radio strings into useful data.
#     They do not have to inherit from :class:`ParserModule`, but can if they
#     want. They must implement :meth:`pre_parse` and :meth:`parse` as described
#     below.
#     """
#     def __init__(self, parser):
#         self.parser = parser
#         self.loadable_manager = parser.loadable_manager
# 
#     def pre_parse(self, string):
#         """
#         Go though *string* and attempt to extract a callsign, returning
#         it as a string. If *string* is not parseable by this module, raise
#         :py:class:`CantParse`. If *string* might be parseable but no callsign
#         could be extracted, raise :py:class:`CantExtractCallsign`.
#         """
#         raise ValueError()
# 
#     def parse(self, string, config):
#         """
#         Go through *string* which has been identified as the format this
#         parser module should be able to parse, extracting the data as per
#         the information in *config*, which is the ``sentence`` dictionary
#         extracted from the payload's configuration document.
#         """
#         raise ValueError()
# 
# class CantParse(Exception):
#     """Parser module cannot parse the given sentence."""
#     pass
# 
# Path: habitat/utils/checksums.py
# def crc16_ccitt(data):
# def xor(data):
# def fletcher_16(data, modulus=255):


import re
from ..parser import ParserModule, CantParse
from ..utils import checksums
<data>,...,<data>*<checksum>

The number of custom data fields and their types are configurable.

Data fields are typically human readable (or at the least ASCII) readings
of sensors or other system information. See the :py:mod:`habitat.sensors`
module for more information on supported formats.

Checksums work on the message content between the ``$$`` and the ``*``,
non-inclusive, and are given as hexadecimal (upper or lower case) after
the ``*`` in the message.

Supported checksums are CRC16-CCITT with polynomial 0x1021 and start 0xFFFF,
Fletcher-16 and an 8bit XOR over the characters. The corresponding values
for configuration are ``crc16-ccitt``, ``fletcher-16`` and ``xor``.
For compatibility, a varient of Fletcher16 using modulus 256 is also provided,
as ``fletcher-16-256``. Don't use it for new payloads.
``none`` may also be specified as a checksum type if no checksum is used; in
this case the message should not include a terminating ``*``.

.. seealso:: :ref:`ukhas-parser-config`

"""



checksum_algorithms = [
    "crc16-ccitt", "xor", "fletcher-16", "fletcher-16-256", "none"]



# Path: habitat/parser.py
# class ParserModule(object):
#     """
#     Base class for real ParserModules to inherit from.
# 
#     **ParserModules** are classes which turn radio strings into useful data.
#     They do not have to inherit from :class:`ParserModule`, but can if they
#     want. They must implement :meth:`pre_parse` and :meth:`parse` as described
#     below.
#     """
#     def __init__(self, parser):
#         self.parser = parser
#         self.loadable_manager = parser.loadable_manager
# 
#     def pre_parse(self, string):
#         """
#         Go though *string* and attempt to extract a callsign, returning
#         it as a string. If *string* is not parseable by this module, raise
#         :py:class:`CantParse`. If *string* might be parseable but no callsign
#         could be extracted, raise :py:class:`CantExtractCallsign`.
#         """
#         raise ValueError()
# 
#     def parse(self, string, config):
#         """
#         Go through *string* which has been identified as the format this
#         parser module should be able to parse, extracting the data as per
#         the information in *config*, which is the ``sentence`` dictionary
#         extracted from the payload's configuration document.
#         """
#         raise ValueError()
# 
# class CantParse(Exception):
#     """Parser module cannot parse the given sentence."""
#     pass
# 
# Path: habitat/utils/checksums.py
# def crc16_ccitt(data):
# def xor(data):
# def fletcher_16(data, modulus=255):


# Path: habitat/parser_modules/ukhas_parser.py
import re
from ..parser import ParserModule, CantParse
from ..utils import checksums

<data>,...,<data>*<checksum>

The number of custom data fields and their types are configurable.

Data fields are typically human readable (or at the least ASCII) readings
of sensors or other system information. See the :py:mod:`habitat.sensors`
module for more information on supported formats.

Checksums work on the message content between the ``$$`` and the ``*``,
non-inclusive, and are given as hexadecimal (upper or lower case) after
the ``*`` in the message.

Supported checksums are CRC16-CCITT with polynomial 0x1021 and start 0xFFFF,
Fletcher-16 and an 8bit XOR over the characters. The corresponding values
for configuration are ``crc16-ccitt``, ``fletcher-16`` and ``xor``.
For compatibility, a varient of Fletcher16 using modulus 256 is also provided,
as ``fletcher-16-256``. Don't use it for new payloads.
``none`` may also be specified as a checksum type if no checksum is used; in
this case the message should not include a terminating ``*``.

.. seealso:: :ref:`ukhas-parser-config`

"""



checksum_algorithms = [
    "crc16-ccitt", "xor", "fletcher-16", "fletcher-16-256", "none"]



class UKHASParser(ParserModule):