mwings package

mwings module

final class mwings.Twelite(port=None, rx_buffer_size=1024, timeout=100, tz=None, debugging=False)[source]

Bases: Thread

MWings main class

Constructor

Parameters:
  • port (str | None) – Name for the serial port to use / set None to disable serial

  • rx_buffer_size (int) – Receive buffer size

  • timeout (int) – Timeout for each packet in milliseconds

  • tz (tzinfo) – Timezone for datetime data. Default is UTC (Aware). Use ZoneInfo() for others.

  • debugging (bool) – Print debug info if true

add_listener(event: PacketType, handler: Callable[[BarePacket], None]) None[source]
add_listener(event: PacketType, handler: Callable[[SomeParsedPacket], None]) None

Register a handler for receiving packets

Parameters:
on(event)[source]

Generate a decorator to register a handler for receiving packets

Parameters:

event (common.PacketType) – Identifier for packets to receive

Returns:

Decorator to register a handler for receiving packets

Return type:

Callable[[common.SomeCallable], common.SomeCallable]

parse(character: str, use_lf: bool = False) PacketType | None[source]
parse(character: bytes, use_lf: bool = False) PacketType | None
parse(character: int, use_lf: bool = False) PacketType | None

Parse a single character

Parameters:
  • character (Any) – character to parse

  • use_lf (bool) – If use LF instead of CRLF, set True

Returns:

If completed, returns packet type identifier

Return type:

common.PacketType | None

Raises:
  • RuntimeError – Serial IS initialized

  • ValueError – Unsupported character

parse_line(line, use_lf=True)[source]

Parse a single string

Useful when use local log file instead of serial port rx

Parameters:
  • line (str) – String line

  • use_lf (bool) – Use LF instead of CRLF (For f.readline, set True as default)

Returns:

Latest packet type identifier if available else None

Return type:

common.PacketType | None

Raises:

RuntimeError – Serial IS initialized

receive()[source]

Wait for parsing of a single packet

Returns:

Identifier for packet received

Return type:

common.PacketType

Notes

This function blocks current thread

run()[source]

Run the thread to receive continuously

Call this function via Twelite.start()

Notes

Overrides threading.Thread.run()

Return type:

None

send(data: BarePacket) bool[source]
send(data: SomeCommand) bool

Send data to the device with ModBus format

Parameters:

data (Any) – Data to send

Returns:

True if succeeded

Return type:

bool

static set_timezone(tz)[source]

Set timezone for received data

Parameters:

tz (tzinfo) – tzinfo object. Typically Zoneinfo(“IANA/City”). None for UTC.

Return type:

None

start()[source]

Start the thread to receive continuously

Notes

Overrides threading.Thread.start()

Return type:

None

stop()[source]

Stop the thread to receive continuously

Return type:

None

property timezone: tzinfo

Get timezone set

Returns:

Timezone set for mwings

Return type:

tzinfo

update()[source]

Update parsing state with serial data

Returns:

Returns packet type identifier if available else None

Return type:

common.PacketType | None

Internal submodules

mwings.utils module

mwings.utils.ask_user(prompt, regex, on_error, ex_verifier=None, max_attempts=None)[source]

Ask user for something in text

Parameters:
  • prompt (str) – Prompt message

  • regex (str) – Regular expression for validate user input

  • on_error (str) – Message for invalid input

  • ex_verifier (Callable[[str], bool] | None) – Extra verifier in addition to regex

  • max_attempts (int | None) – Max count for attempts. None to infinite

Returns:

Valid user input

Return type:

str

mwings.utils.ask_user_for_port()[source]

Ask the user for the port to use

If there’s only one port, auto selects without asking.

Returns:

Port name (COM or fd)

Return type:

str

Notes

If the console is not available, raise EnvironmentError. If there’s no ports, raise IOError.

mwings.utils.byte_count_from(character_count)[source]

Convert to byte count from character count

Parameters:

character_count (int) – bytes count in ascii format

Returns:

bytes count in binary format

Return type:

int

mwings.utils.character_from(hexvalue)[source]

Convert to character from hex

Parameters:

hexvalue (int) – Binary integer value (0x0-0xF)

Returns:

Integer value of an ASCII character (‘0’-‘F’)

Return type:

int

mwings.utils.find_ascii(port, data, timeout, debugging=False)[source]

Find ASCII-formatted bytes in serial rx data

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (str) – ASCII-formatted bytes to find

  • timeout (int) – Timeout in seconds

  • debugging (bool) – Print debug info if true

Returns:

Found if true

Return type:

bool

mwings.utils.find_binary(port, data, timeout, with_terminal=False, terminal=0, debugging=False)[source]

Find binary bytes in serial rx data

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (bytes) – Binary data bytes to find

  • timeout (int) – Timeout in seconds

  • with_terminal (bool) – Use terminal byte for data input or not

  • terminal (int) – Terminal byte for data input

  • debugging (bool) – Print debug info if true

Returns:

Found if true

Return type:

bool

mwings.utils.flush_rx_buffer(port)[source]

