#ifndef _VIRTUALSERIALPORT_H
#define _VIRTUALSERIALPORT_H

#include "ErrorHandler.h"
#include "SerialDevice.h"

extern "C" 
{
  # include "vspDm.h"
};

struct sio32Chan;

/*
CLASS 
VirtualSerialPort

DESCRIPTION
VirtualSerialPort allows serial communications applications to interface
with a channel on an IBC's serial card, using DataManager as the underlying
transport layer.

AUTHOR
Tom O'Reilly
*/
class VirtualSerialPort : public SerialDevice, ErrorHandler {
  public:

  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] systemName: e.g., "TIBURON"
  // [input] appName: e.g., "MWSLED"
  // [input] name: Name of VSP
  // [input] channel: Card channel number (0-3)
  // [input] sio32Channel: serial channel struct
  // [input] cardNo: Serial card number. Start at 0 and increment for each
  // card added.
  // [input] cardAddr: Card address
  VirtualSerialPort(const char *systemName,
		    const char *appName,
		    const char *deviceName,
		    Word channel,
		    sio32Chan *sio32Channel,
		    Int16 cardNo,
		    Word cardAddr
		    );

  ~VirtualSerialPort();

  ///////////////////////////////////////////////////////////////////
  // Initialize DM items and micro
  virtual STATUS handleResetEvent();
  
  ///////////////////////////////////////////////////////////////////
  // Add DM items to monitored group
  // [input] dmMonitor: DmMonitor which monitors component
  virtual STATUS startMonitoring(DmMonitor *dmMonitor);

  ///////////////////////////////////////////////////////////////////
  // Process changes to DM items
  virtual STATUS processDmChanges(DmGroup *dmGroup);

  ///////////////////////////////////////////////////////////////////
  // Start providers for sampling
  virtual STATUS startSampling();

  ///////////////////////////////////////////////////////////////////
  // Read micro and update DM items
  virtual STATUS sampleMicro();

  ///////////////////////////////////////////////////////////////////
  // Call after receiving SRQ
  virtual MBool handleSrq(Word requestCode, Byte *packet);

  ///////////////////////////////////////////////////////////////////
  // Call after receiving reset SRQ
  virtual STATUS handleResetSrq();
  
  ///////////////////////////////////////////////////////////////////
  // Associated DataManager items
  ibcVspDmItems vspDmItems;

 protected:


  Word _cardAddr;

  sio32Chan *_sio32Chan;
};


#endif

