org.mbari.siam.devices.workhorse
Class WorkhorseADCP

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by org.mbari.siam.core.DeviceService
                  extended by org.mbari.siam.core.BaseInstrumentService
                      extended by org.mbari.siam.core.PolledInstrumentService
                          extended by org.mbari.siam.devices.workhorse.WorkhorseADCP
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ScheduleOwner, Device, DeviceServiceIF, Instrument, Safeable
Direct Known Subclasses:
DigiWorkhorseADCP

public class WorkhorseADCP
extends PolledInstrumentService
implements Instrument, Safeable

The WorkhorseADCP class represents the InstrumentServices driver for controlling the RDI Workhorse ADCP. WorkhorseADCP is sub-classed from AggregateInstrumentService . The primary responsibilities of this class is to:-

 

Capture and verify sample data from the instrument.

See Also:
Device, Instrument, PowerPort, AggregateInstrumentService, Serialized Form

Nested Class Summary
 class WorkhorseADCP.Attributes
          Configurable Workhorse attributes
static interface WorkhorseADCP.DataStructure
           
static class WorkhorseADCP.PD0DataStructure
          This class encapsulates access to the workhorses binary data format
 
Field Summary
 WorkhorseADCP.Attributes _attributes
           
protected  int _ensembleIntervalSec
           
protected  long _initialInterval
           
protected  WorkhorseADCP.PD0DataStructure _pd0Struct
           
protected  boolean _safed
           
protected  org.mbari.siam.devices.workhorse.WorkhorseADCP.DevicePacketParser devicePacketParser
           
 
Fields inherited from class org.mbari.siam.core.BaseInstrumentService
_defaultSamplerTask, _defaultSampleScheduleName, _errorCache, _instrumentAttributes, _lastPacket, _lastSensorDataPacket, _maxSampleBytes, _messagePacket, _nPowerRequests, _nWakeRequests, _packetLog, _recordType, _running, _samplerWakeupTime, _scheduleKey, _schedules, _sensorDataPacket, _turbinator, MAX_BASE_RECORDTYPE, RECORDTYPE_DEFAULT, RECORDTYPE_METADATA, RECORDTYPE_UNDEFINED
 
Fields inherited from class org.mbari.siam.core.DeviceService
_fromDevice, _instrumentPort, _nodeProperties, _parentNode, _regEntry, _sandBox, _serviceCachePath, _serviceName, _servicePropertiesPath, _serviceXMLPath, _toDevice, CACHED_PROPERTIES_FILENAME, PROPERTIES_FILENAME, XML_FILENAME
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface org.mbari.siam.distributed.Device
ERROR, INITIAL, INSTRUMENT_STATE, MDATA_ALL, OK, SAFE, SAMPLING, SERVICE_ATTRIBUTES, SERVICE_CACHE, SERVICE_PROPERTIES, SERVICE_XML, SHUTDOWN, SLEEPING, SUSPEND, UNKNOWN
 
Constructor Summary
WorkhorseADCP()
          Allocates a new WorkhorseADCP
 
Method Summary
protected  ScheduleSpecifier createDefaultSampleSchedule()
          Return specifier for initial sampling schedule.
protected  void enterCommandMode()
          sends a break to the Workhorse a waits for a prompt
 void enterSafeMode()
          Enter mode for resource-restricted environment.
protected  void exitCommandMode()
          restarts sampling and exits command mode
 DevicePacketParser getDevicePacketParser()
          Get instruments' DevicePacketParser, which returns JDDAC records.
protected  byte[] getInstrumentStateMetadata()
          Not implemented
 PacketParser getParser()
          Return a PacketParser.
protected  java.lang.String getProperty(java.lang.String response)
          Returns the property value from the Workhorse response
 SerialPortParameters getSerialPortParameters()
          Return parameters to use on serial port.
protected  PowerPolicy initCommunicationPowerPolicy()
          Return initial value of communication power policy.
protected  int initCurrentLimit()
          Specify current limit in increments of 120 mA upto 11880 mA.