Flush serial rx buffer

Parameters:

port (serial.Serial) – pyserial instance

Return type:

None

mwings.utils.flush_tx_buffer(port)[source]

Flush serial tx buffer

Parameters:

port (serial.Serial) – pyserial instance

Return type:

None

mwings.utils.get_ports()[source]

Get port informations

Returns:

List of port names

Return type:

list[str]

mwings.utils.hex_from(character)[source]

Convert to hex from character

Parameters:

character (int) – Integer value of an ASCII character (‘0’-‘F’)

Returns:

Binary integer value (0x0-0xF)

Return type:

int

mwings.utils.is_initialized(port)[source]

Check if the serial port is initialized

Parameters:

port (serial.Serial) – pyserial instance

Returns:

initialized if true

Return type:

bool

mwings.utils.is_readable(port)[source]

Check if the serial port is readable

Parameters:

port (serial.Serial) – pyserial instance

Returns:

readable if true

Return type:

bool

mwings.utils.is_there_some_ports()[source]

Check if there is some ports exists

Returns:

True if exists

Return type:

bool

mwings.utils.is_writable(port)[source]

Check if the serial port is writable

Parameters:

port (serial.Serial) – pyserial instance

Returns:

writable if true

Return type:

bool

mwings.utils.lrc8(data)[source]

Calculate 8-bit LRC for given data

Parameters:

data (bytes) – Bytes to calculate

Returns:

LRC checksum

Return type:

int

mwings.utils.millis()[source]

Get current time in milliseconds

Returns:

Current epoch in milliseconds

Return type:

int

mwings.utils.open_on_system(path)[source]

Open the file in the given path on system using default application

Parameters:

path (Path) – pathlib.Path for file

Return type:

None

mwings.utils.write_binary(port, data)[source]

Write binary integer value to the serial port

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (int | bytes) – Binary integer value or bytes

Return type:

None

mwings.utils.write_in_ascii(port, data)[source]

Write binary in ASCII format to the serial port

Parameters:
  • port (serial.Serial) – pyserial instance

  • data (int) – Binary integer value or bytes

Return type:

None

mwings.common module

