/****************************************************************************/
/* Copyright (c) 2008 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : CameraDriver.h                                                */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 05/01/2008                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/

#ifndef _Camera_H
#define _Camera_H
#include "SerialDeviceExt.h"
#include "PeriodicTask.h"
//#include "PolledSerialDriver.h"
#include "CameraIF.h"
#include "CameraLog.h"
#include "CameraOutput.h"
#include "NavigationIF.h"
#include "XPort.h"
#include "XPortGPIO.h"
#include "Bicam.h"

/**
   Benthic Imaging AUV Camera
*/
class Camera : public PeriodicTask {

  /** Camera driver logger */
  friend class CameraLog;

public:

	Camera(SerialDeviceExt *device, Boolean test=False, Boolean sim=False);
  ~Camera();

  ////////////////////////////////////////////////////////////////////
  // Initialize device. Returned DeviceIF::Status
  // will be propagated to subscribers in other tasks.
  void initialize();
 
  ////////////////////////////////////////////////////////////////////
  // Read a fixed-length record - use the default:
	void readData();

  ////////////////////////////////////////////////////////////////////
  // 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


protected:
  /** Serial Port (via terminal server) */
  SerialDeviceExt *_device;
  /** Camera driver log */
  CameraLog *_log;
  /** Camera output interface */
  CameraOutput *_output;
  /** Navigation interface */
  NavigationIF *_navigationIF;
  /** Current vehicle position */
  NavigationIF::Position _position;
  /** Current vehical attitude */
  NavigationIF::Attitude _attitude;
  /** XPort to use for camera control .
      @see XPort
  */
  XPort xport;
  /** BicamGPS manages NMEA GPS output to camera via XPort serial port. */
  BicamGPS camGPS;
  /** XPortGPIO manages camera trigger via XPort GPIO pins. */
  XPortGPIO camTrigger;
  /** XPortGPIO manages Camera Vicor 12V power supply disable via XPort GPIO pins. */
  XPortGPIO cameraDisable;
  /** XPortGPIO manages Strobe Vicor 12V power supply disable via XPort GPIO pins. */
  XPortGPIO strobeDisable;
  /** XPortGPIO manages laser disable via XPort GPIO pins. */
  XPortGPIO laserDisable;

  /** Strobe enable start delay */
  unsigned int _strobeEnableStartDelaySec;

private:
  /** number of photos to take. */
  long _nPhotos;
  /** number of photos taken. */
  long _photoCntr;
  /** sample periods to count */
  long _nSamplePeriods;
  /** sample period counter */
  long _samplePeriodCntr;
  /** distance between photos */
  double _distance;
  /** is first cycle */
  Boolean _first;
  /** unknown */
  double _dmg;
  /** unknown */
  double _dmgIncr;
  /** unknown */
  double _xLast;
  /** unknown */
  double _yLast;
  /** is running if TRUE*/
  Boolean _running;
  /** do test if TRUE */
  Boolean _test;
  /** Simulate if TRUE */
  Boolean _sim;

};

#endif
