#ifndef _VXSTUBS_H
#define _VXSTUBS_H

/* Stub definitions for UNIX version of VxWorks code */
#include <stdio.h>
#include <mbari/types.h>

#define SRQ_PACKET_LEN 256

extern "C" 
{
# include <dmUnix.h>
# include <semLib.h>
# include <datamgr.h>
# include <powerTypes.h>
# include <microDm.h>
};

#define COM_LINK_ERROR_DM           "COM_LINK_ERROR"
#define MICRO_ENABLE_TRYS       5


#ifdef ZILCH
typedef struct                      /* Data Manager Item Table for table    */
{                                   /* driven item initialization           */
    DM_Item *dmItem;                /* pointer to actual dm item handle     */
    char    *errorMsg;              /* Message to display of dmCreate fails */
    char    *name;                  /* Data Manager Item Name               */
    DM_Type type;                   /* Data Manager Item Type               */
    DM_Num  len;                    /* Data Manager Item Element Count      */
} dmItemList;

#endif

typedef enum
{
    LINK_DOWN,
    LINK_UP
} serialComState;

typedef enum
{
    IN_TASK,
    OUT_TASK,
    AUX_IN_TASK,
    SRQ_TASK
} microTaskId;

typedef struct
{
    SEM_ID  taskSyncSem;	    /* Task synchonization semaphore        */
    Int32   taskId;		    /* Child Task Ident from taskSpawn      */
} microChildTask;

typedef struct
{
  int dummy;
  
} sio32Chan;


typedef struct
{
    DM_Item        comErrorDm;	    /* Communications link status Item      */
    DM_Item        powerSwitchDm;   /* Device Power Switch Item             */
    SEM_ID	   powerSwitchSem;  /* Power switch wakeup semaphore        */

    sio32Chan      sio32DataChan;   /* Serial Communications Chan           */
    serialComState serialLinkState; /* Serial Communications Link Status    */
    Nat16          resetEventCount; /* Counts micro reset events            */
    MBool          announceResets;  /* Announce reset events if set TRUE    */ 
    MBool          microConfigured; /* Set after params are sent to micro   */

    Nat16	   numChildTasks;   /* Number of child tasks                */
    microChildTask *childTasks;     /* Child Task Synchronization           */
} microIOControl;


/* Function prototypes */

/* From microTask.h */
Void setSerialLinkState(microIOControl *microIOCtrl, serialComState linkState);
switchStatus microDevPowerSwitchState(microIOControl *microIOCtrl);

/* From microCmd.h */
STATUS sendMicroCommand( Reg sio32Chan *sio32Channel, Void *reply,
     Int32 replyLen, Int32 nWords, ... );

STATUS microCommand(Reg sio32Chan *sio32Channel, Word command, Word *value);

Void wordToBuf(Reg Char *buffer, Reg Word data);
Void wordsToBuf(Reg Char *buffer, Int32 nWords, ... );
Word wordFromBuf(Reg Void *buffer, Reg Int16 index);
Void wordsFromBuf(Void *buffer, Int32 nWords, ... );
STATUS microCmdStringReply( Reg sio32Chan *sio32Channel, Word command,
                 Byte *reply, Int16 replyLen );

STATUS microWriteBufReply(sio32Chan *sio32DataChan, Word blen, Byte *buffer);

STATUS microResetCmd( sio32Chan *sio32Channel );
STATUS microCmdEnable( sio32Chan *sio32Channel );
STATUS microGetIdent( sio32Chan *sio32Channel, Char *identString );
STATUS microSerialNo( sio32Chan *sio32Channel, Char *serialNo );
STATUS microSetSerialNo( sio32Chan *sio32Channel, Char *serialNo );
STATUS microSoftwareRev( sio32Chan *sio32Channel, Char *softwareRev );
STATUS microGetRamTest( sio32Chan *sio32Channel, MBool *ramTestStatus );
STATUS microGetWaterAlarm( sio32Chan *sio32Channel, Word *waterAlarmStatus );
STATUS microGetPacketRxTimeout( sio32Chan *sio32DataChan, Nat16 *rxTimeout );
STATUS motorSetPacketRxTimeout( Reg sio32Chan *sio32DataChan, Nat16 rxTimeout);
STATUS microPing( sio32Chan *sio32Channel, Word txSeqNo, Word *rxSeqNo );
STATUS microSetGndFltTestState(sio32Chan *sio32Channel, MBool gfTestState);

/* From sio32Client.h */
STATUS sio32ChanInit(Nat16 serialChannel, char *sio32DevName,
		     sio32Chan *sio32DataChan);

STATUS sio32ChanDestroy(Nat16 channel, sio32Chan *sio32DataChan);


/* From microDm.h */
STATUS  initMicroDmItemList(dmItemList *dmItems, const char *prefix,
                         const char * taskName );

DM_Item initMicroDmItem( const char *dmPrefix, char *itemName,
                         DM_Type itemType, DM_Num numElements );

STATUS writeDmItem(DM_Item dmItem, void *value, DM_Size itemSize);
STATUS urgentWriteDmItem(DM_Item dmItem, void *value, DM_Size itemSize);
STATUS writeBooleanDmItem(DM_Item dmItem, MBool status);
STATUS updateMicroIdentDm( sio32Chan *sio32DataChan, DM_Item microIdentDm );
STATUS updateSerialNoDm( sio32Chan *sio32DataChan, DM_Item serialNoDm );
STATUS writeMicroSerialNo( sio32Chan *sio32DataChan, DM_Item serialNoDm );
STATUS updateSoftwareRevDm( sio32Chan *sio32DataChan, DM_Item softwareRevDm );
STATUS microResetEventDm(DM_Item microResetDm);
STATUS updateMicroRamTestDm( sio32Chan *sio32DataChan, DM_Item microRamTestDm );

STATUS initMicroPacketRxTimeoutDm( sio32Chan *sio32DataChan,
                         DM_Item rxTimeoutDm );

STATUS setPacketRxTimeout( sio32Chan *sio32DataChan, DM_Item packetRxTimeoutDm);
STATUS microWriteGndFaultTest( sio32Chan *sio32DataChan, DM_Item gfTestDm);

void taskSafe();
void taskUnsafe();

/*
UNIX emulation of taskSpawn(). This function will actually do a fork(),
then try to exec a program specified by the "name" argument, passing
arg1-arg10 as command line arguments. The entryPt
argument is ignored; it's up to the application programmer to ensure that
the exec'ed program enters the correct function. */
int taskSpawn(char *name, 
	      int priority, 
	      int options, 
	      int stackSize, 
	      FUNCPTR entryPt,
	      int arg0, int arg1, int arg2, int arg3, int arg4, 
	      int arg5, int arg6, int arg7, int arg8, int arg9);

#endif
