LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
DccCmdMonitor Class Reference

#include <DccCmdMonitor.h>

Public Types

enum  COMMAND_TYPE {
  ALL , SPEED , FUNCTION , TURNOUT_BOARD ,
  TURNOUT_OUTPUT , SIGNAL , CV
}
 

Public Member Functions

 DccCmdMonitor (int dcc_interrupt_pin)
 
void init (Track track)
 
void process ()
 
bool getMsg (COMMAND_TYPE type, char *msg, uint8_t *nBytes)
 
bool get (COMMAND_TYPE type, uint16_t addr, uint8_t *param3, uint8_t *param4)
 
void startMonitor (uint16_t addr)
 
void stopMonitor (uint16_t addr)
 

Private Member Functions

void remove (COMMAND_TYPE type, uint16_t addr)
 
bool isMonitored (uint16_t addr)
 

Detailed Description

class for monitoring DCC commands

Note
must specify DCC address to be monitored
to print to serial monitor messages define MONITOR_PRINT_DCC_COMMANDS
Example:
#include "DccCmdMonitor.h"
#define MONITOR_DCC_MAIN_PIN 16 // ESP32 pin for DCC interrupts of main track DCC signals
setup() {
monitorDccCmdMain.init(Track::MAIN); // Initialize monitoring of the MAIN track
monitorDccCmdMain.startMonitor(addr); // monitor a specific DCC address on the main track (i.e. cab's address for monitoring speed)
monitorDccCmdMain.stopMonitor(addr); // stop monitoring a specific DCC address
}
loop() {
monitorDccCmdMain.process();
// To monitor a layout for specific DCC commands being issued, use get() to retrieve command specific information
// Following are the get() formats for each of the support DCC command types
// For each monitored DCC command type, get() returns information after the command is received from a command station and queued
// Parameters 3 and 4 are passed by address and updated by get()
bool success = monitorDccCmdMain.get(SPEED, addr, &direction, &speed); // for the specified DCC address, get a queued speed command's speed and direction
bool success = monitorDccCmdMain.get(FUNCTION, addr, &state, &funcGrp); // for the specified DCC address, get a queued function command function group and state
bool success = monitorDccCmdMain.get(TURNOUT_BOARD, addr, &dir, &outputPair); // for the specified DCC address, get a queued turnout board command's output pair (1-4) and direction
bool success = monitorDccCmdMain.get(TURNOUT_OUTPUT, addr, &dir, 0); // for the specified DCC address, get a queued turnout output command's direction
bool success = monitorDccCmdMain.get(SIGNAL, addr, &state, 0); // for the specified DCC address, get a queued signal command's state
bool success = monitorDccCmdMain.get(CV, cv, &value, 0); // for the specified CV, get a queued CV command's state
bool success = monitorDccCmdMain.getMsg(ALL, &msg[0], &nBytes)); // get any type of availabile formatted message to send to serial
}
#define MONITOR_DCC_MAIN_PIN
ESP32 pin for DCC interrupts of main track DCC signals.
Definition: Config.h:146
Monitoring of DCC commands.Used for monitor a cab's speed changed by another command station.
bool getMsg(COMMAND_TYPE type, char *msg, uint8_t *nBytes)
void init(Track track)
bool get(COMMAND_TYPE type, uint16_t addr, uint8_t *param3, uint8_t *param4)
void stopMonitor(uint16_t addr)
@ FUNCTION
indicates DCC Function (FN) command
Definition: DccCmdMonitor.h:89
@ TURNOUT_OUTPUT
indicates DCC Turnout Output command
Definition: DccCmdMonitor.h:91
@ ALL
indicates all types of DCC commands
Definition: DccCmdMonitor.h:87
@ SPEED
indicates DCC Speed command
Definition: DccCmdMonitor.h:88
@ SIGNAL
indicates DCC Signal command
Definition: DccCmdMonitor.h:92
@ TURNOUT_BOARD
indicates DCC Turnout Board command
Definition: DccCmdMonitor.h:90
@ CV
indicates DCC CV change command
Definition: DccCmdMonitor.h:93
void startMonitor(uint16_t addr)
void setup()
Arduino setup routine for the Audio Card firmware.
Definition: Audio_Card.ino:254
void loop()
Main loop: poll for complete packets and dispatch commands.
Definition: Audio_Card.ino:269

