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

📄 fm11rf005_test_mini.c

📁 pos机contactless源码
💻 C
字号:
/*FM11RF005 Test program
  Wang Yue 2005-8-26
 */

#include <stdio.h>
#include <stdlib.h>
#include <api.h>
#include <ExEH0218.h>
#include <contactless.h>
#include "common.h"

unsigned char FM_PASS[6] = "\xFF\xFF\xFF\xFF\x00\x00";

static short FM11RF005_read(void);
static short FM11RF005_write(void);


short FM11RF005_test_mini(void)
{
	BROWINFO  	INFO_sub;		
	int	  	retint;	
	unsigned char	menu_info[50];
		
	if(Get_Language()==LANG_CHN)
	{
		strcpy(menu_info,"1.读测试        2.写测试        ");		
	}
	else
	{
		strcpy(menu_info,"1.Read Test     2.Write Test    ");		
	}	     
        				
	INFO_sub.lPtr = 0;
	INFO_sub.cPtr = 0;
	INFO_sub.startLine = 0;
	while(1)
	{
		clr_scr();
		INFO_sub.iStr = menu_info;
		INFO_sub.mInt = 2;
		INFO_sub.lineMax = 16;
		INFO_sub.sFont = 0;
		INFO_sub.numEnable = 0;		
		INFO_sub.qEvent = EXIT_KEY_F1;		
		INFO_sub.autoexit = 0;			
				
		retint = brow_select(&INFO_sub);	
		switch( retint )
		{
			case 0:
				FM11RF005_read();
				break;
			case 1:
				FM11RF005_write();			
				break;
			default:				
				//RCX_Close();
				return -1;					
				break;									
		}
	}
	
	//RCX_Close();
	return 0;		
}


static short FM11RF005_read() 
{
	unsigned char 	ATQ[3];
	unsigned char 	sno[4];
	unsigned char	sak;
	unsigned char 	databuf[80];
	unsigned char 	tmpbuf[30];
	char 		ret;
		
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		bno;		
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	unsigned char		hintstr5[20];
	unsigned char		hintstr6[20];
	unsigned char 		errstr[30];
		
	if(Get_Language()==LANG_CHN)
	{
		strcpy(errstr,"接口打开错误");
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"读错误");
		strcpy(hintstr4,"第%d块内容为:");
		strcpy(hintstr5,"读序列号错误");
		strcpy(hintstr6,"认证错误");
	}	
	else
	{
		strcpy(errstr,"Interface Error!");
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"read error");
		strcpy(hintstr4,"Block %d:");
		strcpy(hintstr5,"Read SN Error!");
		strcpy(hintstr6,"Authen Error!");
	}
	
	if(RCX_Init(CARD_TYPE_14443A))
	{
		DispStr_CE(0,3,errstr,DISP_POSITION|DISP_CLRSCR);
		delay_and_wait_key(0,EXIT_KEY_ALL,0);
		//RCX_Close();
		return -1;
	}  
	
	if( input_block_num(15,&bno) != 0 )
	{
		return 2;
	}	
			
	SPT_set(1);
	for ( trycnt=11; trycnt>0; )	
	{
		if(!SPT_read())
		{			
			sprintf(tmpbuf,hintstr1,--trycnt);
			DispStr_CE(0,0,tmpbuf,DISP_POSITION|DISP_CLRLINE);
			SPT_set(64);
  		}
  		
		ret = FM11RF_Request(PICC_REQALL,ATQ);
		if ( ret==RCX_OK )
		{
			read_ok = 1;
			break;
		}			
	}
	
	if ( !read_ok )
	{		
		DispStr_CE(0,3,hintstr2,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	clr_scr();
			
	FM11RF_Select1(sno,&sak);
	
	memset(sno,0x00,sizeof(sno));
	ret = FM11RF_Read4Bytes(1,sno);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr5,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 5;
	}	
			
	ret = FM11RF_AuthKey(PICC_AUTHENT1A,sno,FM_PASS,bno);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr6,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 5;
	}
			
	memset(databuf,0x00,sizeof(databuf));
	ret = FM11RF_Read4Bytes(bno,databuf);	
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	sprintf(tmpbuf,hintstr4,bno);
	DispStr_CE(0,2,tmpbuf,DISP_POSITION|DISP_CLRLINE);
	sprintf(tmpbuf,"%02X %02X %02X %02X",databuf[0],databuf[1],databuf[2],databuf[3]);
	DispStr_CE(0,4,tmpbuf,DISP_CENTER|DISP_CLRLINE);
	delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
	
	//RCX_Close();
	
	return 0;	
}


static short FM11RF005_write()
{
	unsigned char 	ATQ[3];
	unsigned char 	sno[4];
	unsigned char	sak;
	unsigned char 	databuf[80];
	unsigned char 	tmpbuf[30];
	char 		ret;
		
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		bno;		
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	unsigned char		hintstr5[20];
	unsigned char		hintstr6[20];
	unsigned char 		errstr[30];	
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(errstr,"接口打开错误");
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"写错误");
		strcpy(hintstr4,"写成功");
		strcpy(hintstr5,"读序列号错误");
		strcpy(hintstr6,"认证错误");
	}	
	else
	{
		strcpy(errstr,"Interface Error!");
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"write error");
		strcpy(hintstr4,"write success");
		strcpy(hintstr5,"Read SN Error!");
		strcpy(hintstr6,"Authen Error!");	
	}
			
	if(RCX_Init(CARD_TYPE_14443A))
	{
		DispStr_CE(0,3,errstr,DISP_POSITION|DISP_CLRSCR);
		delay_and_wait_key(0,EXIT_KEY_ALL,0);
		//RCX_Close();
		return -1;
	}  
	
	if( input_block_num(15,&bno) != 0 )
	{
		return 2;
	}
	
	if(input_block_content(databuf)!=0)
	{
		return 2;
	}
	ASCIIHex2Char(databuf,8);	
	clr_scr();
		
	SPT_set(1);
	for ( trycnt=11; trycnt>0; )	
	{
		if(!SPT_read())
		{			
			sprintf(tmpbuf,hintstr1,--trycnt);
			DispStr_CE(0,0,tmpbuf,DISP_POSITION|DISP_CLRLINE);
			SPT_set(64);
  		}
  		
		ret = FM11RF_Request(PICC_REQALL,ATQ);
		if ( ret==RCX_OK )
		{
			read_ok = 1;
			break;
		}			
	}
	
	if ( !read_ok )
	{		
		DispStr_CE(0,3,hintstr2,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	clr_scr();
		
	FM11RF_Select1(sno,&sak);
	
	memset(sno,0x00,sizeof(sno));
	ret = FM11RF_Read4Bytes(1,sno);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr5,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 5;
	}	
			
	ret = FM11RF_AuthKey(PICC_AUTHENT1A,sno,FM_PASS,bno);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr6,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 5;
	}
	
	clr_scr();
		
	ret = FM11RF_Write4Bytes(bno,databuf);	
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
		
	DispStr_CE(0,3,hintstr4,DISP_POSITION|DISP_CLRLINE);
	delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
	
	return 0;	
}

⌨️ 快捷键说明

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