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

📄 icode1_test_mini.c

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

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

static short ICODE1_read(void);
static short ICODE1_write(void);


short ICODE1_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:
				ICODE1_read();
				break;
			case 1:
				ICODE1_write();			
				break;
			default:				
				//RCX_Close();
				return -1;					
				break;									
		}
	}
	
	//RCX_Close();
	return 0;		
}


static short ICODE1_read() 
{	
	short 		retshort;
	unsigned char 	databuf[64];
	unsigned char 	tmpbuf[30];
	unsigned char	snr[100];
	char		status[8];	
	unsigned char	hash = 1;
	unsigned char 	ts = 1;
			
	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 		errstr[30];
		
	if(Get_Language()==LANG_CHN)
	{
		strcpy(errstr,"接口打开错误");
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"读错误");
		strcpy(hintstr4,"第%d块内容为:");
	}	
	else
	{
		strcpy(errstr,"Interface Error!");
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"read error");
		strcpy(hintstr4,"Block %d:");
	}	
	
	if( input_block_num(15,&bno) != 0 )
	{
		return 2;
	}
	
	if(RCX_Init(CARD_TYPE_ICODE1_STD))
	{
		DispStr_CE(0,3,errstr,DISP_POSITION|DISP_CLRSCR);
		delay_and_wait_key(0,EXIT_KEY_ALL,0);
		//RCX_Close();
		return -1;
	}  
			
	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);
  		}
  		  		
		retshort = ICODE1_Anticollision_Select(hash,ts,0,0,snr,status);
		if(status[0]==RCX_OK )
		{
			read_ok = 1;
			break;
		}
		RCX_RF_Reset(10);			
	}
	
	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();
		
	memset(databuf,0,sizeof(databuf));
	memset(status,0,sizeof(status));
	retshort = ICODE1_Select_Read(ts,bno,1,databuf,status);
	//retshort = ICODE1_Select_Read(ts,2,1,databuf,status);		    
	if(status[0] != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRLINE);
		dump_memory(status,1,6);		
		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 ICODE1_write()
{
	short 		retshort;
	unsigned char 	databuf[64];
	unsigned char 	tmpbuf[30];
	unsigned char	snr[100];
	char		status[8];	
	unsigned char	hash = 1;
	unsigned char 	ts = 1;
		
	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 		errstr[30];	
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(errstr,"接口打开错误");
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"写错误");
		strcpy(hintstr4,"写成功");
	}	
	else
	{
		strcpy(errstr,"Interface Error!");
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"write error");
		strcpy(hintstr4,"write success");	
	}
	
	if(RCX_Init(CARD_TYPE_ICODE1_STD))
	{
		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);
  		}
  		  		
		retshort = ICODE1_Anticollision_Select(hash,ts,0,0,snr,status);
		if ( status[0]==RCX_OK )
		{
			read_ok = 1;
			break;
		}			
	}
	
	clr_scr();
	
	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();
	
	memset(status,0,sizeof(status));
	retshort = ICODE1_WriteBlock(8,1,bno,databuf,status);		    
	if(status[0] != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRLINE);		
		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 );
	
	//RCX_Close();
	return 0;	
}

⌨️ 快捷键说明

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