#include "NDTSRS2AErrors.h"
#include "NDTSError.h"
typedef struct 
{
	RS2A_ReturnCode code ;
	char *pCodeString ;
} RS2A_Error ;

RS2A_Error RS2A_ApiErrors[] = 
{
	{RS2A_OK,																"RS2A_OK"},
	{RS2A_TakeSnapshot_UnsupportedTriggerMode,								"RS2A_TakeSnapshot fail: unsupported trigger mode"}, 
	{RS2A_TakeSnapshot_TimeoutWaitingForSamples,							"RS2A_TakeSnapshot fail: time out waiting for samples"},
	{RS2A_PropertyOutOfRange,												"A property index is outside the range of 0..RS2A_ReturnNumberOfPropertyIndices() -1"},
	{RS2A_PropertyNoLongerUsed,												"A property index is no longer in use"},
	{RS2A_PropertyValueOutOfRange,											"A property value has been clamped"},
	{RS2A_PropertyMinUpdated,												"A property minimum value has changed"},
	{RS2A_PropertyMaxUpdated,												"A property maximum value has changed"},
	{RS2A_propertyFlagUpdated,												"A property type has changed"},
	{RS2A_InvalidGateIndex,													"The gate index is not valid"},
	{RS2A_EnumStringNotFound,												"There is no enum string for this property index / enum number"},
	{RS2A_PropertySetWhenScanning,											"A property can only be set when isScanning is False"},
	{RS2A_TCG_ValueOutOfRange,												"A TCG value is not within the correct range for that value"},
	{RS2A_PropertyIsReadOnly,												"The property is read only"},
	{RS2A_IOBitNumberIsOutOfRange,											"This IO number is out of range"},
	{RS2A_IOBitIsReadOnly,													"This Digital IO is read only"},
	{RS2A_IOBitIsWriteOnly,													"This Digital IO is write only"},
	{RS2A_NotInitialised,													"This function should not be called before Factory->Initialise()"},
	{RS2A_NoHardwareFound,													"No RapiDAQ hardware has been found"},

	{RS2A_LastError,														"Unknown"}
} ;


RS2A_API const char * CALL_CONV RS2A_GetCodeString(int errorCode)
{
	int i = 0 ;

	while (RS2A_ApiErrors[i].code != errorCode && RS2A_ApiErrors[i].code != RS2A_LastError)
		i++ ;

	return RS2A_ApiErrors[i].pCodeString ;
}

void RS2A_HandleRS2AError(RS2A_ReturnCode errorCode) 
{
	NDTS_HandleError(errorCode) ;
}

void RS2A_HandleRS2AErrorWithLogLevel(RS2A_ReturnCode errorCode,  NDTS_LogLevel logLevel) 
{
	NDTS_HandleErrorWithLogLevel(errorCode, logLevel) ;
}

// The RS2A error log combines the error logs from the other DLL's
// This is a C interface that is not currently used by the C++ or .net interfaces
RS2A_API int  CALL_CONV RS2A_ReturnNumberOfErrorLogLines()
{
	return NDTS_ReturnNumberOfErrorLogLines() ;
}

RS2A_API NDTS_Boolean RS2A_GetErrorLogLine(int lineNumber, char *pMessageBuffer, int numberOfBytesInMessageBuffer)
{
	return NDTS_GetErrorLogLine(lineNumber, pMessageBuffer, numberOfBytesInMessageBuffer) ;
}


RS2A_API NDTS_Boolean RS2A_ClearErrorLog() 
{
	return NDTS_ClearErrorLog() ;
}
