#include "DccCommander.hpp"
Public Member Functions | |
DccCommanderClass () | |
void | begin (int i, int j, int interruptNumber, boolean inInterruptMonitor = false, boolean inUseRawDccAddresses = false) |
void | RaiseEventWhen (boolean inRaiseEventOnActivation, int inRaiseEventDebounceDelay = 200) |
void | PriorityLoop () |
unsigned long | loop () |
unsigned long | GetLastDccId () |
void | printCommander () |
Static Public Member Functions | |
static void | SetAccessoryDecoderPacketHandler (DccAccDecoderPacket func) |
static void | DccAccessoryDecoderPacket (int address, boolean activate, uint8_t data) |
static DccCommanderClass & | GetCurrent () |
static void | printEvent (unsigned long inId, COMMANDERS_EVENT_TYPE inEventType, int inEventData) |
This commanders receive accessory packets from DCC controller, and convert it in Commanders events. The event id is a compressed version of dcc id and dcc accessory id.
Text from NMRA standard definition (https://www.nmra.org/sites/default/files/s-9.2.1_2012_07.pdf , paragraph 420):
The format for packets intended for Accessory Digital Decoders is:
{preamble} 0 10AAAAAA 0 1AAACDDD 0 EEEEEEEE 1Accessory Digital Decoders can be designed to control momentary or constant-on devices, the duration of time each output is active being controlled by configuration variables CVs #515 through 518. Bit 3 of the second byte "C" is used to activate or deactivate the addressed device. (Note if the duration the device is intended to be on is less than or equal the set duration, no deactivation is necessary.) Since most devices are paired, the convention is that bit "0" of the second byte is used to distinguish between which of a pair of outputs the accessory decoder is activating or 430 deactivating. Bits 1 and 2 of byte two are used to indicate which of 4 pairs of outputs the packet is controlling. The most significant bits of the 9-bit address are bits 4-6 of the second data byte. By convention these bits (bits 4-6 of the second data byte) are in ones complement.
When an accessory is activated through my MS2, these packets are sent:
id / data / 1 id / data / 1 id / data / 1 id / data / 0
One an Ecos, only the '1' packets are sent, out of the standard...
id / data / 1 id / data / 1 id / data / 1
The last flag is to activate for a while (three times at 1 !) and then deactivate the motor ! DccCommander will react only on the first event to avoid double events. By default the '0' packet is used to raise an event, but for an Ecos or a '1' only Dcc central, use RaiseEventWhen() function with first argument to true.
In the Commanders interpretation of a DCC packet, id is given by 'A' bits, data from the 'D' bits, and the activate flag by the 'C' bit. The id is not the number you can see on a MS2, and on most DCC controllers. There is a small computation between id and data to obtain the real MS2 accessory number : real_id (1 to 320) and real_data (0 or 1 for right or left). It works on all known controllers, except on Multimaus...
The translated id and the activation flag are then translated into an unsigned long to be used as a Commanders id. The formula is
real_data * 10000 + real_id .
DCCINT is the macro used to build the unsigned long, DCCID the one to use to get the real id number from this long int, and DCCACTIVATION the other to get the real_data.
Events thrown:
reason | id | type | data |
---|---|---|---|
data = 0 | accessory id | COMMANDERS_EVENT_MOVE | COMMANDERS_MOVE_RIGHT |
data = 1 | accessory id | COMMANDERS_EVENT_MOVE | COMMANDERS_MOVE_LEFT |
Definition at line 81 of file DccCommander.hpp.
|
inline |
Default constructor.
Definition at line 94 of file DccCommander.hpp.
void DccCommanderClass::begin | ( | int | i, |
int | j, | ||
int | interruptNumber, | ||
boolean | inInterruptMonitor = false , |
||
boolean | inUseRawDccAddresses = false |
||
) |
Initialize the instance.
i | Manufacturer ID of this decoder. Can be 0 in common case... |
j | Manufacturer version number for this decoder. Can be 0 in common case... |
interruptNumber | Interrupt number used by DCC_Decoder. The interrupt is raised when a signal is detected on the associated pin. |
inInterruptMonitor | If true, the Commanders status led will blink when DccCommander receive a new accessory packet. Default is false. |
inUseRawDccAddresses | Dcc id and accessory id are converted into a more readable way to be used, but if this flag is true, the original values can be preserved instead of these converted value. Default is false. |
Definition at line 111 of file DccCommander.cpp.
|
static |
Decode the packet data, and raise a Commander event.
address | raw address of the decoder, directly got from the DCC packet. |
activate | flag from the DCC packet. True means activate the accessory motor. |
data | additional data, adding bits to decoder accessory, and including the number of the accessory. |
Definition at line 23 of file DccCommander.cpp.
|
inlinestatic |
Get the current instance of DccCommanderClass
Definition at line 134 of file DccCommander.hpp.
|
inline |
Gets the last DCC id received.
Definition at line 128 of file DccCommander.hpp.
|
virtual |
void DccCommanderClass::printCommander | ( | ) |
Print this commander on the console.
Definition at line 253 of file DccCommander.cpp.
|
static |
Print the given event on the console.
Definition at line 202 of file DccCommander.cpp.
|
virtual |
Priority loop function. Just a new call to the loop function. By this way, the DCC commander loop is sure to be called two or more times when other commanders are only called once !
Reimplemented from Commander.
Definition at line 141 of file DccCommander.cpp.
void DccCommanderClass::RaiseEventWhen | ( | boolean | inRaiseEventOnActivation, |
int | inRaiseEventDebounceDelay = 200 |
||
) |
Defines on which DCC packet the Commanders event should be raised. By default, an event is raised when the desactivation packet is received. After the reception on the 'event' packet, there is no other reception on the accessory during a given delay, 200ms by default.
inRaiseEventOnActivation | if true, the event will be raised only at reception of a desactivation packet. |
When | a 'event' packet has been received, no other event will be raised on this accessory during this delay. |
Definition at line 135 of file DccCommander.cpp.
|
static |
Set the callback function which will be called when an accessory packet will be decoded. Set it to NULL or 0 to inactivate this function.
Definition at line 196 of file DccCommander.cpp.