
#include "..\comp\CardRead\StMchDig\StAnlDig.h"
#include "..\comp\CardRead\StMchDig\StCmdDig.h"
#include "..\comp\CardRead\StMchDig\StTmODig.h"
#include "..\comp\cardread\CdRdIDig.h"

CStateMachineDigCard* CStCancelDig::m_pcInstance = NULL;

/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
CStCancelDig::CStCancelDig()
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCancelDig::CStCancelDig");
#endif
}

/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
CStCancelDig::~CStCancelDig()
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCancelDig::~CStCancelDig");
#endif
}


/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
int CStCancelDig::ReceiveTimeOut(CCardReaderDig* pcParent)
{
	int iResult = 0;
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCancelDig::ReceiveTimeOut");
#endif

	if(pcParent->TimeOut() != ACK)
	{
		iResult = ChangeState(pcParent, CStTimOutDig::Instance());
		if(iResult >= 0)
			iResult = pcParent->GetState()->ReceiveTimeOut(pcParent);
	}
	else
	{
		if(iResult >= 0)
			iResult = pcParent->GetState()->WaitAck(pcParent);
	}
	return iResult;
}

/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
int CStCancelDig::WaitResponce(CCardReaderDig* pcParent)
{
	int iResult;
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCancelDig::WaitResponce");
#endif
	iResult = pcParent->WaitResponce();
	if(iResult >= 0)
	{
		iResult = ChangeState(pcParent, CStCommandDig::Instance());
	}
	return iResult;
}

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

/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
int CStCancelDig::WaitAck(CCardReaderDig* pcParent)
{
	int iResult = ERROR_NONE_AVAILABLE;

#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStCancelDig::WaitResponce");
#endif

	if(pcParent->SetRetries() == 0)
	{
		iResult = pcParent->SendDleEot();
		
		if(iResult >= 0)
			iResult = pcParent->WaitAck();

		if(iResult >= 0)
			iResult = ChangeState(pcParent, CStCommandDig::Instance());
		else
			iResult = pcParent->GetState()->WaitAck(pcParent);
	}
	else
	{
		pcParent->CloseConnection();
		iResult = pcParent->LecteurInit();
		if(iResult >= 0)
		{
			iResult = ChangeState(pcParent, CStCommandDig::Instance());
			iResult = ERROR_RETIES;
		}
	}
	return iResult;
}

/**************************************************************************
<METHOD>
	<CLASS>CStCancelDig</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>
**************************************************************************/
int CStCancelDig::ReceiveDleEot(CCardReaderDig* pcParent)
{	return ChangeState(pcParent, CStCommandDig::Instance());
}