protected  void initializeInstrument()
          Called by the framework to initialize the instrument prior to sampling.
protected  PowerPolicy initInstrumentPowerPolicy()
          Return initial value of instrument power policy.
protected  int initInstrumentStartDelay()
          Specify startup delay (millisec)
protected  int initMaxSampleBytes()
          Specify maximum bytes in raw sample.
protected  byte[] initPromptString()
          Specify prompt string.
protected  byte[] initSampleTerminator()
          Specify sample terminator.
protected  byte[] mkCmd(java.lang.String cmd)
          Utility method to construct a message of the form: -

protected  int mkInt(byte loByte, byte hiByte)
          Cludge to create an int from 2 bytes (There is probably a better way of doing this but this works)
 java.lang.Object parseDataPacket(SensorDataPacket pkt)
          Parse the ADCP data into a Velocity object
protected  java.lang.String[] parseProperty(java.lang.String response, java.lang.String delim, int fieldCount)
          splits the response into fields defined by the delim string and returns these in an array.
protected  void powerOnCallback()
          Called after power is applied; return when instrument is ready for use.
 void printData(byte[] buf)
          Print instrument data contained in input buffer.
protected  int readSample(byte[] sample)
          Called by the framework to fetch the sample data returned from the instrument and copy to sample buffer.
protected  int readUntilDelay(java.io.InputStream instream, byte[] outbuf, long timeout)
          Read characters from input stream into buffer and returns the number of bytes read.
protected  void requestSample()
          This method should be called _preemptionSec seconds before the expected receipt of the sample.
protected  void sendBreak()
          sends a break longer then 350mS required by the Workhorse
protected  void sendCommand(java.lang.String cmd)
          Method to send commands to the Workhorse.
protected  java.lang.String sendRequest(java.lang.String request)
          Sends a request to the Workhorse for parametric data.
 void setClock(long t)
          Not implemented.
protected  java.lang.String shutdownInstrument()
          Shutdown instrument sampling.
 int test()
          Run device's self-test routine.
protected  void validateSample(byte[] buffer, int nBytes)
          Validates the sampled data by summing nBytes-2 bytes modulo 0x10000 and comparing this with the last two bytes of the packet.
 
Methods inherited from class org.mbari.siam.core.PolledInstrumentService
acquire, doScheduledTask, setAttributes
 
Methods inherited from class org.mbari.siam.core.BaseInstrumentService
acquireSample, addDefaultPacketFilters, addSchedule, addSchedule, annotate, assertSamplingState, cacheProperties, callDataListeners, canSummarize, checkInputProperties, cleanupServiceState, clearDefaultPacketFilters, clearPropertiesCache, createPacketLog, createTask, createTurbinators, disableSummary, enableSummary, endDeviceAccess, getAllSchedules, getChildren, getCommunicationPowerPolicy, getCurrentLimit, getDefaultPacketFilters, getDefaultSampleSchedule, getDefaultSampleScheduleName, getFileBytes, getInstrumentPowerPolicy, getInstrumentServiceBlock, getInstrumentStartDelay, getLastSample, getMaxSampleBytes, getMaxSampleTries, getMetadata, getMetadata, getMetadataPayload, getPackets, getPackets, getParent, getPortDiagnostics, getPortDiagnosticsSummary, getPromptString, getProperties, getProperty, getSampleBuf, getSampleSchedule, getSampleTerminator, getSampleTimeout, getSchedule, getScheduleKey, getSchedules, getServicePropertiesBytes, initialize, initializeDriverDefaults, initializePooledResources, interruptDeviceAccess, logPacket, managePowerSleep, managePowerWake, nPowerRequests, postSample, powerOff, powerOffCallback, powerOn, prepareToRun, prepareToSample, processSample, removeAllSchedules, removeSchedule, resetPortDiagnostics, resume, resumeSchedule, running, setClock, setCommunicationPowerPolicy, setCurrentLimit, setDefaultSampleScheduleName, setInstrumentPowerPolicy, setInstrumentServiceBlock, setInstrumentStartDelay, setMaxSampleBytes, setMaxSampleTries, setPromptString, setProperty, setRecordType, setSampleTerminator, setSampleTimeout, shutdown, sleepingUntil, snooze, startDeviceAccess, summaryEnabled, suspend, suspendSchedule, sync, syncSchedule
 
