#ifndef  _PROTOCOL_Optics
#define  _PROTOCOL_Optics

#ifdef _OT_CPP_
#undef _OT_CPP_
#endif

#define FP_MAXWAITTIME 2000
#define DELAY_TIME     150
///////////////////错误返回码////////////////////
#define FP_OK                0x00
#define FP_COMM_ERR          0x01
#define FP_NO_FINGER         0x02
#define FP_GET_IMG_ERR       0x03
#define FP_FP_TOO_DRY        0x04
#define FP_FP_TOO_WET        0x05
#define FP_FP_DISORDER       0x06
#define FP_LITTLE_FEATURE    0x07
#define FP_NOT_MATCH         0x08
#define FP_NOT_SEARCHED      0x09
#define FP_MERGE_ERR         0x0a
#define FP_ADDRESS_OVER      0x0b
#define FP_READ_ERR          0x0c
#define FP_UP_TEMP_ERR       0x0d
#define FP_RECV_ERR          0x0e
#define FP_UP_IMG_ERR        0x0f
#define FP_DEL_TEMP_ERR      0x10
#define FP_CLEAR_TEMP_ERR    0x11
#define FP_SLEEP_ERR         0x12
#define FP_INVALID_PASSWORD  0x13
#define FP_RESET_ERR         0x14
#define FP_INVALID_IMAGE     0x15
#define FP_HANGOVER_UNREMOVE 0X17
 

///////////////缓冲区//////////////////////////////
#define CHAR_BUFFER_A          0x01
#define CHAR_BUFFER_B          0x02
#define MODEL_BUFFER           0x03

//////////////////串口号////////////////////////
#define COM1                   0x01
#define COM2                   0x02
#define COM3                   0x03

//////////////////波特率////////////////////////
#define BAUD_RATE_9600         0x00
#define BAUD_RATE_19200        0x01
#define BAUD_RATE_38400        0x02
#define BAUD_RATE_57600        0x03   //default
#define BAUD_RATE_115200       0x04

#define MAX_PACKAGE_SIZE_ 350   //数据包最大长度
//#define CHAR_LEN		1024	//512->1024 [2009.11.12]

#ifdef _OT_CPP_
extern "C"
{
#endif

	typedef struct {
		UINT16 year;
		UINT8 month;
		UINT8 day;
		UINT8 week;
		UINT8 hour;
		UINT8 minute;
		UINT8 second;
	}DATA_FORM;

	//==============================================================================//
	int WINAPI	FPGetUSBDevNum(int* iNums);//获取 FG_USB 设备数
	int WINAPI	FPGetUDiskNum(int* iNums); //获取 UDISK 设备数
	int WINAPI	FPOpenDeviceEx(HANDLE* pHandle, int nDeviceType,int iCom=1,int iBaud=1,int nPackageSize=2,int iDevNum=0);
	int WINAPI	FPCloseDeviceEx(HANDLE hHandle);
//	int WINAPI	FPGetPacketSize(HANDLE);
	int WINAPI  JFPetPackSize(HANDLE hHandle=NULL, int nPackSize=2);
	int WINAPI	FPAutoOpen(HANDLE* pHandle,int *type, int nAddr=0xFFFFFFFF,UINT uPwd=0x00,int bVfy=1);
	//==============================================================================//
	///////////////////////////////////////////////
	//////             指令                  //////
	///////////////////////////////////////////////
	//检测手指并录取图像
	int WINAPI	FPGetImage(HANDLE hHandle,int nAddr);
	int WINAPI	FPGetImageEx(HANDLE hHandle,int nAddr);
	int WINAPI	FPGetImage_Enroll(HANDLE hHandle,int nAddr);	// 0x29 注册时获取图像	//2010.6.25 blue
	
	//根据原始图像生成指纹特征
	int WINAPI	FPGenChar(HANDLE hHandle,int nAddr,int iBufferID);
	int WINAPI	FPGenCharEx(HANDLE hHandle,int nAddr,int iBufferID);
	
	//精确比对CharBufferA与CharBufferB中的特征文件
	int WINAPI	FPMatch(HANDLE hHandle,int nAddr,int* iScore);
	
	//以CharBufferA或CharBufferB中的特征文件搜索整个或部分指纹库
//	int WINAPI	FPSearch(HANDLE hHandle,int nAddr,int iBufferID, int iStartPage, int iPageNum, int *iMbAddress);
	int WINAPI	FPSearch(HANDLE hHandle,int nAddr,int iBufferID, int iStartPage, int iPageNum, int *iMbAddress,int *iscore=NULL);
	
	//将CharBufferA与CharBufferB中的特征文件合并生成模板存于ModelBuffer
	int	WINAPI	FPRegModule(HANDLE hHandle,int nAddr);
	
	//将ModelBuffer中的文件储存到flash指纹库中
	int WINAPI	FPStoreChar(HANDLE hHandle,int nAddr,int iBufferID, int iPageID);
	
	//从flash指纹库中读取一个模板到ModelBuffer
	int WINAPI	FPLoadChar(HANDLE hHandle,int nAddr,int iBufferID,int iPageID);
	
	//将特征缓冲区中的文件上传给上位机
	int WINAPI	FPUpChar(HANDLE hHandle,int nAddr,int iBufferID, unsigned char* pTemplet, int* iTempletLength);
	
	//从上位机下载一个特征文件到特征缓冲区
	int WINAPI	FPDownChar(HANDLE hHandle,int nAddr,int iBufferID, unsigned char* pTemplet, int iTempletLength);
	int WINAPI  FPDownChar_Test(HANDLE hHandle,int nAddr,int iBufferID, unsigned char* pTemplet, int iTempletLength,int nAddr1,int ipack=MAX_PACKAGE_SIZE_,WORD whead=0xEF01,WORD wCheck=0x0000,int iErr=0);

	//上传原始图像
	int WINAPI	FPUpImage(HANDLE hHandle,int nAddr,unsigned char* pImageData, int* iImageLength);

	//上传图像，多次
	int WINAPI	FPUpImageEx(HANDLE hHandle,int nAddr,int imgwidth,int imgheight,unsigned char* pImageData, int* iImageLength);
	
	int WINAPI	FPUpImages(HANDLE hHandle, int nAddr,int offset, unsigned char* pImageData, int iImageLength);

	//下载原始图像
	int WINAPI	FPDownImage(HANDLE hHandle,int nAddr,unsigned char *pImageData, int iLength);
	
	//上传原始图像
	int WINAPI	FPImgData2BMP(unsigned char* pImgData,const char* pImageFile);
	
	//下载原始图像
	int WINAPI	FPGetImgDataFromBMP(HANDLE hHandle,const char *pImageFile,unsigned char *pImageData,int *pnImageLen);
	
	//删除flash指纹库中的一个特征文件
	int WINAPI	FPDelChar(HANDLE hHandle,int nAddr,int iStartPageID,int nDelPageNum);
	
	//清空flash指纹库
	int WINAPI	FPEmpty(HANDLE hHandle,int nAddr);
	
	//读参数表
	int WINAPI	FPReadParTable(HANDLE hHandle,int nAddr,unsigned char* pParTable);

	//++读Flash
	int WINAPI	FPReadInfPage(HANDLE hHandle,int nAddr, unsigned char* pInf);

	//++高速搜索
//	int WINAPI	FPHighSpeedSearch(HANDLE hHandle,int nAddr,int iBufferID, int iStartPage, int iPageNum, int *iMbAddress);
	int WINAPI	FPHighSpeedSearch(HANDLE hHandle,int nAddr,int iBufferID, int iStartPage, int iPageNum, int *iMbAddress,int *iscore=NULL);

	//++读有效模板个数
	int WINAPI	FPTemplateNum(HANDLE hHandle,int nAddr,int *iMbNum);

	//++指纹图细化
	int WINAPI	FPGenBinImage(HANDLE hHandle,int nAddr, int nImgType);
	
	//休眠指令
	int WINAPI	FPPowerDown(HANDLE hHandle,int nAddr);
	
	//设置设备握手口令
	int WINAPI	FPSetPwd(HANDLE hHandle,int nAddr,unsigned char* pPassword);
	
	//验证设备握手口令
	int WINAPI	FPVfyPwd(HANDLE hHandle,int nAddr,unsigned char* pPassword);
	
	//系统复位，进入上电初始状态
	int WINAPI	FPReset(HANDLE hHandle,int nAddr);
		
	//读记事本
	int WINAPI	FPReadInfo(HANDLE hHandle,int nAddr,int nPage,unsigned char* UserContent);
	
	//写记事本
	int WINAPI	FPWriteInfo(HANDLE hHandle,int nAddr,int nPage,unsigned char* UserContent);

	//++注册模板
	int WINAPI	FPEnroll(HANDLE hHandle,int nAddr,int* nID);
	
	//++写模块寄存器
	int WINAPI	FPWriteReg(HANDLE hHandle,int nAddr,int iRegAddr,int iRegValue);
	//写模块寄存器－波特率设置
	int WINAPI	FPSetBaud(HANDLE hHandle,int nAddr,int nBaudNum);
	//写模块寄存器－安全等级设置
	int WINAPI	FPSetSecurLevel(HANDLE hHandle,int nAddr,int nLevel);
	//写模块寄存器－数据包大小设置
	int WINAPI	FPSetPacketSize(HANDLE hHandle,int nAddr,int nSize);
	
	int WINAPI	FPUpChar2File(HANDLE hHandle,int nAddr,int iBufferID, const char* pFileName);
	int WINAPI	FPDownCharFromFile(HANDLE hHandle,int nAddr,int iBufferID, const char* pFileName);
	
	//获取随机数
	int WINAPI	FPGetRandomData(HANDLE hHandle,int nAddr,unsigned char* pRandom);

	//设置芯片地址
	int WINAPI	FPSetChipAddr(HANDLE hHandle,int nAddr,unsigned char* pChipAddr);

	//++自动验证指纹
	int WINAPI	FPIdentify(HANDLE hHandle,int nAddr,int *iMbAddress);
	
	int WINAPI	FPDoUserDefine(HANDLE hHandle,int nAddr,int GPIO,int STATE);

	///////////////////////////////////////////////////////////////////////++2008-12-12
	int WINAPI	FPUpdatOnline(HANDLE hHandle,int nAddr,unsigned char *pImageData, int iLength);
	int WINAPI	FPBurnCode(HANDLE hHandle,int nAddr,int nType,unsigned char *pImageData, int iLength);
	int WINAPI	FPPortControl(HANDLE hHandle,int nAddr,BOOL bOpen);
	int WINAPI	FPFingerData2BMPData(unsigned char *pFingerData, unsigned char *pBMPData,int* nBMPDataLen);
	int WINAPI	FPShowFingerData(HWND hWnd,unsigned char *pFingerData);
	///////////////////////////////////////////////////////////////////////++

	//读模版索引表	nPage,0,1,2,3对应模版从0-256，256-512，512-768，768-1024
	int WINAPI	FPReadIndexTable(HANDLE hHandle,int nAddr,int nPage,unsigned char* UserContent);

	//自定义发送包	2009-03-04
	//pRecvData=NUll时，表示不分解获取数据
	int	WINAPI	FP_SB(HANDLE hHandle,int nAddr,unsigned char *pSendData,int iLen,unsigned char *pRecvData,int *pRecvLen,int flag=1);
	
	#define DEVICE_USB		0
	#define DEVICE_COM		1
	#define DEVICE_UDisk	2
	#define DEVICE_LBUSB	3

	#define IMAGE_X 256
	#define IMAGE_Y 288
	
	#define IMAGEISO_X 256
	#define IMAGEISO_Y 360
	
	#define IMAGEFPC_X 152
	#define IMAGEFPC_Y 200

	#define	IMGSIZE_SIZEFPC	30400
	#define	IMGSIZE_SIZESTD	73728
	#define	IMGSIZE_SIZEISO	92160

	//根据错误号获取错误信息
	char* WINAPI	FPErr2Str(int nErrCode);

	///////////////////////////////////////////////////////////////////////2010-03-26
	int	WINAPI	FPEnableTestMsg(int bEl_S, int bEl_R);
	void TestMsg(unsigned char *pData,int iLen,char* msg=NULL,int bRS=0);//bRS=0[SendData] 1[RecvData]
	///////////////////////////////////////////////////////////////////////

	//下载ELF解析的段数据到目标板 0x28 2010-09-03
	int WINAPI	FPDownElfData(HANDLE hHandle, int nAddr, int nAddr_Data, unsigned char* pElfData, int nLen, int nIdx=1, HWND hMsg=NULL,UINT msgid=1);
	int WINAPI	FPTestPro(HWND hMsg,UINT msgid,int tm=100);

	int WINAPI	FPCalibrateSensor(HANDLE hHandle,int nAddr);


	int WINAPI	FPSetUpConfig(HANDLE hHandle,int nAddr,BYTE imagefmt, BYTE isofmt);
	int WINAPI	FPGetUpConfig(HANDLE hHandle,int nAddr,BYTE *imagefmt, BYTE *isofmt);
	int WINAPI	FPSetUartDelay(HANDLE hHandle,int nAddr,int uartdelay);
	int WINAPI	FPSetBtName(HANDLE hHandle,int nAddr,BYTE* buffer,int size);
	int WINAPI	FPWifiDownload(HANDLE hHandle, int nAddr, BYTE bFlash);

	int WINAPI	FPGetDeviceModel(HANDLE hHandle,int nAddr,DWORD* uModel);
	int WINAPI	FPGetDeviceVersion(HANDLE hHandle,int nAddr,BYTE* bVersion);
	
	int WINAPI	FPSoundBeep(HANDLE hHandle, int nAddr, int beeptype);
	int WINAPI	FPCMosConfig(HANDLE hHandle, int nAddr, BYTE* cfgdat, int size);

	int WINAPI FPFlashReadID(HANDLE hHandle, int nAddr, BYTE * idbuf);
	int WINAPI FPFlashReadData(HANDLE hHandle, int nAddr, int readaddr, int readsize,BYTE * buffer);
	int WINAPI FPFlashWriteData(HANDLE hHandle, int nAddr, int writeaddr, int writesize, BYTE * buffer);
	


	int WINAPI	FPGetCardSN(HANDLE hHandle, int nAddr,BYTE* cardsn);
	int WINAPI	FPCardReadFull(HANDLE hHandle, int nAddr, BYTE* cardsn, int ctype, int sector, BYTE* password, BYTE * buffer, int size);
	int WINAPI	FPCardWriteFull(HANDLE hHandle, int nAddr, BYTE* cardsn, int ctype, int sector, BYTE* password, BYTE * buffer, int size);
	int WINAPI	FPCardReadSector(HANDLE hHandle, int nAddr, BYTE* cardsn, int sector, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardWriteSector(HANDLE hHandle, int nAddr, BYTE* cardsn, int sector, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardReadBlock(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardWriteBlock(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);

	int WINAPI	FPCardReadVal(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardWriteVal(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardIncVal(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);
	int WINAPI	FPCardDecVal(HANDLE hHandle, int nAddr, BYTE* cardsn, int block, BYTE* password, BYTE * buffer);

	int WINAPI	FPSetDateTime(HANDLE hHandle, int nAddr, BYTE* datetime, int size);

	int WINAPI	FPGetBtInfo(HANDLE hHandle, int nAddr, BYTE* buffer, int* size);

#ifdef _OT_CPP_
}
#endif

#endif                                                     