/****************************************************************************/
/* Copyright (c) 2000 MIT Sea Grant                                         */
/* MIT Sea Grant Proprietary Information. All rights reserved.              */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : PS8000.h                                                      */
/* Author   : Don Eickstedt                                                 */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 05/29/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _PS8000_H
#define _PS8000_H

#include <time.h>
#include <sys/kernel.h>
#include "SerialParameters.h"
#include "SerialDevice.h"
#include "LblLog.h"
#include "PS8000Log.h"
#include "LblIF.h"
#include "Task.h"
#include "LblDriverOutput.h"

//this is always fixed for the PS8000, so we'll just define it here
//
#define BAUD 9600
#define PARITY "NONE"
#define STOP_BITS 1
#define DATA_BITS 8

//timeout used for command confirmations (ms) - you can try changing it if you
//have problems, but the longest return time I've seen is about 250ms, most
//are in the 50-60 ms range
//
#define TIMEOUT 500

class PS8000 : public Task
{

public:
  
  friend class PS8000Log;

  PS8000(SerialParameters *serialParams);

  ~PS8000();
  
  // ping - pings the PS8000
  // returns: 0 on success, -1 on error
  // 
  int ping();

  // times - retrieves return times for the 10 channels on the PS8000
  //         times are then transmitted to the LBL server for processing
  // returns: 0 on success, -1 on error
  // 
  int times();

  //processes commands sent by LBL server
  virtual void processCommand(Command *command);

protected:

  // initialize - initializes the PS8000
  //            - master mode
  //            - high power
  //            - ping lockout -- in config file
  //            - emergency slave disabled
  int initialize(int num_beacon);

  // SharedData object to hold output; read by server
  LblDriverOutput *_output;

  //pointer to text log object
  LblLog *_textLog;

  //pointer to text log object
  PS8000Log *_log;

  //pointer to serial device object for PS8000
  SerialDevice *_ps8000;
  
  //time of PS8000 ping
  struct timespec p_time;

  //keeps track of which receive channel each beacon is on
  //this is LBL board-set dependent
  short _beacon_channel[7]; 

  //if true, print status messages to log
  Boolean verbose;

  //upper bound on channel timeout -- lower bound is 0.0 (s)
  double range_gate;

  //ps8000 will not start listening until afetr the ping lockout expires (s)
  double ping_lockout;

  //Pointer to the tof array.  It must be declared as a class variable to 
  //be logged. 

  LblIF::RTimes *_rt;

};
#endif 









