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


/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include <stdio.h>
#include "..\comp\CardRead\StMchDig\StEnqDig.h"
#include "..\comp\CardRead\StMchDig\StCmdDig.h"
#include "..\comp\cardread\CdRdIDig.h"
/**************************************************************************
LOCAL VARIABLES
Always start with « static »-keyword
**************************************************************************/
CStateMachineDigCard* CStCommandDig::m_pcInstance = NULL;
/**************************************************************************
<METHOD>
	<CLASS>CStCommandDig</CLASS>
	<NAME>CStCommandDig</NAME>
	<TYPE > LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CStCommandDig::CStCommandDig()
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCommandDig::CStCommandDig");
#endif
	;
}


/**************************************************************************
<METHOD>
	<CLASS>CStCommandDig</CLASS>
	<NAME>~CStCommandDig</NAME>
	<TYPE> LOCAL | GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO>IN | OUT | INOUT</IO>
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CStCommandDig::~CStCommandDig()
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCommandDig::~CStCommandDig");
#endif
	;
}

/**************************************************************************
<METHOD>
	<CLASS>CStCommandDig</CLASS>
	<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>
</METHOD>
**************************************************************************/
CStateMachineDigCard* CStCommandDig::Instance(void)
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCommandDig::Instance");
#endif
	if(m_pcInstance == NULL)
		m_pcInstance = new CStCommandDig();
	return m_pcInstance;
}

/**************************************************************************
<METHOD>
	<CLASS>CStCommandDig</CLASS>
	<NAME>SendCommand</NAME>
	<TYPE >LOCAL</TYPE>
	<DESCRIPTION>
		envoie la command et si positif passe en attende du ACk.
		Change d'état: Attente du ack pour envvoyer le caractère ENQ
	</DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME>pcParent</NAME>
			<TYPE>CCardReaderDig</TYPE>
			<IO>IN</IO>
			<DESCRIPTION>
				pointeur sa la classe parent
			</DESCRIPTION>
		</PARAMETER>
		<PARAMETER>
			<NAME>szCommand</NAME>
			<TYPE>char*</TYPE>
			<IO>IN</IO>
			<DESCRIPTION>
				contient la commande à envoyer
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
	<RETURNS>
		<TYPE>int</TYPE>
		<DESCRIPTION>
			0 is retruned, if sucess
		</DESCRIPTION>
	</RETURNS>
</METHOD>
**************************************************************************/

int CStCommandDig::SendCommand(CCardReaderDig* pcParent, char* szCommand)
{
	int iResult = ERROR_NONE_AVAILABLE;
	
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCommandDig::SendCommand");
#endif

	iResult = pcParent->SendCommand(szCommand);
	
	if(iResult >= 0)
	{	
		iResult = ChangeState(pcParent, CStEnqDig::Instance());
		if(iResult >= 0)
		{
			iResult = pcParent->WaitAck();
		}
		ChangeState(pcParent, CStCommandDig::Instance());/*PMD*/
	}
	return iResult;
}
