Morelia.Commands package

Submodules

Morelia.Commands.PodCommands module

class Morelia.Commands.PodCommands.CommandSet

Bases: object

POD_Commands manages a dictionary containing available commands for a POD device.

__commands

Dictionary containing the available commands for a POD device. Each entry is formatted as { key(command number) : value([command name, number of argument ASCII bytes, number of return bytes, binary flag ) }.

Type:

dict[int,list[str|tuple[int]|bool]]

AddCommand(commandNumber: int, commandName: str, argumentBytes: tuple[int], returnBytes: tuple[int], isBinary: bool, description: str) bool

Adds a command entry to the current commands dictionary (__commands) if the command does not exist.

Parameters:
  • commandNumber (int) – Integer of the command number.

  • commandName (str) – String of the command’s name.

  • argumentBytes (tuple[int]) – Integer of the number of bytes in the argument.

  • returnBytes (tuple[int]) – Integer of the number of bytes in the return.

  • isBinary (bool) – Boolean flag to mark if the command is binary (True) or standard (False).

  • description (str) – String description of the command.

Returns:

True if the command was successfully added, False if the command could not be added because it already exists.

Return type:

bool

ArgumentHexChar(cmd: int | str) tuple[int] | None

Gets the tuple for the number of hex characters in the argument for a given command.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

Tuple representing the number of bytes in the argument for cmd. If the command could not be found, return None.

Return type:

tuple[int]|None

CommandNumberFromName(name: str) int | None

Gets the command number from the command dictionary using the command’s name.

Parameters:

name (str) – String of the command’s name.

Returns:

Integer representing the command number. If the command could not be found, return None.

Return type:

int|None

Description(cmd: int | str) str | None

Gets the description for a given command.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

String description for the command. If the command could not be found, return None.

Return type:

str|None

DoesCommandExist(cmd: int | str) bool

Checks if a command exists in the __commands dictionary.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

True if the command exists, false otherwise.

Return type:

bool

static GetBasicCommands() dict[int, list[str | tuple[int] | bool]]

Creates a dictionary containing the basic POD command set (0,1,2,3,4,5,6,7,8,9,10,11,12).

Returns:

Dictionary containing the available commands for this POD device. Each entry is formatted as { key(command number) : value([command name, number of argument ASCII bytes, number of return bytes, binary flag, description) }.

Return type:

dict[int,list[str|tuple[int]|bool|str]]

GetCommands() dict[int, list[str | tuple[int] | bool]]

Gets the contents of the current command dictionary (__commands).

Returns:

Dictionary containing the available commands for a POD device. Each entry is formatted as { key(command number) : value([command name, number of argument ASCII bytes, number of return bytes, binary flag, description) }.

Return type:

dict[int, list[str|tuple[int]|bool|str]]

IsCommandBinary(cmd: int | str) bool | None

Gets the binary flag for a given command.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

Boolean flag that is True if the command is binary and False if standard. If the command could not be found, return None.

Return type:

bool|None

static NoValue() int

Gets value of __NOVALUE.

Returns:

Value of __NOVALUE.

Return type:

int

RemoveCommand(cmd: int | str) bool

Removes the entry for a given command in __commands dictionary.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

True if the command was successfully removed, False if the command does not exist.

Return type:

bool

RestoreBasicCommands() None

Sets the current commands (__commands) to the basic POD command set.

ReturnHexChar(cmd: int | str) tuple[int] | None

Gets the tuple for the number of hex characters in the return for a given command.

Parameters:

cmd (int | str) – Integer command number or string command name.

Returns:

Tuple representing the number of hex characters in the return for cmd. If the command could not be found, return None.

Return type:

tuple[int]|None

Search(cmd: int | str, idx: int | None = None) str | tuple[int] | bool | None

Searches the __commands dictionary for the command.

Parameters:
  • cmd (int | str) – Integer command number or string command name.

  • idx (int, optional) – Index for the desired value in the command information list. Defaults to None.

Returns:

If an idx was given, this returns the idx value of the command information list if the command was found (None otherwise). If no idx is given, this returns true if the command is found (False otherwise).

Return type:

str|tuple[int]|bool|str|None

static U16() int

Gets value of __U16.

Returns:

Value of __U16.

Return type:

int

static U32() int

Gets value of __U32.

Returns:

Value of __U32.

Return type:

int

static U8() int

Gets value of __U8.

Returns:

Value of __U8.

Return type:

int

ValidateCommand(cmd: str | int, pld: int | bytes | tuple[int | bytes] | None = None)

Raises an exception if the command and its payload are invalid for this POD device.

Parameters:
  • cmd (str | int) – Command name or number.

  • pld (int | bytes | tuple[int | bytes] | None, optional) – Standard command packet payload. Defaults to None.

Raises:
  • Exception – Command ‘+str(cmd)+’ does not exist.

  • Exception – This command does not take a payload.

  • Exception – This command requires a payload.

  • Exception – Command needs more than one argument in the payload. Use a tuple of values.

  • Exception – Payload must have ‘+str(sum(args))+’ bytes.

  • Exception – Payload must have ‘+str(len(args))+’ integer items in the tuple.

  • Exception – Bytes in the payload are the wrong sizes. The sizes must be ‘+str(args)+’.’

  • Exception – The payload tuple must only contain int or bytes items.

  • Exception – Payload is of incorrect type. It must be an int, bytes, or tuple of int/bytes.

__ARGUMENTS: int = 1

Class-level integer representing the index key for the number of bytes in an argument for __commands list values.

__BINARY: int = 3

Class-level integer representing the index key for the binary flag for __commands list values.

__DESCRIPTION: int = 4

Class-level integer representing the index key for the description for __commands list values.

__NAME: int = 0

Class-level integer representing the index key for the command name for __commands list values.

__NOVALUE: int = -1

Class-level integer used to mark when a list item in __commands means ‘no value’ or is undefined.

__RETURNS: int = 2

Class-level integer representing the index key for the number of bytes in the return for __commands list values.

__U16: int = 4

Class-level integer representing the number of hexadecimal characters for an unsigned 16-bit value.

__U32: int = 8

Class-level integer representing the number of hexadecimal characters for an unsigned 32-bit value.

__U8: int = 2

Class-level integer representing the number of hexadecimal characters for an unsigned 8-bit value.

Module contents