Methods inherited from class org.mbari.siam.core.DeviceService
addDataListener, advertiseService, createRegistryEntry, getAttributes, getCommPortName, getFrameworkVersion, getId, getInstrumentPort, getLocation, getName, getRemoteSerialPort, getRemoteSerialPort, getSamplingCount, getSamplingErrorCount, getSamplingRetryCount, getStatus, host, incRetryCount, initializePropertyDefaults, registryEntry, registryName, removeDataListener, setInstrumentPort, setNodeProperties, setParent, setSerialPort, setStatusError, setStatusInitial, setStatusOk, setStatusSafe, setStatusSampling, setStatusShutdown, setStatusSuspend
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mbari.siam.distributed.Instrument
acquireSample, addDefaultPacketFilters, annotate, cacheProperties, clearDefaultPacketFilters, clearPropertiesCache, disableSummary, enableSummary, getDefaultPacketFilters, getLastSample, getPackets, getPackets, getPortDiagnostics, getPortDiagnosticsSummary, getProperties, getProperty, getSampleSchedule, getSchedules, resetPortDiagnostics, setClock, setProperty, summaryEnabled
 
Methods inherited from interface org.mbari.siam.distributed.Device
getChildren, getCommPortName, getFrameworkVersion, getId, getLocation, getMetadata, getName, getParent, getSamplingCount, getSamplingErrorCount, getSamplingRetryCount, getStatus, host, powerOff, powerOn, prepareToRun, resume, shutdown, suspend
 
Methods inherited from interface org.mbari.siam.distributed.DeviceServiceIF
getName
 
Methods inherited from interface org.mbari.siam.core.ScheduleOwner
addSchedule, getAllSchedules, getScheduleKey, removeAllSchedules, removeSchedule, resumeSchedule, sleepingUntil, suspendSchedule, syncSchedule
 

Field Detail

_attributes

public WorkhorseADCP.Attributes _attributes

_ensembleIntervalSec

protected int _ensembleIntervalSec

_initialInterval

protected long _initialInterval

devicePacketParser

protected org.mbari.siam.devices.workhorse.WorkhorseADCP.DevicePacketParser devicePacketParser

_safed

protected boolean _safed

_pd0Struct

protected WorkhorseADCP.PD0DataStructure _pd0Struct
Constructor Detail

WorkhorseADCP

public WorkhorseADCP()
              throws java.rmi.RemoteException
Allocates a new WorkhorseADCP

Throws:
java.rmi.RemoteException - .
Method Detail

initInstrumentStartDelay

protected int initInstrumentStartDelay()
Specify startup delay (millisec)

Specified by:
initInstrumentStartDelay in class BaseInstrumentService

initPromptString

protected byte[] initPromptString()
Specify prompt string.

Specified by:
initPromptString in class BaseInstrumentService

initSampleTerminator

protected byte[] initSampleTerminator()
Specify sample terminator.

Specified by:
initSampleTerminator in class BaseInstrumentService

initMaxSampleBytes

protected int initMaxSampleBytes()
Specify maximum bytes in raw sample.

Specified by:
initMaxSampleBytes in class BaseInstrumentService

initCurrentLimit

protected int initCurrentLimit()
Specify current limit in increments of 120 mA upto 11880 mA.

Specified by:
initCurrentLimit in class BaseInstrumentService

initInstrumentPowerPolicy

protected PowerPolicy initInstrumentPowerPolicy()
Return initial value of instrument power policy.

Specified by:
initInstrumentPowerPolicy in class BaseInstrumentService

initCommunicationPowerPolicy

