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

📄 ultralight_test_mini.c

📁 pos机contactless源码
💻 C
字号:
/*ultralight Test Program*/

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

static short input_page_num(unsigned char *retno);
static short input_page_content(unsigned char *inbuf);
static short ultralight_init(void);
static short ultralight_read(void);
static short ultralight_write(void);

short ultralight_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:
				ultralight_read();
				break;
			case 1:
				ultralight_write();			
				break;
			default:				
				return -1;					
				break;									
		}
	}
	
	//RCX_Close();
	return 0;		
}

short ultralight_init()
{		
	unsigned char databuf[20],ATQ[3],sno[4],sak;
	unsigned char tmpbuf[40];
	unsigned char errstr[30];
	char ret;
	
	if(Get_Language()==LANG_CHN)
	{		
		strcpy(errstr,"接口打开错误");
	}
	else
	{		
		strcpy(errstr,"Interface Error!");
	}   	
	
	if(RCX_Init(TYPE_A_ISO14443))
	{
		DispStr_CE(0,3,errstr,DISP_POSITION|DISP_CLRSCR);
		delay_and_wait_key(0,EXIT_KEY_ALL,0);
		RCX_Close();
		return -1;
	}  
		
	ret = CardTypeARequest(PICC_REQALL,ATQ);
	if( (ret)||(ATQ[0]!=0x44 )||(ATQ[1]!=0x00 ) )
	{		
		return -1;
	}
	ret = CardTypeAAnticoll(PICC_ANTICOLL1,sno);		
	ret |= CardTypeASelect(PICC_ANTICOLL1,sno,&sak);		
	if(sak&0x04)
	{		
		ret |= CardTypeAAnticoll(PICC_ANTICOLL2,sno);	
		ret |= CardTypeASelect(PICC_ANTICOLL2,sno,&sak);			
		if(sak&0x04)
		{		
			ret |= CardTypeAAnticoll(PICC_ANTICOLL3,sno);				
			ret |= CardTypeASelect(PICC_ANTICOLL3,sno,&sak);			
		}
	}
	if( ret )
	{		
		return -1;
	}	
	
	return 0;
}

//ultralight read
short ultralight_read(void) 
{
	unsigned char 		databuf[1024];	
	unsigned char 		tmpbuf[30];
	char 			ret;
	short 			retshort;
	unsigned short  	datalen;		
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		pno;		//page number
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"读错误");
		strcpy(hintstr4,"第%d页内容为:");
	}
	else
	{	
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"read error");
		strcpy(hintstr4,"Page %d:");
	}
		
	if(input_page_num(&pno) != 0 )
	{
		//RCX_Close();
		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);
  		}  			
		if( !ultralight_init() )
		{
			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 );
		//RCX_Close();
		return 1;
	}
	
	clr_scr();
	
	ret = CardMFCRead16Bytes(pno,databuf);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		//RCX_Close();
		return 1;
	}
	
	sprintf(tmpbuf,hintstr4,pno);
	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;	
}


short ultralight_write(void)
{
	unsigned char 		databuf[1024];	
	unsigned char 		tmpbuf[30];
	char 			ret;
	short 			retshort;
	unsigned short  	datalen;		
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		pno;		
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"写错误");
		strcpy(hintstr4,"写成功");
	}
	else
	{	
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"write error");
		strcpy(hintstr4,"write success");		
	}
	if( input_page_num(&pno) != 0 )
	{
		//RCX_Close();
		return 2;
	}	
	
	if(input_page_content(databuf)!=0)
	{
		//RCX_Close();
		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);
  		}
  	
		if( !ultralight_init() )
		{
			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 );
		//RCX_Close();
		return 1;
	}
	
	clr_scr();
		
	ret = CardMFCWrite4Bytes(pno,databuf);
	if(ret != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		//RCX_Close();
		return 1;
	}
		
	DispStr_CE(0,3,hintstr4,DISP_POSITION|DISP_CLRLINE);
	delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
	
	//RCX_Close();
	return 0;	
}


static short input_page_num(unsigned char *retno)
{
	GETSTR_PARAM 	gs;
	unsigned char 	str1[30];
	unsigned char 	tmpbuf[30];

	if(Get_Language()==LANG_CHN)	
	{
		strcpy(str1,"页号(4-15)");
	}
	else
	{
		strcpy(str1,"PageNO(4-15)");
	}
		
	clr_scr();
	gs.qx = 0;
	gs.qy = 0;
	gs.pPrompt = str1;
	gs.sFont = 0;
	gs.alpha = 0;
	gs.nullEnable = 0;
	gs.csChar = '_';
	gs.pwChar = 0;
	gs.spChar = 0;
	gs.pStr = tmpbuf;
	gs.maxNum = 2;
	gs.minNum = 1;
	gs.minValue = 4;
	gs.maxValue = 15;
	gs.retNum = 0;
	gs.qEvent = EXIT_KEY_F1;
	if ( !huGetStr_E(&gs) )
	{
		*retno = gs.retValue;	//>=0
		return 0;
	}
	
	return -1;
}


static short input_page_content(unsigned char *inbuf)
{
	GETSTR_PARAM 	gs;
	unsigned char 	str1[30];
	unsigned char 	str2[30];
	unsigned char 	str3[30];
	
	if(Get_Language()==LANG_CHN)
	{
		sprintf(str1,"页数值:");
		strcpy(str2,"按16进制输入");
		strcpy(str3,"8个数字");
	}
	else
	{
		sprintf(str1,"Value:");
		strcpy(str2,"input in hex");
		strcpy(str3,"8 characters");
	}
		
	clr_scr();
	DispStr_CE(0,4,str2,DISP_POSITION);
	DispStr_CE(0,6,str3,DISP_POSITION);
	gs.qx = 0;
	gs.qy = 0;
	gs.pPrompt = str1;
	gs.sFont = 0;
	gs.alpha = 0;
	gs.nullEnable = 0;
	gs.csChar = '_';
	gs.pwChar = 0;
	gs.spChar = 0;
	gs.pStr = inbuf;
	gs.maxNum = 8;
	gs.minNum = 8;
	gs.minValue = 0;
	gs.maxValue = -1;
	gs.retNum = 0;
	gs.qEvent = EXIT_KEY_F1;
	
	return huGetStr_E(&gs);
}

⌨️ 快捷键说明

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