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.

Attributes:

__commands (dict[int,list[str|tuple[int]|bool]]): 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 ) }.

add_command(command_number, command_name, argument_bytes, return_bytes, is_binary, description)

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

Return type:

bool

Args:

command_number (int): Integer of the command number. command_name (str): String of the command’s name. argument_bytes (tuple[int]): Integer of the number of bytes in the argument. return_bytes (tuple[int]): Integer of the number of bytes in the return. is_binary (bool): Boolean flag to mark if the command is binary (True) or standard (False). description (str): String description of the command.

Returns:

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

argument_hex_char(cmd)

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

Return type:

tuple[int] | None

Args:

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

Returns:

tuple[int]|None: Tuple representing the number of bytes in the argument for cmd. If the command could not be found, return None.

command_number_from_name(name)

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

Return type:

int | None

Args:

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

Returns:

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

description(cmd)

Gets the description for a given command.

Return type:

str | None

Args:

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

Returns:

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

does_command_exist(cmd)

Checks if a command exists in the __commands dictionary.

Return type:

bool

Args:

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

Returns:

bool: True if the command exists, false otherwise.

static get_basic_commands()

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

Return type:

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

Returns:

dict[int,list[str|tuple[int]|bool|str]]: 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) }.

get_commands()

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

Return type:

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

Returns:

dict[int, list[str|tuple[int]|bool|str]]: 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) }.

static get_uint16()

Gets value of __UINT16.

Return type:

int

Returns:

int: Value of __UINT16.

static get_uint32()

Gets value of __UINT32.

Return type:

int

Returns:

int: Value of __UINT32.

static get_uint8()

Gets value of __UINT8.

Return type:

int

Returns:

int: Value of __UINT8.

is_command_binary(cmd)

Gets the binary flag for a given command.

Return type:

bool | None

Args:

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

Returns:

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

static no_value()

Gets value of __NO_VALUE.

Return type:

int

Returns:

int: Value of __NO_VALUE.

remove_command(cmd)

Removes the entry for a given command in __commands dictionary.

Return type:

bool

Args:

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

Returns:

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

restore_basic_commands()

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

Return type:

None

return_hex_char(cmd)

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

Return type:

tuple[int] | None

Args:

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

Returns:

tuple[int]|None: Tuple representing the number of hex characters in the return for cmd. If the command could not be found, return None.

search(cmd, idx=None)

Searches the __commands dictionary for the command.

Return type:

str | tuple[int] | bool | None

Args:

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:

str|tuple[int]|bool|str|None: 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).

validate_command(cmd, pld=None)

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

Args:

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.

Module contents