Package org.opentcs.drivers.peripherals

# Class BasicPeripheralCommAdapter

java.lang.Object
org.opentcs.drivers.peripherals.BasicPeripheralCommAdapter

All Implemented Interfaces:
  `Lifecycle`, `PeripheralCommAdapter`

    public abstract class BasicPeripheralCommAdapter
    extends java.lang.Object
    implements PeripheralCommAdapter

A base class for peripheral communication adapters mainly providing command queue processing.

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `BasicPeripheralCommAdapter​(PeripheralProcessModel processModel, EventHandler eventHandler)` | Creates a new instance.

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `protected abstract void` | `connectPeripheral()` | Initiates a communication channel to the peripheral device.
  `void` | `disable()` | Disables this comm adapter, i.e.
  `protected abstract void` | `disconnectPeripheral()` | Closes the communication channel to the peripheral device.
  `void` | `enable()` | Enables this comm adapter, i.e.
  `protected EventHandler` | `getEventHandler()` |
  `PeripheralProcessModel` | `getProcessModel()` | Returns a model of the peripheral device's and its communication adapter's attributes.
  `void` | `initialize()` | (Re-)Initializes this component before it is being used.
  `boolean` | `isEnabled()` | Checks whether this communication adapter is enabled.
  `boolean` | `isInitialized()` | Checks whether this component is initialized.
  `protected void` | `sendProcessModelChangedEvent​(PeripheralProcessModel.Attribute attributeChanged)` |
  `protected void` | `setProcessModel​(PeripheralProcessModel processModel)` |
  `void` | `terminate()` | Terminates the instance and frees resources.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.opentcs.drivers.peripherals.PeripheralCommAdapter

  `canProcess, execute, process`

- ## Constructor Details

  - ### BasicPeripheralCommAdapter

    public BasicPeripheralCommAdapter​(PeripheralProcessModel processModel, EventHandler eventHandler)
    Creates a new instance.
    Parameters:
      `processModel` - A model of the peripheral device's and its communication adapter's attributes.
      `eventHandler` - The handler used to send events to.

- ## Method Details

  - ### initialize

    public void initialize()
    (Re-)Initializes this component before it is being used.

    Overriding methods are expected to call this implementation, too.

    Specified by:
      `initialize` in interface `Lifecycle`

  - ### isInitialized

    public boolean isInitialized()
    Description copied from interface: `Lifecycle`
    Checks whether this component is initialized.
    Specified by:
      `isInitialized` in interface `Lifecycle`
    Returns:
      `true` if, and only if, this component is initialized.

  - ### terminate

    public void terminate()
    Terminates the instance and frees resources.

    Overriding methods are expected to call this implementation, too.

    Specified by:
      `terminate` in interface `Lifecycle`

  - ### enable

    public void enable()
    Enables this comm adapter, i.e. turns it on.

    Overriding methods are expected to call this implementation, too.

    Specified by:
      `enable` in interface `PeripheralCommAdapter`

  - ### isEnabled

    public boolean isEnabled()
    Description copied from interface: `PeripheralCommAdapter`
    Checks whether this communication adapter is enabled.
    Specified by:
      `isEnabled` in interface `PeripheralCommAdapter`
    Returns:
      `true` if, and only if, this communication adapter is enabled.

  - ### disable

    public void disable()
    Disables this comm adapter, i.e. turns it off.

    Overriding methods are expected to call this implementation, too.

    Specified by:
      `disable` in interface `PeripheralCommAdapter`

  - ### getProcessModel

    public PeripheralProcessModel getProcessModel()
    Description copied from interface: `PeripheralCommAdapter`
    Returns a model of the peripheral device's and its communication adapter's attributes.
    Specified by:
      `getProcessModel` in interface `PeripheralCommAdapter`
    Returns:
      A model of the peripheral device's and its communication adapter's attributes.

  - ### setProcessModel

    protected void setProcessModel​(PeripheralProcessModel processModel)

  - ### getEventHandler

    protected EventHandler getEventHandler()

  - ### sendProcessModelChangedEvent

    protected void sendProcessModelChangedEvent​(PeripheralProcessModel.Attribute attributeChanged)

  - ### connectPeripheral

    protected abstract void connectPeripheral()
    Initiates a communication channel to the peripheral device. This method should not block, i.e. it should not wait for the actual connection to be established, as the peripheral device could be temporarily absent or not responding at all. If that's the case, the communication adapter should continue trying to establish a connection until successful or until `disconnectPeripheral()` is called.

  - ### disconnectPeripheral

    protected abstract void disconnectPeripheral()
    Closes the communication channel to the peripheral device.