Skip to main content

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

I'm on the road so I can't reference my source, but my handling 24-bit commands goes something like this:

To build the command, initialize a 32-bit unsigned int _command with 0xFE << 16; // high order byte of 3
// now build the low order 16 bits
_command |= (k_TMCC_SwitchType + (_addressValue << k_address_shift) + k_TMCC_ThroughThrough));

// at this point you have an unsigned int with the TMCC1 command that easily passed around your code.
// Using shifts (and bit masks), convert the unsigned into into a byte array and output to the UART.

For parsing an incoming steam of 3-byte TMCC data, convert the bytes to an unsigned int.  Extract the address and data bits using masks and shifts.  Zero the address and data bits in the unsigned int so the unsigned int contains bits for only the top level TMCC type (i.e. eng, train, switch, acc) and command.  Use this value to index a struct table with additional info such as text description of the command, pointers to action functions, etc.  Beats the ugly if-else parsing of TMCC 24-bit words.

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

×
×
×
×
×