/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _VEHICLECOMPONENT_H
#define _VEHICLECOMPONENT_H
static char VehicleComponent_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/VehicleComponent.h,v 1.8 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: VehicleComponent.h,v $
Revision 1.8  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.7  1998/05/18 20:18:38  oreilly
*** empty log message ***

Revision 1.6  1998/02/23 16:12:15  oreilly
*** empty log message ***

Revision 1.5  1997/10/03 09:34:28  oreilly
*** empty log message ***

 * Revision 1.4  97/09/10  08:53:55  08:53:55  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.3  97/05/06  16:32:43  16:32:43  oreilly (Thomas C. O'Reilly)
 * Added 3x5 micros
 * 
 * Revision 1.2  97/03/20  12:38:46  12:38:46  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.1  96/10/28  09:14:15  09:14:15  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/


#include "ErrorHandler.h"
#include "SList.h"


/*
CLASS 
VehicleComponent

DESCRIPTION
Base class for vehicle components, such as power buses, 
various micros, etc.

AUTHOR
Tom O'Reilly
*/
class VehicleComponent : public ErrorHandler
{
  public:
  
  ///////////////////////////////////////////////////////////////////
  // Concrete VehicleComponent types
  typedef enum 
  {
    UnknownType,
    VehicleBaseType, 
    BusType, 
    SwitchType,
    VicorSwitchType,
    MotorSwitchType,
    IsoIoSwitchType,
    SwitchStatusType,
    IbcType,
    DconType,
    MotorMicroType,
    SemiMotorMicroType,
    ThreeByFiveType,
    CameraMicroType,
    PanTiltMicroType,
    Sio32MicroType,
    TelemMicroType,
    PduMicroType,
    BellypackMicroType,
    CommRelaysType,
    ToolsledType
      
  } Type;

  static const char *const vehicleBaseMnem;
  static const char *const busMnem;
  static const char *const switchMnem;
  static const char *const vicorSwitchMnem;
  static const char *const motorSwitchMnem;
  static const char *const isoIoSwitchMnem;
  static const char *const switchStatusMnem;
  static const char *const ibcMnem;
  static const char *const dconMnem;
  static const char *const motorMicroMnem;
  static const char *const semiMotorMicroMnem;
  static const char *const cameraMicroMnem;
  static const char *const panTiltMicroMnem;
  static const char *const sio32MicroMnem;
  static const char *const telemMicroMnem;
  static const char *const pduMicroMnem;
  static const char *const commRelaysMnem;
  static const char *const toolsledMnem;
  
  VehicleComponent(const char *name);
  ~VehicleComponent();  

  const char *name()
  {
    return _name;
  }
  
  virtual Type type() = 0;

  virtual const char *className()
  {
    return "VehicleComponent";
  }
  
  void addChild(VehicleComponent *child);

  void print(int level = 0);
  void printChildren(int level = 0);
  MBool hasGrandChildren();
  
  ///////////////////////////////////////////////////////////////////
  // Is component itself a kind of switch? (As opposed to being a parent
  // of switches? 
  virtual MBool isSwitch()
  {
    return FALSE;
  }

  virtual MBool isMicro()
  {
    return FALSE;
  }
  
  void setParent(VehicleComponent *parent)
  {
    _parent = parent;
  }

  static Type mnemonicType(const char *mnemonic);
  SList<VehicleComponent *>childList;

  protected:
  char *_name;
  VehicleComponent *_parent;
};


/*
CLASS 
VehicleBase

DESCRIPTION
VehicleBase forms the root of the VehicleConfiguration containment tree

AUTHOR
Tom O'Reilly
*/
class VehicleBase : public VehicleComponent
{
  public:
  VehicleBase(const char *name);
  ~VehicleBase();

  virtual Type type()
  {
    return VehicleBaseType;
  }

  virtual const char *className()
  {
    return "VehicleBase";
  }
  
};


/*
CLASS 
Bus

DESCRIPTION
Power bus VehicleComponent

AUTHOR
Tom O'Reilly
*/
class Bus : public VehicleComponent
{
  public:
  Bus(const char *name);
  ~Bus();
  
  virtual Type type()
  {
    return BusType;
  }

  virtual const char *className()
  {
    return "Bus";
  }

};


class Switch: public VehicleComponent
{
  public:
  Switch(const char *name, const char *dmSwitchPrefix);
  ~Switch();

  virtual const char *className()
  {
    return "Switch";
  }

  const char *dmSwitchPrefix()
  {
    return _dmSwitchPrefix;
  }

  virtual MBool isSwitch()
  {
    return TRUE;
  }
  
  virtual Type type()
  {
    return SwitchType;
  }

  virtual MBool readOnly();
  
  protected:
  char *_dmSwitchPrefix;
};


class IsoIoSwitch : public Switch
{
  public:
  
  IsoIoSwitch(const char *name, const char *dmSwitchPrefix);
  ~IsoIoSwitch();
  
  virtual Type type()
  {
    return IsoIoSwitchType;
  }
  
  virtual const char *className()
  {
    return "IsoIoSwitch";
  }
  
};


class VicorSwitch : public Switch
{
  public:
  
  VicorSwitch(const char *name, const char *dmSwitchPrefix);
  ~VicorSwitch();
  
  virtual Type type()
  {
    return VicorSwitchType;
  }
  
  virtual const char *className()
  {
    return "VicorSwitch";
  }
  
};


class MotorSwitch : public Switch
{
  public:
  MotorSwitch(const char *name, const char *dmSwitchPrefix,
	      const char *dmEnablePrefix);

  ~MotorSwitch();  

  virtual Type type()
  {
    return MotorSwitchType;
  }

  const char *dmEnablePrefix()
  {
    return _dmEnablePrefix;
  }

  virtual const char *className()
  {
    return "MotorSwitch";
  }
  

  protected:
  char *_dmEnablePrefix;
};


class SwitchStatus : public Switch
{
  public:
  SwitchStatus(const char *name, const char *dmSwitchPrefix);
  ~SwitchStatus();  

  virtual Type type()
  {
    return SwitchStatusType;
  }

  virtual const char *className()
  {
    return "SwitchStatus";
  }

  virtual MBool readOnly();

};


class CommRelaysComponent : public VehicleComponent
{
  public:
  CommRelaysComponent(const char *name, const char *dmPrefix);
  ~CommRelaysComponent();
  
  virtual Type type()
  {
    return CommRelaysType;
  }
  
  virtual const char *className()
  {
    return "CommRelaysComponent";
  }

  const char *dmPrefix()
  {
    return _dmPrefix;
  }
  
  protected:
  const char *_dmPrefix;
  
};


class ToolsledComponent : public VehicleComponent
{
  public:
  ToolsledComponent(const char *typeMnem);
  ~ToolsledComponent();
  
  virtual Type type()
  {
    return ToolsledType;
  }
  
  virtual const char *className()
  {
    return "ToolsledComponent";
  }

  static const char *const protoBenthicMnem;
  static const char *const benthicMnem;
  static const char *const midwaterMnem;
  static const char *const geologyMnem;
  static const char *const drillSledMnem;

  enum SledType
  {
    ProtoBenthic, Benthic, Midwater, Geology, DrillSled, Unknown
  };
  
  SledType sledType();
  
  // Print valid types
  static const char *validTypes();
  
  static const char *typeMnem(SledType type);

  static SledType mnemType(const char *mnem);
  
  protected:

  SledType _sledType;
  
};
 
#endif


