/****************************************************************************/
/* Copyright (c) 2012 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : DeltaT.h                                                 */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 09/17/2012                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _DELTAT_H
#define _DELTAT_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "PeriodicTask.h"
#include "DeviceIF.h"
#include "DeltaTInput.h"
#include "DeltaTOutput.h"
#include "DeltaTLog.h"

#define DeltaTTaskName "deltaTdriver"

/*
CLASS 
DeltaT

DESCRIPTION
Imagenex DeltaT Device Driver Interface

AUTHOR
Henthorn

*/

class DeltaT : public Task {

  friend class DeltaTLog;

public:
  
  /////////////////////////////////////////////////////////
  // Constructor, not used...
  DeltaT(unsigned int port = 4040);

  /////////////////////////////////////////////////////////
  // overloaded Constructor
  //DeltaT();

  ///////////////////////////////////////////////////////
  //destructor
  virtual  ~DeltaT();

  //////////////////////////////////////////////////////////////// 
  // initialization function
  virtual DeviceIF::Status initialize();

  // Start logging
  //
  virtual void start();

  // Stop logging
  //
  virtual void stop();

  ////////////////////////////////////////////////////////////////////
  // run
  virtual void run();

protected:
  int _sockfd, _port;
  struct sockaddr_in _idtapp_addr;

  Boolean _enabled;
  Boolean _sendCmd;

  unsigned char _receive_buf[6553];
  DeltaTLog *_log;

  DeltaTInput  *_input;
  DeltaTOutput *_output;

  char _xcmd_buf[256];
  void setExternalControlSwitches();
  void sendExternalControlSwitches();

  void processData(int nbytes_in_record);

};

#endif
