/******************************************************************************
 *
 *	NDT Solutions RapiDAQ Software Development Kit v1.0beta
 *
 ******************************************************************************
 *
 *  File:        HLPRX.h.
 *
 *  Description: Primary header file for RapiDAQ SDK.
 *
 *	Revision:    04/02/05 - Frog (frog@ndtsolutions.com).
 *
 ******************************************************************************/



#ifndef HLPRX_H
#define HLPRX_H


/*
 *	 __cplusplus, __declspec(...), and __stdcall are Microsoft specific.
 */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HLPRX_EXPORTS
	#define HLPRX_API __declspec(dllexport)
#else
	#define HLPRX_API __declspec(dllimport)
#endif
 
#ifdef STDCALL
	#define CALL_CONV __stdcall
#else
	#define CALL_CONV
#endif

#include "NDTSEnums.h"
#include "RQStructs.h"
/*
 *	enums
 */

	
typedef enum 
{
	HLPRX_BFPoint5Mhz = 0,
	HLPRX_BF1Mhz,
	HLPRX_BF2Point5Mhz,
	HLPRX_BF5Mhz,
	HLPRX_BF10Mhz,
	HLPRX_BF15Mhz,
	HLPRX_BFNone,
} HLPRX_BandpassFilter ;

/*
 *	Functions 
 */

// Administration
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_Initialise();
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_Uninitialise(void);

HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetRepetitionRate(unsigned long pulsesPerSecond);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetRepetitionRate(unsigned long *pulsesPerSecond);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetRange(unsigned long stepIndex, unsigned long sampleCount);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetRange(unsigned long stepIndex, unsigned long *sampleCount);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetDelay(unsigned long stepIndex, unsigned long sampleCount);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetDelay(unsigned long stepIndex, unsigned long *sampleCount);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetNumberOfSequenceSteps(unsigned long numberOfSequenceSteps);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetNumberOfSequenceSteps(unsigned long *pNumberOfSequenceSteps);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetGain(unsigned long stepIndex, short gain);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetGain(unsigned long stepIndex, short *pGain);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetPulserVoltage(unsigned long volts);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetPulserVoltageEnable(NDTS_Boolean isEnabled);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_StartSequence();
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_StopSequence();

// TCG settings are passed through here so the coarse gain levels can be set on the PRX card
// This is done in HLPRX_SubmitTCGCurve not HLPRX_SetEnhancedTCG to avoid having to save any
// values
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_ClearTCGCurve(unsigned long cardIndex);
HLPRX_API NDTS_Boolean  CALL_CONV HLPRX_SubmitTCGCurve(unsigned long cardIndex, unsigned long step, short *pCurve, unsigned long nPts, short gain);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetEnhancedTCG(unsigned long cardIndex);

/* Band pass filters are a wrapper round
PRX_SetBackendLowpassFilter(), PRX_SetBackendHighpassFilter(), PRX_SetFrontendLowpassFilter(), PRX_SetFrontendHighpassFilter(), 
*/

//HLPRX_SetBandpassFilter has been replaced by HLPRX_SetFilter
//HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetBandpassFilter(unsigned long card, unsigned long block, HLPRX_BandpassFilter value) ;
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetFilter(unsigned long step, HLPRX_BandpassFilter value) ;
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetFilter(unsigned long step, HLPRX_BandpassFilter *pValue) ;


// Write a 16 bit value to the digital IO on the SFD interface card.  
// The bottom 16 bits of value correspond to digital out 0 to digital out 15.
// All 16 outputs are re-written when this function is called.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetSFDInterfaceDigitalOutput(unsigned long value) ;

// For Baoti, this will read from the parallel printer port to the lowest 8 bits of value
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetSFDInterfaceDigitalInput(unsigned long *value) ;

// Write to one of the 16 analogue outputs on the SFD interface card.  
// analogueOutputNumber is from 0..15 to identify which analogue output to update.
// analogueValue is a 12 bit value (0..4095) corresponding to 0 to 100% of the output voltage.
// Only the analogue output corresponding to the selected analogueOutputNumber is altered when this function is called.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetSFDInterfaceAnalogueOutput(unsigned long analogueOutputNumber, unsigned long analogueValue) ;

// Take a snapshot of all the scans since the last call, for use with HLPRX_GetAScanAndGateDataFromSnapshot()
// Returns the number of BScans in the snapshot.
// If the function is called before any BScans are captured, it will return NDTS_BFalse and 
// numberOfCapturedBScans will be set to zero.  The snapshot will remain as the previously captured
// snapshot if one exists.
// This function may block for the time it takes to complete the capture of the current BScan,
// I.e. a worst case of the BScan rep rate.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_TakeSnapshot(unsigned long *pNumberOfCapturedBScans) ;


// Extract data from a snapshot.  
// step is the sequence step for which the data will be extracted.
// selection is how to select the data from the B-Scans, e.g. max, latest, ...
// gateIndex is the gate to use when selecting the Ascan data.  
// *pBuffer is a pointer to a buffer in which the Ascan data will be placed
// *pAmplitude and *pDepth will contain the amplitude and depth gate data.
//
// The Bscan is chosen individually for each gate.  For example if selection is max and gate 1 has its
// maximum amplitude on Bscan 5 whilst gate 2 has its max amp on Bscan 7, the amp and depth data 
// for gate 1 will be taken from Bscan 5, whilst the amp and depth data for gate 2 will be taken from Bscan 7.
// If gateIndex is set to 1, the Ascan returned will be that from BScan 5 (the one with max amp for gate 1).
//
// Noise filtering is also applied on a gate by gate basis.  This means that the Ascan that is returned has
// been noise filtered according to the amplitude of the gate specified in gateIndex and not accross the entire
// Ascan.  It also means that an Ascan may for example show a noise peak in the enabled area of gate 2 but gate 2's amplitude
// and depth values will be returned from a different Bscan that does not have noise in the enabled period of gate2.
//
// Replaces RQ_GetPRXOutput() but does not require a PRX card index.

// Replaced HLPRX_ExtractDataFromSnapshot() with HLPRX_GetAScanAndGateDataFromSnapshot which takes the buffer size in samples rather than bytes
//HLPRX_API NDTS_Boolean HLPRX_ExtractDataFromSnapshot(unsigned long step, short *pBuffer, unsigned long scanBufferBytes, short *pAmplitude, short *pDepth);
HLPRX_API NDTS_Boolean HLPRX_GetAScanAndGateDataFromSnapshot(unsigned long step, short *pBuffer, unsigned long numberOfBufferValues, short *pAmplitude, short *pDepth);

// Deprecated but used by InspectionWare.  Replace with HLPRX_SetAScanSelectionGate in next round of IW integration
//HLPRX_API NDTS_Boolean HLPRX_SetSnapshotParameters(unsigned long step, NDTS_SnapshotDataSelection selection, unsigned long gateIndex);
HLPRX_API NDTS_Boolean HLPRX_SetAScanSelectionGate(unsigned long step, unsigned long gateIndex);

// Trigger on position - gets all the gate and encoder data 
//
// bScanIndex is 0..pNumberOfCapturedBScans from TakeSnapShot.
//
// The gate data is written to a 2D array of type RQ_GateOutput,  ppGateData[nSteps][nGates]
// nSteps is the number of active steps and nGates the number of enabled gates.  The gate data is packed 
// so if e.g. gates 0, 5 and 6 are enabled nGates = 3.
// If the nGates or nSteps don't match what the SDK expects, any extra values are padded with zero.
// RQ_GateOutput is defined in RQOffline.h
//
// The encoder values are written to an array of longs, pEncoders[nEncoders]. nEncoders should be 6 for our current hardware.
// HLPRX_GetGateAndEncoderDataFromSnapshot was written for a previous version lab view and may not be appropriate for other applications
// It isn't used by the latest LabView vi.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetGateAndEncoderDataFromSnapshot(unsigned long bScanIndex, NDTS_GateOutput *pGateData, int nSteps, int nGates, long *pEncoders, int nEncoders);
// This function returns the gate values as 1 dimensional arrays of ints.  It takes a step index as well as a B Scan index
HLPRX_API NDTS_Boolean HLPRX_GetGateDataFromSnapshot(unsigned long bScanIndex, unsigned long stepIndex, int *pGateAmpData, int *pGateToFData, int nGates);
HLPRX_API NDTS_Boolean HLPRX_GetEncoderDataFromSnapshot(unsigned long bScanIndex, long *pEncoders, int nEncoders);



HLPRX_API NDTS_Boolean CALL_CONV HLPRX_ResetEncoder(unsigned long encoderIndex);

// Summer 2008 full A Scan capture

// Full A Scan capture is disabled by default.  
// When enabled, A Scan data is captured in free running mode and transferred to memory on the PC by the data collection thread.
// On a RapiDAQ with PRX firmware, collection in free running mode takes place continuously at the A Scan rep rate.  
// As soon as one set of A Scan data is captured, capture starts again from step 0.
// It is therefore important to make sure the A Scan range and rep rate are set to values that won't overload the PCI bus
// before enabling full A Scan capture.
HLPRX_API NDTS_Boolean HLPRX_SetFullAScanCapture(NDTS_Boolean doFullAScanCapture);
// Returns one A Scan from the snapshot.  Parameters are similar to the functions above, both a bScanIndex and a step must be speicified to identify
// the A Scan within the snapshot.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetFullAScanDataFromSnapshot(unsigned long bScanIndex, unsigned long step, short *pBuffer, unsigned long numberOfBufferValues);

// Gets all the B scans for a step into the buffer.  The buffer is filled with the samples for b scan index 0, followed by the samples for b scan index 1 etc.
// numberOfBufferValues must be a 1-d array of shorts that is large enough to hold the samples for all the b scan indices in the snapshot.
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetFullAScanDataFromSnapshotForAllBScans(unsigned long step, short *pBuffer, unsigned long numberOfBufferValues);


// Summary data from HLPRX_GetAScanAndGateDataFromSnapshot() is always available, whether doAScanCapture is true or false.
// Gate trigger on position data from HLPRX_GetGateAndEncoderDataFromSnapshot is also always available, even if doFullAScanCapture is false.
// The full A Scan trigger on position data from HLPRX_GetFullAScanDataFromSnapshot is only available if doAScanCapture is true.



HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetOverSampling(unsigned long block, unsigned long numberOfOversamples);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetOverSampling(unsigned long step, unsigned long *pOversamplingMultiplier);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetOverSamplingAllSteps(unsigned long numberOfOversamples);

// The pulseLength is in sampleClockPeriod / 2 steps.
// The RapiDAQ will generate a negative going pulse of the specified length.
// Applications normally specify the centre frequency of the probe.  
// (1) The application converts frequency to pulseLength using length = (1 / f) * sampleClockRate.
// (2) The probe seems to see the negative going pulse of one half of a waveform.
// (1) and (2) cancel each other out and the probe gets the frequency it expects.
// However, the negative going pulse on the scope appears half as wide as if the pulseLength were expressed in the sampleClockRate

HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetTransducerPulseWidth(unsigned long step, unsigned long pulseWidth);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetTransducerPulseWidth(unsigned long step, unsigned long *pPulseWidth);

HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetSamplingFrequency(unsigned long frequencyInHz);


// Hardware gates 
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_AddGate(unsigned long step, RQ_Gate *pGate);
HLPRX_API NDTS_Boolean CALL_CONV HLPRX_GetGate(unsigned long step, unsigned long gateIndex, RQ_Gate *pGate);
HLPRX_API unsigned long CALL_CONV HLPRX_ReturnMaximumNumberOfGates();


typedef enum
{
	HLPRX_GTMinus40,
	HLPRX_GTMinus20,
	HLPRX_GTPlus20
} HLPRX_GainTweak;

HLPRX_API NDTS_Boolean CALL_CONV HLPRX_SetGainTweak(HLPRX_GainTweak whichAttenuator, short level);

HLPRX_API unsigned long HLPRX_ReturnNumberOfErrorLogLines();
HLPRX_API NDTS_Boolean HLPRX_GetErrorLogLine(unsigned long  lineNumber, char *pMessageBuffer, unsigned long  numberOfBytesInMessageBuffer);
HLPRX_API NDTS_Boolean HLPRX_ClearErrorLog() ;
HLPRX_API NDTS_Boolean HLPRX_SetRectifierMode(RQ_Rectification mode) ;
HLPRX_API NDTS_Boolean HLPRX_SetRectification(unsigned long stepIndex, RQ_Rectification mode) ;
HLPRX_API NDTS_Boolean HLPRX_GetRectification(unsigned long stepIndex, RQ_Rectification *pMode) ; 


// Pulser interface to work with variable number of cards
HLPRX_API NDTS_Boolean HLPRX_GetNumberOfChannels(unsigned long *numberOfChannels) ;
HLPRX_API NDTS_Boolean HLPRX_SetTransmitChannel(unsigned long stepIndex, unsigned long channelIndex) ;
HLPRX_API NDTS_Boolean HLPRX_SetStepToParallelFire(unsigned long stepIndex) ;
HLPRX_API NDTS_Boolean HLPRX_SetReceiveChannel(unsigned long stepIndex, unsigned long channelIndex) ;
HLPRX_API NDTS_Boolean HLPRX_SetChannelPulseEchoOrThroughTransmission(unsigned long channelIndex, NDTS_Boolean isPulseEcho) ;



#ifdef __cplusplus
}
#endif

#endif
