Class BiDiBTrafficController

java.lang.Object
jmri.jmrix.bidib.BiDiBTrafficController
All Implemented Interfaces:
CommandStation

public class BiDiBTrafficController extends Object implements CommandStation
The BiDiB Traffic Controller provides the interface for JMRI to the BiDiB Library (jbidibc) - it does not handle any protocol functions itself. Therefor it does not extend AbstractMRTrafficController. Instead, it delegates BiDiB handling to a BiDiB controller instance (serial, simulation, etc.) using BiDiBInterface.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    (package private) org.bidib.jbidibc.messages.Node
     
    static final String
     
    (package private) BiDiBSystemConnectionMemo
    Reference to the system connection memo.
    protected org.bidib.jbidibc.messages.enums.CommandStationState
     
    protected final TreeMap<Long,org.bidib.jbidibc.messages.Node>
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BiDiBTrafficController(org.bidib.jbidibc.core.BidibInterface b)
    Create a new BiDiBTrafficController instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accessoryState(org.bidib.jbidibc.messages.Node node)
     
    void
    Add/Remove an ActionListener to be called when the connection has changed.
    void
    addMessageListener(org.bidib.jbidibc.core.MessageListener messageListener)
    Add a message Listener to the connection
    void
    addRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener)
    Add a raw message Listener to the connection
    void
     
    void
    Request Feedback Status (called BM status in BiDiB - BM (Belegtmelder) is german for "feedback") from all ports on all nodes of this connection.
    void
    Request CONFIGX from all ports on all nodes of this connection.
    void
    Request LC_STAT from all ports on all nodes of this connection.
    int
    checkProgMode(boolean needProgMode, org.bidib.jbidibc.messages.Node node)
    Check if the command station is in the requested state (Normal, PT) If the command station is not in the requested state, a message is sent to BiDiB to switch to the requested state.
    void
    Set the connection to lost state.
    org.bidib.jbidibc.messages.helpers.Context
    Opens the BiDiB connection in the jbidibc library, add listeners and initialize BiDiB.
    org.bidib.jbidibc.messages.LcConfigX
    convertConfig2ConfigX(org.bidib.jbidibc.messages.Node node, org.bidib.jbidibc.messages.LcConfig lcConfig)
    Convert a CONFIG object to a CONFIGX object.
    void
    feedback(org.bidib.jbidibc.messages.Node node)
    Request Feedback Status (called BM status in BiDiB - BM (Belegtmelder) is german for "feedback") from all ports on a given node.
    org.bidib.jbidibc.messages.Feature
    findNodeFeature(org.bidib.jbidibc.messages.Node node, int requestedFeatureId)
    Find a feature for given node.
    List<org.bidib.jbidibc.messages.LcConfigX>
    getAllPortConfigX(org.bidib.jbidibc.messages.Node node, org.bidib.jbidibc.messages.enums.LcOutputType type)
    Request CONFIGX from all ports on a given node and possibly only for a given type.
    org.bidib.jbidibc.core.BidibInterface
    Get Bidib Interface
    org.bidib.jbidibc.messages.Node
    Get the cached global programmer node.
    org.bidib.jbidibc.messages.Node
    Get the first booster node.
    org.bidib.jbidibc.messages.Node
    Get the first and most probably only command station node (also used for Programming on the Main - POM) A cached value is returned here for performance reasons since the function is called very often.
    org.bidib.jbidibc.messages.Node
    Get the most probably only global programmer node (aka service mode node, used for prgramming track - PT, not for POM) If there are more than one suitable node, get the last one (reverse nodes list search).
    org.bidib.jbidibc.messages.Node
    Get the first output node - a node that can control LC ports.
    org.bidib.jbidibc.messages.Node
    getNodeByAddr(byte[] addr)
    Get node by node address from nodelist
    org.bidib.jbidibc.messages.Node
    getNodeByUniqueID(long uniqueId)
    Get node by unique id from nodelist
    org.bidib.jbidibc.messages.Node
    Get node by node username from nodelist
    int
    getNodeFeature(org.bidib.jbidibc.messages.Node node, int requestedFeatureId)
    Get the feature value of a node.
    Map<Long,org.bidib.jbidibc.messages.Node>
    Get the list of nodes found
    org.bidib.jbidibc.messages.LcConfigX
    getPortConfigX(org.bidib.jbidibc.messages.Node node, int portAddr, org.bidib.jbidibc.messages.enums.LcOutputType type)
    Request CONFIGX if a given port on a given node and possibly only for a given type.
    org.bidib.jbidibc.messages.enums.PortModelEnum
    getPortModel(org.bidib.jbidibc.messages.Node node)
     
    org.bidib.jbidibc.messages.Node
    Get root node from nodelist
    Get access to the system connection memo associated with this traffic controller.
    boolean
    Check if we have at least one node capable of Accessory functions
    boolean
    Check if the connection is ready to communicate.
    boolean
    Check if the connection is detached i.e. it is opened, paired but the logon has been rejected.
    boolean
    isGlobalProgrammerNode(org.bidib.jbidibc.messages.Node node)
    A node suitable as a global programmer must be - a command station, - must support service mode programming and - must be a booster
    boolean
    Check of the connection is netBiDiB.
    void
    portLcStat(org.bidib.jbidibc.messages.Node node, int typemask)
    Request LC_STAT from all ports on a given node.
    void
     
    void
    removeMessageListener(org.bidib.jbidibc.core.MessageListener messageListener)
    Remove a message Listener from the connection
    void
    removeRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener)
    Remove a raw message Listener from the connection
    void
    sendBiDiBMessage(org.bidib.jbidibc.messages.message.BidibCommandMessage m, org.bidib.jbidibc.messages.Node node)
    Forward a preformatted BiDiBMessage to the actual interface.
    boolean
    sendPacket(byte[] packet, int repeats)
    Send a specific packet to the rails.
    boolean
    setCurrentGlobalProgrammerNode(org.bidib.jbidibc.messages.Node node)
    Set the global programmer node to use.
    void
    setLogon(boolean logon)
    Set or remove the detached state.
    void
    Set the system connection memo associated with this traffic controller.
    final void
    setWatchdogTimer(boolean state)
     
    void
    Start jbidibc built-in local ping as a watchdog of the connection.
    protected void
     
    void
    TEST(boolean a)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface jmri.CommandStation

    sendAccSignalDecoderPkt, sendAltAccSignalDecoderPkt
  • Field Details

  • Constructor Details

    • BiDiBTrafficController

      public BiDiBTrafficController(org.bidib.jbidibc.core.BidibInterface b)
      Create a new BiDiBTrafficController instance. Must provide a BidibInterface reference at creation time.
      Parameters:
      b - reference to associated jbidibc object, preserved for later.
  • Method Details

    • connnectPort

      public org.bidib.jbidibc.messages.helpers.Context connnectPort(PortAdapter p)
      Opens the BiDiB connection in the jbidibc library, add listeners and initialize BiDiB.
      Parameters:
      p - BiDiB port adapter (serial or simulation)
      Returns:
      a jbidibc context
    • isConnectionReady

      public boolean isConnectionReady()
      Check if the connection is ready to communicate. For netBiDiB this is the case only if the pairing was successful and the server has logged in. For all other connections the connection is ready if it has been successfully opened.
      Returns:
      true if the connection is ready
    • isNetBiDiB

      public boolean isNetBiDiB()
      Check of the connection is netBiDiB.
      Returns:
      true if this connection is netBiDiB
    • connectionLost

      public void connectionLost()
      Set the connection to lost state. All nodes will be removed and the components will be invalidated
    • isDetached

      public boolean isDetached()
      Check if the connection is detached i.e. it is opened, paired but the logon has been rejected.
      Returns:
      true if detached
    • setLogon

      public void setLogon(boolean logon)
      Set or remove the detached state. If logoff is requested (detach), a logon reject is sent to the device and all nodes will be notified that they are no more reachable (lost node). The connection remains active, but other clients may request a logon from the connected device. If a logon is requested (attach), the connected device is asked for a new logon. When the logon is received, the nodes will be re-initialized by the traffic controller.
      Parameters:
      logon - - true for logon (attach), false for logoff (detach)
    • addConnectionChangedListener

      Add/Remove an ActionListener to be called when the connection has changed.
      Parameters:
      l - - an Object implementing the ActionListener interface
    • removeConnectionChangedListener

    • startLocalPing

      public void startLocalPing()
      Start jbidibc built-in local ping as a watchdog of the connection. If there is no response from the device, the connection will be closed.
    • TEST

      public void TEST(boolean a)
    • getBidib

      public org.bidib.jbidibc.core.BidibInterface getBidib()
      Get Bidib Interface
      Returns:
      Bidib Interface
    • getNodeList

      public Map<Long,org.bidib.jbidibc.messages.Node> getNodeList()
      Get the list of nodes found
      Returns:
      list of nodes
    • getNodeByUniqueID

      public org.bidib.jbidibc.messages.Node getNodeByUniqueID(long uniqueId)
      Get node by unique id from nodelist
      Parameters:
      uniqueId - search for this
      Returns:
      node
    • getNodeByAddr

      public org.bidib.jbidibc.messages.Node getNodeByAddr(byte[] addr)
      Get node by node address from nodelist
      Parameters:
      addr - input to search
      Returns:
      node
    • getNodeByUserName

      public org.bidib.jbidibc.messages.Node getNodeByUserName(String userName)
      Get node by node username from nodelist
      Parameters:
      userName - input to search
      Returns:
      node
    • getRootNode

      public org.bidib.jbidibc.messages.Node getRootNode()
      Get root node from nodelist
      Returns:
      node
    • isGlobalProgrammerNode

      public boolean isGlobalProgrammerNode(org.bidib.jbidibc.messages.Node node)
      A node suitable as a global programmer must be - a command station, - must support service mode programming and - must be a booster. - for other nodes than the global command station the local DCC generator must be switched on (MSG_BOOST_STAT returns this as "control")
      Parameters:
      node - to check
      Returns:
      true if the node is suitable as a global progreammer
    • getFirstGlobalProgrammerNode

      public org.bidib.jbidibc.messages.Node getFirstGlobalProgrammerNode()
      Get the most probably only global programmer node (aka service mode node, used for prgramming track - PT, not for POM) If there are more than one suitable node, get the last one (reverse nodes list search). In this case the command station (probably the root node and first entry in the list) should probably not be used as a global programmer and the other have been added just for that purpose. TODO: the user should select the global programmer node if there multiple nodes suitable as a global programmer.
      Returns:
      programmer node or null if none available
    • setCurrentGlobalProgrammerNode

      public boolean setCurrentGlobalProgrammerNode(org.bidib.jbidibc.messages.Node node)
      Set the global programmer node to use.
      Parameters:
      node - to be used as global programmer node or null to remove the currentGlobalProgrammerNode
      Returns:
      true if node is a suitable global programmer node, currentGlobalProgrammerNode is set to that node. false if it is not.
    • getCurrentGlobalProgrammerNode

      public org.bidib.jbidibc.messages.Node getCurrentGlobalProgrammerNode()
      Get the cached global programmer node. If there is no, try to find a suitable node. Note that the global programmer node may dynamically change by user settings. Be sure to update or invalidate currentGlobalProgrammerNode.
      Returns:
      the current global programmer node or null if none available.
    • getFirstCommandStationNode

      public org.bidib.jbidibc.messages.Node getFirstCommandStationNode()
      Get the first and most probably only command station node (also used for Programming on the Main - POM) A cached value is returned here for performance reasons since the function is called very often. We don't expect the command station to change.
      Returns:
      command station node
    • getFirstBoosterNode

      public org.bidib.jbidibc.messages.Node getFirstBoosterNode()
      Get the first booster node. There may be more booster nodes, so prefer the command station and then try the others
      Returns:
      booster node
    • getFirstOutputNode

      public org.bidib.jbidibc.messages.Node getFirstOutputNode()
      Get the first output node - a node that can control LC ports. TODO: the method does not make much sense and its only purpose is to check if we have an output node at all. Therefor it should be converted to "hasOutputNode" or similar.
      Returns:
      output node
    • hasAccessoryNode

      public boolean hasAccessoryNode()
      Check if we have at least one node capable of Accessory functions
      Returns:
      true or false
    • findNodeFeature

      public org.bidib.jbidibc.messages.Feature findNodeFeature(org.bidib.jbidibc.messages.Node node, int requestedFeatureId)
      Find a feature for given node.
      Parameters:
      node - selected node
      requestedFeatureId - as integer
      Returns:
      a Feature object or null if the node does not have the feature at all
    • getNodeFeature

      public int getNodeFeature(org.bidib.jbidibc.messages.Node node, int requestedFeatureId)
      Get the feature value of a node.
      Parameters:
      node - selected node
      requestedFeatureId - feature to get
      Returns:
      the feature value as integer or 0 if the node does not have the feature
    • getPortModel

      public org.bidib.jbidibc.messages.enums.PortModelEnum getPortModel(org.bidib.jbidibc.messages.Node node)
    • addMessageListener

      public void addMessageListener(org.bidib.jbidibc.core.MessageListener messageListener)
      Add a message Listener to the connection
      Parameters:
      messageListener - to be added
    • removeMessageListener

      public void removeMessageListener(org.bidib.jbidibc.core.MessageListener messageListener)
      Remove a message Listener from the connection
      Parameters:
      messageListener - to be removed
    • addRawMessageListener

      public void addRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener)
      Add a raw message Listener to the connection
      Parameters:
      rawMessageListener - to be added
    • removeRawMessageListener

      public void removeRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener)
      Remove a raw message Listener from the connection
      Parameters:
      rawMessageListener - to be removed
    • allPortConfigX

      public void allPortConfigX()
      Request CONFIGX from all ports on all nodes of this connection. Returns after all data has been received. Received data is delivered to registered Message Listeners.
    • getAllPortConfigX

      public List<org.bidib.jbidibc.messages.LcConfigX> getAllPortConfigX(org.bidib.jbidibc.messages.Node node, org.bidib.jbidibc.messages.enums.LcOutputType type)
      Request CONFIGX from all ports on a given node and possibly only for a given type.
      Parameters:
      node - requested node
      type - - if null, request all port types
      Returns:
      Note: always returns null, since data is not collected synchroneously but delivered to registered Message Listeners.
    • getPortConfigX

      public org.bidib.jbidibc.messages.LcConfigX getPortConfigX(org.bidib.jbidibc.messages.Node node, int portAddr, org.bidib.jbidibc.messages.enums.LcOutputType type)
      Request CONFIGX if a given port on a given node and possibly only for a given type.
      Parameters:
      node - requested node
      portAddr - as an integer
      type - - if null, request all port types
      Returns:
      Note: always returns null, since data is not collected synchroneously but delivered to registered Message Listeners.
    • convertConfig2ConfigX

      public org.bidib.jbidibc.messages.LcConfigX convertConfig2ConfigX(org.bidib.jbidibc.messages.Node node, org.bidib.jbidibc.messages.LcConfig lcConfig)
      Convert a CONFIG object to a CONFIGX object. This is a convenience method so the JMRI components need only to handle the CONFIGX format
      Parameters:
      node - context node
      lcConfig - the LcConfig object
      Returns:
      a new LcConfigX object
    • allPortLcStat

      public void allPortLcStat()
      Request LC_STAT from all ports on all nodes of this connection. Returns immediately. Received data is delivered to registered Message Listeners.
    • portLcStat

      public void portLcStat(org.bidib.jbidibc.messages.Node node, int typemask)
      Request LC_STAT from all ports on a given node. Returns immediately. Received data is delivered to registered Message Listeners. The differences for the addressing model an the old LC_STAT handling are hidden to the caller.
      Parameters:
      node - selected node
      typemask - a 16 bit type mask where each bit represents a type, Bit0 is SWITCHPORT, Bit1 is LIGHTPORT and so on. Bit 15 is INPUTPORT. Return LC_STAT only for ports which are selected on the type mask (the correspondend bit is set).
    • allAccessoryState

      public void allAccessoryState()
    • accessoryState

      public void accessoryState(org.bidib.jbidibc.messages.Node node)
    • allFeedback

      public void allFeedback()
      Request Feedback Status (called BM status in BiDiB - BM (Belegtmelder) is german for "feedback") from all ports on all nodes of this connection. Returns immediately. Received data is delivered to registered Message Listeners.
    • feedback

      public void feedback(org.bidib.jbidibc.messages.Node node)
      Request Feedback Status (called BM status in BiDiB - BM (Belegtmelder) is german for "feedback") from all ports on a given node. Returns immediately. Received data is delivered to registered Message Listeners.
      Parameters:
      node - selected node
    • sendBiDiBMessage

      public void sendBiDiBMessage(org.bidib.jbidibc.messages.message.BidibCommandMessage m, org.bidib.jbidibc.messages.Node node)
      Forward a preformatted BiDiBMessage to the actual interface.
      Parameters:
      m - Message to send;
      node - BiDiB node to send the message to
    • checkProgMode

      public int checkProgMode(boolean needProgMode, org.bidib.jbidibc.messages.Node node)
      Check if the command station is in the requested state (Normal, PT) If the command station is not in the requested state, a message is sent to BiDiB to switch to the requested state.
      Parameters:
      needProgMode - true if we request the command station to be in programming state, false if normal state is requested
      node - selected node
      Returns:
      0 if nothing to do, 1 if state has been changed, -1 on error
    • setWatchdogTimer

      public final void setWatchdogTimer(boolean state)
    • getSystemConnectionMemo

      Get access to the system connection memo associated with this traffic controller.
      Returns:
      associated systemConnectionMemo object
    • setSystemConnectionMemo

      Set the system connection memo associated with this traffic controller.
      Parameters:
      m - associated systemConnectionMemo object
    • getSystemPrefix

      Specified by:
      getSystemPrefix in interface CommandStation
    • getUserName

      public String getUserName()
      Specified by:
      getUserName in interface CommandStation
    • sendPacket

      public boolean sendPacket(byte[] packet, int repeats)
      Send a specific packet to the rails. Not supported! We probably don't need the command station interface at all... ... besides perhaps consist control or DCC Signal Mast / Head ??
      Specified by:
      sendPacket in interface CommandStation
      Parameters:
      packet - Byte array representing the packet, including the error-correction byte.
      repeats - Number of times to repeat the transmission.
      Returns:
      true if the operation succeeds, false otherwise.
    • terminate

      protected void terminate()