#ifndef _DEVICEINTERFACE_H
#define _DEVICEINTERFACE_H

#include "ErrorHandler.h"
#include "DataManager.h"

#ifdef UNIX
# include "VxStubs.h"
#else
# include <mbari/types.h>
  extern "C" 
  {
#   include "vxWorks.h"
#   include "msgQLib.h"
#   include "semLib.h"
#   include "logLib.h"
#   include "taskLib.h"
#   include "lstLib.h"
#   include "datamgr.h"
#   include "sio32.h"
#   include "sio32Server.h"
#   include "sio32Client.h"
#   include "microCmd.h"
#   include "microcmd.h"
#   include "applic.h"
#   include "powerTypes.h"
#   include "microTask.h"
  };

#endif

/*
CLASS 
DeviceInterface

DESCRIPTION
DeviceInterface is the interface to device drivers.

AUTHOR
Tom O'Reilly
*/

class DeviceInterface : public ErrorHandler
{
  public:

  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] name: Name of interface
  // [input] channelNo: Serial channel number
  // [input] dmPowerName: DM Item name of micro power switch
  DeviceInterface(const char *name,
		  Nat16 channelNo,
		  const char *dmPowerName = NULL);
  
  ~DeviceInterface();
  
  ///////////////////////////////////////////////////////////////////
  // LinkState
  enum LinkState
  {
    LinkDown = LINK_DOWN, LinkUp = LINK_UP
  };

  ///////////////////////////////////////////////////////////////////
  // Read SRQ packet from device. Output buffer has bytes in 
  // device-native endian-ness.
  // [output] packet: Destination for SRQ data
  // [input] maxBytes: Capacity of packet
  // [input] timeout: Timeout in clock ticks
  virtual int readSRQ(Byte *packet,       // o: buffer to hold packet
		      Int16 maxBytes,     // i: bytes in packet buffer
		      Int32 timeout       // i: timeout
		      ) = 0;
  
  ///////////////////////////////////////////////////////////////////
  // Return word from buffer read from device, perform any necessary 
  // byte-swapping
  // [input] packet: Buffer from which word is read
  // [input] index: Index within packet array to read
  virtual Word getWord(Void *packet, Int32 index) = 0;
  
  ///////////////////////////////////////////////////////////////////
  // Send enable command to device
  virtual STATUS enable() = 0;
  
  ///////////////////////////////////////////////////////////////////
  // Send reset command to micro
  virtual STATUS reset() = 0;

  ///////////////////////////////////////////////////////////////////
  // Return serial channel number
  Nat16 channelNo();

  ///////////////////////////////////////////////////////////////////
  // Return SIO-32 channel data
  const sio32Chan *sio32Channel();
  
  ///////////////////////////////////////////////////////////////////
  // Read id string from device
  // [output] string: Destination for id string
  virtual STATUS id(Char *string) = 0; 

  ///////////////////////////////////////////////////////////////////
  // Return serial number from device
  // [output] string: Destination for serialNo string
  virtual STATUS serialNo(Char *string) = 0;
  
  ///////////////////////////////////////////////////////////////////
  // Return software rev from device
  // [output] string: Destination for softwareRev string
  virtual STATUS softwareRev(Char *string) = 0;

  ///////////////////////////////////////////////////////////////////
  // Return RAM test status from device
  // [output] passed: Status of RAM test
  virtual STATUS ramTest(MBool *passed) = 0;
  
  ///////////////////////////////////////////////////////////////////
  // Return status of device power switch
  switchStatus powerSwitchStatus();
  
  ///////////////////////////////////////////////////////////////////
  // Power switch status DmObject
  DmEnumObject *dmPowerSwitchStatus;

  protected:

  Nat16 _channelNo;
  char *_chanName;
};



#endif
