//---------------------------------------------------------------------------
#ifndef nmccomH
#define nmccomH
//---------------------------------------------------------------------------
#endif

typedef unsigned char byte;

typedef struct _NMCMOD {
	_NMCMOD(){p=NULL;};
	byte	modtype;		//module type
    byte	modver;			//module version number
	byte	statusitems;	//definition of items to be returned
	byte	stat;  			//status byte
    byte	groupaddr;		//current group address
    BOOL	groupleader;	//TRUE if group leader
    void *	p;				//pointer to specific module's data structure
    } NMCMOD;

#define MAXSIOERROR 5

//Define PIC baud rate divisors
#define	PB19200		63
#define	PB57600		20
#define	PB115200	10

//Module type definitions:
#define	SERVOMODTYPE	0
#define	ADCMODTYPE		1
#define	IOMODTYPE		2
//The following must be created for each new module type:
//		data structure XXXMOD
//		Initializer function NewXXXMod
//		Status reading function GetXXXStat
//		NMCInit and SendNmcCmd must be modified to include calls
//			to the two functions above

#define CKSUM_ERROR		0x02	//Checksum error bit in status byte

//--------------------- ADC Module specific stuff --------------------------
typedef struct _ADCMOD {
    //******  Move all this data to the NMCMOD structure *******
	short int ad0;	//definition of items to be returned
	short int ad1;
	short int ad2;
	short int ad3;
	short int ad4;
	short int ad5;
    } ADCMOD;


#define MAXNUMMOD	33

//Function prototypes:
ADCMOD * AdcNewMod();
BOOL AdcGetStat(byte addr);

//Initialization and shutdown
int NmcInit(unsigned int port, unsigned int baudrate);

void InitVars(void);
BOOL NmcSendCmd(byte addr, byte cmd, char *datastr, byte n, byte stataddr);
void FixSioError(byte addr);
void NmcShutdown(void);

//Module type independant commands (supported by all module types)
BOOL NmcSetGroupAddr(byte addr, byte groupaddr, BOOL leader);
BOOL NmcDefineStatus(byte addr, byte statusitems);
BOOL NmcReadStatus(byte addr, byte statusitems);
BOOL NmcSynchOutput(byte groupaddr, byte leaderaddr);
BOOL NmcChangeBaud(byte groupaddr, unsigned int baudrate);
BOOL NmcSynchInput(byte groupaddr, byte leaderaddr);
BOOL NmcNoOp(byte addr);
BOOL NmcHardReset(byte addr);

//Retrieve module type independant data from a module's data structure
byte NmcGetStat(byte addr);
byte NmcGetStatItems(byte addr);
byte NmcGetModType(byte addr);
byte NmcGetModVer(byte addr);
byte NmcGetGroupAddr(byte addr);
BOOL NmcGroupLeader(byte addr);




