DCC Command
This class manages the DCC command packets. It provides the APIs for the registration of DCC commands to be serialised. It performs the scheduling and tranmission of command packets.
| Class Method | get |
Get the DCC Command instance. |
| Method | __init__ |
DCC Command object constructor |
| Method | power |
DCC Power On/Off |
| Method | read |
Read CV (POM) |
| Method | reset |
Reset the command counts |
| Method | set |
Set Function Group 1 |
| Method | set |
Set Speed (including direction) |
| Async Method | wait |
Wait for the new state available flag |
| Method | write |
Write CV (POM) |
| Constant | FWD |
Forward direction |
| Constant | OFF |
Power Off |
| Constant | ON |
Power On |
| Constant | REV |
Reverse direction |
| Constant | STOP |
Stopped N.B this is included for completeness |
| Property | counts |
Get the command counts |
| Method | _add |
Add Command to Packet List |
| Method | _get |
Get a command from the packet list |
| Method | _nxt |
Generate next packet. |
| Method | _pom |
Process Program on Main command |
| Class Variable | _dcc |
Undocumented |
| Instance Variable | _active |
Undocumented |
| Instance Variable | _counts |
Undocumented |
| Instance Variable | _dcc |
Undocumented |
| Instance Variable | _idle |
Undocumented |
| Instance Variable | _packet |
Undocumented |
| Instance Variable | _packet |
Undocumented |
| Instance Variable | _pom |
Undocumented |
| Instance Variable | _ready |
Undocumented |
Get the DCC Command instance.
This returns the singleton DCC Command instance. It instantiates DCC Command on the first call.
| Returns | |
| The DCC Command instance |
DCC Command object constructor
This initialises the DCC command manager singleton. An attempt to create a 2nd instance will cause an assertion error.
The dictionary for the packet list is created and the FIFO buffer allocated.
DCC Power On/Off
Start and stop command packet transmission scheduling. PIO stop start and power to track delegated to the DCC tx class (pio_pwr).
Changing the power state will cause the new power state available flag to be set.
| Parameters | |
| p | 1 for power on, 0 for power off, None for get power status |
| Returns | |
| power status as held by the DCC generator |
Read CV (POM)
This initiates reading a CV using Programming on Main in conjunction with RailCom.
The command is validated and the read request scheduled for action. The addressed decoder must be active and the command will be rejected by the command generator class this is not true.
| Parameters | |
| address | decoder address |
| cv | cv number as entered - users count from 1, DCC counts from 0! |
Reset the command counts
This resets the command counts to zero. It is used to reset the command counts after a report has been printed.
Set Function Group 1
This sets or clears a function in group 1. The forward light is usually function number 0.
If there is a function group 1 command in the packet list for the addressed decoder it is updated. Otherwise the command is added to the list.
See NMRA S-9.2.1 Section 2.3.4
| Parameters | |
| address | the address of the decoder - may be short or long |
| f | function number to set or clear |
| state | 1 for set, 0 for clear |
| Returns | |
| True if validation is passed and the command is added to the list or modified. False if validation fails. |
Set Speed (including direction)
If there is a speed command object for the adressed decoder in the list already the object is updated otherwise a new speed command is created. The input is validated. The packet generated will be for a 128 step speed setting and decoders must be configured for 28/128 speed steps.
See NMRA S-9.2.1 Section 2.3.2.1
| Parameters | |
| address | the address of the decoder - may be short or long |
| dir | the direction - forward or reverse - stop is treated as invalid |
| speed | the speed to be set - range 0 to 127 - default 0 |
| Returns | |
| True if validation is passed and the command is added to the list or modified. False if validation fails. |
Wait for the new state available flag
This waits for the asynchio thread safe flag to be set. Setting the flag is triggered by a change to the power on/off status.
Write CV (POM)
This initiates writing a CV using Programming on Main in conjunction with RailCom.
The command is validated and the write request scheduled for action. The addressed decoder must be active and the command will be rejected by the command generator class this is not true.
| Parameters | |
| self | |
| address | |
| cv | cv number as entered - users count from 1, DCC counts from 0! |
| new | the new value for the CV |
Get the command counts
This returns the counts of commands sent by type. The counts are reset by the reset_counts method.
| Returns | |
| A dictionary of command counts by type. |
Generate next packet.
This runs in soft interrupt or timer callback context.
This is called when the next packet in the list is to be serialised out on the DCC interface. If the list is empty or if the next packet is unavailable (e.g. being updated) the DCC Idle packet is serialised.
The function is triggered via a soft ISR. If RailCom is enabled, this is connected to the enable pin rising indicating the end of the cutout period assocated with the preceding command.
TODO If RailCom not enabled this will be triggered by the PIO program itself when serialising the packet end bit.
This function instructs the next Command object in the list to send its command.
Process Program on Main command
The response to a POM command may be delayed. The decoder does not have to put the POM response in the immediately following window and may respond following a subsequent command to that decoder.
To ensure that there is a subsequent command the address is checked to see if in the active list. The command will be rejected if the address is not in the active list or there is a POM command already being processed.
| Returns | |
| True if command accepted False if command rejected |