⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readermodule.c.bak

📁 Use this program to decode the Manchester Code of the RFID. Validate the accessibility of detected c
💻 BAK
📖 第 1 页 / 共 5 页
字号:
    	write_eeprom_bytes(3,SystemDatabase.MasterPin[2]);

	write_eeprom_bytes(6,SystemDatabase.DoorOpenTime);
    	write_eeprom_bytes(7,SystemDatabase.LockReleaseTime);   

    	for (i=0;i<MAX_PINNO;i++)
    	{
		write_eeprom_bytes(12+2*i,SystemDatabase.AutoPin [i][0] );	//100504
    		write_eeprom_bytes(13+2*i,SystemDatabase.AutoPin [i][1] );	    //100504		
    	}
 
    	beep(4);	
}
/*****************************************************************************************************
Get all the System DB out from the eeprom, usually take place after system restart or reset
******************************************************************************************************/
void GetSysDB (void)
{
	idata unsigned char i;
	
	SystemDatabase.OperationMode   = get_eeprom_bytes(0);
    	SystemDatabase.MasterPin[0]    = get_eeprom_bytes(1);

	SystemDatabase.MasterPin[1]    = get_eeprom_bytes(2);
    	SystemDatabase.MasterPin[2]    = get_eeprom_bytes(3);

    	SystemDatabase.DoorOpenTime    = get_eeprom_bytes(6);
    	SystemDatabase.LockReleaseTime = get_eeprom_bytes(7); 
    	
    	for(i=0;i<MAX_PINNO;i++)
    	{
	  	SystemDatabase.AutoPin [i][0]  = get_eeprom_bytes(12+2*i);
    		SystemDatabase.AutoPin [i][1]  = get_eeprom_bytes(13+2*i);  
	}	
}
/********************** End EEprom *****************************/
/*************************************************************************************
Restore cardpos value to default -12/20/2005 10:27PM
**************************************************************************************/
void RestoreCardPos(void)
{
	idata unsigned char addressbyte;
	
	cardpos_last=START_CARD_ADD;//MAX_CARD_PAGE;	//12/20/2005 2:43PM
	addressbyte=high_byte(cardpos_last);	//12/18/2005 2:45PM
        write_eeprom_bytes(8, addressbyte);//12/18/2005 2:45PM
        write_eeprom_bytes(9, (unsigned char)cardpos_last);//12/18/2005 2:45PM
	
}
char stobcd(char * s, char* bcdstr, char start, char end)
{
unsigned char	i, j;

    i = start - end + 1;
    if (i & 0x01 || i < 2)
       return 0;

    for (i=start, j=0; i<=end; j++)
    {
	bcdstr [j] =  ((s[i++]-'0') << 4) & 0xf0;
	bcdstr [j] |= (s[i++]-'0') & 0x0f;
    }

    return 1;
}
unsigned char IsGoodDigitStr (char *buf, unsigned char start, unsigned char end)
{
	for (;start <= end ; start++)
    	{
    		if (buf [start] <'0' || buf [start] >'9')
    		{	
           		put_c('W');
           		return 0;
           	}	
    	}
    	return 1;
}
char Mystrncmp (unsigned char* str1, unsigned char *str2, unsigned char n)
{
char i;

    for (i=0;i<n;i++)
    	if (str1[i] != str2[i])
           return 0;

    return 1;
}
void ShowMainEntered (void)
{
	beep(3);	
	flush_keypad();
	Flags.WaitingKey = 1;
	ReloadKeyTimeOut();

}
char GetDigit (unsigned char * ddata, char NoofDigit)
{
	if (key_count >= NoofDigit)
    	{
	    	if (IsGoodDigitStr(KeyChar, 0, NoofDigit - 1))
	        {
	        	stobcd(KeyChar, ddata, 0, NoofDigit - 1);
	            	flush_keypad();
	            	ReloadKeyTimeOut();
	            	return 1;
	        }	        
        	//ShowError();
        	return 0;
    	}
    	return 9;
}
unsigned char stoshort(char * s, char start, char end)
{
unsigned char	a=0;
	end=0;		//kk add 
	a  = (*(s+start) << 4) & 0xf0;
    	a |= *(s+start+1) & 0x0f;

	return a;
}
// max in BCD
char Get2Digit (unsigned char * ddata, unsigned char max)
{
unsigned char  tbyte;

	if (key_count > 1)
    	{
    		if (IsGoodDigitStr(KeyChar, 0, 1))
        	{
	            	tbyte = stoshort(KeyChar, 0, 1);
	
	            	if (tbyte<=max)
	            	{
	        		*ddata = tbyte;
	            		return 1;
	            	}
        	}
        	ShowErrInMainEntered();
        	key_count       = 0;
        	return 0;
    	}
    	return 9;
}
void door_relay_on(void)
{
	//ALARMRELAY=RELAY_ON;	//1/10/2006 12:42PM
	DOORRELAY=RELAY_ON;	//ON
	LED_GREEN=LED_ON;	//indication
	return;	
}