final class mwings.common.AccelEvent(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Event ID for state of the magnet sensor

DICE_1

Dice roll: 1

Type:

int

DICE_2

Dice roll: 2

Type:

int

DICE_3

Dice roll: 3

Type:

int

DICE_4

Dice roll: 4

Type:

int

DICE_5

Dice roll: 5

Type:

int

DICE_6

Dice roll: 6

Type:

int

SHAKE

Shake

Type:

int

MOVE

Move

Type:

int

NONE

No events

Type:

int

final class mwings.common.AppPalNoticeBlinkSpeed(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Blinking speed ID for App_PAL (NOTICE)

ALWAYS_ON

Always on

Type:

int

SLOW

Slow blinking

Type:

int

MEDIUM

Medium blinking

Type:

int

FAST

Fast blinking

Type:

int

final class mwings.common.AppPalNoticeColor(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Color ID for App_PAL (NOTICE)

RED

RED color

Type:

int

GREEN

GREEN color

Type:

int

BLUE

BLUE color

Type:

int

YELLOW

YELLOW color

Type:

int

PURPLE

PURPLE color

Type:

int

LIGHT_BLUE

LIGHT_BLUE color

Type:

int

WHITE

WHITE color

Type:

int

WARM_WHITE

WARM_WHITE color

Type:

int

final class mwings.common.AppPalNoticeRGBWColor(*, red=0, green=0, blue=0, white=15)[source]

Bases: BaseModel

Color in RGBW for App_PAL (NOTICE)

Parameters:
red

Red value 0-0xF

Type:

UInt8

green

Green value 0-0xF

Type:

UInt8

blue

Blue value 0-0xF

Type:

UInt8

white

White value 0-0xF

Type:

UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'blue': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=15)]), 'green': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=15)]), 'red': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=15)]), 'white': FieldInfo(annotation=UInt8, required=False, default=15, metadata=[Ge(ge=0), Le(le=15)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

u16()[source]

Returns UInt16 representation

Returns:

RGBW as UInt16

Return type:

UInt16

final class mwings.common.BarePacket(payload, checksum=None, logical_and_command_id=None)[source]

Bases: BaseModel

Bare packet dataclass

payload

Data payload

Type:

bytes

checksum

LRC checksum for data payload

Type:

UInt8

Overridden constructor

Parameters:
  • payload (bytes) – Payload data

  • checksum (UInt8, optional) – LRC8 checksum

  • logical_and_command_id (tuple[UInt8, UInt8], optional) – Logical ID and Command ID (if set, payload should be shorter

i16_at(index)[source]

Get 2 bytes as an signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int16

i32_at(index)[source]

Get 4 bytes as an signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int32

i8_at(index)[source]

Get 1 byte as a signed integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

Int8

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'checksum': FieldInfo(annotation=UInt8, required=True), 'payload': FieldInfo(annotation=bytes, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

u16_at(index)[source]

Get 2 bytes as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt16

u32_at(index)[source]

Get 4 bytes as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt32

u8_at(index)[source]

Get 1 byte as an unsigned integer for the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else zero

Return type:

UInt8

u8_from(index)[source]

Get bytes from the specified position in the payload

Parameters:

index (int) – Position index

Returns:

return data if valid else None

Return type:

bytes | None

class mwings.common.CommandBase(*, destination_logical_id=120)[source]

Bases: ABC, BaseModel

Base dataclass for commands

Parameters:

destination_logical_id (UInt8) –

destination_logical_id

Logical ID for the source device

Type:

UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

abstract is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Pure virtual function

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class mwings.common.CommandSerializerBase[source]

Bases: ABC

Base class for packet serializers

abstract static serialize(command)[source]

Serialize the given command

Parameters:

command (SomeCommand) – Some command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

BarePacket | None

class mwings.common.CrossSectional(length, elements)[source]

Bases: FixedTuple[T]

Tuple for cross-sectional data such as ADC voltages

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

class mwings.common.DtypedDecimal[source]

Bases: ABC

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwings.common.FixedList(length, initial_elements)[source]

Bases: MutableSequence[T]

List with fixed length

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • initial_elements (Iterable[T]) – Initial items in iterable representation

Raises:

ValueError – Invalid length

append(value)[source]

Append an item

Parameters:

value (T) – Value of the item to append

Raises:

IndexError – FixedList does not support append()

Return type:

None

extend(values)[source]

Extend the sequence

Parameters:

values (Iterable[T]) – Sequence to extend

Raises:

IndexError – FixedList does not support extend()

Return type:

None

insert(index, value)[source]

Insert an item for the specific index

Parameters:
  • index (int) – Index to insert

  • value (T) – Value of item to insert

Raises:

IndexError – Out of range

Return type:

None

pop(index=-1)[source]

Pop an item

Parameters:

index (int) – Index to pop

Returns:

An poped item

Return type:

T

Raises:

RuntimeError – FixedList does not support pop()

remove(value)[source]

Remove an item

Parameters:

value (T) – Value of item to remove

Raises:

RuntimeError – FixedList does not support remove()

Return type:

None

class mwings.common.FixedTuple(length, elements)[source]

Bases: Sequence[T]

Tuple with fixed length

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

class mwings.common.Float32(value=None)[source]

Bases: float, DtypedDecimal

Parameters:

value (float | None) –

Return type:

Float32

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwings.common.Float64(value=None)[source]

Bases: float, DtypedDecimal

Parameters:

value (float | None) –

Return type:

Float64

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

class mwings.common.Int16(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int16

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwings.common.Int32(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int32

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwings.common.Int8(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

Int8

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

final class mwings.common.MagnetState(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Event ID for state of the magnet sensor

For App_ARIA, App_CUE and App_PAL(OPENCLOSE)

NOT_DETECTED

No magnet

Type:

int

N_POLE_IS_CLOSE

N pole is close

Type:

int

S_POLE_IS_CLOSE

S pole is close

Type:

int

class mwings.common.PacketParserBase[source]

Bases: ABC

Base class for packet parsers

abstract static is_valid(bare_packet)[source]

Check if the given bare packet is valid or not

Parameters:

bare_packet (BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Pure virtual function

abstract static parse(bare_packet)[source]

Parse the given bare packet

Parameters:

bare_packet (BarePacket) – Bare packet content

Returns:

Parsed packet content if valid otherwise None

Return type:

ParsedPacketBase | None

Notes

Pure virtual function

final class mwings.common.PacketType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Packet type identifier for receiving handlers

BARE

Identifier for bare packets

Type:

str

ACT

Identifier for act packets

Type:

str

APP_TWELITE

Identifier for App_Twelite packets

Type:

str

APP_IO

Identifier for App_IO packets

Type:

str

APP_ARIA

Identifier for App_ARIA packets

Type:

str

APP_CUE

Identifier for App_CUE packets

Type:

str

APP_CUE_PAL_EVENT

Identifier for App_CUE (PAL Move or Dice mode) packets

Type:

str

APP_PAL_OPENCLOSE

Identifier for App_PAL (OPENCLOSE) packets

Type:

str

APP_PAL_AMB

Identifier for App_PAL (AMB) packets

Type:

str

APP_PAL_MOT

Identifier for App_PAL (MOT) packets

Type:

str

APP_UART_ASCII

Identifier for App_Uart (Mode A) packets

Type:

str

APP_UART_ASCII_EXTENDED

Identifier for App_Uart (Mode A, Extended) packets

Type:

str

class mwings.common.ParsedPacketBase(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None)[source]

Bases: ABC, BaseModel

Base dataclass for data of parsed packets

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

mwings_implementation

Implementation of mwings; In this case: “python”

Type:

str

mwings_version

Version of mwings in PEP440 format declared in the pyproject.toml

Type:

str

time_parsed

Date and time parsed in ISO 8601 format

Type:

str | None

hostname

Hostname for the running system

Type:

str

system_type

System type for the running system (e.g. “Linux”)

Type:

str

packet_type

Type of the received packet

Type:

PacketType

sequence_number

Sequence number for the packet

Type:

UInt16

source_serial_id

Serial ID for the source device

Type:

UInt32

source_logical_id

Logical ID for the source device

Type:

UInt8

lqi

Link quality indicator for the source device (Max: 255)

Type:

UInt8

supply_voltage

Supply voltage for the source device in mV

Type:

UInt16

Notes

Immutable (frozen) object

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_source_logical_id(lid)[source]

Check source logical id

Must be in range between 0 and 100 or 120 and 127

Parameters:

lid (UInt8) – Input

Returns:

Valid input

Return type:

UInt8

Raises:

ValueError – Out of range

classmethod datetime_must_be_clear(dt)[source]

Check time received

Must be aware timezone as mw.common.Timezone

Parameters:

dt (datetime) – Input

Returns:

Valid input

Return type:

datetime

Raises:

ValueError – Native or not same as mw.common.Timezone

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

serialize_packet_type(packet_type)[source]

Print packet_type in readable names for JSON or something

Parameters:

packet_type (PacketType) – Type of the packet

Returns:

Serialized text for JSON or something

Return type:

str

serialize_source_serial_id(source_serial_id)[source]

Print source_serial_id in HEX for JSON or something

Parameters:

source_serial_id (UInt32) – Source serial ID

Returns:

Serialized text for JSON or something

Return type:

str

serialize_time_parsed(dt)[source]

Print time_parsed in ISO 8601 format

Parameters:

dt (datetime, optional) – Date and time received

Returns:

Serialized text for JSON or something

Return type:

str | None

Notes

Date and time should be UTC, but python uses “+00:00” suffix instead of “Z”. However, it can be parsed in other environments like ECMAScript’s Date().

to_df(include=None, exclude=None, verbose=True)[source]

Export to a pandas DataFrame

Requires optional dependency: pandas

Parameters:
  • include (set[str], optional) – Columns to include in the DataFrame

  • exclude (set[str], optional) – Columns to include in the DataFrame

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

Returns:

Output DataFrame

Return type:

pd.DataFrame

Raises:

EnvironmentError – No pandas found

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

Export to a dictionary (or OrderedDict)

Parameters:
  • include (set[str], optional) – Properties to include in the dictionary

  • exclude (set[str], optional) – Properties to exclude in the dictionary

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

  • spread (bool) – Spread cross-sectional tuple values into separated properties if True

  • sort_keys (bool) – Returns a sorted OrderedDict if True

Returns:

Output dictionary (or OrderedDict)

Return type:

dict[str, Any]

Notes

Higher-level implementation of pydantic’s model_dump()

to_json(include=None, exclude=None, verbose=True, spread=False, indent=2, sort_keys=False)[source]

Export to a JSON string

Parameters:
  • include (set[str], optional) – Properties to include the JSON

  • exclude (set[str], optional) – Properties to exclude the JSON

  • verbose (bool) – Set False to exclude system information. Only valid if include and exclude are None.

  • spread (bool) – Spread cross-sectional tuple values into separated properties if True

  • indent (int, optional) – Space-indentation width (default: 2, None to single-line)

  • sort_keys (bool) – Sort properties by keys if True

Returns:

Output JSON

Return type:

str

class mwings.common.SomeCallable

TypeVar for handlers

alias of TypeVar(‘SomeCallable’, bound=Callable[[…], Any])

class mwings.common.SomeCommand

TypeVar for all classes derived from CommandBase

alias of TypeVar(‘SomeCommand’, bound=CommandBase)

class mwings.common.SomeParsedPacket

TypeVar for all classes derived from ParsedPacketBase

alias of TypeVar(‘SomeParsedPacket’, bound=ParsedPacketBase)

class mwings.common.T

TypeVar for generics

alias of TypeVar(‘T’)

class mwings.common.TimeSeries(length, elements)[source]

Bases: FixedTuple[T]

Tuple for time series data such as acceleration samples

Constructor for the sequence

Parameters:
  • length (int) – Fixed length

  • elements (Iterable[T]) – Items to contain

Raises:

ValueError – Invalid length

mwings.common.Timezone: tzinfo = datetime.timezone.utc

Global tzinfo

class mwings.common.UInt16(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt16

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwings.common.UInt32(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt32

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

class mwings.common.UInt8(value=None)[source]

Bases: int, DtypedDecimal

Create immutable instance

Parameters:

value (int, optional) – Value to set

Returns:

Wrapped value

Return type:

UInt8

Raises:

ValueError – Out of range

get_dtype()[source]

Provide dtype info for pandas

Returns:

dtype identifier

Return type:

str

hex()[source]

Returns hex representation

python hex() function does not accept object of subclass derived from int.

Returns:

Hex string (lower case)

Return type:

str

mwings.parsers module

mwings.parsers.app_twelite module

final class mwings.parsers.app_twelite.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Twelite

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_twelite.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_logical_id=120, relay_count=0, periodic=False, di_changed=<mwings.common.CrossSectional object>, di_state=<mwings.common.CrossSectional object>, ai_voltage=<mwings.common.CrossSectional object>)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Twelite

Parameters:
destination_logical_id

Logical ID for the destination (parent) device

Type:

common.UInt8

relay_count

Number of relay stations

Type:

common.UInt8

periodic

True if the packet is a periodic transmit packet

Type:

bool

di_changed

State for each digital interfaces; True if changed

Type:

common.CrossSectional[bool]

di_state

Input status for each digital interfaces

Type:

common.CrossSectional[bool]

ai_voltage

Voltage in mV for each analog interfaces

Type:

common.CrossSectional[common.UInt16]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_ai_voltage(aiv)[source]

Check voltage of analog interfaces

Must be in range between 0 and 3700 (VCCmax3600+margin100)

Parameters:

aiv (common.CrossSectional) – Input

Returns:

Valid input

Return type:

common.CrossSectional

Raises:

ValueError – Out of range

classmethod check_destination_logical_id(lid)[source]

Check destination lid

Must be in range between 0 and 100 or 120 and 127 but 122 (Router) is invalid

Parameters:

lid (int) – Input

Returns:

Valid input

Return type:

int

Raises:

ValueError – Out of range

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ai_voltage': FieldInfo(annotation=CrossSectional[UInt16], required=False, default=<mwings.common.CrossSectional object>), 'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'di_changed': FieldInfo(annotation=CrossSectional[bool], required=False, default=<mwings.common.CrossSectional object>), 'di_state': FieldInfo(annotation=CrossSectional[bool], required=False, default=<mwings.common.CrossSectional object>), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'periodic': FieldInfo(annotation=bool, required=False, default=False), 'relay_count': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=3)]), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.app_io module

final class mwings.parsers.app_io.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_IO

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_io.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>)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_IO

Parameters:
relay_count

Number of relay stations

Type:

common.UInt8

di_state

Input state for each DI ports

Type:

common.CrossSectional[bool]

di_valid

Valid state for each DI ports; True if used

Type:

common.CrossSectional[bool]

di_interrupt

Interrupt state for each DI ports; True if detected via ISR

Type:

common.CrossSectional[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'di_interrupt': FieldInfo(annotation=CrossSectional[bool], required=False, default=<mwings.common.CrossSectional object>), 'di_state': FieldInfo(annotation=CrossSectional[bool], required=False, default=<mwings.common.CrossSectional object>), 'di_valid': FieldInfo(annotation=CrossSectional[bool], required=False, default=<mwings.common.CrossSectional object>), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'relay_count': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=3)]), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.app_aria module

final class mwings.parsers.app_aria.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_ARIA

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_aria.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, temp_100x=0, humid_100x=0, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_ARIA

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • temp_100x (Int16) –

  • humid_100x (UInt16) –

  • magnet_state (MagnetState) –

  • magnet_state_changed (bool) –

temp_100x

100x temperature in °C

Type:

common.Int16

humid_100x

100x humidity in RH%

Type:

common.UInt16

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'humid_100x': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=10000)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'magnet_state': FieldInfo(annotation=MagnetState, required=False, default=<MagnetState.NOT_DETECTED: 0>), 'magnet_state_changed': FieldInfo(annotation=bool, required=False, default=False), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'temp_100x': FieldInfo(annotation=Int16, required=False, default=0, metadata=[Ge(ge=-4000), Le(le=12500)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwings.parsers.app_cue module

final class mwings.parsers.app_cue.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_CUE

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_cue.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, sample_count=10, samples_x=<mwings.common.TimeSeries object>, samples_y=<mwings.common.TimeSeries object>, samples_z=<mwings.common.TimeSeries object>, has_accel_event=False, accel_event=AccelEvent.NONE, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_CUE

Parameters:
sample_count

Number of accel samples

Type:

common.UInt8

samples_x

Accel samples for x axis

Type:

common.TimeSeries[common.Int16]

samples_y

Accel samples for y axis

Type:

common.TimeSeries[common.Int16]

samples_z

Accel samples for z axis

Type:

common.TimeSeries[common.Int16]

has_accel_event

True if an accel event is available

Type:

bool

accel_event

Accel event

Type:

common.AccelEvent

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'accel_event': FieldInfo(annotation=AccelEvent, required=False, default=<AccelEvent.NONE: 255>), 'has_accel_event': FieldInfo(annotation=bool, required=False, default=False), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'magnet_state': FieldInfo(annotation=MagnetState, required=False, default=<MagnetState.NOT_DETECTED: 0>), 'magnet_state_changed': FieldInfo(annotation=bool, required=False, default=False), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sample_count': FieldInfo(annotation=UInt8, required=False, default=10, metadata=[Ge(ge=10), Le(le=10)]), 'samples_x': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'samples_y': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'samples_z': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

serialize_accel_event(accel_event)[source]

Print accel_event in readable names for JSON or something

Parameters:

accel_event (common.AccelEvent) – Accel event

Returns:

Serialized text for JSON or something

Return type:

str

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwings.parsers.app_cue_pal_event module

final class mwings.parsers.app_cue_pal_event.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_CUE (PAL Move or Dice mode)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_cue_pal_event.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, accel_event=AccelEvent.NONE)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_CUE (PAL Move or Dice mode)

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • ai1_voltage (UInt16) –

  • accel_event (AccelEvent) –

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

accel_event

Accel event

Type:

common.AccelEvent

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'accel_event': FieldInfo(annotation=AccelEvent, required=False, default=<AccelEvent.NONE: 255>), 'ai1_voltage': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=3700)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

serialize_accel_event(accel_event)[source]

Print accel_event in readable names for JSON or something

Parameters:

accel_event (common.AccelEvent) – Accel event

Returns:

Serialized text for JSON or something

Return type:

str

mwings.parsers.app_pal_openclose module

final class mwings.parsers.app_pal_openclose.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (OPENCLOSE)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_pal_openclose.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, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (OPENCLOSE)

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • ai1_voltage (UInt16) –

  • magnet_state (MagnetState) –

  • magnet_state_changed (bool) –

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

magnet_state

Magnet state

Type:

common.MagnetState

magnet_state_changed

True if the magnet state was changed

Type:

bool

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ai1_voltage': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=3700)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'magnet_state': FieldInfo(annotation=MagnetState, required=False, default=<MagnetState.NOT_DETECTED: 0>), 'magnet_state_changed': FieldInfo(annotation=bool, required=False, default=False), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

serialize_magnet_state(magnet_state)[source]

Print magnet_state in readable names for JSON or something

Parameters:

magnet_state (common.MagnetState) – Magnet state

Returns:

Serialized text for JSON or something

Return type:

str

mwings.parsers.app_pal_amb module

final class mwings.parsers.app_pal_amb.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (AMB)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_pal_amb.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, temp_100x=0, humid_100x=0, illuminance=0)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (AMB)

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • ai1_voltage (UInt16) –

  • temp_100x (Int16) –

  • humid_100x (UInt16) –

  • illuminance (UInt32) –

ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

temp_100x

100x temperature in °C

Type:

common.Int16

humid_100x

100x humidity in RH%

Type:

common.UInt16

illuminance

Illuminance in lux

Type:

common.UInt32

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ai1_voltage': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=3700)]), 'humid_100x': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=10000)]), 'illuminance': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=157000)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'temp_100x': FieldInfo(annotation=Int16, required=False, default=0, metadata=[Ge(ge=-4000), Le(le=12500)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.app_pal_mot module

final class mwings.parsers.app_pal_mot.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_PAL (MOT)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_pal_mot.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)[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_PAL (MOT)

Parameters:
ai1_voltage

Voltage for AI1 port in mV

Type:

common.UInt16

sample_count

Number of accel samples

Type:

common.UInt8

samples_x

Accel samples for x axis

Type:

common.TimeSeries[common.Int16]

samples_y

Accel samples for y axis

Type:

common.TimeSeries[common.Int16]

samples_z

Accel samples for z axis

Type:

common.TimeSeries[common.Int16]

sampling_frequency

Sampling frequency in Hz

Type:

UInt16

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_sampling_frequency(freq)[source]

Check for sampling_frequency

Parameters:

freq (int) – Input

Returns:

Valid input

Return type:

int

Raises:

ValueError – Raise if the specified frequency is not supported

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ai1_voltage': FieldInfo(annotation=UInt16, required=False, default=0, metadata=[Ge(ge=0), Le(le=3700)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sample_count': FieldInfo(annotation=UInt8, required=False, default=16, metadata=[Ge(ge=16), Le(le=16)]), 'samples_x': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'samples_y': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'samples_z': FieldInfo(annotation=TimeSeries[Int16], required=False, default=<mwings.common.TimeSeries object>), 'sampling_frequency': FieldInfo(annotation=UInt16, required=False, default=25), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.app_uart_ascii module

final class mwings.parsers.app_uart_ascii.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Uart (Mode A)

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.app_uart_ascii.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, command_id=0, data=b'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Uart (Mode A)

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • command_id (UInt8) –

  • data (bytes) –

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_data(data)[source]

Check for data

Parameters:

data (bytes) – Input

Returns:

Valid input

Return type:

bytes

Raises:

ValueError – Byte length is not in range between 1 and 80

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'data_base64': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'data_hexstr': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'command_id': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Lt(lt=128)]), 'data': FieldInfo(annotation=bytes, required=False, default=b'', exclude=True), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.app_uart_ascii_extended module

