#ifndef Reader_InterfaceH
#define Reader_InterfaceH

//-------------------------------------------------------------
//Header-File for partial implementation of iid_driver_ce10.dll
//-------------------------------------------------------------
//-author: SJ / MSS--------------------------------------------
//-last modified: 2004-06-23-----------------------------------
//------2005-08-05 - modification to iiddrv30.dll (iID3000-----
//-------------------system)-----------------------------------
//------2007-07 - iID3000 PRO Sample code----------------------
//----------------mod. for iiddrv30_pro.dll--------------------
//-------------------------------------------------------------
//------2016-11-18 - updated for iiddrv30_pro.dll v0x10.0x55---
//-------------------------------------------------------------
//------2017-09-06 - updated for iiddrv30_pro.dll v0x10.0x57---
//-------------------------------------------------------------

//constants for setting masks for iID driver functions 
const	int GROUP_ISO15693	= 0x01;
const	int GROUP_IID_L		= 0x02;
const   int GROUP_IID_D		= 0x04;
const   int GROUP_IID_G		= 0x08;
const   int GROUP_64BITRO	= 0x10;
const	int GROUP_ICODEUID	= 0x20;
const	int GROUP_LEGICUID	= 0x40;
const	int GROUP_ICODE1	= 0x80;
const	int GROUP_MIFAREUL	= 0x100;
const	int GROUP_PICOTAG	= 0x200;
const	int GROUP_IIDK		= 0x800;
const	int GROUP_LEGICFS	= 0x40000000;
const	int GROUP_DEFAULT	= 0xFFF;

//define DLL-functions 
typedef HANDLE	(CALLBACK* MP_reader_open_interface) (LPTSTR lpszPort);
typedef BYTE	(CALLBACK* MP_reader_close_interface) (HANDLE hPort);
typedef HANDLE	(CALLBACK* MP_reader_get_port_state) (HANDLE hPort);
typedef BYTE	(CALLBACK* MP_reader_set_port_type) (BYTE porttype, LPTSTR lpszPort);
typedef BYTE	(CALLBACK* MP_reader_set_interface_type) (INT32 frequency);
typedef BYTE	(CALLBACK* MP_reader_set_protocol_type) (INT32 protocol);
typedef HANDLE  (CALLBACK* MP_reader_get_handle) ();
typedef BYTE    (CALLBACK* MP_driver_set_timeout) (INT32 NewTimeOut);
typedef INT32   (CALLBACK* MP_driver_get_timeout) ();
typedef BYTE    (CALLBACK* MP_driver_set_system_mask) (INT32 NewMask);
typedef INT32   (CALLBACK* MP_driver_get_system_mask) ();
typedef BYTE	(CALLBACK* MP_driver_get_driver_version)  (INT32* main_version, INT32* sub_version);

typedef BYTE	(CALLBACK* MP_driver_get_transponder_parameters) (INT32* tag_type, INT32* tag_max_length, INT32* tag_system, INT32* tag_extra_param, BYTE data[]); 
typedef BYTE	(CALLBACK* MP_driver_set_transponder_page) (INT32 Page);
typedef BYTE	(CALLBACK* MP_iso18000_6_c_read_epc_gen2) (HANDLE hPort, UINT32 driverParam, BYTE* numIDs, BYTE tagTypes[], BYTE lengths[], BYTE data[]);
typedef BYTE	(CALLBACK* MP_get_EPC_extended_parameter) ();
typedef BYTE	(CALLBACK* MP_set_EPC_extended_parameter) (BYTE extParameter);
typedef BYTE	(CALLBACK* MP_uii_decode) (UINT32 driverParam, UINT32 convertType, BYTE toDecode[], INT32 from, INT32 length, BYTE decoded[], INT32 *decodedLength);
typedef	BYTE	(CALLBACK* MP_iso18000_6_c_read_words) (HANDLE hPort, UINT32 driverParam, UINT32 stdParam, UINT32 dataBank, UINT32 address, UINT32 length, BYTE EPC_code[], BYTE a, BYTE read_data[]);
typedef BYTE	(CALLBACK* MP_iso18000_6_c_write_words) (HANDLE hPort, UINT32 driverParam, UINT32 stdParam, UINT32 dataBank, UINT32 address, UINT32 length, BYTE EPC_code[], BYTE bCodeLength, BYTE bData[]);

