Klasse BasicVehicleCommAdapter

java.lang.Object
org.opentcs.drivers.vehicle.BasicVehicleCommAdapter
Alle implementierten Schnittstellen:
PropertyChangeListener, EventListener, Lifecycle, VehicleCommAdapter

public abstract class BasicVehicleCommAdapter extends Object implements VehicleCommAdapter, PropertyChangeListener
A base class for communication adapters mainly providing command queue processing.

Implementation notes:

  • Konstruktordetails

    • BasicVehicleCommAdapter

      public BasicVehicleCommAdapter(VehicleProcessModel vehicleModel, int commandsCapacity, String rechargeOperation, ScheduledExecutorService executor)
      Creates a new instance.
      Parameter:
      vehicleModel - An observable model of the vehicle's and its comm adapter's attributes.
      commandsCapacity - The number of commands this comm adapter accepts. Must be at least 1.
      rechargeOperation - The string to recognize as a recharge operation.
      executor - The executor to run tasks on.
  • Methodendetails

    • initialize

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

      Overriding methods are expected to call this implementation, too.

      Angegeben von:
      initialize in Schnittstelle Lifecycle
    • terminate

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

      Overriding methods are expected to call this implementation, too.

      Angegeben von:
      terminate in Schnittstelle Lifecycle
    • isInitialized

      public boolean isInitialized()
      Beschreibung aus Schnittstelle kopiert: Lifecycle
      Checks whether this component is initialized.
      Angegeben von:
      isInitialized in Schnittstelle Lifecycle
      Gibt zurück:
      true if, and only if, this component is initialized.
    • enable

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

      Overriding methods are expected to call this implementation, too.

      Angegeben von:
      enable in Schnittstelle VehicleCommAdapter
    • disable

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

      Overriding methods are expected to call this implementation, too.

      Angegeben von:
      disable in Schnittstelle VehicleCommAdapter
    • isEnabled

      public boolean isEnabled()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Checks whether this communication adapter is enabled.
      Angegeben von:
      isEnabled in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      true if, and only if, this communication adapter is enabled.
    • getProcessModel

      public VehicleProcessModel getProcessModel()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Returns an observable model of the vehicle's and its comm adapter's attributes.
      Angegeben von:
      getProcessModel in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      An observable model of the vehicle's and its comm adapter's attributes.
    • createTransferableProcessModel

      public VehicleProcessModelTO createTransferableProcessModel()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Returns a transferable/serializable model of the vehicle's and its comm adapter's attributes.
      Angegeben von:
      createTransferableProcessModel in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      A transferable/serializable model of the vehicle's and its comm adapter's attributes.
    • getUnsentCommands

      public Queue<MovementCommand> getUnsentCommands()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Returns this adapter's queue of unsent commands.

      Unsent MovementCommands are commands that the comm adapter received from the VehicleController it's associated with. When a command is sent to the vehicle, the command is removed from this queue and added to the queue of sent commands.

      Angegeben von:
      getUnsentCommands in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      This adapter's queue of unsent commands.
      Siehe auch:
    • getSentCommands

      public Queue<MovementCommand> getSentCommands()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Returns this adapter's queue of sent commands.

      Sent MovementCommands are commands that the comm adapter has sent to the vehicle already but which have not yet been processed by it.

      Angegeben von:
      getSentCommands in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      This adapter's queue of sent commands.
      Siehe auch:
    • getCommandsCapacity

      public int getCommandsCapacity()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Indicates how many commands this comm adapter accepts.

      This capacity considers both the queue of unsent commands and the queue of sent commands. This means that:

      • The number of elements in both queues combined must not exceed this number.
      • The vehicle will have at most this number of (not yet completed) commands at any given point of time.
      Angegeben von:
      getCommandsCapacity in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      The number of commands this comm adapter accepts.
    • canAcceptNextCommand

      public boolean canAcceptNextCommand()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Checks whether this comm adapter can accept the next (i.e. one more) command.
      Angegeben von:
      canAcceptNextCommand in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      true, if this adapter can accept another command, otherwise false.
    • getRechargeOperation

      public String getRechargeOperation()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Returns the string the comm adapter recognizes as a recharge operation.
      Angegeben von:
      getRechargeOperation in Schnittstelle VehicleCommAdapter
      Gibt zurück:
      The string the comm adapter recognizes as a recharge operation.
    • enqueueCommand

      public boolean enqueueCommand(MovementCommand newCommand)
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Appends a command to this communication adapter's queue of unsent commands.

      The return value of this method indicates whether the command was really added to the queue. The primary reason for a commmand not being added to the queue is that it would exceed the adapter's commands capacity.

      Angegeben von:
      enqueueCommand in Schnittstelle VehicleCommAdapter
      Parameter:
      newCommand - The command to be added to this adapter's queue of unsent commands.
      Gibt zurück:
      true if, and only if, the new command was added to the queue.
    • clearCommandQueue

      public void clearCommandQueue()
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Clears this communication adapter's command queues (i.e. the queues of unsent and sent commands).

      All commands in the queue that have not been sent to this adapter's vehicle, yet, will be removed. Whether commands the vehicle has already received are still executed is up to the implementation and/or the vehicle.

      Angegeben von:
      clearCommandQueue in Schnittstelle VehicleCommAdapter
    • execute

      public void execute(AdapterCommand command)
      Beschreibung aus Schnittstelle kopiert: VehicleCommAdapter
      Executes the given AdapterCommand.
      Angegeben von:
      execute in Schnittstelle VehicleCommAdapter
      Parameter:
      command - The command to execute.
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      Processes updates of the VehicleProcessModel.

      Overriding methods should also call this.

      Angegeben von:
      propertyChange in Schnittstelle PropertyChangeListener
      Parameter:
      evt - The property change event published by the model.
    • getName

      public String getName()
      Returns this communication adapter's name.
      Gibt zurück:
      This communication adapter's name.
    • getExecutor

      public ScheduledExecutorService getExecutor()
      Returns the executor to run tasks on.
      Gibt zurück:
      The executor to run tasks on.
    • sendCommand

      public abstract void sendCommand(MovementCommand cmd) throws IllegalArgumentException
      Converts the given command to something the vehicle can understand and sends the resulting data to the vehicle.

      Note that this method is called from the kernel executor and thus should not block.

      Parameter:
      cmd - The command to be sent.
      Löst aus:
      IllegalArgumentException - If there was a problem with interpreting the command or communicating it to the vehicle.
    • canSendNextCommand

      protected boolean canSendNextCommand()
      Checks whether a new command can be sent to the vehicle.

      This method returns true only if there is at least one command in the queue of unsent commands waiting to be sent.

      Gibt zurück:
      true if, and only if, a new command can be sent to the vehicle.
    • connectVehicle

      protected abstract void connectVehicle()
      Initiates a communication channel to the vehicle. This method should not block, i.e. it should not wait for the actual connection to be established, as the vehicle 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 disconnectVehicle is called.
    • disconnectVehicle

      protected abstract void disconnectVehicle()
      Closes the communication channel to the vehicle.
    • isVehicleConnected

      protected abstract boolean isVehicleConnected()
      Checks whether the communication channel to the vehicle is open.

      Note that the return value of this method does not indicate whether communication with the vehicle is currently alive and/or if the vehicle is considered to be working/responding correctly.

      Gibt zurück:
      true if, and only if, the communication channel to the vehicle is open.
    • createCustomTransferableProcessModel

      protected VehicleProcessModelTO createCustomTransferableProcessModel()
      Creates a transferable process model with the specific attributes of this comm adapter's process model set.

      This method should be overriden by implementing classes.

      Gibt zurück:
      A transferable process model.