📄 finger.c
字号:
#include "reg58.h"
#include "intrins.h"
#define _FINGER_C_
#include "finger.h"
#include "rxd.h"
#include "timer.h"
#include "define.h"
//#include "keypad.h"
#include "inout.h"
#include "system.h"
#include "setup.h"
#include "user.h"
#include "373.h"
#include "keypad.h"
//unsigned short code comm_parameter[]=
//{
// 2,0,0,1024,4,1,0,0,2,480,0,0,16,16,16,16,
//};/
//unsigned short code ack_parameter[]=
//{
// 0,0,0,0,1024,0,0,480,0,0,0,0,0,16,2,
//};
bit getfimpackage(unsigned char cmd)
{
unsigned char temptime,tempcrchigh,tempcrclow;
unsigned short datalen;
temptime=timerh;
while((timerh-temptime)<TFIMRXDTIME)
{
if(rxd0packflag)
{
//unsigned char crclow,crchigh;
rxd0packflag=0;
datalen=(uart0buff[2]<<8)|uart0buff[1];
//datalen|=uart0buff[1];
tempcrclow=uart0buff[datalen+3];
tempcrchigh=uart0buff[datalen+4];
//tempbuff[0]=uart0buff[datalen+3];
//tempbuff[1]=uart0buff[datalen+4];
checkcrc(datalen+2);
//if((tempbuff[0]==uart0buff[datalen+3])&&(tempbuff[1]==uart0buff[datalen+4]))
if((tempcrclow==uart0buff[datalen+3])&&(tempcrchigh==uart0buff[datalen+4]))
{
if(uart0buff[PFIMRXDCOMM]!=cmd)return FALSE;
if(uart0buff[PFIMRETURN])return FALSE;
return TRUE;
}
else return FALSE;
}
}
return FALSE;
}
void fimrxdready()
{
rxd0packflag=0;
//rxd0len=0xffff;
}
bit rchecklink()
{
//rfimcommnp(RCHECKLINK);
//unsigned char code checklinkcmd[13]={0x81,0x08,00,00,00,00,00,01,00,01,00,0x4A,0x6C };
unsigned char code commbuff[13]={0x81,0x08,00,00,00,00,00,01,00,01,00,0x4A,0x6C };
//while(1)
//{
code2uart0(commbuff,13);
sendstring(13);
//}
fimrxdready();
return getfimpackage(RCHECKLINK);
//if(getfimpackage(RCHECKLINK))
//{
// if(uart0buff[PFIMRXDCOMM]!=RCHECKLINK)return FALSE;
// if(uart0buff[PFIMRETURN])return FALSE;
//}
}
bit rsetcommstate()
{
unsigned char code commbuff[13]={0x81,0x0a,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x04,0x00};
code2uart0(commbuff,13);
checkcrc(12);
sendstring(15);
fimrxdready();
return getfimpackage(RSETCOMMSTATE);
}
/*bit rmatchfinger()
{
rfimcommnp(RCAPTURECHECKIMAGE);
fimrxdready();
return getfimpackage(RMATCHFINGER);
//if(getfimpackage(RMATCHFINGER))
//{
// if(uart1buff[PFIMRXDCOMM]!=RMATCHFINGER)return FALSE;
// if(uart1buff[PFIMRETURN])return FALSE;
//}
//return TRUE;
}*/
bit rcapturecheckimage()
{
unsigned char code commbuff[11]={0x81,0x08,0x00,0x00,0x00,0x00,0x00,0x01,0x00,RCAPTURECHECKIMAGE,0x00};
code2uart0(commbuff,11);
checkcrc(10);
sendstring(13);
fimrxdready();
return getfimpackage(RCAPTURECHECKIMAGE);
}
/////////////////////////////////////////////////////////////////////
bit rextractfeature(unsigned char extractstep,unsigned char flag)
{
unsigned char code commbuff[13]={0x81,0x0a,0x00,0x00,0x00,0x00,0x00,0x01,0x00,REXTRACTFEATURE,0x00,0x00,0x00};
code2uart0(commbuff,13);
uart0buff[11]=extractstep;
uart0buff[12]=flag;
checkcrc(12);
sendstring(15);
fimrxdready();
return getfimpackage(REXTRACTFEATURE);
}
/////////////////////////////////////////////////////////////
bit radduser(unsigned char flag)
{
unsigned char code commbuff[]={0x81,41,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x20,0x00};
code2uart0(commbuff,11);
if(flag==ADDUSERNOFINGER)
{
//buffcopycomm((unsigned char*)puser,uart0buff+11,32);
uart0buff[PRFIMPARAM]=currentsn;
uart0buff[PRFIMPARAM+1]=currentsn>>8;
uart0buff[43]=0;
checkcrc(43);
sendstring(46);
}
else
{
uart0buff[43]=1;
uart0buff[PRFIMPARAM]=currentsn;
uart0buff[PRFIMPARAM+1]=currentsn>>8;
uart0buff[1]=0x09;
uart0buff[2]=0x02;
checkcrc(523);
sendstring(526);
}
fimrxdready();
return getfimpackage(RADDUSER);
}
////////////////////////////////////////////////
bit rdeletealluser()
{
unsigned char code commbuff[14]={0x81,0x09,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x21,0x00,0x00,0x98,0xBB};
code2uart0(commbuff,14);
sendstring(14);
fimrxdready();
return getfimpackage(RDELETEUSER);
}
/////////////////////////////////////////////////////////////////////
bit rdeleteuserbysn()
{
unsigned char code commbuff[17]={0x81,0x0e,0x00,0x00,0x00,0x00,0x00,0x01,0x00,RDELETEUSER,0x00,0x01,0x00,0x00,0x01,0x00,0xff};
code2uart0(commbuff,17);
uart0buff[13]=(unsigned char)currentsn;
uart0buff[15]=(unsigned char)(currentsn>>8);
checkcrc(16);
sendstring(19);
fimrxdready();
return getfimpackage(RDELETEUSER);
}
bit rgetuserbysn(unsigned char flag)
{
unsigned char code commbuff[18]={0x81,0x0f,0x00,0x00,0x00,0x00,0x00,0x01,0x00,RGETUSER,0x00,0x01,0x00,0x00,0x01,0x00,0xff,0x00};
code2uart0(commbuff,18);
uart0buff[13]=(unsigned char)currentsn;
uart0buff[15]=(unsigned char)(currentsn>>8);
if(flag!=ADDUSERNOFINGER)uart0buff[17]=1;
checkcrc(17);
sendstring(20);
fimrxdready();
if(getfimpackage(RGETUSER))
{
if(uart0buff[PAFIMPARAM])return FALSE;
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////////
bit capturecheckimage()
{
unsigned char temptime;
temptime=timerh;
while((timerh-temptime)<TFIMCAPTURETIME)
{
if(rcapturecheckimage())return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////////////////
bit registerfp()
{
displaymessage(LMTOREGISTERFP,LINE1);
displaymessage(LMPUTFPON,LINE2);
delayTimerh(TMSGWAITTIME);
if(!capturecheckimage()) return FALSE;
if(!rextractfeature(0,0)) return FALSE;
set_373(BEEPPORT);
delay60ms();
clr_373(BEEPPORT);
//if(!waitliftfinger()) return FALSE;
displaymessage(LMLIFTANDPUT,LINE1);
displaymessage(LMWAITTING,LINE2);
delayTimerh(TMSGWAITTIME);
set_373(BEEPPORT);
delay60ms();
clr_373(BEEPPORT);
if(!capturecheckimage()) return FALSE;
if(!rextractfeature(1,0)) return FALSE;
//if(!waitliftfinger()) return FALSE;
set_373(BEEPPORT);
delay60ms();
clr_373(BEEPPORT);
displaymessage(LMLIFTANDPUTAGAIN,LINE1);
displaymessage(LMWAITTING,LINE2);
delayTimerh(TMSGWAITTIME);
set_373(BEEPPORT);
delay60ms();
clr_373(BEEPPORT);
if(!capturecheckimage()) return FALSE;
if(!rextractfeature(2,0)) return FALSE;
if(!radduser(ADDUSERNOFINGER)) return FALSE;
set_373(BEEPPORT);
delay60ms();
clr_373(BEEPPORT);
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////
void init_finger()
{
//unsigned short usernum;
//if(!rchecklink())return FALSE;
//i/f(!rsetcommstate())return FALSE; //change baud rate to 38400
//while(!rcheckline());
//return TRUE;
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
delayTimerh(T500MS); //051017
if(!rchecklink())
{
}
else
{
rsetcommstate();
}
TR2=0;
delayTimerl(T5MS);
//TH1=253;
RCAP2L=0XEE;
delayTimerl(T5MS);
TR2=1;
}
//////////////////////////////////////////////////////////////
bit rfinduserbyfim()
{
unsigned char code commbuff[]={0x81,0x0a,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x28,0x00,0x00,0x00};
code2uart0(commbuff,13);
//uart0buff[13]=currentsn;
//uart0buff[15]=(currentsn>>8);
checkcrc(12),
sendstring(15);
fimrxdready();
return getfimpackage(RFINDUSER);
}
//////////////////////////////////////////////////////////////
bit rfinduserbysn()
{
unsigned char code commbuff[]={0x81,0x0f,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x28,0x00,0x01,0x00,0x00,0x01,0x00,0xff,0x00};
code2uart0(commbuff,18);
uart0buff[13]=currentsn;
uart0buff[15]=(currentsn>>8);
checkcrc(17),
sendstring(20);
fimrxdready();
return getfimpackage(RFINDUSER);
}
//////////////////////////////////////////////////////////////
//capture the finger and match the finger whoes sn is currentsn
bit captureandmatchuser()
{
displaymessage(LMWAITTING,LINE2);
displaymessage(LMPUTFINGER,LINE1);
delayTimerh(TMSGWAITTIME);
if(!capturecheckimage()) return FALSE;
if(!rextractfeature(3,0)) return FALSE;
if(!rfinduserbysn()) return FALSE;
return TRUE;
}
//////////////////////////////////////////////////////////////
//capture the finger and find the finger through all users
bit captureandfinduser()
{
displaymessage(LMWAITTING,LINE2);
displaymessage(LMPUTFINGER,LINE1);
delayTimerh(TMSGWAITTIME);
if(!capturecheckimage()) return FALSE;
if(!rextractfeature(3,0)) return FALSE;
//if(!rfinduserbysn()) return FALSE;
if(!rfinduserbyfim()) return FALSE;
return TRUE;
}
//////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -