Skip to main content

Reply to "Sending TMCC Commands to Legacy Base over Serial Connections"

Professor Chaos,

I have finally got back to my arduino project and have built a byte/serial buffer similar to the one you use. I was wondering if you could answer me a question I have about your train control code in reference to the variable repeats in your send TMCC command. How does this come to play and how does it become greater than zero?  I have posted what I'm talking about below. I'm just not sure where the value for this variable is coming from originally. 

void sendTMCCCommand (SysTypes deviceType, byte deviceID, byte commandField, byte dataField, byte repeats) // deposit TMCC command in buffer
{
const byte TMCCCommand0 = 0xfe;
byte TMCCCommand1;
byte TMCCCommand2;

TMCCCommand1 = deviceType | (deviceID >> 1); // Byte 2 is combination of type field and first 7 bit of TMCC address
TMCCCommand2 = (deviceID << 7) | (commandField << 5) | dataField; // Byte 3 is last bit of TMCC address, command field (2 bits), plus data field

while (repeats > 0) {
TMCCBuffer.put(TMCCCommand0);
TMCCBuffer.put(TMCCCommand1);
if (TMCCBuffer.put(TMCCCommand2) == 0) { // write data to buffer; returns 0 if buffer capacity exceeded
debug << F("TMCC command buffer overflow") << endl;
FAULT();
}

repeats--;
}

processTMCCBuffer(); // attempt immediate execution
}

 

As always thanks for the help.

Chris

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×