/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : SimulatedDevice.h                                             */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _SIMULATEDDEVICE_H
#define _SIMULATEDDEVICE_H

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

#include "DeviceInterface.h"

/*
CLASS 
SimulatedDevice

DESCRIPTION
Subclass of DeviceInterface; provides interface between onboard vehicle
software and vehicle model running somewhere on the network.

AUTHOR
Tom O'Reilly

*/
class SimulatedDevice : public DeviceInterface {

public:

  SimulatedDevice(const char *name,
		  const char *simServerHostName,
		  int simServerPort);

  ~SimulatedDevice();

  ///////////////////////////////////////////////////////////////////
  // Read from device, return number of bytes read
  int read(char *buf, int maxBytes);

  ///////////////////////////////////////////////////////////////////
  // Write to device
  virtual int write(char *buf, int nBytes);

  ///////////////////////////////////////////////////////////////////
  // Reset device
  virtual void reset();

  ///////////////////////////////////////////////////////////////////
  // Name of simulation host
  const char *serverHost() {
    return _serverHost;
  }

  ///////////////////////////////////////////////////////////////////
  // Port number on simulation host
  int serverPort() {
    return _serverPort;
  }

protected:

  ///////////////////////////////////////////////////////////////////
  // Convert string as sent to/received from actual DeviceInterface to
  // simulation format string.
  virtual int actualToSimulated(const char *actual, const char *simulated) = 0;

  ///////////////////////////////////////////////////////////////////
  // Convert simulation string as sent to/received from simulator to
  // actual device format.
  virtual int simulatedToActual(const char *simulated, const char *actual) = 0;


private:

  struct hostent *_hostEnt;
  struct sockaddr_in _server;
  int _socket;
  Boolean _connected;
  const char *_serverHost;
  int _serverPort;
};

#endif

