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

📄 common.c

📁 pos机contactless源码
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <api.h>
#include <ExEH0218.h>
#include <contactless.h> 
#include "common.h"

//Language option: LANG_CHN LANG_ENG
unsigned char	g_lang = LANG_CHN;	

//dump_memory()
//Output the content in Hex
//buf: the buffer to outpub
//cnt: data length in byte
//line:the origin line to display
void  dump_memory(void *buf,short int cnt,short line) 
{
      unsigned short cntr;
      unsigned char stmp[30];
      unsigned char *bufchar;
      
      bufchar = (unsigned char *)buf;
      memset(stmp,0,30);
      Disp_set_font_attribute(DISP_FONT_TYPE_5x7_ENG);
      for (cntr = 0; cntr < cnt; cntr ++) 
      {
		sprintf( stmp+2*cntr,"%02X", bufchar[cntr]);
      }
      stmp[cnt*2] = 0;  
      DispStr_CE(0,line,stmp,DISP_CLRLINE|DISP_POSITION|DISP_5x7);
      return ;
}


//input block number
short input_block_num(unsigned short maxnum,unsigned char *retno)
{
	GETSTR_PARAM 	gs;
	unsigned char 	str1[30];
	unsigned char 	tmpbuf[30];

	if(Get_Language()==LANG_CHN)
	{
		sprintf(str1,"块号(0-%d)",maxnum);
	}
	else
	{
		sprintf(str1,"BlockNO(0-%d)",maxnum);
	}
		
	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 = 0;
	gs.maxValue = maxnum;
	gs.retNum = 0;
	gs.qEvent = EXIT_KEY_F1;
	if ( !huGetStr_E(&gs) )
	{
		*retno = gs.retValue;	//>=0
		return 0;
	}
	
	return -1;
}

//input card block content 
short input_block_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);
}

//input strings by ASCII
short input_block_content_ascii(unsigned char *inbuf)
{
	GETCSTR_PARAM 	G_gs;
	unsigned char 	str1[30];
	unsigned char 	str2[30];
	//unsigned char	str3[30];
	
#ifndef VER_ENG	
	sprintf(str1,"块数值:");
	strcpy(str2,"输入4字符");
	//strcpy(str3,"8个数字");
#else
	sprintf(str1,"Value:");
	strcpy(str2,"input 4 char");
	//strcpy(str3,"8 characters");
#endif
		
	clr_scr();
	DispStr_CE(0,4,str2,DISP_POSITION);
	//DispStr_CE(0,6,str3,DISP_POSITION);
		
	G_gs.qx = 0;
	G_gs.qy = 0;
	G_gs.line = 0;
//	G_gs.pPrompt = str1;		
	G_gs.defaultMode = 1;
	G_gs.eDisable = 0;		
	G_gs.nullEnable = 0;		
	G_gs.csChar = '_';
	G_gs.pStr = inbuf;		
	G_gs.maxNum = 4;
	G_gs.minNum = 4;
	G_gs.retNum = 0;
	G_gs.autoexit = 0;
	G_gs.qEvent = EXIT_KEY_F1;
	
	return huGetStr_CEX(&G_gs);
}

//Hex strings to ASCII strings 
short ASCIIHex2Char(unsigned char *databuf,unsigned char hexnum)
{
	unsigned char tmpbuf[256];
	unsigned char loopidx;
	
	memcpy(tmpbuf,databuf,hexnum);
	for(loopidx=0;loopidx<hexnum/2;loopidx++)
	{
		databuf[loopidx] = (tmpbuf[loopidx*2]-0x30)*16+(tmpbuf[loopidx*2+1]-0x30);
	}
	return 0;
}


//set the language to lang
short Set_Language(unsigned short lang)
{
	g_lang = lang;
}

//get the current language type
unsigned short	Get_Language(void)
{
	return g_lang;
}

//the menu for select the language
short Select_Language(void)
{
	SELE_INLINE	s_lan;
	int		ret;
	
	DispStr_CE(0,0,"请选择语言",DISP_CENTER|DISP_CLRSCR);
	DispStr_CE(0,2,"Select Language",DISP_CENTER);
	
	s_lan.count = 2;
	s_lan.line = 5;
	s_lan.enable46 = 1;
	s_lan.flagch = 0;
	s_lan.defsele = 0;
	s_lan.selepstr[0].xx = 18;
	s_lan.selepstr[1].xx = 60;
	strcpy(s_lan.selepstr[0].pstr,"中文");
	strcpy(s_lan.selepstr[1].pstr,"English");
	s_lan.qEvent = 0;
	
	ret = select_in_line(&s_lan);
	if(ret==0)
	{
		Set_Language(LANG_CHN);
	}
	else
	{
		Set_Language(LANG_ENG);
	}	
	
	return 0;	
}

⌨️ 快捷键说明

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