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


/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include <stdio.h>
#include <mem.h>
#include <string.h>
#include <dos.h>
#include <STDLIB.H>

#include "..\LibUrne\LibUrne.h"
#include "..\comp\TypePc\TYPEPC.h"

/*JITES*/
#include "..\comp\UrnCrd\CdrdVJit.h"
#include "..\comp\UrnCrd\CdrdUJit.h"
#include "..\comp\battery\Batjites.h"
#include "..\comp\lcd\lcdjtUr.h"
#include "..\comp\urneled\ledjites.h"
#include "..\comp\keyboard\keyjites.h"
#include "..\comp\urneled\SrLedJIt.h"

/*DIGIVOTE*/
#include "..\comp\UrnCrd\CdRdudig.h"
#include "..\comp\battery\BatDigiv.h"
#include "..\comp\lcd\lcdDigUr.h"
#include "..\comp\urneled\LedDigiv.h"
#include "..\comp\keyboard\keydigiv.h"
#include "..\comp\urneled\SRLEDDIG.H"

#include "..\comp\timer\Timer.h"
#include "..\comp\File\CFile.h"

/**************************************************************************
LOCAL VARIABLES
Always start with « static »-keyword
**************************************************************************/
static CCardReaderUrneManager* gpcValidator = NULL;
static CCardReaderUrneManager* gpcUrne = NULL;
uchar gucPortValidator = 1;
uchar gucPortUrne = 2;
COM gPortValidator;

static CTimer* gpcTimer1 = NULL;
static CTimer* gpcTimer2 = NULL;

/**************************************************************************
FUNCTION PROTOTYPE
**************************************************************************/
CCardReaderUrneManager* GetCardReader(uchar* pucPort);

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
CCardReaderUrneManager* GetCardReader(uchar* pucPort)
{
	CCardReaderUrneManager* pcTp;
	if(*pucPort == gucPortValidator) /*Port validator*/
	{
		pcTp = gpcValidator;
	}
	else /*Port Urne*/
	{
		pcTp = gpcUrne;
	}
	return pcTp;
}

/**************************************************************************
<FUNCTION>
	<NAME>InitLibrary</NAME>
	<TYPE>GLOBAL</TYPE>
	<DESCRIPTION>
		Initialize the class according to the type of PC
	</DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME>iTypePc</NAME>
			<TYPE>int</TYPE>
			<IO>IN</IO>
			<DESCRIPTION>
				Type of Pc
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE>int</TYPE>
		<DESCRIPTION>
			The value 0 returned if success
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int InitLibrary(int iTypePc)
{
	int iResult = 0;

	/*Create the global timer*/
	if(gpcTimer1 == NULL)
		gpcTimer1 = new CTimer();
	if(gpcTimer2 == NULL)
		gpcTimer2 = new CTimer();


	switch(iTypePc)
	{
		case CTypePc::eJiteUrneVer1:
		case CTypePc::eJiteUrneVer2:
			CLcdJitesUrne::Instance();
			CLedJites::Instance();
			CKeyboardJites::Instance();
			CBatteryJites::Instance();
			gpcValidator = CCardReaderValidatorJites::Instance();
			gpcUrne = CCardReaderUrneJites::Instance();
			gpcValidator->SetPointerCom(&gPortValidator);
			CSerialLedJites::Instance();
			break;
		case CTypePc::eDigivotUrne2:
		case CTypePc::eDigivotUrne1:
			CLcdDigivotUrne::Instance();
			CLedDigivote::Instance();
			CKeyboardDigivote::Instance();
			CBatteryDigivote::Instance();
			gpcValidator = CCardReaderValidatorDig::Instance();
			gpcValidator->SetType('1');
			gpcUrne = CCardReaderValidatorDig::Instance();
			gpcUrne->SetType('2');
			CSerialLedDigivote::Instance();
			break;
		case CTypePc::eDigivotMav1:
		case CTypePc::eDigivotMav2:
		case CTypePc::eJiteMavVer2:
		case CTypePc::eJiteMavVer1:
		default:
			iResult = ERROR_INSTANCE;
			break;
	}
	return iResult;
}

/**************************************************************************
<FUNCTION>
	<NAME>LoadDefinitionFile</NAME>
	<TYPE>GLOBAL</TYPE>
	<DESCRIPTION>
		Load the information of configuration being in a file.
		This information has summers safeguarded by another program.
	</DESCRIPTION>
	<RETURNS>
		<TYPE>s_PcType</TYPE>
		<DESCRIPTION>
			Turn over in a structure with the information detection by another program.
			If s_PcType.iStatus = 0 then success.
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
s_PcType LoadDefinitionFile(void)
{
    int iRep = 0;
	s_PcType sResult;
    CTypePc hPcType;

    CFile hFile("c:\\PcType.dat","r");
    iRep = hFile.Read((void*) &hPcType, sizeof(hPcType));
	if(iRep >= 0)
	{
		sResult.iPcType = (int)hPcType.GetPcType();
		sResult.iLigthPenType = (int)hPcType.GetLightPenType();
		sResult.iMgCardType = (int)hPcType.GetMagCardType();
		sResult.iStatus = 0;
	}
	else
	{
		sResult.iStatus = iRep;
	}
    return sResult;
}
/**************************************************************************
<FUNCTION>
	<NAME>FreeResource</NAME>
	<TYPE>GLOBAL</TYPE>
	<DESCRIPTION>
		Release all resources.
	</DESCRIPTION>
</FUNCTION>
**************************************************************************/
void FreeResource(void)
{
	CBattery::DestroyInst();
	CKeyboard::DestroyInst();
	//CLcd::DestroyInst();
	CLed::DestroyInst();
	delete gpcTimer1;
	delete gpcTimer2;
	gpcTimer1 = NULL;
	gpcTimer2 = NULL;
}

int LecteurInit(uchar *pucPort, s_Parameters* psParm)
{
	int iReturn;
	iReturn = GetCardReader(pucPort)->LecteurInit(psParm);

	if(GetCardReader(pucPort) == gpcValidator)
		CSerialLed::Inst()->SetPointerCom(gpcValidator->GetPointerCom());

	return iReturn;
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
/*Keyboard*/
int Getch(char cColor)
{
	int iReturn = ERROR_INSTANCE;
	if(CKeyboard::Inst() != NULL)
		iReturn = CKeyboard::Inst()->Getch(cColor);
	return iReturn;
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int Kbhit(char cColor,int iLoop)
{
	int iReturn = ERROR_INSTANCE;
	if(CKeyboard::Inst() != NULL)
		iReturn = CKeyboard::Inst()->Kbhit(cColor, iLoop);
	return iReturn;
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
/*Led*/
void Light_LED(char cLed)
{
	if(CLed::Inst() != NULL)
		CLed::Inst()->SetLED(cLed);
}
#pragma argsused
/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
/*Led valideuse*/
int Lecteur_Set_Led(uchar *psPort,int cColor)
{
	int iReturn = ERROR_INSTANCE;
	if(CSerialLed::Inst() != NULL)
		iReturn = CSerialLed::Inst()->SetLed(cColor);
	return iReturn;
}


/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
void Battery_Off(void)
{
	if(CBattery::Inst() != NULL)
		CBattery::Inst()->SetBattery(CBattery::eOff);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
void Battery_On(void)
{
	if(CBattery::Inst() != NULL)
		CBattery::Inst()->SetBattery(CBattery::eOn);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
char ReadBatteryState(void)
{
	char cReturn = ERROR_INSTANCE;
	if(CBattery::Inst() != NULL)
		cReturn = CBattery::Inst()->GetStateBattery();
	return cReturn;
}
/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurRead(uchar *pucPort)
{
	return GetCardReader(pucPort)->SendReadCommande(NULL);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurValide(uchar *pucPort, char* pzString)
{
	return GetCardReader(pucPort)->ReadCommande(pzString);
}
/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurEnregistre(uchar *pucPort, char* pzString)
{
	return GetCardReader(pucPort)->ReadCommande(pzString);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurWrite(uchar *psPort, char* pzString)
{
	return GetCardReader(psPort)->SendWriteCommande(pzString);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurStatusWrite(uchar *pucPort, char* pzString)
{
	return GetCardReader(pucPort)->WriteCommande(pzString);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurEject(uchar *psPort, uchar ucDirection)
{
	return GetCardReader(psPort)->SendEjectCommande(ucDirection);
}
/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurStatusEject(uchar *pucPort, char* pzString){
	return GetCardReader(pucPort)->EjectCommande(pzString);
}
/**************************** PMD *********************************************/
int Lecteur_CardPosition(uchar *psPort)
{
	return GetCardReader(psPort)->CardPosition();
}
/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurGetPosition(uchar *psPort)
{
	return GetCardReader(psPort)->SendStatusCommande();
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurVide(uchar *psPort, char* pzString)
{
	return GetCardReader(psPort)->StatusCommande(pzString);
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurDeblock(uchar *psPort)
{
	return GetCardReader(psPort)->SendDeblock();
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurStatusDeblock(uchar *psPort, char* pzString)
{
	return GetCardReader(psPort)->Deblock(pzString);
}


/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurPutTempo(uchar *pucPort, char* pzString)
{
	int iReturn = ERROR_INSTANCE;
	if(*pucPort == gucPortValidator) /*Port validator*/
	{
		iReturn = gpcValidator->Tempo(pzString);
	}
	else /*Port Urne*/
	{
		iReturn = gpcUrne->Tempo(pzString);
	}
	return iReturn;
}

/**************************************************************************
<FUNCTION>
	<NAME></NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE></TYPE>
		<DESCRIPTION>
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
int LecteurStatusFeed(uchar *psPort)
{
	int iReturn = _LECTEUR_BUSY;

	if((iReturn = GetCardReader(psPort)->WaitCard()) == 0)
	{
		iReturn = _LECTEUR_GOOD;
	}

	return iReturn;
}

int CloseConnection(uchar *pucPort)
{
	return GetCardReader(pucPort)->CloseConnection();
}

int CheckQueue(uchar *pucPort)
{
	 GetCardReader(pucPort)->CheckQueue();
	 return 0;
}

int GetVersionCommande(uchar *pucPort, char* pzLectBuffer)
{
	return GetCardReader(pucPort)->GetVersionCommande(pzLectBuffer);
}


int GetProtocol(uchar *pucPort, char* pzLectBuffer)
{
	return GetCardReader(pucPort)->GetProtocol(pzLectBuffer);
}
void Lcd_Affiche(int Ligne, int Colonne, char *Chaine)
{
	CLcd::Inst()->Display(Ligne, Colonne, Chaine);
}

void Lcd_Init(void)
{
	CLcd::Inst()->Initialise();
}

/**************************************************************************
<FUNCTION>
	<NAME>GetTimer</NAME>
	<TYPE>GLOBAL</TYPE>
	<DESCRIPTION>Current value of timer</DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME>ucTime</NAME>
			<TYPE>uchar</TYPE>
			<IO>IN</IO>
			<DESCRIPTION>
				id of timer.
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE>unsigned long</TYPE>
		<DESCRIPTION>
			return the current value
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
ulong GetTimer(uchar ucTimer)
{
	if(ucTimer == 1)
		return gpcTimer1->GetTimer();
	else
		return gpcTimer2->GetTimer();
}

/**************************************************************************
<FUNCTION>
	<NAME>SetTimer</NAME>
	<TYPE>GLOBAL </TYPE>
	<DESCRIPTION>Set the current value into timer</DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME>ucTime</NAME>
			<TYPE>uchar</TYPE>
			<IO>IN</IO>
			<DESCRIPTION>
				id of timer.
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE>unsigned long</TYPE>
		<DESCRIPTION>
			return the current value
		</DESCRIPTION>
	</RETURNS>
</FUNCTION>
**************************************************************************/
ulong SetTimer(uchar ucTimer)
{
	if(ucTimer == 1)
		return gpcTimer1->SetTimer();
	else
		return gpcTimer2->SetTimer();
}

/*
	return 1 si >
*/
uchar TimerCompare(uchar ucTimer, ulong ulDelay)
{
	if(ucTimer == 1)
		return gpcTimer1->TimerCompare(ulDelay);
	else
		return gpcTimer2->TimerCompare(ulDelay);
}

ulong CurrentTime(void)
{
	return gpcTimer1->CurrentTime();
}