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


/**************************************************************************
INCLUDE FILE
**************************************************************************/
#include "..\comp\CardRead\StMchDig\StRepDig.h"
#include "..\comp\CardRead\StMchDig\StTmODig.h"
#include "..\comp\CardRead\StMchDig\StCmdDig.h"
#include "..\comp\CardRead\StMchDig\StAnlDig.h"
#include "..\comp\cardread\CdRdIDig.h"

/**************************************************************************
LOCAL VARIABLES
Always start with « static »-keyword
**************************************************************************/
CStateMachineDigCard* CStResponceDig::m_pcInstance = NULL;

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

/**************************************************************************
<METHOD>
	<CLASS>CStResponceDig</CLASS>
	<NAME>CStResponceDig</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
int CStResponceDig::CancelCommand(CCardReaderDig* pcParent)
{
	int iResult;
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStResponceDig::CancelCommand");
#endif

	iResult = ChangeState(pcParent, CStCancelDig::Instance());
	if(iResult >= 0)
		iResult = pcParent->GetState()->WaitAck(pcParent);

	return iResult;
}

/**************************************************************************
<METHOD>
	<CLASS>CStResponceDig</CLASS>
	<NAME>CStResponceDig</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
int CStResponceDig::ReceiveTimeOut(CCardReaderDig* pcParent)
{
	int iResult = 0;
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStResponceDig::ReceiveTimeOut");
#endif
	if(pcParent->TimeOut() != ACK)
	{
		iResult = ChangeState(pcParent, CStTimOutDig::Instance());
		if(iResult >= 0)
			iResult = pcParent->GetState()->ReceiveTimeOut(pcParent);
	}
	else
	{
		iResult = pcParent->SendEnq();	
		if(iResult >= 0)
			iResult = pcParent->GetState()->WaitResponce(pcParent);
	}
	return iResult;
}

#pragma argsused
/**************************************************************************
<METHOD>
	<CLASS>CStResponceDig</CLASS>
	<NAME>CStResponceDig</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
int CStResponceDig::ReceiveDleEot(CCardReaderDig* pcParent)
{
	int iResult = ERROR_NONE_AVAILABLE;
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStResponceDig::ReceiveDleEot");
#endif
	return iResult;
}

/**************************************************************************
<METHOD>
	<CLASS>CStResponceDig</CLASS>
	<NAME>CStResponceDig</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
int CStResponceDig::WaitResponce(CCardReaderDig* pcParent)
{
	int iResult = ERROR_NONE_AVAILABLE;

#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStResponceDig::WaitResponce");
#endif
	
	iResult = pcParent->WaitResponce();
	if(iResult >= 0)
	{
		iResult = ChangeState(pcParent, CStCommandDig::Instance());
	}
	else
	{
		if(pcParent->SetRetries() == 0)
		{
			iResult = pcParent->SendEnq();
			if(iResult >= 0)
				iResult = pcParent->GetState()->WaitResponce(pcParent);
		}
		else
		{
			iResult = ChangeState(pcParent, CStCommandDig::Instance());
			iResult = ERROR_RETIES;
		}
	}
	return iResult;
}

/**************************************************************************
<METHOD>
	<CLASS>CStResponceDig</CLASS>
	<NAME>CStResponceDig</NAME>
	<TYPE> LOCAL  GLOBAL </TYPE>
	<DESCRIPTION></DESCRIPTION>
	<PARAMETERS>
		<PARAMETER>
			<NAME></NAME>
			<TYPE></TYPE>
			<IO> IN | OUT | INOUT</ IO >
			<DESCRIPTION>
			</DESCRIPTION>
		</PARAMETER>
	</PARAMETERS>
</METHOD>
**************************************************************************/
CStateMachineDigCard* CStResponceDig::Instance(void)
{
#ifdef STESUD_TRACE
	CTrace::Instance()->Show("CStResponceDig::Instance");
#endif
	if(m_pcInstance == NULL)
		m_pcInstance = new CStResponceDig();
	return m_pcInstance;
}