class mwings.parsers.app_uart_ascii_extended.PacketParser[source]

Bases: PacketParserBase

Packet parser for App_Uart (Mode A, Extended)

final static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

final static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

class mwings.parsers.app_uart_ascii_extended.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'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from App_Uart (Mode A, Extended)

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • destination_serial_id (UInt32) –

  • command_id (UInt8) –

  • data (bytes) –

destination_serial_id

Serial ID for the destination (parent) device

Type:

common.UInt32

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod check_data(data)[source]

Check for data

Parameters:

data (bytes) – Input

Returns:

Valid input

Return type:

bytes

Raises:

ValueError – Byte length is not in range between 1 and 80

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'data_base64': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'data_hexstr': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'command_id': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Lt(lt=128)]), 'data': FieldInfo(annotation=bytes, required=False, default=b'', exclude=True), 'destination_serial_id': FieldInfo(annotation=UInt32, required=False, default=120, metadata=[Ge(ge=0), Le(le=4294967295)]), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.parsers.act module

final class mwings.parsers.act.PacketParser[source]

Bases: PacketParserBase

Packet parser for act

static is_valid(bare_packet)[source]

Check the given bare packet is valid or not

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

True if valid

Return type:

bool

Notes

Static overridden method

static parse(bare_packet)[source]

Try to parse the given bare packet

Parameters:

bare_packet (common.BarePacket) – Bare packet content

Returns:

Parsed packet data if valid else None

Return type:

ParsedPacket | None

Notes

Static overridden method

final class mwings.parsers.act.ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, command_id=0, data=b'')[source]

Bases: ParsedPacketBase

Dataclass for parsed packets from act

Parameters:
  • time_parsed (AwareDatetime | None) –

  • packet_type (PacketType) –

  • sequence_number (UInt16 | None) –

  • source_serial_id (UInt32) –

  • source_logical_id (UInt8) –

  • lqi (UInt8 | None) –

  • supply_voltage (UInt16 | None) –

  • command_id (UInt8) –

  • data (bytes) –

command_id

Command ID

Type:

common.UInt8

data

Data body (Hidden in JSON or something)

Type:

bytes

data_base64

Data body in Base64 for JSON or something

Type:

str

data_hexstr

Data body in ASCII string

Type:

str

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {'data_base64': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'data_hexstr': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'hostname': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_implementation': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'mwings_version': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True), 'system_type': ComputedFieldInfo(wrapped_property=<property object>, return_type=<class 'str'>, alias=None, alias_priority=None, title=None, description=None, examples=None, json_schema_extra=None, repr=True)}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'command_id': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Lt(lt=127)]), 'data': FieldInfo(annotation=bytes, required=False, default=b'', exclude=True), 'lqi': FieldInfo(annotation=Union[UInt8, NoneType], required=False, metadata=[Ge(ge=0), Le(le=255)]), 'packet_type': FieldInfo(annotation=PacketType, required=False, default=<PacketType.BARE: 'bare'>), 'sequence_number': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'source_logical_id': FieldInfo(annotation=UInt8, required=False, default=0), 'source_serial_id': FieldInfo(annotation=UInt32, required=False, default=0, metadata=[Ge(ge=0), Le(le=4294967295)]), 'supply_voltage': FieldInfo(annotation=Union[UInt16, NoneType], required=False, metadata=[Ge(ge=0), Le(le=65535)]), 'time_parsed': FieldInfo(annotation=Union[AwareDatetime, NoneType], required=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mwings.serializers module

mwings.serializers.app_twelite module

final class mwings.serializers.app_twelite.Command(*, destination_logical_id=120, di_to_change=<mwings.common.FixedList object>, di_state=<mwings.common.FixedList object>, pwm_to_change=<mwings.common.FixedList object>, pwm_duty=<mwings.common.FixedList object>)[source]

Bases: CommandBase

Dataclass for App_Twelite command

Parameters:
di_to_change

To enable modification on a specific digital interface, set True

Type:

common.FixedList[bool]

di_state

Output status for each digital interfaces

Type:

common.FixedList[bool]

pwm_to_change

To enable modification on a specific PWM interface, set True

Type:

common.FixedList[bool]

pwm_duty

Duty for each PWM interfaces (0 to 1024, can be disabled with 0xFFFF)

Type:

common.FixedList[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'di_state': FieldInfo(annotation=FixedList[bool], required=False, default=<mwings.common.FixedList object>), 'di_to_change': FieldInfo(annotation=FixedList[bool], required=False, default=<mwings.common.FixedList object>), 'pwm_duty': FieldInfo(annotation=FixedList[int], required=False, default=<mwings.common.FixedList object>), 'pwm_to_change': FieldInfo(annotation=FixedList[bool], required=False, default=<mwings.common.FixedList object>)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

final class mwings.serializers.app_twelite.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Twelite

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Twelite command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwings.serializers.app_io module

final class mwings.serializers.app_io.Command(*, destination_logical_id=120, di_to_change=<mwings.common.FixedList object>, di_state=<mwings.common.FixedList object>)[source]

Bases: CommandBase

Dataclass for App_Io command

Parameters:
di_to_change

To enable modification on a specific digital interface, set True

Type:

common.FixedList[bool]

di_state

Output status for each digital interfaces

Type:

common.FixedList[bool]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'di_state': FieldInfo(annotation=FixedList[bool], required=False, default=<mwings.common.FixedList object>), 'di_to_change': FieldInfo(annotation=FixedList[bool], required=False, default=<mwings.common.FixedList object>)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

final class mwings.serializers.app_io.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Io

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Io command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwings.serializers.app_pal_notice module

final class mwings.serializers.app_pal_notice.Command(*, destination_logical_id=120, color=AppPalNoticeColor.WHITE, blink_speed=AppPalNoticeBlinkSpeed.ALWAYS_ON, brightness=8, duration_in_sec=5)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) command

Parameters:
color

Color

Type:

common.AppPalNoticeColor

Blinking speed

Type:

common.AppPalNoticeBlinkSpeed

brightness

Brightness from 0 to 0xF

Type:

common.UInt8

duration_in_sec

Duration in seconds

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'blink_speed': FieldInfo(annotation=AppPalNoticeBlinkSpeed, required=False, default=<AppPalNoticeBlinkSpeed.ALWAYS_ON: 0>), 'brightness': FieldInfo(annotation=UInt8, required=False, default=8, metadata=[Ge(ge=0), Le(le=15)]), 'color': FieldInfo(annotation=AppPalNoticeColor, required=False, default=<AppPalNoticeColor.WHITE: 6>), 'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'duration_in_sec': FieldInfo(annotation=UInt8, required=False, default=5, metadata=[Ge(ge=0), Le(le=255)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Print blink_speed in readable names for JSON or something

Parameters:

blink_speed (common.AppPalNoticeBlinkSpeed) – Blinking speed

Returns:

Serialized text for JSON or something

Return type:

str

serialize_color(color)[source]

Print color in readable names for JSON or something

Parameters:

color (common.AppPalNoticeColor) – Color

Returns:

Serialized text for JSON or something

Return type:

str

final class mwings.serializers.app_pal_notice.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwings.serializers.app_pal_notice_detailed module

final class mwings.serializers.app_pal_notice_detailed.Command(*, destination_logical_id=120, color=AppPalNoticeRGBWColor(red=0, green=0, blue=0, white=15), blink_duty_percentage=100, blink_period_in_sec=1.0, duration_in_sec=1)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) detailed command

