/      日本語

mwings.parsers.app_io Module

Parsers for packets sent from the remote control app and data structures to store their contents.

Parsers for packets sent from the remote control app and data structures to store their contents.

src/mwings/parsers/app_io.py

PacketParser

Static class for a parser that interprets packets representing data sent from the remote control app.

Inherits from: common.PacketParserBase

is_valid()

is_valid(bare_packet)

Checks whether the given raw packet is valid.

Arguments

NameTypeDescription
bare_packetcommon.BarePacketRaw packet data

Returns

TypeValueDescription
boolTrueValid, parsable
FalseInvalid, not parsable

parse()

parse(bare_packet)

Parses the given raw packet.

Arguments

NameTypeDescription
bare_packetcommon.BarePacketRaw packet data

Returns

TypeValueDescription
optional ParsedPacketData of type ParsedPacketParsed data
NoneParsing failed

ParsedPacket

Data structure to store the result of interpreting packets representing data sent from the remote control app.

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, relay_count=0, di_state=<mwings.common.CrossSectional object>, di_valid=<mwings.common.CrossSectional object>, di_interrupt=<mwings.common.CrossSectional object>)

Arguments

Properties inherited from the base class are also listed.

NameTypeDescription
time_parsedoptional AwareDatetimeParsing timestamp
packet_typecommon.PacketTypePacket type
sequence_numberoptional common.UInt16Sequence number
source_serial_idcommon.UInt32Source serial ID
source_logical_idcommon.UInt8Source logical device ID
lqioptional common.UInt8Radio communication quality
supply_voltageoptional common.UInt16Always None because ADC is not used
relay_countcommon.UInt8Number of relays
di_changedcommon.CrossSectional[bool](12)Digital interface change status
di_statecommon.CrossSectional[bool](12)Digital interface state
di_interruptcommon.CrossSectional[bool](12)Digital interface interrupt status

You can pass a dictionary unpacked with **.

to_df()

to_df(include=None, exclude=None, verbose=True)

Converts the parsed data to a pandas DataFrame.

Arguments

NameTypeDescription
includeoptional set[str]Set of columns (members) to include in the DataFrame
excludeoptional set[str]Set of columns (members) to exclude from the DataFrame
verboseboolInclude system information (only when other args are None)

Returns

TypeValueDescription
pd.DataFrame-Converted DataFrame

Exceptions

  • EnvironmentError if pandas is not installed

to_dict()

to_dict(include=None, exclude=None, verbose=True, spread=False, sort_keys=False)

Converts the parsed data to a dictionary.

Arguments

NameTypeDescription
includeoptional set[str]Set of keys (members) to include in the dictionary
excludeoptional set[str]Set of keys (members) to exclude from the dictionary
verboseboolInclude system information (only when other args are None)
spreadboolWhether to split non-time-series list-like data
sort_keysboolWhether to sort keys

Returns

TypeValueDescription
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 to JSON format.

Arguments

NameTypeDescription
includeoptional set[str]Set of keys (members) to include in the JSON
excludeoptional set[str]Set of keys (members) to exclude from the JSON
verboseboolInclude system information (only when other args are None)
spreadboolWhether to split non-time-series list-like data
indentoptional intNumber of spaces for indentation (None for no newline)
sort_keysboolWhether to sort keys

Returns

TypeValueDescription
str-Converted JSON string

model_*()