void door_relay_off(void)
{
	//ALARMRELAY=RELAY_OFF;	//1/10/2006 12:42PM
	DOORRELAY=RELAY_OFF;
	LED_GREEN=LED_OFF;
	return;
}

unsigned char bcdtohex (unsigned char dat)
{
	return (( ((dat & 0xf0) >> 4) * 10) + (dat & 0x0f));
}
void turn_relay_on (void)
{
	if (SystemDatabase.LockReleaseTime> MAX_LOCK_RELEASE_TIME)
       		SystemDatabase.LockReleaseTime = MAX_LOCK_RELEASE_TIME;

    	if (SystemDatabase.DoorOpenTime > MAX_DOOR_OPEN_TIME)
        	SystemDatabase.DoorOpenTime = MAX_DOOR_OPEN_TIME;

	door_relay_duration     = bcdtohex (SystemDatabase.LockReleaseTime);
	dooropentime            = bcdtohex (SystemDatabase.DoorOpenTime);
	Flags.doorwasopened = 0;

	door_relay_on();
	beep (3);
    
}
/**************************************************************************************
Find the card from eeprom page 32 till MAX_CARD_PAGE 
update global variable =>cardpos-return the same position of the card found
***************************************************************************************/
unsigned char FindThisCard (void)
{
	idata unsigned int pg;

	for(pg=START_CARD_ADD; pg<=cardpos_last; pg+=4)//for(pg=32; pg<=MAX_CARD_PAGE;pg+=4)	//remember to put '=' in the actual 1
	{
		if(get_eeprom_bytes(pg)==gcrec.CardNo[0])	//2
			if(get_eeprom_bytes1()==gcrec.CardNo[1])
				if(get_eeprom_bytes1()==gcrec.CardNo[2])	//1
				{                            		         	    
					gcrec.Lockcount = get_eeprom_bytes1();	//get lock out count                            		     	    
					cardpos=pg;
					return 1;					
				}		
	}
	return 0;

    
}

char GetCardNoDetails (unsigned char * ddata, char NoofDigit)
{

	if (key_count >= NoofDigit)
    	{    		
    		if (IsGoodDigitStr(KeyChar, 0, NoofDigit - 1))
        	{
    			for (tempi=0;tempi<NoofDigit;tempi++)
            			ddata[tempi] = KeyChar[tempi];
            		
        		return 1;
        	}
        	
        	ShowErrInMainEntered();
        	
    	}
    	else if(key_count ==7)			//take care of single card install
	{	
		if(KeyChar[6]=='#')		//for keycount==7 we have 6 keys in. Check if install 1 card
		{
			for (tempi=0;tempi<6;tempi++)	//real card number
            			ddata[tempi] = KeyChar[tempi];
            		for (tempi=6;tempi<9;tempi++)	//pack "0001" for user for card install
            			ddata[tempi] = '0';
            		ddata[9] = '1';	
        		return 1;			
		}				
	}
    	return 0;
}

void mess_lcd(unsigned char lineno,unsigned char *str)
{
	lineno=0;
	CommPutStr(str);
}

char CheckAutoPin(void)
{
unsigned char idata ddata [5],i,rst;
	
	rst=GetDigit (ddata, 4);
	
	if (rst==1)
        {	  
	    	if (!ddata[0] && !ddata [1])	ShowError();
	    
	    	else
	    	{
	    		for (i=0;i<MAX_PINNO;i++)
			{
	
	            		if (Mystrncmp (SystemDatabase.AutoPin[i], ddata, 2))
	                  	{
					  turn_relay_on();
					  put_c('K');
					  beep(4);
					  ResetUserEvent();
	    				 return 1;	    					
	  			}
			}			
	    	}
	    	ShowError();
	    	ResetUserEvent();
	    	return 0;
	    	
	}
	else if(!rst)
	{	
		ShowError();	
		return 0;
	}
	else return 2;	
}