Parameters:
color

Color in RGBW (0-0xF)

Type:

common.AppPalNoticeRGBWColor

Blink duty in %

Type:

common.UInt8

Blink period in sec (0-10.2)

Type:

common.Float64

duration_in_sec

Duration in seconds

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'blink_duty_percentage': FieldInfo(annotation=UInt8, required=False, default=100, metadata=[Ge(ge=0), Le(le=100)]), 'blink_period_in_sec': FieldInfo(annotation=Float64, required=False, default=1.0, metadata=[Ge(ge=0.0), Le(le=10.2)]), 'color': FieldInfo(annotation=AppPalNoticeRGBWColor, required=False, default=AppPalNoticeRGBWColor(red=0, green=0, blue=0, white=15)), 'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'duration_in_sec': FieldInfo(annotation=UInt8, required=False, default=1, metadata=[Le(le=255)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

final class mwings.serializers.app_pal_notice_detailed.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwings.serializers.app_pal_notice_event module

final class mwings.serializers.app_pal_notice_event.Command(*, destination_logical_id=120, event_id=0)[source]

Bases: CommandBase

Dataclass for App_PAL (NOTICE) event command

Parameters:
  • destination_logical_id (UInt8) –

  • event_id (UInt8) –

event_id

Event id

Type:

common.UInt8

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120), 'event_id': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Le(le=16)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