//type definitions for iid-driver-specification
typedef BYTE (CALLBACK* MP_initialize) ();
typedef BYTE (CALLBACK* MP_terminate) ();
//following 3 functions should not be used officially
typedef BYTE (CALLBACK* MP_readBytes) (BYTE identifier[],INT32 from,INT32 length,BYTE *pByteArray);
typedef BYTE (CALLBACK* MP_writeBytes) (BYTE identifier[],INT32 from,INT32 length,BYTE *pByteArray, BYTE lock);
typedef BYTE (CALLBACK* MP_identify) (BYTE *pByteArray);
typedef BYTE (CALLBACK* MP_read_reader_id) (INT32* reader_id, BYTE *pByteArray);

typedef BYTE (CALLBACK* MP_c_reader_set_auto_off_iid3000) (HANDLE m_HCom, BYTE setting);

typedef BYTE (CALLBACK* MP_iso18000_6_c_read_epc_rssi_gen2) (HANDLE m_HCom, UINT32 driverParam, BYTE* numIDs, BYTE tagTypes[], BYTE lengths[], BYTE data[], FLOAT rssiValues[]);
typedef BYTE (CALLBACK* MP_iso18000_6_c_read_words_secure) (HANDLE m_HCom, UINT32 driverParam, UINT32 stdParam, UINT32 dataBank, UINT32 dataAddress, UINT32 dataLength, BYTE EPC_code[], BYTE EPC_length, BYTE accessPassword[], BYTE readData[]);
typedef BYTE (CALLBACK* MP_iso18000_6_c_write_words_secure) (HANDLE m_HCom, UINT32 driverParam, UINT32 stdParam, UINT32 dataBank, UINT32 dataAddress, UINT32 dataLength, BYTE EPC_code[], BYTE EPC_length, BYTE accessPassword[], BYTE writeData[]);
typedef BYTE (CALLBACK* MP_iso18000_6_c_lock) (HANDLE m_HCom, UINT32 driverParam, UINT32 stdParam, UINT32 payload, BYTE EPC_code[], BYTE EPC_length);
typedef BYTE (CALLBACK* MP_iso18000_6_c_lock_secure) (HANDLE m_HCom, UINT32 driverParam, UINT32 stdParam, UINT32 payload, BYTE EPC_code[], BYTE EPC_length, BYTE accessPassword[]);
typedef BYTE (CALLBACK* MP_iso18000_6_c_write_epc_gen2) (HANDLE m_HCom, UINT32 driverParam, UINT32 stdParam, BYTE EPC_code[], BYTE EPC_length, BYTE newPC[], BYTE newEPC[], BYTE newEPClength, BYTE accessPassword[]);

typedef BYTE (CALLBACK* MP_c_get_extended_status_information) ();

typedef BYTE (CALLBACK* MP_uii_encode) (UINT32 driverParam, UINT32 convertType, BYTE toEncode[], INT32 from, INT32 length, BYTE encoded[], INT32* encodedLength);

typedef BYTE (CALLBACK* MP_set_AFI_mask) (BYTE afi);
typedef BYTE (CALLBACK* MP_get_AFI_mask) (BYTE* afi);

//Variables
MP_reader_open_interface PROC_reader_openinterface;
MP_reader_close_interface PROC_reader_closeinterface;
MP_reader_get_port_state PROC_reader_get_port_state;
MP_reader_set_port_type PROC_reader_set_port_type;
MP_reader_set_interface_type PROC_reader_set_interface_type;
MP_reader_set_protocol_type PROC_reader_set_protocol_type;
MP_reader_get_handle PROC_reader_get_handle;
MP_driver_set_timeout PROC_driver_set_timeout;
MP_driver_get_timeout PROC_driver_get_timeout;
MP_driver_set_system_mask PROC_driver_set_system_mask;
MP_driver_get_system_mask PROC_driver_get_system_mask;
MP_driver_get_driver_version PROC_driver_get_driver_version;

MP_driver_get_transponder_parameters PROC_driver_get_transponder_parameters;
MP_driver_set_transponder_page PROC_driver_set_transponder_page;
MP_iso18000_6_c_read_epc_gen2 PROC_iso18000_6_c_read_epc_gen2;
MP_get_EPC_extended_parameter PROC_get_EPC_extended_parameter;
MP_set_EPC_extended_parameter PROC_set_EPC_extended_parameter;
MP_uii_decode PROC_uii_decode;
MP_iso18000_6_c_read_words PROC_iso18000_6_c_read_words;
MP_iso18000_6_c_write_words PROC_iso18000_6_c_write_words;

//functions for iid-driver-specification
MP_initialize PROC_initialize;
MP_terminate PROC_terminate;
MP_readBytes PROC_readBytes;
MP_writeBytes PROC_writeBytes;
MP_identify PROC_identify;
MP_read_reader_id PROC_read_reader_id;
MP_c_reader_set_auto_off_iid3000 PROC_c_reader_set_auto_off_iid3000;

MP_iso18000_6_c_read_epc_rssi_gen2 PROC_iso18000_6_c_read_epc_rssi_gen2;
MP_iso18000_6_c_read_words_secure PROC_iso18000_6_c_read_words_secure;
MP_iso18000_6_c_write_words_secure PROC_iso18000_6_c_write_words_secure;
MP_iso18000_6_c_lock PROC_iso18000_6_c_lock;
MP_iso18000_6_c_lock_secure PROC_iso18000_6_c_lock_secure;
MP_iso18000_6_c_write_epc_gen2 PROC_iso18000_6_c_write_epc_gen2;

MP_c_get_extended_status_information PROC_c_get_extended_status_information;

MP_uii_encode PROC_uii_encode;

MP_get_AFI_mask PROC_get_AFI_mask;
MP_set_AFI_mask PROC_set_AFI_mask;

#endif

//global variables e.g. for Port-Handle
BYTE  ReadArray[100];
BYTE  WriteArray[100];
int	  Reader_Id, Reader_Ver;
int	  MSS_Result;
long  wait;	
int   MSS_Result_ext;

void SuccessBeep();
void FailBeep();

BOOL Init_Driver(LPTSTR lpszDriverName);


