org.mbari.siam.devices.sunburst
Class SAMI

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.sunburst.SAMI
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ScheduleOwner, Device, DeviceServiceIF, Instrument

public class SAMI
extends PolledInstrumentService
implements Instrument

This SAMI class is the InstrumentServices driver for sampling the Sunburst SAMI CO2 sensor. This driver has limited ability to change the SAMI sampling parameters. At initialization, or when the system changes its sampling schedule or blank attribute, it will stop the SAMI and restart it with the new schedule and/or blank interval. In order to do so, it must wait until the next sample time (as defined by the default sampleSchedule), at which time it will issue ^C to stop it and then reprogram it. Note that this process can take up to one entire sampleSchedule interval, which can be up to 6 hours.

In all other cases, this SAMI driver simply listens passively for an instrument sample every sampleSchedule seconds. The instrument must be set up externally prior to deployment.

See Also:
BaseInstrumentService, PolledInstrumentService, Instrument, Serialized Form

Nested Class Summary
 class SAMI.SAMIAttributes
          Configurable SAMI attributes
 
Field Summary
 SAMI.SAMIAttributes _attributes
           
protected  java.util.Calendar _calendar
           
protected  byte[] _colon
           
protected  byte[] _comma
           
protected  boolean _firstInit
          TRUE if just finished initializing instrument
protected  boolean _inBlank
          indicates we're currently running a blank sample
protected  byte[] _lineBuffer
          Line buffer for operations
protected  byte[] _newline
           
protected  long _nextInterval
          Seconds to next sample
protected  byte[] _pound
           
protected  boolean _reinit
          boolean to reinitialize the device
protected  int _sampleIntervalSec
          Sample interval seconds derived from default sample schedule
protected  java.text.DateFormat _timeFormatter
           
 
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
SAMI()
          Allocates a new SAMI
 
Method Summary
 int addSchedule(java.lang.String name, java.lang.String schedule, boolean overwrite)
          We override addschedule so we know when to reinitialize the device for the new schedule.
protected  ScheduleSpecifier createDefaultSampleSchedule()
          Return specifier for initial sampling schedule.
protected  void enterCommandMode()
          Sends a ^C to the SAMI and wait for a prompt
 PacketParser getParser()
          Return a PacketParser.
 SerialPortParameters getSerialPortParameters()
          Return parameters to use on serial port.
protected  int getSetSampleInterval()
          Get sample interval closest to that supported by device.
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  SensorDataPacket processSample(byte[] sample, int nBytes)
          Process raw sample bytes, return TimeStampedData object.
protected  int readSample(byte[] sample)
          Read raw sample bytes from serial port into buffer, return number of bytes read.
protected  int readUntilDelayOrNewline(java.io.InputStream instream, byte[] buffer, long timeout)
          Internal method to read one line from instrument
protected  void reinitializeInstrument()
          Called from within requestSample() whenever the system has updated a schedule or attribute that causes the need to reinitialize the instrument
protected  void requestSample()
          This method should be called guardSec seconds before the expected receipt of the sample.
protected  java.lang.String shutdownInstrument()
          Shutdown instrument sampling.
 int test()
          Run device's self-test routine.
protected  boolean waitForSample(long waitSeconds)
          Local protected method to wait for first character of sample
protected  void writeDebug(int val, java.lang.String field, java.lang.String prompt)
           
protected  void writeDeviceInteger(int val)
          Convert integer to ASCII, send it to instrument followed by carriage return.
 
Methods inherited from class org.mbari.siam.core.PolledInstrumentService
acquire, doScheduledTask, setAttributes
 
Methods inherited from class org.mbari.siam.core.BaseInstrumentService
acquireSample, addDefaultPacketFilters, addSchedule, annotate, assertSamplingState, cacheProperties, callDataListeners, canSummarize, checkInputProperties, cleanupServiceState, clearDefaultPacketFilters, clearPropertiesCache, createPacketLog, createTask, createTurbinators, disableSummary, enableSummary, endDeviceAccess, getAllSchedules, getChildren, getCommunicationPowerPolicy, getCurrentLimit, getDefaultPacketFilters, getDefaultSampleSchedule, getDefaultSampleScheduleName, getDevicePacketParser, getFileBytes, getInstrumentPowerPolicy, getInstrumentServiceBlock, getInstrumentStartDelay, getInstrumentStateMetadata, 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, powerOnCallback, prepareToRun, prepareToSample, printData, removeAllSchedules, removeSchedule, resetPortDiagnostics, resume, resumeSchedule, running, setClock, setClock, setCommunicationPowerPolicy, setCurrentLimit, setDefaultSampleScheduleName, setInstrumentPowerPolicy, setInstrumentServiceBlock, setInstrumentStartDelay, setMaxSampleBytes, setMaxSampleTries, setPromptString, setProperty, setRecordType, setSampleTerminator, setSampleTimeout, shutdown, sleepingUntil, snooze, startDeviceAccess, summaryEnabled, suspend, suspendSchedule, sync, syncSchedule, validateSample
 
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, 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
getAllSchedules, getScheduleKey, removeAllSchedules, removeSchedule, resumeSchedule, sleepingUntil, suspendSchedule, syncSchedule
 

Field Detail

_attributes

public SAMI.SAMIAttributes _attributes

_sampleIntervalSec

protected int _sampleIntervalSec
Sample interval seconds derived from default sample schedule


_reinit

protected boolean _reinit
boolean to reinitialize the device


_firstInit

protected boolean _firstInit
TRUE if just finished initializing instrument


_inBlank

protected boolean _inBlank
indicates we're currently running a blank sample


_nextInterval

protected long _nextInterval
Seconds to next sample


_lineBuffer

protected byte[] _lineBuffer
Line buffer for operations


_comma

protected byte[] _comma

_pound

protected byte[] _pound

_colon

protected byte[] _colon

_newline

protected byte[] _newline

_timeFormatter

protected java.text.DateFormat _timeFormatter

_calendar

protected java.util.Calendar _calendar
Constructor Detail

SAMI

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

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 java.io.IOException,
                             TimeoutException,
                             java.lang.InterruptedException,
                             InvalidDataException,
                             InitializeException
This method should be called guardSec seconds before the expected receipt of the sample. If 2*guardSec expires with no sample, method will wait _sampleIntervalSec, and, if a character is available, will sync() the driver. If no character is still available, it will throw a TimeoutException

Specified by:
requestSample in class PolledInstrumentService
Throws:
java.io.IOException
TimeoutException
java.lang.InterruptedException
InvalidDataException
InitializeException

readSample

protected int readSample(byte[] sample)
                  throws TimeoutException,
                         java.io.IOException,
                         java.lang.Exception
Read raw sample bytes from serial port into buffer, return number of bytes read. Reads characters from serial port until sample terminator string is encountered.

Overrides:
readSample in class BaseInstrumentService
Parameters:
sample - output buffer
Throws:
TimeoutException
java.io.IOException
java.lang.Exception

processSample

protected SensorDataPacket processSample(byte[] sample,
                                         int nBytes)
                                  throws java.lang.Exception
Process raw sample bytes, return TimeStampedData object. By default, raw sample is encapsulated in TimeStampedData object, and no additional processing is done.

Overrides:
processSample in class BaseInstrumentService
Parameters:
sample - raw sample
nBytes - number of bytes in raw sample
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

addSchedule

public int addSchedule(java.lang.String name,
                       java.lang.String schedule,
                       boolean overwrite)
We override addschedule so we know when to reinitialize the device for the new schedule.

Specified by:
addSchedule in interface ScheduleOwner
Overrides:
addSchedule in class BaseInstrumentService
Parameters:
name - Schedule name
schedule - Representation of schedule
overwrite - If true, replace existing schedule
Returns:
Scheduler.UNDEFINED, Scheduler.INVALID_SCHEDULE

getParser

public PacketParser getParser()
                       throws NotSupportedException
Return a PacketParser.

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

waitForSample

protected boolean waitForSample(long waitSeconds)
                         throws java.io.IOException,
                                java.lang.InterruptedException
Local protected method to wait for first character of sample

Returns:
true if sample character available, else false
Throws:
java.lang.InterruptedException - if Device status changes from Device.SAMPLING
java.io.IOException

enterCommandMode

protected void enterCommandMode()
                         throws java.io.IOException,
                                TimeoutException
Sends a ^C to the SAMI and wait for a prompt

Throws:
java.io.IOException
TimeoutException

getSetSampleInterval

protected int getSetSampleInterval()
                            throws InitializeException
Get sample interval closest to that supported by device. Change default sample schedule if it doesn't agree with supported interval. Return new interval.

Throws:
InitializeException

readUntilDelayOrNewline

protected int readUntilDelayOrNewline(java.io.InputStream instream,
                                      byte[] buffer,
                                      long timeout)
                               throws java.io.IOException,
                                      TimeoutException
Internal method to read one line from instrument

Throws:
java.io.IOException
TimeoutException

writeDeviceInteger

protected void writeDeviceInteger(int val)
                           throws java.io.IOException
Convert integer to ASCII, send it to instrument followed by carriage return. Then flush instrument stream

Throws:
java.io.IOException

writeDebug

protected void writeDebug(int val,
                          java.lang.String field,
                          java.lang.String prompt)

reinitializeInstrument

protected void reinitializeInstrument()
                               throws java.io.IOException,
                                      InitializeException,
                                      TimeoutException,
                                      java.lang.InterruptedException
Called from within requestSample() whenever the system has updated a schedule or attribute that causes the need to reinitialize the instrument

Throws:
java.io.IOException
InitializeException
TimeoutException
java.lang.InterruptedException

test

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

Specified by:
test in interface Device


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.