Package jmri.jmrix.bidib
Class BiDiBTrafficController
java.lang.Object
jmri.jmrix.bidib.BiDiBTrafficController
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final String(package private) org.bidib.jbidibc.messages.Nodestatic final String(package private) BiDiBSystemConnectionMemoReference to the system connection memo.protected org.bidib.jbidibc.messages.enums.CommandStationStatestatic final String -
Constructor Summary
ConstructorsConstructorDescriptionBiDiBTrafficController(org.bidib.jbidibc.core.BidibInterface b) Create a new BiDiBTrafficController instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccessoryState(org.bidib.jbidibc.messages.Node node) voidAdd/Remove an ActionListener to be called when the connection has changed.voidaddMessageListener(org.bidib.jbidibc.core.MessageListener messageListener) Add a message Listener to the connectionvoidaddRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener) Add a raw message Listener to the connectionvoidvoidRequest Feedback Status (called BM status in BiDiB - BM (Belegtmelder) is german for "feedback") from all ports on all nodes of this connection.voidRequest CONFIGX from all ports on all nodes of this connection.voidRequest LC_STAT from all ports on all nodes of this connection.intcheckProgMode(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.voidSet the connection to lost state.org.bidib.jbidibc.messages.helpers.ContextOpens the BiDiB connection in the jbidibc library, add listeners and initialize BiDiB.org.bidib.jbidibc.messages.LcConfigXconvertConfig2ConfigX(org.bidib.jbidibc.messages.Node node, org.bidib.jbidibc.messages.LcConfig lcConfig) Convert a CONFIG object to a CONFIGX object.voidfeedback(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.FeaturefindNodeFeature(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.BidibInterfacegetBidib()Get Bidib Interfaceorg.bidib.jbidibc.messages.NodeGet the cached global programmer node.org.bidib.jbidibc.messages.NodeGet the first booster node.org.bidib.jbidibc.messages.NodeGet 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.NodeGet 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.NodeGet the first output node - a node that can control LC ports.org.bidib.jbidibc.messages.NodegetNodeByAddr(byte[] addr) Get node by node address from nodelistorg.bidib.jbidibc.messages.NodegetNodeByUniqueID(long uniqueId) Get node by unique id from nodelistorg.bidib.jbidibc.messages.NodegetNodeByUserName(String userName) Get node by node username from nodelistintgetNodeFeature(org.bidib.jbidibc.messages.Node node, int requestedFeatureId) Get the feature value of a node.Get the list of nodes foundorg.bidib.jbidibc.messages.LcConfigXgetPortConfigX(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.PortModelEnumgetPortModel(org.bidib.jbidibc.messages.Node node) org.bidib.jbidibc.messages.NodeGet root node from nodelistGet access to the system connection memo associated with this traffic controller.booleanCheck if we have at least one node capable of Accessory functionsbooleanCheck if the connection is ready to communicate.booleanCheck if the connection is detached i.e. it is opened, paired but the logon has been rejected.booleanisGlobalProgrammerNode(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 boosterbooleanCheck of the connection is netBiDiB.voidportLcStat(org.bidib.jbidibc.messages.Node node, int typemask) Request LC_STAT from all ports on a given node.voidvoidremoveMessageListener(org.bidib.jbidibc.core.MessageListener messageListener) Remove a message Listener from the connectionvoidremoveRawMessageListener(org.bidib.jbidibc.messages.base.RawMessageListener rawMessageListener) Remove a raw message Listener from the connectionvoidsendBiDiBMessage(org.bidib.jbidibc.messages.message.BidibCommandMessage m, org.bidib.jbidibc.messages.Node node) Forward a preformatted BiDiBMessage to the actual interface.booleansendPacket(byte[] packet, int repeats) Send a specific packet to the rails.booleansetCurrentGlobalProgrammerNode(org.bidib.jbidibc.messages.Node node) Set the global programmer node to use.voidsetLogon(boolean logon) Set or remove the detached state.voidSet the system connection memo associated with this traffic controller.final voidsetWatchdogTimer(boolean state) voidStart jbidibc built-in local ping as a watchdog of the connection.protected voidvoidTEST(boolean a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.CommandStation
sendAccSignalDecoderPkt, sendAltAccSignalDecoderPkt
-
Field Details
-
ASYNCCONNECTIONINIT
- See Also:
-
ISNETBIDIB
- See Also:
-
USELOCALPING
- See Also:
-
nodes
-
mSavedMode
-
debugSavedNode
org.bidib.jbidibc.messages.Node debugSavedNode -
mMemo
Reference to the system connection memo.
-
-
Constructor Details
-
BiDiBTrafficController
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
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
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
Check of the connection is netBiDiB.- Returns:
- true if this connection is netBiDiB
-
connectionLost
Set the connection to lost state. All nodes will be removed and the components will be invalidated -
isDetached
Check if the connection is detached i.e. it is opened, paired but the logon has been rejected.- Returns:
- true if detached
-
setLogon
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
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
-
getBidib
Get Bidib Interface- Returns:
- Bidib Interface
-
getNodeList
Get the list of nodes found- Returns:
- list of nodes
-
getNodeByUniqueID
Get node by unique id from nodelist- Parameters:
uniqueId- search for this- Returns:
- node
-
getNodeByAddr
Get node by node address from nodelist- Parameters:
addr- input to search- Returns:
- node
-
getNodeByUserName
Get node by node username from nodelist- Parameters:
userName- input to search- Returns:
- node
-
getRootNode
Get root node from nodelist- Returns:
- node
-
isGlobalProgrammerNode
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
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
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
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
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
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
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
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 noderequestedFeatureId- as integer- Returns:
- a Feature object or null if the node does not have the feature at all
-
getNodeFeature
Get the feature value of a node.- Parameters:
node- selected noderequestedFeatureId- 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
Add a message Listener to the connection- Parameters:
messageListener- to be added
-
removeMessageListener
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
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 nodetype- - 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 nodeportAddr- as an integertype- - 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 nodelcConfig- the LcConfig object- Returns:
- a new LcConfigX object
-
allPortLcStat
Request LC_STAT from all ports on all nodes of this connection. Returns immediately. Received data is delivered to registered Message Listeners. -
portLcStat
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 nodetypemask- 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
-
accessoryState
-
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
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
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 requestednode- selected node- Returns:
- 0 if nothing to do, 1 if state has been changed, -1 on error
-
setWatchdogTimer
-
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:
getSystemPrefixin interfaceCommandStation
-
getUserName
- Specified by:
getUserNamein interfaceCommandStation
-
sendPacket
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:
sendPacketin interfaceCommandStation- Parameters:
packet- Byte array representing the packet, including the error-correction byte.repeats- Number of times to repeat the transmission.- Returns:
trueif the operation succeeds,falseotherwise.
-
terminate
-