void CheckData (void)
{
unsigned char idata tvar, checkcard, ddata [5],rt;
    //kickdog();
        
	switch (SubMenuItem)
    	{
    		case 0 :Process_Card ();		
                				
                checkcard = 1;             //to make sure not card reading interefere in master mode
                			   //alarm arning mode and card plus pin mode		              
		if (key_count >= 3)
		{
        		if (KeyChar [0] == '#' && KeyChar [1] != '#' )
          	    	{   // Entering Master Pin
              	    		if (key_count >= 7)
				{
              	        		if (IsGoodDigitStr (KeyChar , 1, 6))
                        		{
        	                		checkcard = 0;
						stobcd(KeyChar, ddata, 1, 6);
						ResetUserEvent();
						if (!Mystrncmp (SystemDatabase.MasterPin, ddata, 3))
						{   //No								
							//CommPutStr("master pin error");	//kk test
						    	ShowError();						    	
						}
						else
						{   //ok								
							//CommPutStr("master pin correct");	//kk test
							ShowMainEntered ();
							SubMenuItem = 1;							
						}

                        		}
                    		}
                	}			
                        
                    	else if ((key_count >= 4) &&(SystemDatabase.OperationMode & O_AUTOPIN) 
                    		&& !(SystemDatabase.OperationMode & O_SECURITYOFF)) 
                  
			{
                		CheckAutoPin();
                		checkcard = 0;
                  	}
            	  }
         
                //original                
                if (checkcard && Flags.gnewcard)
                {
			if (!(SystemDatabase.OperationMode & O_SECURITYOFF))
                    	{
                	    	if((SystemDatabase.OperationMode & O_CARDnPIN) || (SystemDatabase.OperationMode & O_CARD))
                	    	{
	                	    	if (FindThisCard ())	//070604
	            			{
	                	    		if(SystemDatabase.OperationMode & O_CARDnPIN)
						{                	    			
	                    	    			ShowMainEntered ();
	                		    		SubMenuItem = 2;   
	                		    		checkcard = 0;                         		
	                		    	}
	                		    	else if(SystemDatabase.OperationMode & O_CARD)	
	                        		{
	                        			turn_relay_on();						
							put_c('I');	
							ResetUserEvent();	                    		                     			
	                        		}
	                        	}
	                        	else ShowError();
	                        }	
                        	
                        }	
		}		
                break;
                
	        case 1 : // Process Command
	                if (Get2Digit (&tvar, 0x99)==1)
	                {
	                	ResetUserEvent();                   	
				if (tvar>= 0x23 || !tvar)
	                   	{
	                        	//mess_lcd(1, "No Such Command ");
	                        	flush_keypad();
					Flags.WaitingKey = 1;
					ReloadKeyTimeOut();
	      				MainMenuItem=0x99;
	                   	}
	                   	else
	                   	{
	                       		ShowMainEntered ();
	                  	   	MainMenuItem = tvar;	                  	   	
	                   	}
	                }
	                break;
	        
	        case 2 :	
	        		if(gcrec.Lockcount<=2)	//RAM already has this after search card in 
	        		{          		//process card module		        			
	        			rt=CheckAutoPin();
	        			if(!rt)	
	        			{	        					
	        				if (SystemDatabase.OperationMode & O_LOCKOUT)	
	        					lockoutcount=gcrec.Lockcount+1;		        				                               		                            			                   			
                            			ShowError ();
                            			InstallThisCard();  
                            			                          			                            			                           			
                            		}
                            		else if(rt==1)
                            		{
                            			lockoutcount=0;
                            			InstallThisCard();                            			
                            		}
                            		card_exist=0;                            		                            		
	        		}	        		
	        		else
	        		{	
	        			ShowError();
	        			beepbeep(3);	        			
	        		}
	        		break;	             
	        default:	ResetUserEvent();	break;
    	}
}

char GetOperationModeOnOff (unsigned char kbit)
{
	if((kbit==O_CARD) || (kbit==O_CARDnPIN) || (kbit==O_AUTOPIN) || (kbit==O_CARDorPIN))
	{	
				SystemDatabase.OperationMode &=0xDC;	//1101 1100 mask on card,pin, card+pin
				SystemDatabase.OperationMode |= kbit;
				return 1;
	}
	else
	{
		if (key_count > 0)
    		{    		
			if (IsGoodDigitStr(KeyChar, 0, 0))
        		{
				if(KeyChar[0] =='1' || KeyChar[0] == '0')
				{
					if (KeyChar[0] == '1')
					{
						SystemDatabase.OperationMode |= kbit;
						put_c('S');
					}
					else if (KeyChar[0] == '0')
					{     
						put_c('R');
	
						SystemDatabase.OperationMode &= ~kbit;					
					}
				}
				else 
				{
					
						ShowErrInMainEntered();
						return 0;
					
				}		
			}
			else
			{
				ShowErrInMainEntered();
				return 0;
			} 
			
			beep(8);
			return 1;
		}	
        	
    	}
    	//kickdog();
    	return 9;
}
void longtos (char* ddata, unsigned long *tno)
{
char idata *tptr;

    tptr = (char*) tno;

    for (tempi=0;tempi<3;tempi++)
    	ddata[tempi] =  *(tptr+ (tempi+1));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -