Class CbusCommandStation

  • All Implemented Interfaces:
    CommandStation

    public class CbusCommandStation
    extends java.lang.Object
    implements CommandStation
    CommandStation for CBUS communications. Unlike some other systems, we will hold minimal command station state in the software model. The actual command station state should always be referred to.
    • Method Detail

      • sendPacket

        public boolean sendPacket​(byte[] packet,
                                  int repeats)
        Send a specific packet to the rails.
        Specified by:
        sendPacket in interface CommandStation
        Parameters:
        packet - Byte array representing the packet, including the error-correction byte. Must not be null.
        repeats - Number of times to repeat the transmission, but is ignored in the current implementation
        Returns:
        true if the operation succeeds, false otherwise.
      • releaseSession

        protected void releaseSession​(int handle)
        Release a session freeing up the slot for reuse.
        Parameters:
        handle - the handle for the session to be released
      • sendKeepAlive

        protected void sendKeepAlive​(int handle)
        Send keep alive (DKEEP) packet for a throttle.
        Parameters:
        handle - The handle of the session to which it applies
      • setSpeedDir

        protected void setSpeedDir​(int handle,
                                   int speed_dir)
        Set loco speed and direction.
        Parameters:
        handle - The handle of the session to which it applies
        speed_dir - Bit 7 is direction (1 = forward) 6:0 are speed
      • setFunctions

        protected void setFunctions​(int group,
                                    int handle,
                                    int functions)
        Send a CBUS message to set functions.
        Parameters:
        group - The function group
        handle - The handle of the session for the loco being controlled
        functions - Function bits
      • setSpeedSteps

        protected void setSpeedSteps​(int handle,
                                     int mode)
        Send a CBUS message to change the session speed step mode.
        Parameters:
        handle - The handle of the session to which it applies
        mode - the speed step mode
      • getMasterCommandStation

        @CheckForNull
        protected CbusNode getMasterCommandStation()
        Get the master command station from the CBUS Node Table

        Full CBUS spec is defined as to comply with CBUS Developers Guide Version 6b

        eg. CANCMD FW v3 supports the main loco OPCs but not full spec, will return null. eg. CANCMD FW v4 supports the full steal / share spec, will return the CbusNode.

        Returns:
        the Master Command Station, else null if not found
      • isStealAvailable

        protected boolean isStealAvailable()
        Get if Steal is available on the Command Station

        Steal availability can change, so CbusThrottleManager checks this value when it struggles on initial attempt to obtain a throttle

        Returns:
        false if not available, defaults to true
      • isShareAvailable

        protected boolean isShareAvailable()
        Get if Share is available on the Command Station.

        Share availability can change, so CbusThrottleManager checks this value when it struggles on initial attempt to obtain a throttle.

        Returns:
        false if not available, defaults to true