mwings.parsers.app_uart_ascii_extended Module
Parsers for packets sent from the serial communication app (format mode: extended) and data structures to store their contents.
PacketParser
Static class parser for interpreting packets representing data sent from the serial communication app (format mode: extended).
Inherits from:
common.PacketParserBase
is_valid()
is_valid(bare_packet)
Checks whether the given bare packet is valid.
Parameters
| Name | Type | Description |
|---|---|---|
bare_packet | common.BarePacket | Raw packet data |
Returns
| Type | Value | Description |
|---|---|---|
bool | True | Valid, parsable |
False | Invalid, not parsable |
parse()
parse(bare_packet)
Parses the given bare packet.
Parameters
| Name | Type | Description |
|---|---|---|
bare_packet | common.BarePacket | Raw packet data |
Returns
| Type | Value | Description |
|---|---|---|
optional ParsedPacket | Instance of ParsedPacket | Parsed data |
None | Parsing failed |
ParsedPacket
Data structure to store the results of parsing packets representing data sent from the serial communication app (format mode: extended).
Inherits from:
common.ParsedPacketBase
ParsedPacket()
ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, destination_serial_id=120, command_id=0, data=b'')
Parameters
Including inherited properties.
| Name | Type | Description |
|---|---|---|
time_parsed | optional AwareDatetime | Parsing timestamp |
packet_type | common.PacketType | Packet type |
sequence_number | optional common.UInt16 | Not available, always None |
source_serial_id | common.UInt32 | Sender’s serial ID |
source_logical_id | common.UInt8 | Sender’s logical device ID |
lqi | common.UInt8 | Radio signal quality |
supply_voltage | optional common.UInt16 | Not available, always None |
destination_serial_id | common.UInt32 | Receiver’s serial ID |
command_id | common.UInt8 | Command ID |
data | bytes | Data |
You can also pass a dictionary unpacked with
**.
In addition to the constructor arguments, the following @computed_field are available.
| Name | Type | Description |
|---|---|---|
mwings_implementation | str | MWings implementation ("python" only) |
mwings_version | str | MWings version (PEP440 format) |
hostname | str | Host machine name |
system_type | str | System type (e.g., "Linux") |
data_base64 | str | Base64 representation of the data |
data_hexstr | str | Hexadecimal string representation of the data |
data field is not included in JSON, etc. Please use data_base64 or data_hexstr.Applicable field_validator
source_logical_id: Automatically validates the value rangecheck_source_logical_id(lid)
time_parsed: Automatically validates that the timezone is attacheddatetime_must_be_clear(dt)
sampling_frequency: Validates the valuecheck_sampling_frequency(freq)
data: Automatically validates the lengthcheck_data(data)
Applicable field_serializer
packet_type: Serializes the enum name as-is in JSON, etc.serialize_packet_type(packet_type)
source_serial_id: Serializes as a hexadecimal string in JSON, etc.serialize_source_serial_id(source_serial_id)
time_parsed: Serializes as ISO 8601 string in JSON, etc.serialize_time_parsed(dt)
- ``
to_df()
to_df(include=None, exclude=None, verbose=True)
Converts the parsed data into a pandas DataFrame.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of columns (members) to include in the DataFrame |
exclude | optional set[str] | Set of columns (members) to exclude from the DataFrame |
verbose | bool | Whether to include system information (only when other arguments are None) |
Returns
| Type | Description |
|---|---|
pd.DataFrame | Converted DataFrame |
Exceptions
EnvironmentErrorif pandas is not installed
to_dict()
to_dict(include=None, exclude=None, verbose=True, spread=False, sort_keys=False)
Converts the parsed data into a dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of keys (members) to include in the dictionary |
exclude | optional set[str] | Set of keys (members) to exclude from the dictionary |
verbose | bool | Whether to include system information (only when other arguments are None) |
spread | bool | Whether to split list-like data that is not time series |
sort_keys | bool | Whether to sort keys |
Returns
| Type | Description |
|---|---|
dict[str, Any] | Converted dictionary |
to_json()
to_json(include=None, exclude=None, verbose=True, spread=False, indent=2, sort_keys=False)
Converts the parsed data into JSON format.
Parameters
| Name | Type | Description |
|---|---|---|
include | optional set[str] | Set of keys (members) to include in the JSON |
exclude | optional set[str] | Set of keys (members) to exclude from the JSON |
verbose | bool | Whether to include system information (only when other arguments are None) |
spread | bool | Whether to split list-like data that is not time series |
indent | optional int | Number of spaces for indentation (None for no line breaks) |
sort_keys | bool | Whether to sort keys |
Returns
| Type | Description |
|---|---|
str | Converted JSON string |
model_*()
pydantic.BaseModel.