#include <windows.h>
#include <stdio.h>
#include <io.h>

#include "PRXInternal.h"

PRX_Errors PRX_ApiErrors[] = 
{
	{PRX_OK,															"PRX_OK"},
	{PRX_InvalidCardNumber,												"Invalid card number"},
	{PRX_Initialise_AlreadyInitialised,									"PRX_Initialise fail: already initialised"},
	{PRX_Initialise_FindPCIDeviceFail,									"PRX_Initialise fail: pciPciDeviceFind error"},
	{PRX_Initialise_PCIDeviceOpenFail,									"PRX_Initialise fail: pciPciDeviceOpen error"},
	{PRX_Initialise_PCIBarMapFail,										"PRX_Initialise fail: pciPciBarMap error"},
	{PRX_Initialise_PCICommonBufferPropertiesFail,						"PRX_Initialise fail: pciPciCommonBufferProperties error"},
	{PRX_Initialise_PCICommonBufferMapFail,								"PRX_Initialise fail: pciPciCommonBufferMap error"},
	
	{ PRX_Uninitialise_IsInitialisedFail					, "PRX_Uninitialise_IsInitialisedFail					"}, 
	{ PRX_Uninitialise_IsPciInitialisedFail				, "PRX_Uninitialise_IsPciInitialisedFail				"}, 
	{ PRX_Uninitialise_PCIBarUnmapFail					, "PRX_Uninitialise_PCIBarUnmapFail					"}, 
	{ PRX_Uninitialise_PCIDeviceCloseFail					, "PRX_Uninitialise_PCIDeviceCloseFail					"}, 
	
	{ PRX_OpenDMAChannel_IspciInitialisedFail				, "PRX_OpenDMAChannel_IspciInitialisedFail				"}, 
	{ PRX_OpenDMAChannel_DMAChannelAlreadyOpen			, "PRX_OpenDMAChannel_DMAChannelAlreadyOpen			"}, 
	{ PRX_OpenDMAChannel_pciDmaBlockChannelOpenFail		, "PRX_OpenDMAChannel_pciDmaBlockChannelOpenFail		"}, 
	
	{ PRX_CloseDMAChannel_IspciInitialisedFail			, "PRX_CloseDMAChannel_IspciInitialisedFail			"}, 
	{ PRX_CloseDMAChannel_IsDMAChannelOpenFail			, "PRX_CloseDMAChannel_IsDMAChannelOpenFail			"}, 
	{ PRX_CloseDMAChannel_pciDmaBlockChannelCloseFail		, "PRX_CloseDMAChannel_pciDmaBlockChannelCloseFail		"}, 
	
	{ PRX_PerformDMATransfer_IspciInitialisedFail			, "PRX_PerformDMATransfer_IspciInitialisedFail			"}, 
	{ PRX_PerformDMATransfer_IsDMAChannelOpenFail			, "PRX_PerformDMATransfer_IsDMAChannelOpenFail			"}, 
	{ PRX_PerformDMATransfer_pciDmaBlockTransferFail		, "PRX_PerformDMATransfer_pciDmaBlockTransferFail		"}, 
	
	{ PRX_SetRegister_IspciInitialisedFail				, "PRX_SetRegister_IspciInitialisedFail				"}, 
	{ PRX_SetRegister_OffsetOutOfRange					, "PRX_SetRegister_OffsetOutOfRange					"}, 
	{ PRX_GetRegister_IspciInitialisedFail				, "PRX_GetRegister_IspciInitialisedFail				"}, 
	{ PRX_GetRegister_OffsetOutOfRange					, "PRX_GetRegister_OffsetOutOfRange					"}, 
	{ PRX_SetSystemRegister_OutOfRange					, "PRX_SetSystemRegister_OutOfRange					"}, 
	{ PRX_GetSystemRegister_OutOfRange					, "PRX_GetSystemRegister_OutOfRange					"}, 
	{ PRX_SetSamplingRegister_OutOfRange					, "PRX_SetSamplingRegister_OutOfRange					"}, 
	{ PRX_GetSamplingRegister_OutOfRange					, "PRX_GetSamplingRegister_OutOfRange					"}, 
	{ PRX_SetPeripheralRegister_OutOfRange				, "PRX_SetPeripheralRegister_OutOfRange				"}, 
	{ PRX_GetPeripheralRegister_OutOfRange				, "PRX_GetPeripheralRegister_OutOfRange				"}, 
	{ PRX_GetSRAMLong_OffsetOutOfRange					, "PRX_GetSRAMLong_OffsetOutOfRange					"}, 
	{ PRX_SetValue_InvalidPropertyName					, "PRX_SetValue_InvalidPropertyName					"}, 

	{PRX_SetSequence_TooManyBlocks,										"PRX_SetSequence fail: Too Many Blocks sent"},
	{PRX_GetSequence_TooManyBlocks,										"PRX_GetSequence fail: Too Many Blocks requested"},
	{PRX_SetTransmitPulseEnable_InvalidFlags,							"PRX_SetTransmitPulseEnable fail: Invalid Flags"},
	{PRX_SetStepSkipCount_InvalidCount,									"PRX_SetSkipCount fail: Skip Count Too Large requested"},
	{PRX_SetReceiveChannel_InvalidChannel,								"PRX_SetReceiveChannel fail: Invalid Channel"},
	{PRX_SetFineGain_InvalidGain,										"PRX_SetFineGain fail: Invalid Gain"},
	{PRX_SetBackendLowpassFilter_InvalidLevel,							"PRX_SetBackendLowpassFilter fail: Invalid Level"},
	{PRX_SetBackendHighpassFilter_InvalidLevel,							"PRX_SetBackendHighpassFilter fail: Invalid Level"},
	{PRX_SetFrontendLowpassFilter_InvalidLevel,							"PRX_SetFrontendLowpassFilter fail: Invalid Level"},
	{PRX_SetFrontendHighpassFilter_InvalidLevel,						"PRX_SetFrontendHighpassFilter fail: Invalid Level"},
	{PRX_SetInputImpedance_InvalidLevel,								"PRX_SetInputImpedance fail: Invalid Level"},
	{PRX_SetCoarseGain_InvalidLevel,									"PRX_SetCoarseGain fail: Invalid Level"},
	{PRX_SetOversamplingDelay_InvalidLength,							"PRX_SetOversamplingDelay fail: Invalid Length"},
	{PRX_SetNumberOfOversamples_InvalidNumberOfOversamples,				"PRX_SetNumberOfOversamples fail: Invalid Number Of Oversamples"},
	{PRX_SetPulseWidth_InvalidWidth,									"PRX_SetPulseWidth fail: Invalid Width"},
	{PRX_SetPulseTrainLength_InvalidLength,								"PRX_SetPulseTrain Length fail: Invalid Length"},
	{PRX_SetPretriggerDelay_InvalidDelay,								"PRX_SetPretriggerDelay fail: Invalid Delay"},
	{PRX_SetRepetitionTime_InvalidLength,								"PRX_SetRepetitionTime fail: Invalid Length"},


	{PRX_Uninitialise_IsInitialisedFail,								"PRX_Uninitialise fail not initialised"},
	{PRX_Uninitialise_IsPciInitialisedFail,								"PRX_Uninitialise fail: pci not initialised"},
	{PRX_Uninitialise_PCIBarUnmapFail,									"PRX_Uninitialise fail: pciPciBarUnmap error"},
	{PRX_Uninitialise_PCIDeviceCloseFail,								"PRX_Uninitialise fail: pciPciDeviceClose error"},
	{PRX_OpenDMAChannel_IspciInitialisedFail,							"PRX_OpenDMAChannel fail: pci not initialised"},
	{PRX_OpenDMAChannel_DMAChannelAlreadyOpen,							"PRX_OpenDMAChannel fail: DMA channel already open"},
	{PRX_OpenDMAChannel_pciDmaBlockChannelOpenFail,						"PRX_OpenDMAChannel fail: pciDmaBlockChannelOpen error"},
	{PRX_CloseDMAChannel_IspciInitialisedFail,							"PRX_CloseDMAChannel fail: pci not initialised"},
	{PRX_CloseDMAChannel_IsDMAChannelOpenFail,							"PRX_CloseDMAChannel fail: DMA channel not open"},
	{PRX_CloseDMAChannel_pciDmaBlockChannelCloseFail,					"PRX_CloseDMAChannel fail: pciDmaBlockChannelClose error"},
	{PRX_PerformDMATransfer_IspciInitialisedFail,						"PRX_PerformDMATransfer fail: pci not initialised"},
	{PRX_PerformDMATransfer_IsDMAChannelOpenFail,						"PRX_PerformDMATransfer fail: DMA channel not open"},
	{PRX_PerformDMATransfer_pciDmaBlockTransferFail,					"PRX_PerformDMATransfer fail: pciDmaBlockTransfer error"},
	{PRX_SetRegister_IspciInitialisedFail,								"PRX_SetRegister fail: pci not initialised"},
	{PRX_SetRegister_OffsetOutOfRange,									"PRX_SetRegister fail: offset out of range"},
	{PRX_GetRegister_IspciInitialisedFail,								"PRX_GetRegister fail: pci not initialised"},
	{PRX_GetRegister_OffsetOutOfRange,									"PRX_GetRegister fail: offset out of range"},
	{PRX_SetSystemRegister_OutOfRange,									"PRX_SetSystemRegister fail: offset out of range"},
	{PRX_GetSystemRegister_OutOfRange,									"PRX_GetSamplingRegister fail: offset out of range"},
	{PRX_SetSamplingRegister_OutOfRange,									"PRX_SetSamplingRegister fail: offset out of range"},
	{PRX_GetSamplingRegister_OutOfRange,									"PRX_GetSamplingRegister fail: offset out of range"},
	{PRX_SetPeripheralRegister_OutOfRange,								"PRX_SetPeripheralRegister fail: offset out of range"},
	{PRX_GetPeripheralRegister_OutOfRange,								"PRX_GetPeripheralRegister fail: offset out of range"},

	{ PRX_GetSRAMLong_OffsetOutOfRange					, "PRX_GetSRAMLong_OffsetOutOfRange					"}, 
	{ PRX_SetValue_InvalidPropertyName					, "PRX_SetValue_InvalidPropertyName					"}, 
	{ PRX_SetSequence_TooManyBlocks						, "PRX_SetSequence_TooManyBlocks						"}, 
	{ PRX_GetSequence_TooManyBlocks						, "PRX_GetSequence_TooManyBlocks						"}, 
	{ PRX_SetTransmitPulseEnable_InvalidFlags				, "PRX_SetTransmitPulseEnable_InvalidFlags				"}, 
	{ PRX_SetReceiveChannel_InvalidChannel				, "PRX_SetReceiveChannel_InvalidChannel				"}, 
	{ PRX_SetFineGain_InvalidGain							, "PRX_SetFineGain_InvalidGain							"}, 
	{ PRX_SetBackendLowpassFilter_InvalidLevel			, "PRX_SetBackendLowpassFilter_InvalidLevel			"}, 
	{ PRX_SetBackendHighpassFilter_InvalidLevel			, "PRX_SetBackendHighpassFilter_InvalidLevel			"}, 
	{ PRX_SetFrontendLowpassFilter_InvalidLevel			, "PRX_SetFrontendLowpassFilter_InvalidLevel			"}, 
	{ PRX_SetFrontendHighpassFilter_InvalidLevel			, "PRX_SetFrontendHighpassFilter_InvalidLevel			"}, 
	{ PRX_SetInputImpedance_InvalidLevel					, "PRX_SetInputImpedance_InvalidLevel					"}, 
	{ PRX_SetCoarseGain_InvalidLevel						, "PRX_SetCoarseGain_InvalidLevel						"}, 
	{ PRX_SetOversamplingDelay_InvalidLength				, "PRX_SetOversamplingDelay_InvalidLength				"}, 
	{ PRX_SetPulseWidth_InvalidWidth						, "PRX_SetPulseWidth_InvalidWidth						"}, 
	{ PRX_SetPretriggerDelay_InvalidDelay					, "PRX_SetPretriggerDelay_InvalidDelay					"}, 
	{ PRX_SetRepetitionTime_InvalidLength					, "PRX_SetRepetitionTime_InvalidLength					"}, 
	{ PRX_SetStepSkipCount_InvalidCount					, "PRX_SetStepSkipCount_InvalidCount					"}, 
	{ PRX_SetPulseTrainLength_InvalidLength				, "PRX_SetPulseTrainLength_InvalidLength				"}, 
	{ PRX_SetPulseEchoEnable_InvalidFlags                 , "PRX_SetPulseEchoEnable_InvalidFlags                 "}, 
	{ PRX_SetHVLevel_InvalidLevel			                , "PRX_SetHVLevel_InvalidLevel			                "}, 
	{ PRX_SetNumberOfOversamples_InvalidNumberOfOversamples, "PRX_SetNumberOfOversamples_InvalidNumberOfOversamples"}, 
	{ PRX_GetIsSafe_FETLoadTooLarge,						 "PRX_GetIsSafe: FET Load Too Large"},
	{PRX_CheckState_InvalidCardIndex,						"PRX_CheckState_InvalidCardIndex"},

	{ PRX_LastError , "PRX_LastError "}
} ;


PRX_API const char * CALL_CONV PRX_GetCodeString(PRX_ReturnCode errorCode)
{
	int i = 0 ;

	while (PRX_ApiErrors[i].code != errorCode && PRX_ApiErrors[i].code != PRX_LastError)
		i++ ;

	return PRX_ApiErrors[i].codeString ;
}

const char *NDTS_GetCodeString(int errorCode)
{
	return PRX_GetCodeString(errorCode) ;
}