protected PowerPolicy initCommunicationPowerPolicy()
Return initial value of communication power policy.

Specified by:
initCommunicationPowerPolicy in class BaseInstrumentService

createDefaultSampleSchedule

protected ScheduleSpecifier createDefaultSampleSchedule()
                                                 throws ScheduleParseException
Return specifier for initial sampling schedule.

Specified by:
createDefaultSampleSchedule in class PolledInstrumentService
Throws:
ScheduleParseException

getSerialPortParameters

public SerialPortParameters getSerialPortParameters()
                                             throws gnu.io.UnsupportedCommOperationException
Return parameters to use on serial port.

Overrides:
getSerialPortParameters in class DeviceService
Throws:
gnu.io.UnsupportedCommOperationException

initializeInstrument

protected void initializeInstrument()
                             throws InitializeException,
                                    java.lang.Exception
Called by the framework to initialize the instrument prior to sampling. Normally this method will use properties determined by the setProperties method.

Overrides:
initializeInstrument in class BaseInstrumentService
Throws:
InitializeException
java.lang.Exception

requestSample

protected void requestSample()
                      throws TimeoutException,
                             java.lang.Exception
This method should be called _preemptionSec seconds before the expected receipt of the sample. If a sample fails to be be detected for a period of 2 * _preemptionSec then a timeout exception will be called. If a sample is detected the method reschedules the service for _ensembleIntervalSec-_preemptionSec returning control to the framework to continue reading the sample in the normal way.

Specified by:
requestSample in class PolledInstrumentService
Throws:
TimeoutException - thrown if no data is detected for a period of twice the preemptionSec
java.lang.Exception - not thrown

readSample

protected int readSample(byte[] sample)
                  throws TimeoutException,
                         java.io.IOException,
                         java.lang.Exception
Called by the framework to fetch the sample data returned from the instrument and copy to sample buffer. The packet is examined to retrieve the length from the header. This is used to determine how many further bytes to read.

Overrides:
readSample in class BaseInstrumentService
Parameters:
sample -
Returns:
sample size (bytes)
Throws:
TimeoutException - sample time exceeded
java.io.IOException - error in input stream
java.lang.Exception - Bad header id (should really be in validateSample(..)) Packet exceeded packet length indicator (should really be in validateSample(..))

readUntilDelay

protected int readUntilDelay(java.io.InputStream instream,
                             byte[] outbuf,
                             long timeout)
                      throws TimeoutException,
                             java.io.IOException,
                             java.lang.Exception
Read characters from input stream into buffer and returns the number of bytes read.

Parameters:
instream - stream to read from
outbuf - buffer to place read data into
timeout - the time it takes to determine if a short packet has been sent
Returns:
bytes read
Throws:
TimeoutException - short packet sent
java.io.IOException
java.lang.Exception - Bad header id (should really be in validateSample(..)) Packet exceeded packet length indicator (should really be in validateSample(..))

validateSample

protected void validateSample(byte[] buffer,
                              int nBytes)
                       throws InvalidDataException
Validates the sampled data by summing nBytes-2 bytes modulo 0x10000 and comparing this with the last two bytes of the packet.

Overrides:
validateSample in class BaseInstrumentService
Parameters:
buffer - sample data
nBytes - Length of sample data
Throws:
InvalidDataException - checksum failed

getParser

public PacketParser getParser()
                       throws NotSupportedException
Return a PacketParser.

Specified by:
getParser in interface Instrument
Overrides:
getParser in class BaseInstrumentService
Throws:
NotSupportedException

parseDataPacket

public java.lang.Object parseDataPacket(SensorDataPacket pkt)
                                 throws InvalidDataException
Parse the ADCP data into a Velocity object

Throws:
InvalidDataException

getInstrumentStateMetadata

protected byte[] getInstrumentStateMetadata()
Not implemented

Overrides:
getInstrumentStateMetadata in class BaseInstrumentService
Returns:
N/A

setClock

public void setClock(long t)
Not implemented. Samples are locally timestamped

