/**************************************************************************
<MODULE NAME>
<FILENAME></FILENAME>
<HISTORY>
	<MODIFICATION>
		<DATE></DATE>
		<AUTHOR></AUTHOR>
		< DESCRIPTION>
		< /DESCRIPTION>
	</MODIFICATION>
</HISTORY>
</MODULE NAME>
**************************************************************************/

#ifndef __SERIAL_H__
#define __SERIAL_H__

/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include <bios.h>
#include "..\comp\system\system.h"

/**************************************************************************
<CLASS>
	<NAME>CSerial</NAME>
	<MOTHERS>
		<MOTHER></MOTHER>
	</MOTHERS>
	<DESCRIPTION>
		This class is the manager for serial port
	</DESCRIPTION>
</CLASS>
**************************************************************************/
class CSerial
{

public:
	/*Settings For RS232*/
	enum e_command
	{
		eComInit = 0, 		/*Set up the serial port as specified in the data argument (see below).*/
		eComSend = 1, 		/*Transmit the data character through the selected serial port*/
		eComReceive = 2, 	/*Accepts an input character through the selected serial port.*/
		eComStatus = 3 		/*Return the current status of the selected serial port.*/
	};
	enum e_BaudRate
	{
		eCom110  = 0,
		eCom150  = 32,
		eCom300  = 64,
		eCom600  = 96,
		eCom1200 = 128,
		eCom2400 = 160,
		eCom4800 = 192,
		eCom9600 = 224
	};
	
	enum e_DataWordLength
	{
		eComCHR7 = 2,
		eComCHR8 = 3
	};

	enum e_StopBits
	{
		eComStop1 = 0,
		eComStop2 =	4
	};


	enum e_ParityValue
	{
		eComNOPARITY = 0,
		eComODDPARITY = 8,
		eComEVENPARITY = 24
	};
	
	enum e_Status
	{
		eTimeOutError = 0x8000,
		eTsrEmpty = 0x4000,
		eThrEmpty = 0x2000,
		eBreakError = 0x1000,
		eFramingError = 0x0800,
		eParityError = 0x0400,
		eOverrunError = 0x0200,
		eDataReady = 0x0100,
		eDcd = 0x80,
		eRi = 0x40,
		eDsr = 0x20,
		eCts = 0x10,
		eDdcd = 0x08,
		eDri = 0x04,
		eDdsr = 0x02,
		eDcts = 0x01,
		eNoErrors = 0
	};

	enum sError
	{
		eNoDsr = -11,
		eNoCts = -12,
		eSerialComError = -13/*,
		eTimeOutError*/
	};

	// Constructor, destructor
	CSerial();
	~CSerial();

	// Method
	int Open( int iPort, int iSetting );
	int Close( void );

	unsigned long ReadDataWaitingETX( char *, int );
	int SendData( const char *, int );
	int ReadDataWaiting( void );
	unsigned int GetStatus(void);
	int WriteByte( unsigned char );
	int ReadByte(void);
 
	// inline
	int IsOpened( void ){ return( m_iOpened ); }

protected:
	// Method

	private:
	// attribute
	int m_iOpened; 
	int m_iPort;
	/* if m_iOpened = 1 then com port opended else if m_iOpened = 0 then closed */
};

#endif
