/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : SimulatedEchoSounder.h                                        */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
//////////////////////////////////////////////////////////////////////
//
// PURPOSE:  Simulate the Range Finder.  
// AUTHOR:   McEwen, Following O'Reilly's Template
// DATE:     99/12/8
//
//////////////////////////////////////////////////////////////////////
//
#ifndef _SimulatedEchoSounder_H
#define _SimulatedEchoSounder_H
#include "EchoSounderIF_SK.h"
#include "SimulatorIF.h"
#include "Attributes.h"
#include "AttributeParser.h"
#include "EchoSounderLog.h"
#include "TimeP.h"

class SimulatedEchoSounder : public EchoSounderIF_SK {

   friend class EchoSounderLog;

public:

  SimulatedEchoSounder();
  ~SimulatedEchoSounder();

protected:

  ///////////////////////////////////////////////////////////////////
  // Called when the simulator says new data is ready
//  void compute(TaskInterface *taskInterface, EventCode code);
  void compute(void);

  virtual void name(DeviceIF::Name name);
  virtual void serialNumber(DeviceIF::Name id);
  virtual DeviceIF::Status initialize();
  virtual DeviceIF::Status powerOn();
  virtual DeviceIF::Status powerOff();
  virtual DeviceIF::Status status();
  virtual DeviceIF::Status dataLoggingOn();
  virtual DeviceIF::Status dataLoggingOff();

  virtual void xzAngle(double *radians);
  virtual void maxRange(double *meters);
  virtual DeviceIF::Status moveHead(double trainCmd);
  virtual DeviceIF::Status range(Boolean *echoReceived, double *value, 
				 TimeIF::TimeSpec *sampleTime);
  virtual DeviceIF::Status get(EchoSounderIF::Data *data);
  virtual DeviceIF::Status enable();
  virtual DeviceIF::Status disable();

  virtual int spawnAuxTasks();

  virtual double getHeadAngle(void);
  virtual double getHeadAngle(short tindx);
  virtual DeviceIF::Status headAngleCmd(double trainCmd);
  virtual DeviceIF::Status scanSectorCmd(double sector);
  virtual Boolean isScanning(void);

  SimulatorIF *_simulator;
  //
  // Class variables:
  //

  // Mount angle of rangefinder      
  double _mountAngle;

  // Maximum measurable range
  long  _maxRange;
  double  _noReturnRange;
  long  _startGain;
  long  _absorption;
  double _absorpEng;
  long  _pulseLen;
  long  _minRange;
  long  _triggerCtrl;
  Boolean _profile;
  long  _delay;
  char  _serialStatus;
  double _trainRef;
  short  _train;
  double _sectorEng;
  unsigned char _sector;
  double _stepSizeEng;
  long   _stepSize;
  long _acousticFreqEng;
  long _acousticFreq;
  double _pingPeriod;
  long _pulseLenEng;
  long  _minRangeEng;

  short _ranges[EchoSounderIF::ScanArraySize];
  long  _times [EchoSounderIF::ScanArraySize];
  //TimeIF::TimeSpec  _times[EchoSounderIF::ScanArraySize];
  short _toffset;
  short _tindx;
  short _tindxMax;
  short _tindxMin;

  double _xzAngle;

  double zMax;

  short _range;

  double _los_B[3], _grazing;
  double _minGrazing;

  long bisectCnt[1];

  TimeIF::TimeSpec _sampleTime;

  timespec _epoch;

  int _k;

  Boolean _echoReceived;

  enum ScanDirection { Ascending, Descending };
  ScanDirection _scanDirection;


  //PSA916Log *_log;

  EchoSounderLog *_log;
  char _echoData[EchoSounderIF::EchoArraySize];

  long _askTime, _ansTime;

  Attributes _attributes;
};

#endif
