#include "NDTS2100Errors.h"
#include "NDTSError.h"
typedef struct 
{
	NDTS2100_ReturnCode code ;
	char *pCodeString ;
} NDTS2100_Error ;

NDTS2100_Error NDTS2100_ApiErrors[] = 
{
	{NDTS2100_OK,																"NDTS2100_OK"},
	{NDTS2100_TakeSnapshot_UnsupportedTriggerMode,								"NDTS2100_TakeSnapshot fail: unsupported trigger mode"}, 
	{NDTS2100_TakeSnapshot_TimeoutWaitingForSamples,							"NDTS2100_TakeSnapshot fail: time out waiting for samples"},
	{NDTS2100_PropertyOutOfRange,												"A property index is outside the range of 0..NDTS2100_ReturnNumberOfPropertyIndices() -1"},
	{NDTS2100_PropertyNoLongerUsed,												"A property index is no longer in use"},
	{NDTS2100_PropertyValueOutOfRange,											"A property value has been clamped"},
	{NDTS2100_PropertyMinUpdated,												"A property minimum value has changed"},
	{NDTS2100_PropertyMaxUpdated,												"A property maximum value has changed"},
	{NDTS2100_propertyFlagUpdated,												"A property type has changed"},
	{NDTS2100_InvalidGateIndex,													"The gate index is not valid"},
	{NDTS2100_EnumStringNotFound,												"There is no enum string for this property index / enum number"},
	{NDTS2100_PropertySetWhenScanning,											"A property can only be set when isScanning is False"},
	{NDTS2100_TCG_ValueOutOfRange,												"A TCG value is not within the correct range for that value"},
	{NDTS2100_PropertyIsReadOnly,												"The property is read only"},
	{NDTS2100_IOBitNumberIsOutOfRange,											"This IO number is out of range"},
	{NDTS2100_IOBitIsReadOnly,													"This Digital IO is read only"},
	{NDTS2100_IOBitIsWriteOnly,													"This Digital IO is write only"},
	{NDTS2100_NotInitialised,													"This function should not be called before Factory->Initialise()"},
	{NDTS2100_NoHardwareFound,													"No NDTS2100 hardware has been found"},

	{NDTS2100_LastError,														"Unknown"}
} ;


NDTS2100_API const char * CALL_CONV NDTS2100_GetCodeString(int errorCode)
{
	int i = 0 ;

	while (NDTS2100_ApiErrors[i].code != errorCode && NDTS2100_ApiErrors[i].code != NDTS2100_LastError)
		i++ ;

	return NDTS2100_ApiErrors[i].pCodeString ;
}

void NDTS2100_HandleNDTS2100Error(NDTS2100_ReturnCode errorCode) 
{
	NDTS_HandleError(errorCode) ;
}

void NDTS2100_HandleNDTS2100ErrorWithLogLevel(NDTS2100_ReturnCode errorCode,  NDTS_LogLevel logLevel) 
{
	NDTS_HandleErrorWithLogLevel(errorCode, logLevel) ;
}

// The NDTS2100 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
NDTS2100_API int  CALL_CONV NDTS2100_ReturnNumberOfErrorLogLines()
{
	return NDTS_ReturnNumberOfErrorLogLines() ;
}

NDTS2100_API NDTS_Boolean NDTS2100_GetErrorLogLine(int lineNumber, char *pMessageBuffer, int numberOfBytesInMessageBuffer)
{
	return NDTS_GetErrorLogLine(lineNumber, pMessageBuffer, numberOfBytesInMessageBuffer) ;
}


NDTS2100_API NDTS_Boolean NDTS2100_ClearErrorLog() 
{
	return NDTS_ClearErrorLog() ;
}
