#ifndef _METHANESENSOR_H
#define _METHANESENSOR_H

#include "SerialDeviceDriver.h"
#include "DataLogWriter.h"
#include "IntegerData.h"
#include "ShortData.h"

#define MethaneLogName "methane"

/*
CLASS 
MethaneLog

DESCRIPTION
Logs methane sensor data through the DataLogWriter interface.

To use this class, instantiate an instance within a MethaneSensor object
and periodically invoke the write() method:

AUTHOR
Tom O'Reilly
*/
class MethaneLog : public DataLogWriter {

public:

  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] fileFormat: Specifies either DataLog::AsciiFormat or 
  //         DataLog::BinaryFormat.
  MethaneLog(DataLog::FileFormat fileFormat);

  ~MethaneLog();


  IntegerData channel1;
  IntegerData channel2;
  IntegerData channel3;

protected:

  ///////////////////////////////////////////////////////////////////
  // Set values in record array elements. This virtual method is called
  // by DataLogWriter::write()
  virtual void setFields();
};


/*
CLASS 
MethaneSensor

DESCRIPTION
Driver for Gernot's "METS" methane sensor

AUTHOR
Tom O'Reilly
*/
class MethaneSensor : public SerialDeviceDriver {

public:

  ////////////////////////////////////////////////////////////////////
  // Constructor
  // [input] serialDevice: Associated SerialDevice
  MethaneSensor(SerialDevice *serialDevice, Boolean verbose);
  virtual ~MethaneSensor();

  ////////////////////////////////////////////////////////////////////
  // Initialize device. Returned DeviceIF::Status 
  // will be propagated to subscribers in other tasks.
  virtual DeviceIF::Status initialize();

  ////////////////////////////////////////////////////////////////////
  // Request a data packet from the device.
  virtual DeviceIF::Status requestData();

  ////////////////////////////////////////////////////////////////////
  // Read a fixed-length record
  virtual DeviceIF::Status readRecord(unsigned char *record,
				      int maxRecordBytes,
				      const char *recordTerminator,
				      unsigned readTimeout,
				      int *nBytesRead);
  
  ////////////////////////////////////////////////////////////////////
  // Process device data record. Returned DeviceIF::Status
  // will be propagated to subscribers in other tasks.
  // [input] record: Record from device
  // [input] nRecordBytes: Bytes in record
  virtual DeviceIF::Status processRecord(unsigned char *record, 
					 int nRecordBytes);

protected:

  MethaneLog *_log;
  Boolean _verbose;
};

#endif
