////////////////////////////////////////////////////////////////////////////////////////////////
// Summer 2008 - DataCollection.h contains files that are used by both collect.h and snapshot.h
// Most of the functions are for either the PRX style of collection (snapshotProtected.h) or
// RapiDAQ style of collection (defined in collect.h) 

#ifndef DATACOLLECTION_H
#define DATACOLLECTION_H

#include "NDTSEnums.h"
#include "RawScan.h"

#ifdef __cplusplus
extern "C" {
#endif


#ifdef DC_EXPORTS
	#define DC_API __declspec(dllexport)
#else
	#define DC_API __declspec(dllimport)
#endif
 
#ifdef STDCALL
	#define CALL_CONV __stdcall
#else
	#define CALL_CONV
#endif



// Typedefs for the function pointers that are passed in from the associated SDK	
typedef void (* FPSDK_Lock)(unsigned long cardIndex);
typedef void (* FPSDK_Unlock)(unsigned long cardIndex);
typedef NDTS_Boolean (* FPSDK_GetNumberOfBScansInSRAM)(unsigned long cardIndex, unsigned long *pNumberOfScans);
typedef NDTS_Boolean (* FPSDK_SetRAMWindow)(unsigned long cardIndex);
typedef NDTS_Boolean (* FPSDK_GetCScanBaseSRAMAddress)(unsigned long cardIndex, unsigned long *baseAddress);
typedef NDTS_Boolean (* FPSDK_GetAScanBaseSRAMAddress)(unsigned long cardIndex, unsigned long *baseAddress);

typedef NDTS_Boolean (* FPSDK_GetSampleStorageMode)(unsigned long cardIndex, NDTS_SampleSize *baseAddress);
typedef NDTS_Boolean (* FPSDK_GetScanStorageOptions)(unsigned long cardIndex, NDTS_ScanStorage *baseAddress);
typedef NDTS_Boolean (* FPSDK_CopyStateToRawScan)(unsigned long cardIndex, NDTS_RawScan *pRawScan, NDTS_Boolean copyLiveNumberOfBScans);

typedef NDTS_Boolean (* FPSDK_SetUpdateSampleParametersHook)(unsigned long cardIndex, void (*pFN)(unsigned long cardIndex));
typedef NDTS_Boolean (* FPSDK_ResetFirmware)(unsigned long cardIndex);
typedef NDTS_Boolean (* FPSDK_DataFullRecovery)(unsigned long cardIndex);

typedef unsigned long (* FPSDK_ReturnOversampleCountThisStep)(unsigned long cardIndex, unsigned long aScanIndex);
typedef unsigned long (* FPSDK_ReturnAScanSampleValuesThisStep)(unsigned long cardIndex, unsigned long aScanIndex);
typedef unsigned long (* FPSDK_ReturnGateOffsetThisStep)(unsigned long cardIndex, unsigned long aScanIndex);
typedef unsigned long (* FPSDK_ReturnGateBytesPerBScan)(unsigned long cardIndex);
typedef unsigned long (* FPSDK_ReturnAScanOffsetThisStep)(unsigned long cardIndex, unsigned long aScanIndex);
typedef unsigned long (* FPSDK_ReturnAScanBytesPerBScan)(unsigned long cardIndex);
typedef NDTS_Boolean (* FPSDK_ReturnIsSignAndMag)(unsigned long cardIndex);
typedef NDTS_SnapshotDataSelection (*FPSDK_ReturnSnapshotSelectionForGate)(unsigned long cardIndex, unsigned long step, unsigned long gate);

//////////////////////////////////////////////////////////////////////////////////
// This struct must be filled in by the SDK using the DataCollection.dll and passed to the Initialise function.
//////////////////////////////////////////////////////////////////////////////////
typedef struct
{
	unsigned long numberOfBoards;
	unsigned long addressOfDataSamplingStatusRegister;
	unsigned long SID;  // Secondary PCI ID
	unsigned long maximumNumberOfGates;
	unsigned long maximumNumberOfSamples;  // Max A Scan range
	unsigned long numberOfEncodersInHardware;
	NDTS_Boolean hasCRC;
	NDTS_Boolean isRealHardwareFound;  // NDTS2100 can run in a simulated mode generating random data when no real hardware present
	NDTS_Boolean ignoreHeaderAndCRC;  // NDTS2100 commissioning on cards with faulty RAM - disable the header and CRC checking
	FPSDK_Lock fpLock;
	FPSDK_Unlock fpUnlock;
	FPSDK_GetNumberOfBScansInSRAM fpGetNumberOfBScansInSRAM;
	FPSDK_SetRAMWindow fpSetRAMWindow;
	FPSDK_GetCScanBaseSRAMAddress fpGetCScanBaseSRAMAddress;
	FPSDK_GetAScanBaseSRAMAddress fpGetAScanBaseSRAMAddress;
	FPSDK_SetUpdateSampleParametersHook fpSetUpdateSampleParametersHook;
	FPSDK_ResetFirmware fpResetFirmware;  // Function to call following Data Full error to get firmware on card into consistent state
	FPSDK_DataFullRecovery fpDataFullRecovery;  // Function to call following multiple failures to perform a more time consuming reset of the card.
	FPSDK_GetSampleStorageMode fpGetSampleStorageMode;
	FPSDK_GetScanStorageOptions fpGetScanStorageOptions;
	FPSDK_CopyStateToRawScan fpCopyStateToRawScan;
	FPSDK_ReturnOversampleCountThisStep fpReturnOversampleCountThisStep;
	FPSDK_ReturnAScanSampleValuesThisStep fpReturnAScanSampleValuesThisStep;
	FPSDK_ReturnGateOffsetThisStep fpReturnGateOffsetThisStep;
	FPSDK_ReturnGateBytesPerBScan fpReturnGateBytesPerBScan;
	FPSDK_ReturnAScanOffsetThisStep fpReturnAScanOffsetThisStep;
	FPSDK_ReturnAScanBytesPerBScan fpReturnAScanBytesPerBScan;
	FPSDK_ReturnIsSignAndMag  fpReturnIsSignAndMag;
	FPSDK_ReturnSnapshotSelectionForGate fpReturnSnapshotSelectionForGate;

} DC_AssociatedSDK;


typedef enum 
{
	DC_FRSOAll,
	DC_FRSOAScans,
	DC_FRSOGates
} DC_FreeRawScanMode ;


DC_API NDTS_Boolean CALL_CONV DC_FreeRawScanData(NDTS_RawScan *pRawScan, DC_FreeRawScanMode mode) ;

// Pool memory - some apps like WinRS manage the pool themselves
DC_API NDTS_Boolean CALL_CONV DC_PurgeRawScanPools(unsigned long cardIndex) ;
DC_API NDTS_Boolean CALL_CONV DC_FreeAScan(unsigned long cardIndex, void *pData) ;
// Obsolete DC_API NDTS_Boolean CALL_CONV DC_AllocRawScanMemoryPools(NDTS_RawScan *pRawScan) ;
DC_API NDTS_Boolean CALL_CONV DC_AllocCardMemoryPools(unsigned long cardIndex, NDTS_Boolean isSequence) ;
DC_API NDTS_Boolean CALL_CONV DC_FreeRawScanPools(unsigned long cardIndex) ;

// Make these functions available for SDKs to use if they want to do their own hardware access as well as using the thread
DC_API NDTS_Boolean CALL_CONV DC_WaitForBankSwap(unsigned long cardIndex) ;
DC_API 	NDTS_Boolean CALL_CONV DC_GetAScanNoBankSwap(unsigned long cardIndex, short *pData, unsigned long numberOfBufferValues, unsigned long aScanIndex, unsigned long bScanIndex);
DC_API NDTS_Boolean CALL_CONV DC_SetRequestEarlySampleData(unsigned long cardIndex) ;
DC_API NDTS_Boolean CALL_CONV DC_GetIsSampleDataAvailable(unsigned long cardIndex, NDTS_Boolean *pIsAvailable) ;
DC_API NDTS_Boolean CALL_CONV DC_IndicateSampleDataDownloaded(unsigned long cardIndex);
DC_API NDTS_Boolean CALL_CONV DC_GetIsSomeDataSampled(unsigned long cardIndex, NDTS_Boolean *pSomeDataSampled);

DC_API NDTS_Boolean CALL_CONV DC_GetAScanDMARate(unsigned long cardIndex, unsigned long *pKBsPerSec);


#ifdef __cplusplus
}
#endif

#endif
