Klasse BasicVehicleCommAdapter
- Alle implementierten Schnittstellen:
PropertyChangeListener
,EventListener
,Lifecycle
,VehicleCommAdapter
Implementation notes:
- Accessing the queues of
unsent
andsent
commands from outside should always be protected by synchronization on theBasicVehicleCommAdapter
instance.
-
Konstruktorübersicht
KonstruktorBeschreibungBasicVehicleCommAdapter
(VehicleProcessModel vehicleModel, int commandsCapacity, String rechargeOperation, ScheduledExecutorService executor) Creates a new instance. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
Checks whether this comm adapter can accept the next (i.e. one more)command
.protected boolean
Checks whether a new command can be sent to the vehicle.void
protected abstract void
Initiates a communication channel to the vehicle.protected VehicleProcessModelTO
Creates a transferable process model with the specific attributes of this comm adapter's process model set.Returns a transferable/serializable model of the vehicle's and its comm adapter's attributes.void
disable()
Disables this comm adapter, i.e. turns it off.protected abstract void
Closes the communication channel to the vehicle.void
enable()
Enables this comm adapter, i.e. turns it on.boolean
enqueueCommand
(MovementCommand newCommand) Appends a command to this communication adapter's queue ofunsent commands
.void
execute
(AdapterCommand command) Executes the givenAdapterCommand
.int
Indicates how many commands this comm adapter accepts.Returns the executor to run tasks on.getName()
Returns this communication adapter's name.Returns an observable model of the vehicle's and its comm adapter's attributes.Returns the string the comm adapter recognizes as a recharge operation.Returns this adapter's queue of sent commands.Returns this adapter's queue of unsent commands.void
(Re-)Initializes this component before it is being used.boolean
Checks whether this communication adapter is enabled.boolean
Checks whether this component is initialized.protected abstract boolean
Checks whether the communication channel to the vehicle is open.void
Processes updates of theVehicleProcessModel
.abstract void
Converts the given command to something the vehicle can understand and sends the resulting data to the vehicle.void
Terminates the instance and frees resources.Von Klasse geerbte Methoden java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Von Schnittstelle geerbte Methoden org.opentcs.drivers.vehicle.VehicleCommAdapter
canProcess, onVehiclePaused, processMessage
-
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 SchnittstelleLifecycle
-
terminate
public void terminate()Terminates the instance and frees resources.Overriding methods are expected to call this implementation, too.
-
isInitialized
public boolean isInitialized()Beschreibung aus Schnittstelle kopiert:Lifecycle
Checks whether this component is initialized.- Angegeben von:
isInitialized
in SchnittstelleLifecycle
- 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 SchnittstelleVehicleCommAdapter
-
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 SchnittstelleVehicleCommAdapter
-
isEnabled
public boolean isEnabled()Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Checks whether this communication adapter is enabled.- Angegeben von:
isEnabled
in SchnittstelleVehicleCommAdapter
- Gibt zurück:
true
if, and only if, this communication adapter is enabled.
-
getProcessModel
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Returns an observable model of the vehicle's and its comm adapter's attributes.- Angegeben von:
getProcessModel
in SchnittstelleVehicleCommAdapter
- Gibt zurück:
- An observable model of the vehicle's and its comm adapter's attributes.
-
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 SchnittstelleVehicleCommAdapter
- Gibt zurück:
- A transferable/serializable model of the vehicle's and its comm adapter's attributes.
-
getUnsentCommands
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Returns this adapter's queue of unsent commands.Unsent
MovementCommand
s are commands that the comm adapter received from theVehicleController
it's associated with. When a command is sent to the vehicle, the command is removed from this queue and added to thequeue of sent commands
.- Angegeben von:
getUnsentCommands
in SchnittstelleVehicleCommAdapter
- Gibt zurück:
- This adapter's queue of unsent commands.
- Siehe auch:
-
getSentCommands
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Returns this adapter's queue of sent commands.Sent
MovementCommand
s 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 SchnittstelleVehicleCommAdapter
- 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 thequeue 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 SchnittstelleVehicleCommAdapter
- 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 SchnittstelleVehicleCommAdapter
- Gibt zurück:
true
, if this adapter can accept another command, otherwisefalse
.
-
getRechargeOperation
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Returns the string the comm adapter recognizes as a recharge operation.- Angegeben von:
getRechargeOperation
in SchnittstelleVehicleCommAdapter
- Gibt zurück:
- The string the comm adapter recognizes as a recharge operation.
-
enqueueCommand
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Appends a command to this communication adapter's queue ofunsent 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 SchnittstelleVehicleCommAdapter
- Parameter:
newCommand
- The command to be added to this adapter's queue ofunsent 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 ofunsent
andsent
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 SchnittstelleVehicleCommAdapter
-
execute
Beschreibung aus Schnittstelle kopiert:VehicleCommAdapter
Executes the givenAdapterCommand
.- Angegeben von:
execute
in SchnittstelleVehicleCommAdapter
- Parameter:
command
- The command to execute.
-
propertyChange
Processes updates of theVehicleProcessModel
.Overriding methods should also call this.
- Angegeben von:
propertyChange
in SchnittstellePropertyChangeListener
- Parameter:
evt
- The property change event published by the model.
-
getName
Returns this communication adapter's name.- Gibt zurück:
- This communication adapter's name.
-
getExecutor
Returns the executor to run tasks on.- Gibt zurück:
- The executor to run tasks on.
-
sendCommand
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 thequeue 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 untildisconnectVehicle
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
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.
-