Package jmri.jmrix.can.cbus.node
Class CbusNodeEventManager
- java.lang.Object
-
- jmri.jmrix.can.cbus.node.CbusNodeEventManager
-
public class CbusNodeEventManager extends java.lang.Object
Class to represent a Processing of CAN Frames for a CbusNode.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
nextEvInArray
protected boolean
TEACH_OUTSTANDING_EVS
-
Constructor Summary
Constructors Constructor Description CbusNodeEventManager(CanSystemConnectionMemo memo, CbusBasicNodeWithManagers node)
Create a new CbusNodeNVManager
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNewEvent(CbusNodeEvent newEvent)
Add an event to the node, will not overwrite an existing event.void
deleteEvOnNode(int nn, int en)
Send a message to delete an event stored on this nodejava.util.ArrayList<CbusNodeEvent>
getEventArray()
Get the Node event ArrayListprotected int
getEventRowFromIndex(int index)
Get the Node event Array index from its Index Fieldint
getLoadedNodeEvents()
Returns number of fully loaded events, ie no outstanding event variables.int
getNextFreeIndex()
the next event index for a CbusDummyNode NODE to allocate, NOT a software tool.CbusNodeEvent
getNodeEvent(int nn, int en)
Get a Node event from its Event and Node number combinationCbusNodeEvent
getNodeEventByArrayID(int index)
Get the Node event by ArrayList Index.CbusNodeEvent
getNodeEventByIndex(int index)
Get a Node event from its Index Fieldint
getOutstandingEvVars()
Get the Number of Outstanding Event Variablesint
getOutstandingIndexNodeEvents()
Returns outstanding events from initial event fetch.int
getTotalNodeEvents()
Returns total number of node events, including those with outstanding event variables.protected boolean
isEventIndexValid()
Get if the Node event index is valid.CbusNodeEvent
provideNodeEvent(int nn, int en)
Provide a Node event from its Event and Node number combinationprotected void
remainingEvVarsNotNeeded()
The last message from the node CMDERR5 indicates that all remaining event variables for a particular event are not required.void
removeEvent(int nn, int en)
Remove an event from the CbusNode, does not update hardware.void
resetNodeEvents()
Resets Node Events with null array.void
resetNodeEventsToZero()
Resets Node Events with zero length array.void
sendNewEvSToNode(java.util.ArrayList<CbusNodeEvent> evArray)
Send and teach updated Events to this nodeprotected void
sendNextEvVarToFetch()
Send a request for the next unknown Event Variable to the Physical Nodeprotected void
setEvIndexValid(boolean newval)
Set the Node event index flag as valid or invalid.protected void
setEvVarByIndex(int eventIndex, int eventVarIndex, int newVal)
Used in CBUS_NEVAL response from Node.protected void
setNextEmptyNodeEvent(int nn, int en, int index)
Used to process a CBUS_ENRSP response from node If existing index known, use that slot in the event array, else if event array has empty slot for that index, use that slot.protected void
teachNewEvLoop()
Loop for event teaching, triggered from various placesjava.lang.String
toString()
protected void
updateNodeFromLearn(int nn, int en, int evvarindex, int evvarval)
Update node with new Node Event.
-
-
-
Field Detail
-
nextEvInArray
protected int nextEvInArray
-
TEACH_OUTSTANDING_EVS
protected boolean TEACH_OUTSTANDING_EVS
-
-
Constructor Detail
-
CbusNodeEventManager
public CbusNodeEventManager(CanSystemConnectionMemo memo, CbusBasicNodeWithManagers node)
Create a new CbusNodeNVManager- Parameters:
memo
- System connectionnode
- The Node
-
-
Method Detail
-
getTotalNodeEvents
public int getTotalNodeEvents()
Returns total number of node events, including those with outstanding event variables.- Returns:
- number of events, -1 if events not set
-
getLoadedNodeEvents
public int getLoadedNodeEvents()
Returns number of fully loaded events, ie no outstanding event variables.- Returns:
- number of loaded events, -1 if events not set
-
getOutstandingIndexNodeEvents
public int getOutstandingIndexNodeEvents()
Returns outstanding events from initial event fetch.- Returns:
- number of outstanding index events
-
addNewEvent
public void addNewEvent(@Nonnull CbusNodeEvent newEvent)
Add an event to the node, will not overwrite an existing event. Resets Event Index as Invalid for All Node Events- Parameters:
newEvent
- the new event to be added
-
removeEvent
public void removeEvent(int nn, int en)
Remove an event from the CbusNode, does not update hardware.- Parameters:
nn
- the event Node Numberen
- the event Event Number
-
getNodeEvent
@CheckForNull public CbusNodeEvent getNodeEvent(int nn, int en)
Get a Node event from its Event and Node number combination- Parameters:
en
- the Event event numbernn
- the Event node number- Returns:
- the node event else null if no Event / Node number combination.
-
provideNodeEvent
@Nonnull public CbusNodeEvent provideNodeEvent(int nn, int en)
Provide a Node event from its Event and Node number combinationIf an event for this number pair does not already exist on the node one will be created, else the existing will be returned.
Adds any new CbusNodeEvent to the node event array, which will also be created if it doesn't exist.
- Parameters:
en
- the Event event numbernn
- the Event node number- Returns:
- the node event
-
updateNodeFromLearn
protected void updateNodeFromLearn(int nn, int en, int evvarindex, int evvarval)
Update node with new Node Event.- Parameters:
nn
- Node Numberen
- Event Numberevvarindex
- Event Variable Indexevvarval
- Event Variable Value
-
getNodeEventByIndex
@CheckForNull public CbusNodeEvent getNodeEventByIndex(int index)
Get a Node event from its Index FieldThis is NOT the node array index.
- Parameters:
index
- the Node event index, as set by a node from a NERD request- Returns:
- the node event, else null if the index is not located
-
getEventRowFromIndex
protected int getEventRowFromIndex(int index)
Get the Node event Array index from its Index Field- Parameters:
index
- the Node event index, as set by a node from a NERD request- Returns:
- the array index, else -1 if event index number not found in array
-
getNodeEventByArrayID
@CheckForNull public CbusNodeEvent getNodeEventByArrayID(int index)
Get the Node event by ArrayList Index.- Parameters:
index
- the index of the CbusNodeEvent within the ArrayList- Returns:
- the Node Event
-
getEventArray
@CheckForNull public java.util.ArrayList<CbusNodeEvent> getEventArray()
Get the Node event ArrayList- Returns:
- the list of Node Events
-
getOutstandingEvVars
public int getOutstandingEvVars()
Get the Number of Outstanding Event VariablesSometimes, the Event Variables have to be initialised with an unknown status, this returns a count of unknown Event Variables for the whole Node.
- Returns:
- -1 if main node events array null, else number Outstanding Ev Vars
-
remainingEvVarsNotNeeded
protected void remainingEvVarsNotNeeded()
The last message from the node CMDERR5 indicates that all remaining event variables for a particular event are not required. This sets the remaining ev vars to 0 so are not requested
-
sendNextEvVarToFetch
protected void sendNextEvVarToFetch()
Send a request for the next unknown Event Variable to the Physical NodeIf events are unknown, sends the NERD request and starts that timer, else requests the next Ev Var with unknown status ( represented as int value -1 ) Will NOT send if any Node is in Learn Mode or if there are any outstanding requests from the Node.
-
setEvVarByIndex
protected void setEvVarByIndex(int eventIndex, int eventVarIndex, int newVal)
Used in CBUS_NEVAL response from Node. Set the value of an event variable by event Index and event Variable Index- Parameters:
eventIndex
- Event IndexeventVarIndex
- Event Variable IndexnewVal
- New Value
-
setNextEmptyNodeEvent
protected void setNextEmptyNodeEvent(int nn, int en, int index)
Used to process a CBUS_ENRSP response from node If existing index known, use that slot in the event array, else if event array has empty slot for that index, use that slot.- Parameters:
nn
- Node Numberen
- Event Numberindex
- Index Number
-
isEventIndexValid
protected boolean isEventIndexValid()
Get if the Node event index is valid.- Returns:
- true if event index is valid, else false if invalid or no events on node.
-
setEvIndexValid
protected void setEvIndexValid(boolean newval)
Set the Node event index flag as valid or invalid.Resets all Node Event Indexes to -1 if invalid.
- Parameters:
newval
- true if Event Index Valid, else false
-
sendNewEvSToNode
public void sendNewEvSToNode(@Nonnull java.util.ArrayList<CbusNodeEvent> evArray)
Send and teach updated Events to this node- Parameters:
evArray
- array of CbusNodeEvents to be taught
-
deleteEvOnNode
public void deleteEvOnNode(int nn, int en)
Send a message to delete an event stored on this node- Parameters:
nn
- event node numberen
- event event number
-
teachNewEvLoop
protected void teachNewEvLoop()
Loop for event teaching, triggered from various places
-
resetNodeEvents
public void resetNodeEvents()
Resets Node Events with null array. For when a CbusNode is reset to unknown events.
-
resetNodeEventsToZero
public void resetNodeEventsToZero()
Resets Node Events with zero length array. For when a CbusNode is reset to 0 events
-
getNextFreeIndex
public int getNextFreeIndex()
the next event index for a CbusDummyNode NODE to allocate, NOT a software tool.- Returns:
- next available event index
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- descriptive string
-
-