#include "CRCStatistics.h"
#include "ThreadInternal.h"

NDTS_Boolean CALL_CONV DC_GetCRCStatistics(unsigned long cardIndex, DC_CRCStatistics *pStatistics)
{
	DC_State *pThreadState = DC_ReturnThreadStatePointer(cardIndex) ;

	if (!pThreadState) return NDTS_BFalse; 

	DC_Lock(cardIndex) ;

	*pStatistics = pThreadState->crcState.statistics ;

	DC_Unlock(cardIndex) ;

	return NDTS_BTrue ;
}


NDTS_Boolean CALL_CONV DC_SetCRCBadScanHook(unsigned long cardIndex, void (*pFN)(const DC_BadAScanStatistics *pAScanStatistics, const DC_BadCScanStatistics *pCScanStatistics, void* pContext), void* pContext)
{
	DC_State *pThreadState = DC_ReturnThreadStatePointer(cardIndex) ;
	if (!pThreadState) return NDTS_BFalse; 

	DC_Lock(cardIndex) ;

	pThreadState->crcState.pCRCBadScanHook = pFN ;
	pThreadState->crcState.pCRCBadScanHookContext = pContext ;
	DC_Unlock(cardIndex) ;

	return NDTS_BTrue ;
}

NDTS_Boolean CALL_CONV DC_ResetCRCStatistics(unsigned long cardIndex)
{
	DC_CRCState *pCRCState ;
	DC_State *pThreadState = DC_ReturnThreadStatePointer(cardIndex) ;
	if (!pThreadState) return NDTS_BFalse; 

	DC_Lock(cardIndex) ;

	pCRCState = &(pThreadState->crcState);

	memset(&pCRCState->statistics, 0, sizeof(pCRCState->statistics)) ;

	DC_Unlock(cardIndex) ;

	return NDTS_BTrue ;
}