Definition at line 83 of file DccCmdMonitor.h.

Member Enumeration Documentation

◆ COMMAND_TYPE

indicates the type of DCC command being monitored

Enumerator
ALL 

indicates all types of DCC commands

SPEED 

indicates DCC Speed command

FUNCTION 

indicates DCC Function (FN) command

TURNOUT_BOARD 

indicates DCC Turnout Board command

TURNOUT_OUTPUT 

indicates DCC Turnout Output command

SIGNAL 

indicates DCC Signal command

CV 

indicates DCC CV change command

Definition at line 86 of file DccCmdMonitor.h.

Constructor & Destructor Documentation

◆ DccCmdMonitor()

DccCmdMonitor::DccCmdMonitor ( int  dcc_interrupt_pin)
inline

DccCmdMonitor constructor

Parameters
dcc_interrupt_pinis the ESP32 interrupt pin for the DCC signal

Definition at line 115 of file DccCmdMonitor.h.

Member Function Documentation

◆ get()

bool DccCmdMonitor::get ( COMMAND_TYPE  type,
uint16_t  addr,
uint8_t *  param3,
uint8_t *  param4 
)
inline

Obtains a queued Dcc command

Parameters
typeindicates the type of Dcc command
addrindicates the DCC address of the command
[out]param3command specific data
[out]param4command specific data
Returns
true if message is found

Definition at line 166 of file DccCmdMonitor.h.

Here is the call graph for this function:

◆ getMsg()

bool DccCmdMonitor::getMsg ( COMMAND_TYPE  type,
char *  msg,
uint8_t *  nBytes 
)
inline

Obtains a queued Dcc command formmatted as a message < d parms >

Parameters
typeindicates the type of Dcc command
[in,out]msgpoints at buffer to hold returned message
[out]nBytesnumber of bytes in the message
Returns
true if message is found

Definition at line 147 of file DccCmdMonitor.h.

Here is the caller graph for this function:

◆ init()

void DccCmdMonitor::init ( Track  track)
inline

Initialize the object by invoking NmraDcc object init()

Definition at line 124 of file DccCmdMonitor.h.

Here is the caller graph for this function:

◆ isMonitored()

bool DccCmdMonitor::isMonitored ( uint16_t  addr)
inlineprivate

checks to see if a DCC addr is being monitored

Parameters
addris the DCC address
Returns
true if the address is being monitored

Definition at line 251 of file DccCmdMonitor.h.

◆ process()

void DccCmdMonitor::process ( )
inline

Process possible DCC commands queued by invoking object NmraDcc object process()

Definition at line 137 of file DccCmdMonitor.h.

Here is the caller graph for this function:

◆ remove()

void DccCmdMonitor::remove ( COMMAND_TYPE  type,
uint16_t  addr 
)
inlineprivate

delete a queued command

Parameters
typeindicates the type of Dcc command
addrindicates the DCC address of the command

Definition at line 237 of file DccCmdMonitor.h.

Here is the caller graph for this function:

◆ startMonitor()

void DccCmdMonitor::startMonitor ( uint16_t  addr)
inline

starts monitoring for commands of specified DCC addr on track associated with this object

Parameters
addris the address to start monitoring

Definition at line 217 of file DccCmdMonitor.h.

◆ stopMonitor()

void DccCmdMonitor::stopMonitor ( uint16_t  addr)
inline

stops monitoring for commands of specified DCC addr

Parameters
addris the address to stop monitoring

Definition at line 224 of file DccCmdMonitor.h.


The documentation for this class was generated from the following file: