Class BasicVehicleCommAdapter
- All Implemented Interfaces:
PropertyChangeListener,EventListener,Lifecycle,VehicleCommAdapter
Implementation notes:
- Accessing the queues of
unsentandsentcommands from outside should always be protected by synchronization on theBasicVehicleCommAdapterinstance.
-
Constructor Summary
ConstructorsConstructorDescriptionBasicVehicleCommAdapter(VehicleProcessModel vehicleModel, int commandsCapacity, String rechargeOperation, ScheduledExecutorService executor) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether this comm adapter can accept the next (i.e.protected booleanChecks whether a new command can be sent to the vehicle.voidClears this communication adapter's command queues (i.e.protected abstract voidInitiates a communication channel to the vehicle.protected VehicleProcessModelTOCreates 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.voiddisable()Disables this comm adapter, i.e.protected abstract voidCloses the communication channel to the vehicle.voidenable()Enables this comm adapter, i.e.booleanenqueueCommand(MovementCommand newCommand) Appends a command to this communication adapter's queue ofunsent commands.voidexecute(AdapterCommand command) Executes the givenAdapterCommand.intIndicates 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.booleanChecks whether this communication adapter is enabled.booleanChecks whether this component is initialized.protected abstract booleanChecks whether the communication channel to the vehicle is open.voidProcesses updates of theVehicleProcessModel.abstract voidConverts the given command to something the vehicle can understand and sends the resulting data to the vehicle.voidTerminates the instance and frees resources.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opentcs.drivers.vehicle.VehicleCommAdapter
canProcess, onVehiclePaused, processMessage
-
Constructor Details
-
BasicVehicleCommAdapter
public BasicVehicleCommAdapter(VehicleProcessModel vehicleModel, int commandsCapacity, String rechargeOperation, ScheduledExecutorService executor) Creates a new instance.- Parameters:
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.
-
-
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:
initializein interfaceLifecycle
-
terminate
public void terminate()Terminates the instance and frees resources.Overriding methods are expected to call this implementation, too.
-
isInitialized
public boolean isInitialized()Description copied from interface:LifecycleChecks whether this component is initialized.- Specified by:
isInitializedin interfaceLifecycle- Returns:
trueif, 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.
- Specified by:
enablein interfaceVehicleCommAdapter
-
disable
public void disable()Disables this comm adapter, i.e. turns it off.Overriding methods are expected to call this implementation, too.
- Specified by:
disablein interfaceVehicleCommAdapter
-
isEnabled
public boolean isEnabled()Description copied from interface:VehicleCommAdapterChecks whether this communication adapter is enabled.- Specified by:
isEnabledin interfaceVehicleCommAdapter- Returns:
trueif, and only if, this communication adapter is enabled.
-
getProcessModel
Description copied from interface:VehicleCommAdapterReturns an observable model of the vehicle's and its comm adapter's attributes.- Specified by:
getProcessModelin interfaceVehicleCommAdapter- Returns:
- An observable model of the vehicle's and its comm adapter's attributes.
-
createTransferableProcessModel
Description copied from interface:VehicleCommAdapterReturns a transferable/serializable model of the vehicle's and its comm adapter's attributes.- Specified by:
createTransferableProcessModelin interfaceVehicleCommAdapter- Returns:
- A transferable/serializable model of the vehicle's and its comm adapter's attributes.
-
getUnsentCommands
Description copied from interface:VehicleCommAdapterReturns this adapter's queue of unsent commands.Unsent
MovementCommands are commands that the comm adapter received from theVehicleControllerit'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.- Specified by:
getUnsentCommandsin interfaceVehicleCommAdapter- Returns:
- This adapter's queue of unsent commands.
- See Also:
-
getSentCommands
Description copied from interface:VehicleCommAdapterReturns 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.- Specified by:
getSentCommandsin interfaceVehicleCommAdapter- Returns:
- This adapter's queue of sent commands.
- See Also:
-
getCommandsCapacity
public int getCommandsCapacity()Description copied from interface:VehicleCommAdapterIndicates how many commands this comm adapter accepts.This capacity considers both the
queue of unsent commandsand 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.
- Specified by:
getCommandsCapacityin interfaceVehicleCommAdapter- Returns:
- The number of commands this comm adapter accepts.
-
canAcceptNextCommand
public boolean canAcceptNextCommand()Description copied from interface:VehicleCommAdapterChecks whether this comm adapter can accept the next (i.e. one more)command.- Specified by:
canAcceptNextCommandin interfaceVehicleCommAdapter- Returns:
true, if this adapter can accept another command, otherwisefalse.
-
getRechargeOperation
Description copied from interface:VehicleCommAdapterReturns the string the comm adapter recognizes as a recharge operation.- Specified by:
getRechargeOperationin interfaceVehicleCommAdapter- Returns:
- The string the comm adapter recognizes as a recharge operation.
-
enqueueCommand
Description copied from interface:VehicleCommAdapterAppends 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.- Specified by:
enqueueCommandin interfaceVehicleCommAdapter- Parameters:
newCommand- The command to be added to this adapter's queue ofunsent commands.- Returns:
trueif, and only if, the new command was added to the queue.
-
clearCommandQueue
public void clearCommandQueue()Description copied from interface:VehicleCommAdapterClears this communication adapter's command queues (i.e. the queues ofunsentandsentcommands).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.
- Specified by:
clearCommandQueuein interfaceVehicleCommAdapter
-
execute
Description copied from interface:VehicleCommAdapterExecutes the givenAdapterCommand.- Specified by:
executein interfaceVehicleCommAdapter- Parameters:
command- The command to execute.
-
propertyChange
Processes updates of theVehicleProcessModel.Overriding methods should also call this.
- Specified by:
propertyChangein interfacePropertyChangeListener- Parameters:
evt- The property change event published by the model.
-
getName
Returns this communication adapter's name.- Returns:
- This communication adapter's name.
-
getExecutor
Returns the executor to run tasks on.- Returns:
- 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.
- Parameters:
cmd- The command to be sent.- Throws:
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
trueonly if there is at least one command in thequeue of unsent commandswaiting to be sent.- Returns:
trueif, 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 untildisconnectVehicleis 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.
- Returns:
trueif, 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.
- Returns:
- A transferable process model.
-