Class CbusNodeEventManager


  • public class CbusNodeEventManager
    extends java.lang.Object
    Class to represent a Processing of CAN Frames for a CbusNode.
    • 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 Number
        en - 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 number
        nn - 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 combination

        If 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 number
        nn - 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 Number
        en - Event Number
        evvarindex - Event Variable Index
        evvarval - Event Variable Value
      • getNodeEventByIndex

        @CheckForNull
        public CbusNodeEvent getNodeEventByIndex​(int index)
        Get a Node event from its Index Field

        This 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
      • getOutstandingEvVars

        public int getOutstandingEvVars()
        Get the Number of Outstanding Event Variables

        Sometimes, 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 Node

        If 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 Index
        eventVarIndex - Event Variable Index
        newVal - 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 Number
        en - Event Number
        index - 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 number
        en - 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 class java.lang.Object
        Returns:
        descriptive string