class documentation

DCC Commmand

Base class for a DCC Command packet. This is created for a new command and updated when changed. It holds the raw command as required for serialisation by the PIO. The command can be upto 11 bytes inclusive of address bytes but not counting preamble, error check or packet end.

The device driver for the PIO is a singleton class and it's assumed here that any variables held here specific to the PIO device driver may be held as class variables.

Method __init__ Contruct the DCC Command
Method is_locked Is Locked
Method set_buffer Set buffer contents
Constant BASE_LONG_ADDR DCC long mobile address range base
Constant MAX_LONG_ADDR DCC long address upper limit (inclusive)
Constant MIN_LONG_ADDR DCC long address lower limit (inclusive)
Instance Variable NOT_SENT Return value for command not sent (command being updated)
Instance Variable SENT Return value for command serialised
Instance Variable SENT_POM Return valued for Program on Main second send
Property address Get Address
Property packet_buffer Get the Packet Buffer
Property type Get the command type
Instance Variable _packet_buff Undocumented
def __init__(self, byte_list=None):

Contruct the DCC Command

This method is not called automatically on object instantiation and is called explicitly by __init__ in the inheriting object.

This builds the DCC Command. The supplied byte list is used to create the raw command as serialised by the PIO state machine. It is saved in a word array of sufficient size (max 8 32 bit words). The reference to the PIO state machine is obtained when the first command object is built.

Mobile traction commands etc. are created from the supplied byte list.

POM commands are built as empty templates without a byte list.

Parameters
byte_lista list of the component bytes.
def is_locked(self):

Is Locked

Check to see if the command is locked by looking at the first word. This will be pre-amble if unlocked or 0 if locked.

returns: True if command is locked for editing

def set_buffer(self, byte_list):

Set buffer contents

This builds the raw command content as required by the PIO state machine. The preamble is prepended. The checksum is calculated and appended, as is the packet end bit. The function is called by the constructor. It may also be called to update the command.

It's not assumed that writing 0 to a word in the buffer is atomic. So setting the first word (the preamble) to 0 is used as an indicator that the buffer is being updated and shouldn't be sent. Word 0 is reset to the preamble to indicate update over. IRQs are disabled when writing to word 0.

We build the buffer here in 'slow time' rather than in ISR 'critical time'.

Parameters
byte_lista list of the component bytes.
BASE_LONG_ADDR =

DCC long mobile address range base

Value
const(49152)
MAX_LONG_ADDR =

DCC long address upper limit (inclusive)

Value
const(10239)
MIN_LONG_ADDR =

DCC long address lower limit (inclusive)

Value
const(128)
NOT_SENT =

Return value for command not sent (command being updated)

SENT =

Return value for command serialised

SENT_POM =

Return valued for Program on Main second send

@property
address =

Get Address

This returns the decoder address targeted by the command

Returns
The decoder address as an integer
@property
packet_buffer =

Get the Packet Buffer

This returns the packet as prepared for serialisation. It may be written as is to the PIO state machine FIFO.

@property
type =

Get the command type

This returns the command type. The type is set by the class object inheriting from CommandPacket

Returns
command type
_packet_buff =

Undocumented