BOOL Init_Driver(LPTSTR lpszDriverName)
{
	
	HINSTANCE DLL_Handle;
	
	//---------- LINK DLL --------------------------
	DLL_Handle = NULL;
	DLL_Handle=LoadLibrary(lpszDriverName);
	if (DLL_Handle == NULL) return FALSE;

	PROC_reader_openinterface=(MP_reader_open_interface) GetProcAddress(DLL_Handle,_T("c_openinterface"));
	if (PROC_reader_openinterface==NULL) return FALSE;
	PROC_reader_closeinterface=(MP_reader_close_interface) GetProcAddress(DLL_Handle,_T("c_closeinterface"));
	if (PROC_reader_closeinterface==NULL) return FALSE;
	PROC_reader_get_port_state=(MP_reader_get_port_state) GetProcAddress(DLL_Handle,_T("c_get_port_state"));
	if (PROC_reader_get_port_state==NULL) return FALSE;
	PROC_reader_set_port_type=(MP_reader_set_port_type) GetProcAddress(DLL_Handle,_T("c_set_port_type"));
	if (PROC_reader_set_port_type==NULL) return FALSE;
	PROC_reader_set_interface_type=(MP_reader_set_interface_type) GetProcAddress(DLL_Handle,_T("c_set_interface_type"));
	if (PROC_reader_set_interface_type==NULL) return FALSE;
	PROC_reader_set_protocol_type=(MP_reader_set_protocol_type) GetProcAddress(DLL_Handle, _T("c_set_protocol_type"));
	if (PROC_reader_set_protocol_type==NULL) return FALSE;
	PROC_reader_get_handle=(MP_reader_get_handle) GetProcAddress(DLL_Handle,_T("c_get_handle"));
	if (PROC_reader_get_handle==NULL) return FALSE;
	PROC_driver_set_timeout=(MP_driver_set_timeout) GetProcAddress(DLL_Handle,_T("c_set_timeout"));
	if (PROC_driver_set_timeout==NULL) return FALSE;
	PROC_driver_get_timeout=(MP_driver_get_timeout) GetProcAddress(DLL_Handle,_T("c_get_timeout"));
	if (PROC_driver_get_timeout==NULL) return FALSE;
	PROC_driver_set_system_mask=(MP_driver_set_system_mask) GetProcAddress(DLL_Handle,_T("c_set_system_mask"));
	if (PROC_driver_set_system_mask==NULL) return FALSE;
	PROC_driver_get_system_mask=(MP_driver_get_system_mask) GetProcAddress(DLL_Handle,_T("c_get_system_mask"));
	if (PROC_driver_get_system_mask==NULL) return FALSE;
	PROC_driver_get_driver_version=(MP_driver_get_driver_version) GetProcAddress(DLL_Handle,_T("c_get_driver_version"));
	if (PROC_driver_get_driver_version==NULL) return FALSE;

	PROC_driver_get_transponder_parameters=(MP_driver_get_transponder_parameters) GetProcAddress(DLL_Handle, _T("c_get_transponder_parameters"));
	if (PROC_driver_get_transponder_parameters==NULL) return FALSE;
	PROC_driver_set_transponder_page=(MP_driver_set_transponder_page) GetProcAddress(DLL_Handle, _T("c_set_transponder_page"));
	if (PROC_driver_set_transponder_page==NULL) return FALSE;
	PROC_iso18000_6_c_read_epc_gen2=(MP_iso18000_6_c_read_epc_gen2) GetProcAddress(DLL_Handle, _T("iso18000_6_c_read_epc_gen2"));
	if (PROC_iso18000_6_c_read_epc_gen2==NULL) return FALSE;
	PROC_get_EPC_extended_parameter=(MP_get_EPC_extended_parameter) GetProcAddress(DLL_Handle, _T("c_get_EPC_extended_parameter"));
	if (PROC_get_EPC_extended_parameter==NULL) return FALSE;
	PROC_set_EPC_extended_parameter=(MP_set_EPC_extended_parameter) GetProcAddress(DLL_Handle, _T("c_set_EPC_extended_parameter"));
	if (PROC_set_EPC_extended_parameter==NULL) return FALSE;
	PROC_uii_decode=(MP_uii_decode) GetProcAddress(DLL_Handle, _T("c_uii_decode"));
	if (PROC_uii_decode==NULL) return FALSE;
	PROC_iso18000_6_c_read_words=(MP_iso18000_6_c_read_words) GetProcAddress(DLL_Handle, _T("iso18000_6_c_read_words"));
	if (PROC_iso18000_6_c_read_words==NULL) return FALSE;
	PROC_iso18000_6_c_write_words=(MP_iso18000_6_c_write_words) GetProcAddress(DLL_Handle, _T("iso18000_6_c_write_words"));
	if (PROC_iso18000_6_c_write_words==NULL) return FALSE;

	//general instructions for SAP-interface
	PROC_initialize=(MP_initialize) GetProcAddress(DLL_Handle,_T("c_initialize"));
	if (PROC_initialize==NULL) return FALSE;
	PROC_terminate=(MP_terminate) GetProcAddress(DLL_Handle,_T("c_terminate"));
	if (PROC_terminate==NULL) return FALSE;
	PROC_readBytes=(MP_readBytes) GetProcAddress(DLL_Handle,_T("c_readbytes"));
	if (PROC_readBytes==NULL) return FALSE;
	PROC_writeBytes=(MP_writeBytes) GetProcAddress(DLL_Handle,_T("c_writebytes"));
	if (PROC_writeBytes==NULL) return FALSE;
	PROC_identify=(MP_identify) GetProcAddress(DLL_Handle,_T("c_identify"));
	if (PROC_identify==NULL) return FALSE;
	PROC_read_reader_id=(MP_read_reader_id) GetProcAddress(DLL_Handle,_T("c_read_reader_id"));
	if (PROC_read_reader_id==NULL) return FALSE;

	PROC_c_reader_set_auto_off_iid3000=(MP_c_reader_set_auto_off_iid3000) GetProcAddress(DLL_Handle,_T("c_reader_set_auto_off_iid3000"));
	if (PROC_c_reader_set_auto_off_iid3000==NULL) return FALSE;

	PROC_iso18000_6_c_read_words_secure=(MP_iso18000_6_c_read_words_secure) GetProcAddress(DLL_Handle, _T("iso18000_6_c_read_words_secure"));
	if (PROC_iso18000_6_c_read_words_secure == NULL) return FALSE;
	PROC_iso18000_6_c_write_words_secure = (MP_iso18000_6_c_write_words_secure) GetProcAddress(DLL_Handle, _T("iso18000_6_c_write_words_secure"));
	if (PROC_iso18000_6_c_write_words_secure == NULL) return FALSE;
	PROC_iso18000_6_c_lock = (MP_iso18000_6_c_lock) GetProcAddress(DLL_Handle, _T("iso18000_6_c_lock"));
	if (PROC_iso18000_6_c_lock == NULL) return FALSE;
	PROC_iso18000_6_c_lock_secure = (MP_iso18000_6_c_lock_secure) GetProcAddress(DLL_Handle, _T("iso18000_6_c_lock_secure"));
	if (PROC_iso18000_6_c_lock_secure == NULL) return FALSE;
	PROC_iso18000_6_c_write_epc_gen2 = (MP_iso18000_6_c_write_epc_gen2) GetProcAddress(DLL_Handle, _T("iso18000_6_c_write_epc_gen2"));
	if (PROC_iso18000_6_c_write_epc_gen2 == NULL) return FALSE;
	PROC_c_get_extended_status_information = (MP_c_get_extended_status_information) GetProcAddress(DLL_Handle, _T("c_get_extended_status_information"));
	if (PROC_c_get_extended_status_information == NULL) return FALSE;
	PROC_iso18000_6_c_read_epc_rssi_gen2=(MP_iso18000_6_c_read_epc_rssi_gen2) GetProcAddress(DLL_Handle, _T("iso18000_6_c_read_epc_rssi_gen2"));
	if (PROC_iso18000_6_c_read_epc_rssi_gen2==NULL) return FALSE;
	
	PROC_uii_encode = (MP_uii_encode) GetProcAddress(DLL_Handle, _T("c_uii_encode"));
	if (PROC_uii_encode == NULL) return FALSE;

	PROC_get_AFI_mask = (MP_get_AFI_mask) GetProcAddress(DLL_Handle, _T("c_get_AFI_mask"));
	if (PROC_get_AFI_mask == NULL) return FALSE;
	PROC_set_AFI_mask = (MP_set_AFI_mask) GetProcAddress(DLL_Handle, _T("c_set_AFI_mask"));
	if (PROC_set_AFI_mask == NULL) return FALSE;

	return TRUE;
}