Class Rs232ControllerBuilder

  • All Implemented Interfaces:
    ConnectorFactory

    public class Rs232ControllerBuilder
    extends java.lang.Object
    implements ConnectorFactory
    Creates an instance of a RS232 based controller to a given port, and connects it with the selected menu. This implements the standard builder pattern, an example of use would be along the lines of:
         controller = new Rs232ControllerBuilder()
                 .withRs232(portName, baud)
                 .withMenuTree(menuTree)
                 .withLocalName("myApp")
                 .withUUID(myAppUUID)
                 .build();
         controller.start();
     
    • Constructor Detail

      • Rs232ControllerBuilder

        public Rs232ControllerBuilder()
    • Method Detail

      • withRs232

        public Rs232ControllerBuilder withRs232​(java.lang.String port,
                                                int baud)
        Mandatory, specifies the port name and baud rate for rs232.
        Parameters:
        port - the name of the port
        baud - the baud rate
        Returns:
        itself, calls can be chained.
      • withClock

        public Rs232ControllerBuilder withClock​(java.time.Clock clock)
        Optional, defaults to system clock but can be overriden
        Parameters:
        clock - the clock to use
        Returns:
        itself, can be chained
      • withUUID

        public Rs232ControllerBuilder withUUID​(java.util.UUID uuid)
        Mandatory, the UUID for this instance of the application
        Parameters:
        uuid - the uuid of this app.
        Returns:
        itself, can be chained
      • withExecutor

        public Rs232ControllerBuilder withExecutor​(java.util.concurrent.ScheduledExecutorService executor)
        Optional, defaults to creating a suitable executor for single connectivity
        Parameters:
        executor - the executor which must implement ScheduledExecutorService
        Returns:
        itself, suitable for chaining.
      • withMenuTree

        public Rs232ControllerBuilder withMenuTree​(MenuTree tree)
        Mandatory, the menuTree instance to store the menu items retrieved from the remote side. this menuTree must only be used with one remote.
        Parameters:
        tree - the menu tree to be populated (only use a menu tree with one remote)
        Returns:
        itself, suitable for chaining.
      • withProtocol

        public Rs232ControllerBuilder withProtocol​(MenuCommandProtocol protocol)
        Optional, defaults to the standard protocol. Only use if changing the protocol which is not advised.
        Parameters:
        protocol - a protocol object.
        Returns:
        itself, suitable for chaining.
      • withLocalName

        public Rs232ControllerBuilder withLocalName​(java.lang.String name)
        Optional, Set the name of this connection, defaults to NoName
        Parameters:
        name - the name the remote will see.
        Returns:
        itself, suitable for chaining.
      • build

        public RemoteMenuController build()
        Once the above methods have been called to fill in the blanks, then call build to get the actual instance.
        Specified by:
        build in interface ConnectorFactory
        Returns:
        the actual instance.
      • attemptPairing

        public boolean attemptPairing​(java.util.Optional<java.util.function.Consumer<PairingHelper.PairingState>> maybePairingListener)
        A pairing connection is purely used to initialise the security between the device and the API. Once used it will be closed. However, you can use build on the same builder after a successful pair.
        Specified by:
        attemptPairing in interface ConnectorFactory
        Parameters:
        maybePairingListener - an optional of a consumer that can receive updates, mainly for UI's.
        Returns:
        true if paired otherwise false.