#pragma once

#ifndef _AraTrustFinger_H_
#define _AraTrustFinger_H_

#include "Windef.h"
#include "stdafx.h"
#include "crc.h"

#define DEVICE_MODEL_A400		400	//A400 device


//return code
//General code
#define  GEN_SUCCEDED				   0    //OK 
#define  GEN_PARAM_NULL				   10    //参数内存分配为空

#define  GEN_PAR_ERR				-900	//参数错误，给定函数的参数有错误。
#define  GEN_MEM_ERR				-901	//内存分配失败，没有分配到足够的内存。
#define  GEN_FUC_FAIL				-902	//功能未实现，或不支持该功能
#define  GEN_ILLEGAL_ERR			-903	//非法的错误号。
#define  GEN_FIRMWARE_ERR			-904	//FIRMWARE Error
#define  GEN_INIT_FAIL              -905    //Init fail
#define  GEN_OTHER_ERR				-910	//其他错误

//Device
#define  DEV_NOT_FIND				-100	//设备不存在。初始化的时候，检测到设备不存在。
#define  DEV_NOT_AUTHORIZE          -101    //设备没有授权
#define  DEV_NOT_INIT				-102	//环境未初始化。
#define  DEV_NOT_OPEN				-103	//设备未打开。
#define  DEV_NOT_SUPPORT			-104	//Device not support

#define  DEV_LED_FAIL               -106    //Call Device LED fail
#define  DEV_BEGIN_FAIL				-110	//准备采集一帧图像失败，当前正在获取图像中
#define  DEV_NOT_CALL_BEGIN	        -111	//未调用准备一帧图像
#define  DEV_GET_IMA_FAIL			-112	//获取图像失败
#define  DEV_GET_IMA_TIMEOUT		-113	//获取图像超时
#define  DEV_OCCUPY_OTHER		    -114	//被其它进程或线程占用
#define  SDK_INIT_DONE		        -115	//SDK inited done
#define  DEVICE_OPENED		        -117	//device inited done
#define  DEVICE_DESC_FAIL		    -118	//get device description fail
#define  DEV_COMMUNICATE_FAIL       -119    //设备通讯失败
#define  DEV_COMMUNICATE_UNSUPPORT  -120    //设备通讯协议不支持
#define  DEV_INSTRUCTION_ERROR      -121    //指令错误
#define  DEV_ENCODE_FAIL            -122    //编码失败
#define  DEV_DECODE_FAIL            -123    //解码失败
#define  DEV_TOO_DRY                -124    //设备太干
#define  DEV_TOO_WET                -125    //设备太湿
#define  DEV_LITTLE_FEATURE         -126    //特征太少
#define  DEV_LIVE_CAPTURING         -127    //实时采集运行中
#define  DEV_LIVE_NOT_BEGIN         -128    //实时采集未开始
#define  DEV_LFD_FAIL               -129    //EnableLFD fail
#define  DEV_FAKE_FINGERPRINT       -130    //Fake Fingerprint
#define  DEV_UNKNOWN_FINGERPRINT    -131    //Unknown Fingerprint
#define  DEV_NO_FINGERPRINT         -132    //No Fingerprint
#define  DEV_LIVE_ENDLIVECAPTURE      11    //实时采集结束

//Arithmetic
#define   ALG_INIT_FAIL		        -200 	//初始化指纹算法失败
#define   ALG_NO_WSQ                -201    //没有WSQ算法库
#define   ALG_RAWTOWSQ_FAIL         -202    //原始图像转WSQ错误
#define   ALG_NO_NFIQ               -203    //no NFIQ lib
#define   ALG_RAWTOISO_FAIL         -204    //RAW to ISO fail
#define   ALG_RAWTOANSI_FAIL        -205    //RAW to ANSI fail
#define   ALG_IMG_BUF_NO_DATA		-210	//图像缓冲区没有有效指纹数据
#define   ALG_IMG_QUALITY_LOW		-211	//图像质量太差
#define   ALG_INVALID_BMP_DATA		-212    //不是有效的BMP数据
#define   ALG_BIONE_NOT_INIT        -220	//算法库未初始化
#define   ALG_EXTRACT_FEATURE_FAIL  -221	//提取指纹特征失败
#define   ALG_GEN_TEMPLATE_FAIL     -222	//生成指纹模板失败




typedef struct _ARAFP_DEVICEDESC
{
	char serialNumber[32]; /* Device serial number */
	char manufacturer[32]; /* manufacturer */
	char productName[64]; /* Device product name */
	char productModel[32]; /* Device product model */
	char fwVersion[32]; /* Device firmware version */
	char hwVersion[32]; /* Device revision */

	int imageWidth; /*Device capture max image width*/
	int imageHeight;/*Device capture max image height*/
	int Dpi; /*Device capture max image DPI*/
	unsigned short deviceId; /*Device id*/

	bool isUSBSupported; // device support USE connected type or not
	bool isUARTSupported; //device suppport UART or not
	bool isSPISupported; //device support SPI or not
	bool isLedSupported; //device support led or not
}ARAFP_DevDesc;


int __stdcall ARAFPSCAN_GlobalInit();

int __stdcall ARAFPSCAN_GlobalFree();

int __stdcall ARAFPSCAN_GetDeviceCount(int *nDeviceCount);

int __stdcall ARAFPSCAN_OpenDevice(HANDLE *nHandle,int nIndex);

int __stdcall ARAFPSCAN_CloseDevice(HANDLE *nHandle);

int __stdcall ARAFPSCAN_GetDeviceDescription(const int deviceIndex, ARAFP_DevDesc *pDeviceDesc);

int __stdcall ARAFPSCAN_GetImageInfo(HANDLE nHandle, int *pnWidth, int *pnHeight, int *pnDpi);

int __stdcall ARAFPSCAN_CaptureRawData(HANDLE nHandle, int nTimeout, unsigned char *pRawData);

int __stdcall ARAFPSCAN_CaptureBitmapData(HANDLE nHandle, int nTimeout, unsigned char *pBmpData);

int __stdcall ARAFPSCAN_CaptureISOData(HANDLE nHandle, int nTimeout, int FingerPos, int Imgcompressalg, unsigned char *ISOImgData, int *pLenOutput);

int __stdcall ARAFPSCAN_CaptureANSIData(HANDLE nHandle, int nTimeout, int FingerPos, int Imgcompressalg, unsigned char *ISOImgData, int *pLenOutput);

int __stdcall ARAFPSCAN_SetLedStatus(HANDLE nHandle, int nLedIndex, int pStatus);

int __stdcall ARAFPSCAN_GetLedStatus(HANDLE nHandle, int nLedIndex, int *pnStatus);
 
int __stdcall ARAFPSCAN_ExtractFeature(HANDLE nHandle, int cFingerPos, unsigned char * pFeatureData);

int __stdcall ARAFPSCAN_ExtractANSIFeature(HANDLE nHandle, int cFingerPos, unsigned char * pFeatureData);

int __stdcall ARAFPSCAN_ExtractISOFeature(HANDLE nHandle, int cFingerPos, unsigned char * pFeatureData);

int __stdcall ARAFPSCAN_GeneralizeTemplate(HANDLE nHandle,
	unsigned char * pFeatureData1,
	unsigned char * pFeatureData2,
	unsigned char * pFeatureData3,
	unsigned char * pTemplateData);

int __stdcall ARAFPSCAN_RawToBitmap(unsigned char* pRawData,
	unsigned char* pBmpData,
	int nWidth, int nHeight);

int __stdcall ARAFPSCAN_RawToWSQ(unsigned char* pRawData,
	int nWidth, int nHeight, int dpi, double bitrate, unsigned char* pWSQData, int* lengthWSQ);

int __stdcall ARAFPSCAN_BitmapToRaw(unsigned char* pBmpData,
	unsigned  char* pRawData,
	int pnWidth, int pnHeight);

int __stdcall ARAFPSCAN_GetErrorInfo(int nErrorNo, char pszErrorInfo[256]);

int __stdcall ARAFPSCAN_ImgQuality(int width, int height, BYTE *ipImage, BYTE *Quality);

int __stdcall ARAFPSCAN_GetNFIQScore(int width, int height, BYTE *ipImage, BYTE *Quality);

int __stdcall ARAFPSCAN_Verify(HANDLE nHandle, int Security_Level, unsigned char * pFeatureData, unsigned char * pTemplateData, int *sc,int *presult);

int __stdcall ARAFPSCAN_EnableLFD(HANDLE nHandle, bool pEnableLFD, int LFD_Level);

int __stdcall ARAFPSCAN_BeginLiveCapture(HANDLE nHandle);

int __stdcall ARAFPSCAN_LiveCaptureRawData(HANDLE nHandle, unsigned char *pRawData);

int __stdcall ARAFPSCAN_LiveCaptureBitmap(HANDLE nHandle, unsigned char *pBmpData);

int __stdcall ARAFPSCAN_EndLiveCapture(HANDLE nHandle);
#endif