final class mwings.serializers.app_pal_notice_event.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_PAL (NOTICE)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_PAL (NOTICE) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method

mwings.serializers.app_uart_ascii module

final class mwings.serializers.app_uart_ascii.Command(*, destination_logical_id=120, command_id=0, data)[source]

Bases: CommandBase

Dataclass for App_UART (Mode A) command

Parameters:
  • destination_logical_id (UInt8) –

  • command_id (UInt8) –

  • data (bytes) –

command_id

Command id

Type:

common.UInt8

data

Data to send

Type:

bytes

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

is_valid()[source]

Check if the command content is valid or not

Returns:

True if valid

Return type:

bool

Notes

Overridden

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'command_id': FieldInfo(annotation=UInt8, required=False, default=0, metadata=[Ge(ge=0), Lt(lt=128)]), 'data': FieldInfo(annotation=bytes, required=True, metadata=[MinLen(min_length=1), MaxLen(max_length=80)]), 'destination_logical_id': FieldInfo(annotation=UInt8, required=False, default=120)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

final class mwings.serializers.app_uart_ascii.CommandSerializer[source]

Bases: CommandSerializerBase

Command serializer for App_Uart (Mode A)

static serialize(command)[source]

Serialize the given command

Parameters:

command (common.SomeCommand) – App_Uart (Mode A) command to serialize

Returns:

Serialized bytes and its LRC checksum (8bit) if valid

Return type:

common.BarePacket | None

Notes

Static overridden method