Class OpenGateway

  • All Implemented Interfaces:
    ConnectorListener
    Direct Known Subclasses:
    BUSGateway, USBGateway

    public abstract class OpenGateway
    extends Object
    implements ConnectorListener
    Abstract OpenGateway to connect, send commands and receive events from a OpenWebNet gateway
    Author:
    M. Valla - Initial contribution
    • Field Detail

      • isConnected

        protected boolean isConnected
      • isDiscovering

        protected boolean isDiscovering
      • macAddr

        protected byte[] macAddr
    • Constructor Detail

      • OpenGateway

        public OpenGateway()
    • Method Detail

      • initConnector

        protected abstract void initConnector()
        Init the connector for this OpenGateway.
      • connect

        public void connect()
                     throws OWNException
        Connect to the OpenWebNet gateway.
        Throws:
        OWNException - in case of error during connection
      • isConnected

        public boolean isConnected()
        Returns true if this OpenGateway is connected.
        Returns:
        true if this OpenGateway is connected
      • sendHighPriority

        public Response sendHighPriority​(OpenMessage msg)
                                  throws OWNException
        Send a command message with high priority, and returns the response messages
        Parameters:
        msg - the OpenMessage to be sent
        Returns:
        the Response messages received as response
        Throws:
        OWNException - on send/response reading error
      • isCmdConnectionReady

        public abstract boolean isCmdConnectionReady()
        Returns true if CMD connection is ready to send messages (connector must be connected and in case of BUS connection checks if a CMD was sent recently < 120sec)
        Returns:
        boolean
      • onMonDisconnected

        public void onMonDisconnected​(OWNException e)
        Description copied from interface: ConnectorListener
        This method is called when the MONITOR connection gets disconnected for some error
        Specified by:
        onMonDisconnected in interface ConnectorListener
        Parameters:
        e - the Exception that caused disconnection
      • subscribe

        public void subscribe​(GatewayListener listener)
        Add a listener for events from this OpenGateway.
        Parameters:
        listener - the GatewayListener to add
      • unsubscribe

        public void unsubscribe​(GatewayListener listener)
        Remove a listener for events from this OpenGateway.
        Parameters:
        listener - the GatewayListener to remove.
      • notifyListeners

        protected void notifyListeners​(Consumer<? super GatewayListener> method)
        Generic method to notify registered OpenListener about 'method' event. Thread safe. A (single) notification thread is used.
        Parameters:
        method - the method to be notified
      • isDiscovering

        public boolean isDiscovering()
        Check if the gateway has started a device discovery session
        Returns:
        true if the gateway has started a device discovery session
      • getFirmwareVersion

        public String getFirmwareVersion()
        Returns the firmware version of the gateway (e.g. 1.2.3)
        Returns:
        String containing gateway firmware version, null if unknown
      • getMACAddr

        public String getMACAddr()
        Returns the MAC address of the gateway as human readable String
        Returns:
        gateway MAC address as String (XX:YY:ZZ:...), or null if unknown
      • closeConnection

        public void closeConnection()
        Closes connection to the gateway and releases resources