mwings.parsers.app_pal_mot Module
Parsers for packets sent from PAL App (Motion PAL) or CUE App in Motion PAL Mode (accelerometer measurement), and data structures to store the parsed information.
PacketParser
A static class parser that interprets packets representing data sent from PAL App (Motion PAL) or CUE App (Motion PAL Mode: accelerometer measurement).
Inherits:
common.PacketParserBase
is_valid()
is_valid(bare_packet)
Checks whether the given bare packet is valid.
Arguments
| 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.
Arguments
| Name | Type | Description |
|---|---|---|
bare_packet | common.BarePacket | Raw packet data |
Returns
| Type | Value | Description |
|---|---|---|
optional ParsedPacket | ParsedPacket instance | Parsed data |
None | Parsing failed |
ParsedPacket
A data structure to store the result of parsing packets sent from PAL App (Motion PAL) or CUE App (Motion PAL Mode: accelerometer measurement).
Inherits:
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, ai1_voltage=0, sample_count=16, samples_x=<mwings.common.TimeSeries object>, samples_y=<mwings.common.TimeSeries object>, samples_z=<mwings.common.TimeSeries object>, sampling_frequency=25)
Arguments
Including properties inherited from the base class.
| Name | Type | Description |
|---|---|---|
time_parsed | optional AwareDatetime | Parsing timestamp |
packet_type | common.PacketType | Packet type |
sequence_number | optional common.UInt16 | Sequence number |
source_serial_id | common.UInt32 | Source serial ID |
source_logical_id | common.UInt8 | Source logical device ID |
lqi | optional common.UInt8 | Radio communication quality |
supply_voltage | optional common.UInt16 | Supply voltage (mV) |
router_serial_id | common.UInt32 | Serial ID of the first relay device (0x80000000 if none) v1.0.13+ |
ai1_voltage | common.UInt16 | Voltage of AI1 (mV) |
sample_count | common.UInt8 | Number of acceleration samples per axis |
samples_x | common.TimeSeries[common.Int16] | Acceleration samples on X axis |
samples_y | common.TimeSeries[common.Int16] | Acceleration samples on Y axis |
samples_z | common.TimeSeries[common.Int16] | Acceleration samples on Z axis |
sampling_frequency | common.UInt16 | Acceleration sampling frequency |
You can also pass a dictionary unpacked with
**.
In addition to constructor arguments, the following @computed_field fields are available.
| Name | Type | Description |
|---|---|---|
mwings_implementation | str | MWings implementation (only "python") |
mwings_version | str | MWings version (in PEP440 format) |
hostname | str | Host machine name |
system_type | str | System type (e.g., "Linux") |
Applied field_validator
source_logical_id: Automatically validates the value rangecheck_source_logical_id(lid)
time_parsed: Automatically validates that timezone is attacheddatetime_must_be_clear(dt)
sampling_frequency: Validates the valuecheck_sampling_frequency(freq)
Applied field_serializer
packet_type: Serializes enum name as is for JSON etc.serialize_packet_type(packet_type)
source_serial_id: Serializes as hexadecimal string for JSON etc.serialize_source_serial_id(source_serial_id)
time_parsed: Serializes as ISO 8601 string for JSON etc.serialize_time_parsed(dt)
to_df()
to_df(include=None, exclude=None, verbose=True)
Converts the parsed data into a pandas DataFrame.
Arguments
| 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 effective if 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.
Arguments
| 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 effective if other arguments are None) |
spread | bool | Whether to split non-time-series list-like data |
sort_keys | bool | Whether to sort keys |
spread is set, common.TimeSeries[T] time series data is not split.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.
Arguments
| 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 effective if other arguments are None) |
spread | bool | Whether to split non-time-series list-like data |
indent | optional int | Number of spaces for indentation (None for no newlines) |
sort_keys | bool | Whether to sort keys |
spread is set, common.TimeSeries[T] time series data is not split.Returns
| Type | Description |
|---|---|
str | Converted JSON string |
model_*()
pydantic.BaseModel.