//--------------- COMM Class ---------------

#define _8N1 1
#define _7E1 2

#define COM1 1
#define COM2 2
#define COM3 3
#define COM4 4

#define MAX_IN_QUEUE 20
#define MAX_OUT_QUEUE 20
#define NUM_OPENERRORS 8
#define NUM_WRITEERRORS 14

#define BUFFER_SIZE 32000
#define SKIPDELAY 2000L

#define NOTYPE 0
#define RESEND 1
#define NOT_AVAIL 2
#define ACK 3

#define NOTSENT 0
#define NOACK 1
#define ACKED 2
#define NOTRECV 0
#define RECV 1

#define BOOL int
#define UINT unsigned int

typedef struct{
	int ErrorNumber;
	char *ErrorText;
	} COM_ERRORS;

class CComm
{

public:
	char mError[300];
	int mErrorNumber;
	BOOL mOpened;
	int mIDComDev;
	unsigned mTransmit, mReceive;

	int mPort;
	long mBaud;
	int mParameters;
	int mHeadIn, mTailIn;
	int mHeadOut, mTailOut;

	unsigned char *mBuffer;
	int mBufferPointer;

public:
	CComm( int Port, long Baud = 9600, int Parameters = _8N1, UINT Transmit = 2500, UINT Receive = 2500 );
	~CComm();

	void AssignOpenError( int );
	void AssignReadWriteError( int );

	int InitiateConnection( const char * );
	void FlushIncoming( void );

	int SendStr( void * );
	int SendBlock( void *, int );
	int GetBlock( void *, int );
	char GetCh( void );
	int GetLength( void );
};


//--------------- SV200 Class ---------------

#define SERVO1 1
#define SERVO2 2
#define SERVO3 3
#define SERVO4 4
#define SERVO5 5
#define SERVO6 6
#define SERVO7 7
#define SERVO8 8

#define NC -1

class SV200
{
private:
	CComm *comm;

	char numStr[10];
	int svSelect;
	int savePosition[8];

	void serlXmitStr(char *str);

public:
	SV200(int comPort = COM1, int baudRate = 9600);
	~SV200();

	void svCmmd(char *cmmd, int param);
	void svCmmd2(char *cmmd, int param1, int param2);
	void selectBoard(int board);
	void selectServo(int servo);
	void moveSelect(int position);
	void move(int servo, int position);
	void moveAll(int S1, int S2, int S3, int S4, int S5, int S6, int S7, int S8);
	int getNum(void);
	unsigned char getAD(int channel);
	int adjADJoystick(int position);
};
