📄 event.c
字号:
#include "reg58.h"
#include "intrins.h"
#define _EVENT_C_
#include "event.h"
#include "system.h"
#include "clock.h"
#include "finger.h"
#include "sram.h"
#include "define.h"
#include "timer.h"
#include "lcd.h"
#include "setup.h"
#include "inout.h"
#include "373.h"
#include "keypad.h"
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
unsigned char data eventtype;
/////////////////////////////////////////////////////////////////////////////////////////////
unsigned char code tblevent[]={LMACCESSGRANTED,LMACCESSDENIED,LMPASSWORDERR,LMFINGERERR,LMTSERROR,LMANTIPASSBACK,LMDOORERR};
/////////////////////////////////////////////////////////////////////////////////////////////
void accessevent(unsigned char message)
{
//struct eventdata idata* pevent;
//if(duressflag)message+=0x80;
if(message<EVENTINPUT)
{
if(duressflag)message+=0x80;
}
getdatetime();
tempbuff[0]=datetime[0];
tempbuff[1]=datetime[1];
tempbuff[2]=datetime[2];
tempbuff[3]=datetime[3];
tempbuff[4]=datetime[4];
tempbuff[5]=datetime[5];
tempbuff[6]=datetime[6];
tempbuff[7]=datetime[7];
tempbuff[8]=userid[0];
tempbuff[9]=userid[1];
tempbuff[10]=userid[2];
tempbuff[11]=userid[3];
tempbuff[12]=message;
//tempbuff[13]=0xff;
tempbuff[13]=readFunctions();
tempbuff[14]=0xff;
tempbuff[15]=0xff;
//rappendrecord();
if((message&0x7f)>=EVENTINPUT)
{
tempbuff[8]=0xff;
tempbuff[9]=0xff;
tempbuff[10]=0xff;
tempbuff[11]=0xff;
}
appendevent();
if((message&0x7f)<EVENTINPUT)
{
displaymessage(LMBLANK,LINE1);
displaymessage(tblevent[message&0xf],LINE2);
//delayTimerh(T500MS);
delayTimerh(TMSGWAITTIME);
//displaymessage(LMMAIN,LINE1);
displayMain();
displaytime();
}
if((duressflag)&&((message&0X7F)<EVENTINPUT))
{
duressflag=0;
if(!(message&0x1f))message=OUTPUTDURESS;
}
else
{
switch(message)
{
case EVENTKEYPAD|MESSAGEGRANTED:message=OUTPUTR1IDOK;break;
case EVENTKEYPAD|MESSAGEDENIED:
case EVENTKEYPAD|MESSAGEPASSWORDERR:
case EVENTKEYPAD|MESSAGEFINGERERR:message=OUTPUTR1IDERR;break;
case EVENTKEYPAD|MESSAGETSERR:message=OUTPUTR1TSERR;break;
case EVENTKEYPAD|MESSAGEAPBERR:message=OUTPUTR1APBERR;break;
case EVENTREADER1|MESSAGEGRANTED:message=OUTPUTR1IDOK;break;
case EVENTREADER1|MESSAGEDENIED:
case EVENTREADER1|MESSAGEPASSWORDERR:
case EVENTREADER1|MESSAGEFINGERERR:message=OUTPUTR1IDERR;break;
case EVENTREADER1|MESSAGETSERR:message=OUTPUTR1TSERR;break;
case EVENTREADER1|MESSAGEAPBERR:message=OUTPUTR1APBERR;break;
case EVENTREADER2|MESSAGEGRANTED:message=OUTPUTR2IDOK;break;
case EVENTREADER2|MESSAGEDENIED:
case EVENTREADER2|MESSAGEPASSWORDERR:
case EVENTREADER2|MESSAGEFINGERERR:message=OUTPUTR2IDERR;break;
case EVENTREADER2|MESSAGETSERR:message=OUTPUTR2TSERR;break;
case EVENTREADER2|MESSAGEAPBERR:message=OUTPUTR2APBERR;break;
case EVENTINPUT|MESSAGEEXIT:message=OUTPUTEXIT;break;
case EVENTINPUT|MESSAGECONTACT:message=OUTPUTCONTACT;break;
case EVENTINPUT|MESSAGEAUX1:message=OUTPUTAUX1;break;
case EVENTINPUT|MESSAGEAUX2:message=OUTPUTAUX2;break;
case EVENTINPUT|MESSAGETAMPER:message=OUTPUTTAMPER;break;
default:message=0xff;break;
}
}
//duressflag=0;
if(message<=OUTPUTINOUT)
{
getiodata(message);
if(!(doorunlockflag&&doorontimer>=ALWAYSON))
{
if(tempbuff[0])
{
doorontimer=tempbuff[0];
doorunlockflag=1;
}
}
if(!(alarmonflag&&alarmontimer>=ALWAYSON))
{
if(tempbuff[1])
{
alarmontimer=tempbuff[1];
alarmonflag=1;
}
}
if(!(ttl1onflag&&ttl1ontimer>=ALWAYSON))
{
if(tempbuff[2])
{
ttl1ontimer=tempbuff[2];
ttl1onflag=1;
}
}
if(!(ttl2onflag&&ttl2ontimer>=ALWAYSON))
{
if(tempbuff[3])
{
ttl2ontimer=tempbuff[3];
ttl2onflag=1;
}
}
if(!(beeponflag&&beepontimer>=ALWAYSON))
{
if(tempbuff[4])
{
beepontimer=tempbuff[4];
beeponflag=1;
}
}
}
}
///////////////////////////////////////////////////////////////////////
void readevent(unsigned short itemcount)
{
itemcount+=PAGEEVENTSTART*16;
ram_read16(itemcount,itemcount>>8);
}
///////////////////////////////////////////////////////////////////////
/*void writeevent(unsigned short itemcount)
{
itemcount+=PAGEEVENTSTART*16;
ram_write16(itemcount,itemcount>>8);
}*/
///////////////////////////////////////////////////////////////////////
void appendevent()
{
unsigned short eventwrite,eventread;
eventwrite=readeventstop();
ram_write16(eventwrite+PAGEEVENTSTART*16,(eventwrite+(PAGEEVENTSTART*16))>>8);
eventwrite++;
if(eventwrite>=MAXEVENTNUM)eventwrite=0;
eventread=readeventstart();
//if(eventread==eventwrite)return FALSE;
if(eventread==eventwrite)
{
eventread++;
if(eventread>=MAXEVENTNUM)eventread=0;
}
ram_writep0(EVENTSTART,eventread);
ram_writep0(EVENTSTART+1,eventread>>8);
ram_writep0(EVENTSTOP,eventwrite);
ram_writep0(EVENTSTOP+1,eventwrite>>8);
//ram_write16(eventwrite,eventwrite>>8,(unsigned char idata * )pevent);
//return TRUE;
}
/////////////////////////////////////////////////////////////////////////
unsigned short getneweventnum()
{
unsigned short eventwrite,eventread;
eventwrite=sramgetshort(EVENTSTOP);
eventread=sramgetshort(EVENTSTART);
if(eventwrite<eventread)eventwrite+=MAXEVENTNUM;
return eventwrite-eventread;
}
/////////////////////////////////////////////////////////////////////////
/*bit getevent()
{
unsigned short recordstart;
recordstart=sramgetshort(EVENTSTART);
if(recordstart==sramgetshort(EVENTSTOP))return FALSE;
//ram_read16(recordstart,recordstart>>8);
readevent(recordstart);
return TRUE;
}*/
/////////////////////////////////////////////////////////////////////////
bit removeoneevent()
{
unsigned short eventwrite,eventread;
eventread=readeventstart();
eventwrite=readeventstop();
if(eventread==eventwrite)return FALSE;
eventread++;
if(eventread>=MAXEVENTNUM)eventread=0;
ram_writep0(EVENTSTART,eventread);
ram_writep0(EVENTSTART+1,eventread>>8);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
void clearevent()
{
ram_writep0(EVENTSTART,0);
ram_writep0(EVENTSTART+1,0);
ram_writep0(EVENTSTOP,0);
ram_writep0(EVENTSTOP+1,0);
}
/////////////////////////////////////////////////////////////////////////
bit getnewevent()
{
unsigned short eventstart,eventstop;
eventstart=readeventstart();
eventstop=readeventstop();
if(eventstart==eventstop)return FALSE;
readevent(eventstart);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
void accessok()
{
unsigned short eventcount,eventstop;
if(readapbmode())
{
eventstop=readeventstop();
for(eventcount=0;eventcount<MAXEVENTNUM;eventcount++)
{
if(eventstop==0)eventstop+=MAXEVENTNUM;
eventstop--;
readevent(eventstop);
if(datetime[DTYEAR]!=tempbuff[EVENTYEAR])break;
if(datetime[DTMON]!=tempbuff[EVENTMON])break;
if(datetime[DTDAY]!=tempbuff[EVENTDAY])break;
if(userid[0]!=tempbuff[EVENTUSERID0])continue;
if(userid[1]!=tempbuff[EVENTUSERID1])continue;
if(userid[2]!=tempbuff[EVENTUSERID2])continue;
if(userid[3]!=tempbuff[EVENTUSERID3])continue;
//if((tempbuff[EVENTMESSAGE]&0xf0)!=eventtype)break;//????
if(((tempbuff[EVENTMESSAGE]&0XF0)>=EVENTREADER2)&&(eventtype<EVENTREADER2))break; //here test if the inouttype is the same
if(((tempbuff[EVENTMESSAGE]&0XF0)<EVENTREADER2)&&(eventtype>=EVENTREADER2))break;
accessevent(eventtype|MESSAGEAPBERR);
return;
}
accessevent(eventtype|MESSAGEGRANTED);
}
else accessevent(eventtype|MESSAGEGRANTED);
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -