parser
¶
This module contains a parser that reads data about pump parameters, errors and warnings from text files.
- turboctl.telegram.parser.PARAMETERS¶
The pump has multiple parameters which affect its behaviour. This attribute holds a
dict
of these parameters, represented asParameter
objects, with the numbers of the parameters as the keys.
- turboctl.telegram.parser.ERRORS¶
A
dict
of different error conditions which can affect the pump, represented asErrorOrWarning
objects, with error numbers as the keys.
- class turboctl.telegram.parser.Parameter(number: int, name: str, indices: range, min_value: Union[Data, str], max_value: Union[Data, str], default: Union[Data, List[Data]], unit: str, writable: bool, datatype: type, bits: int, description: str)¶
A class for representing pump parameters.
This is a
dataclass
, so the__init__
,__str__
and__repr__
methods are generated automatically.- indices: range¶
A
range
object describing the indices of the parameter; e.g.range(5)
would mean the parameter has indices numbered 0 to 4. This isrange(0)
for unindexed parameters.
- min_value: Union[Data, str]¶
The minimum value of the parameter.
The minumum value of some parameters depends on the current value of another parameter. In that case,
min_value
is set to'P<number>'
; e.g. ‘P18’ means the value of parameter 18.
- max_value: Union[Data, str]¶
The maximum value of the parameter.
The maximum value of some parameters depends on the current value of another parameter. In that case,
max_value
is set to'P<number>'
; e.g. ‘P18’ means the value of parameter 18.
- default: Union[Data, List[Data]]¶
The default value of the parameter.
If the parameter is indexed and different indices have different default values,
default
will be alist
of default values corresponding to the different indices.
- property fields¶
Return an
OrderedDict
with the attribute names of this objects as keys and their values as values.
- __eq__(other)¶
Return self==value.
- __hash__ = None¶
- __init__(number: int, name: str, indices: range, min_value: Union[Data, str], max_value: Union[Data, str], default: Union[Data, List[Data]], unit: str, writable: bool, datatype: type, bits: int, description: str) None ¶
- __repr__()¶
Return repr(self).
- class turboctl.telegram.parser.ErrorOrWarning(number: int, name: str, possible_cause: str, remedy: str)¶
A class for representing pump errors and warnings.
- property fields¶
Return an
OrderedDict
with the attribute names of this object as keys and their values as values.
- __eq__(other)¶
Return self==value.
- __hash__ = None¶
- __repr__()¶
Return repr(self).
- turboctl.telegram.parser.main()¶
Define
PARAMETERS
,ERRORS
andWARNINGS
.This function is automatically executed when this module is imported or run as a script.
- turboctl.telegram.parser.load_parameters(path=None)¶
Parse the parameter file and return a dictionary of parameters.
This function is automatically called by
main()
, but it can also be called separately in order to create another set of parameters for testing purposes.- Parameters:
path – A text file containing parameter/error/warning data. If path isn’t specified, the file will be
'parameters.txt'
, located in the same directory as this module. The syntax used to define the parameters is explained inparameters.txt
.- Returns:
A
dict
with numbers as keys andParameter
objects as values.- Raises:
FileNotFoundError – If filename cannot be found.
RuntimeError – If a line in filename cannot be parsed.
- turboctl.telegram.parser.load_errors(path=None)¶
Parse the error file and return a dictionary of errors.
This works like
load_parameters()
, but the default file is'errors.txt'
, and the returneddict
containsErrorOrWarning
objects.
- turboctl.telegram.parser.load_warnings(path=None)¶
Parse the warning file and return a dictionary of warnings.
This works like
load_parameters()
, but the default file is'warnings.txt'
, and the returneddict
containsErrorOrWarning
objects.