Specified by:
setClock in interface Instrument
Overrides:
setClock in class BaseInstrumentService
Parameters:
t -

enterSafeMode

public void enterSafeMode()
                   throws java.lang.Exception
Enter mode for resource-restricted environment.

Specified by:
enterSafeMode in interface Safeable
Throws:
java.lang.Exception

getDevicePacketParser

public DevicePacketParser getDevicePacketParser()
                                         throws NotSupportedException
Description copied from class: BaseInstrumentService
Get instruments' DevicePacketParser, which returns JDDAC records. Not supported by default

Overrides:
getDevicePacketParser in class BaseInstrumentService
Throws:
NotSupportedException

sendRequest

protected java.lang.String sendRequest(java.lang.String request)
                                throws java.lang.Exception
Sends a request to the Workhorse for parametric data. The response is returned as a string.

sendRequest makes every attempt to communicate with the unit by a process of resetting, flushing input buffer and resending.

Parameters:
request - string
Returns:
Response returned by the Workhorse
Throws:
java.lang.Exception

sendCommand

protected void sendCommand(java.lang.String cmd)
                    throws java.lang.Exception
Method to send commands to the Workhorse. sendCommand makes every attempt to communicate with the unit by a process of resetting, flushing input buffer and resending.

Note: Trailing '\r' is automatically added to command string.

Parameters:
cmd - Command string to send
Throws:
java.lang.Exception - thrown if the method fails to send the command.

enterCommandMode

protected void enterCommandMode()
                         throws java.lang.Exception
sends a break to the Workhorse a waits for a prompt

Throws:
java.lang.Exception

exitCommandMode

protected void exitCommandMode()
                        throws java.io.IOException,
                               java.lang.Exception
restarts sampling and exits command mode

Throws:
java.io.IOException
java.lang.Exception

sendBreak

protected void sendBreak()
sends a break longer then 350mS required by the Workhorse


mkCmd

protected byte[] mkCmd(java.lang.String cmd)
Utility method to construct a message of the form: -

 

"cmd + \r"

and returns this as a byte array for transmission

Parameters:
cmd - basic command string to construct
Returns:
byte array of command

mkInt

protected int mkInt(byte loByte,
                    byte hiByte)
Cludge to create an int from 2 bytes (There is probably a better way of doing this but this works)

Parameters:
loByte - ls byte
hiByte - ms byte
Returns:
int value of hiByte:loByte

getProperty

protected java.lang.String getProperty(java.lang.String response)
                                throws InvalidPropertyException
Returns the property value from the Workhorse response

Parameters:
response - response string return from Workhorse
Returns:
string representing the property (rhs of ='s)
Throws:
InvalidPropertyException

parseProperty

protected java.lang.String[] parseProperty(java.lang.String response,
                                           java.lang.String delim,
                                           int fieldCount)
                                    throws InvalidPropertyException
splits the response into fields defined by the delim string and returns these in an array. fieldCount limits the number of fields generated.

Parameters:
response - string to parse
delim - field delimiter(s)
fieldCount - number of expected fields
Returns:
array of Strings of each field detected
Throws:
InvalidPropertyException - an illegal response string has been determined

printData

public void printData(byte[] buf)
Description copied from class: BaseInstrumentService
Print instrument data contained in input buffer. By default does nothing, and may be overridden.

Overrides:
printData in class BaseInstrumentService

test

public int test()
Description copied from interface: Device
Run device's self-test routine.

Specified by:
test in interface Device

powerOnCallback

protected void powerOnCallback()
                        throws java.lang.Exception
Called after power is applied; return when instrument is ready for use.

Overrides:
powerOnCallback in class BaseInstrumentService
Throws:
java.lang.Exception

shutdownInstrument

protected java.lang.String shutdownInstrument()
                                       throws java.lang.Exception
Shutdown instrument sampling.

Overrides:
shutdownInstrument in class BaseInstrumentService
Throws:
java.lang.Exception


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.