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

📄 self_detect.c

📁 税控收款机源码:拼音输入法,LCD,VFD驱动,IC卡驱动,税控国标
💻 C
📖 第 1 页 / 共 2 页
字号:
//=========================================================
// filename           :self_detect.c
// version            :
// goal&main function :one part of detecting routines.
// author             :xiao
// date created       :2005-01-10 10:32
// mender             :
// modified date      :
//=========================================================
#include "include.h"

//====================================================
void self_detect_auto(void)
{
    uchar time_min,time_min1;
    uchar timebuf[8];
    uchar key_temp;

    clear_lcd(0,MAX_LCD_NUM);
    read_rtc(timebuf);
    time_min = ((timebuf[4]>>4)&0x0f)*10+(timebuf[4]&0x0f);
   
    self_detect_print();
    while(1)
    {
		key_temp=get_key();
		//if(key_temp!=0)send_char(key_temp);
		if(key_temp ==VOID)
			break;
		//{key_temp=get_key();if(key_temp ==CASH) break;} //CLEAR 
		//self_detect_print();
		//delayms(3000);
		read_rtc(timebuf);
		time_min1 = ((timebuf[4]>>4)&0x0f)*10+(timebuf[4]&0x0f);
		if(time_min1>time_min)
		{
			if((time_min1-time_min)>10)
            {
                time_min = time_min1;
                self_detect_print();
            }
		}
		else
		{
            if( (time_min1+60-time_min)>10)
            {
                time_min = time_min1;
                self_detect_print();
            }
		}
		self_detect_card();
		self_detect_cpu();
		// self_detect_rom();
		self_detect_ram();
		self_detect_mem();
		self_detect_lcd();
		self_detect_com();
	}
}

//====================================================
//function:rom self-detecting
//
//====================================================
/*void self_detect_rom(void)
{
  
  int fd,error,error1;
  uchar buf[100];
  uchar buf1[100];
  uchar i;

  for(i=0;i<100;i++)
  {
    buf[i] = i;
  }

  while(1)
  {
    clear_lcd(0,MAX_LCD_NUM);
    error = 0;
    
    lcd_disp(0,0,0,"creat file......");
    fd = open("temp", O_RDWR| O_CREAT );
    if(fd < 0)
    {
      lcd_disp(1,0,0,"creat file error!");
      error = 1;
      break;
    }

    //sleep(1);

    delayms(1000);
    clear_lcd(0,1);
    lcd_disp(0,0,0,"write file......");
    error1 = write(fd, buf , 100);
    if(error1<0)
    {
      lcd_disp(1,0,0,"write file error!");
      error = 1;
      break;
    }
    //sleep(1);
    delayms(1000);

    lseek(fd,0,SEEK_SET);
    
    clear_lcd(0,1);
    lcd_disp(0,0,0,"read file......");
    error1 = read(fd,buf1,100);
    if(error1<0)
    {
      lcd_disp(1,0,0,"read file error!");
      error = 1;
      break;
    }
    //sleep(1);
    delayms(1000);

    clear_lcd(0,1);
    lcd_disp(0,0,0,"compare......");
    if(memcmp(buf,buf1,100)!=0)
    {
      error = 1;
      break;
    }
    //sleep(1);
    delayms(1000);
    error = 0;
    
    close(fd);     //how to delect the file
    
    break;

  }
  if(error)

    lcd_disp(3,0,0,"ROM检测错误");
  else
  
    lcd_disp(3,0,0,"ROM检测正确");
  //sleep(6);
    delayms(6000);

}
*/
//====================================================
//function:cpu self-detecting
//
//====================================================
void self_detect_card(void)
{
	uchar tempbuf[40];
	uchar rlt;
	clear_lcd(0,MAX_LCD_NUM);
	memset(tempbuf,0,30);
	strcpy(tempbuf,"正在检测税控卡......");
	lcd_disp(0,0,tempbuf);
	rlt=atr_sam(tempbuf); //复位
	if(rlt)
		sprintf(tempbuf,"税控卡检测不正常");
	else
	    sprintf(tempbuf,"税控卡检测正常");
    lcd_disp(3,0,tempbuf);
    delayms(3000);
  
	clear_lcd(0,MAX_LCD_NUM);
	memset(tempbuf,0,30);
	strcpy(tempbuf,"正在检测用户卡......");
	lcd_disp(0,0,tempbuf);
	rlt=atr_cupcard(tempbuf); //复位
	if(rlt)
		sprintf(tempbuf,"用户卡检测不正常");
	else
		sprintf(tempbuf,"用户卡检测正常");
    lcd_disp(3,0,tempbuf);
	delayms(4000);
}

//====================================================
//function:cpu self-detecting
//
//====================================================
void self_detect_cpu(void)
{
    float x,y,z;
    uchar buf[40];

    x = 1234.567;
    y = 2345.678;
    z = x+y;
    clear_lcd(0,MAX_LCD_NUM);
    
    sprintf(buf,"x = %f",x);
    lcd_disp(0,0,buf);
    sprintf(buf,"y = %f",y);
    lcd_disp(1,0,buf);
    sprintf(buf,"z = %f",z);
    lcd_disp(2,0,buf);
    if(abs(z-(x+y))<0.000001)
	 {
	  sprintf(buf,"CPU检测正确");
      lcd_disp(3,0,buf);
	 }
    else
	  {
	  sprintf(buf,"CPU检测错误");
      lcd_disp(3,0,buf);
	 }
    
    delayms(6000);

}
//====================================================
//function:com self-detecting
//
//====================================================
void self_detect_com(void)
{
	uchar i;
	uchar buf;
	uchar tempbuf[30];

	clear_lcd(0,MAX_LCD_NUM);
	memset(tempbuf,0,30);
	strcpy(tempbuf,"正在检测串口1......");
	lcd_disp(0,0,tempbuf);
	for(i=0;i<20;i++)
	{
		send_char(i);
		rece(1,&buf);
		if(buf!=i)break;
	}
	memset(tempbuf,0,30);
	if(i==20)strcpy(tempbuf,"串口1正常");
	else     strcpy(tempbuf,"串口1不正常");
	lcd_disp(3,0,tempbuf);
	delayms(4000);
	clear_lcd(0,MAX_LCD_NUM);
	memset(tempbuf,0,30);
	strcpy(tempbuf,"正在检测串口2......");
	lcd_disp(0,0,tempbuf);
	for(i=0;i<20;i++)
	{
		send_char2(i);
		rece2(1,&buf);
		if(buf!=i)break;
	}
	memset(tempbuf,0,30);
	if(i==20)
		strcpy(tempbuf,"串口2正常");
	else
		strcpy(tempbuf,"串口2不正常");
	lcd_disp(3,0,tempbuf);
	clear_lcd(0,MAX_LCD_NUM);
	delayms(4000);
	self_detect_USB();
	delayms(4000);
}

//====================================================
//function:money box self-detecting
//
//====================================================
/*void self_detect_box(void)
{
	   moneybox_open();
     clear_lcd(0,MAX_LCD_NUM);
     lcd_disp(1,0,0,"打开钱箱");
     //sleep(4);
    delayms(4000);
}
*/
//====================================================
//function:printer self-detecting
//
//====================================================
void self_detect_print(void)
{
	uchar tempbuf[30];
	uchar rlt;
	clear_lcd(0,MAX_LCD_NUM);
	memset(tempbuf,0,30);
	strcpy(tempbuf,"正在检测打印机......");
	lcd_disp(0,0,tempbuf);
	//HYS620
	rlt = GotoHomePosition();
	//_goto_HP();
	//END HYS620
	if(!rlt)
	{
		strcpy(tempbuf,"abcdefghijklmnopqrstuvwxyz");
		rlt=print_str(tempbuf);
		if(!rlt)
		{
			strcpy(tempbuf,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
			rlt=print_str(tempbuf);
		}
		
		if(!rlt)
		{
			strcpy(tempbuf,"01234567890123456789012345");
			rlt=print_str(tempbuf);
		}
		
		if(!rlt)
		{
			strcpy(tempbuf,"阿啊呵吖锕嗄腌");
			rlt=print_str(tempbuf);
		}
		
		if(!rlt)
		{
			strcpy(tempbuf,"爱矮哎哀唉埃挨皑癌蔼艾隘");
			rlt=print_str(tempbuf);
		}
		
		if(!rlt)
		{
			strcpy(tempbuf,"安岸按案俺胺暗氨鞍胺庵胺");
			rlt=print_str(tempbuf);
		}
		
		if(!rlt)
		{
			strcpy(tempbuf,"谢谢您检测此打印机!");
			rlt=print_str(tempbuf);
		}
	}
	memset(tempbuf,0,30);
	if(rlt)
		strcpy(tempbuf,"打印失败,检查打印机");
	else
		strcpy(tempbuf,"打印机正常");
	if(g_printer_sel!=1) Fast_feed_paper_hang(250);
    else 	  Wei_printer_feed_paper(8);	
	
	
	lcd_disp(3,0,tempbuf);
	delayms(6000);
}

//====================================================
//function:memory self-detecting
//
//====================================================
void self_detect_mem(void)
{
	uchar backup[3][11];
	uchar buf[3][11];
   uchar buf1[3][11];
   uchar flag=0;
   uchar tempbuf[30];
   
   uchar xiaozimo[16]={0xfd,0x15,0x7d,0x15,0x7d,0x95,0xff,0x40,
   						0x3f,0x81,0x79,0x0a,0x7a,0x83,0xe0,0x00} ;
   clear_lcd(0,MAX_LCD_NUM);
   memset(tempbuf,0,30);
   strcpy(tempbuf,"正在检测EEPROM......");
   lcd_disp(0,0,tempbuf);
   
   read_eeprom(20,10,backup[0]);
   read_eeprom(0x8000,10,backup[1]);
   read_eeprom(0xfff5,10,backup[2]);

   memcpy(buf[0],"1234567890",10);
   memcpy(buf[1],"ABCDEFGHIJ",10);
   memcpy(buf[2],"abcdefghij",10);
   
   buf[0][10] = 0;
   buf[1][10] = 0;
   buf[2][10] = 0;

   write_eeprom(20,10,buf[0]);
   write_eeprom(0x8000,10,buf[1]);
   write_eeprom(0xfff5,10,buf[2]);

    delayms(2000);
   
   read_eeprom(20,10,buf1[0]);
   read_eeprom(0x8000,10,buf1[1]);
   read_eeprom(0xfff5,10,buf1[2]);

   buf1[0][10] = 0;
   buf1[1][10] = 0;
   buf1[2][10] = 0;

   
    delayms(400);

   if(memcmp(buf[0],buf1[0],10)!=0)
       flag = 1;
   if(memcmp(buf[1],buf1[1],10)!=0)
       flag = 1;
   if(memcmp(buf[2],buf1[2],10)!=0)
       flag = 1;
   clear_lcd(3,1);   
    delayms(10000);
   if(flag)
    {
      memset(tempbuf,0,30);
     strcpy(tempbuf,"EEPROM检测错误");
     lcd_disp(3,0,tempbuf);
      
	}
   else
   { 
   memset(tempbuf,0,30);
   strcpy(tempbuf,"EEPROM检测正常");
   lcd_disp(3,0,tempbuf);
      
   }
   write_eeprom(20,10,backup[0]);
   write_eeprom(0x8000,10,backup[1]);
   write_eeprom(0xfff5,10,backup[2]);
   delayms(2000);
   memset(tempbuf,0,30);
   
   
   strcpy(tempbuf,"正在检测FLASH......");
   lcd_disp(0,0,tempbuf);
   
   
   read_flash(0xdf3f0,16,tempbuf);
   
   
   if(memcmp(tempbuf,xiaozimo,16)!=0) strcpy(tempbuf,"FLASH检测错误");
   else strcpy(tempbuf,"FLASH检测正常");
   lcd_disp(3,0,tempbuf);
   delayms(4000);
   
}

//====================================================
//function:RAM self-detecting
//
//====================================================
void self_detect_ram(void)
{
   uchar backup[3][11];
   uchar buf[3][11];

   uchar buf1[3][11];
   uchar flag=0;
   uchar tempbuf[30];
   uchar i;
   clear_lcd(0,MAX_LCD_NUM);
   memset(tempbuf,0,30);
   strcpy(tempbuf,"正在检测RAM......");
   lcd_disp(0,0,tempbuf);
   for(i=0;i<5;i++)
   {
   flag=0;
   read_sramb(0,10,backup[0]);
   read_sramb(0x40000,10,backup[1]);
   read_sramb(0x7fff0,10,backup[2]);

   memcpy(buf[0],"1234567890",10);
   memcpy(buf[1],"ABCDEFGHIJ",10);
   memcpy(buf[2],"abcdefghij",10);
   
   buf[0][10] = 0;
   buf[1][10] = 0;
   buf[2][10] = 0;

   write_sramb(0,10,buf[0]);
   delayms(100);
   write_sramb(0x40000,10,buf[1]);
   delayms(100);
   write_sramb(0x7fff0,10,buf[2]);

    delayms(2000);
   
   read_sramb(0,10,buf1[0]);
  
   delayms(100);
   read_sramb(0x40000,10,buf1[1]);
   
   delayms(100);
   read_sramb(0x7fff0,10,buf1[2]);
   
   buf1[0][10] = 0;
   buf1[1][10] = 0;
   buf1[2][10] = 0;
   if(memcmp(buf[0],buf1[0],10)!=0)
       flag = 1;
   if(memcmp(buf[1],buf1[1],10)!=0)
       flag = 1;
   if(memcmp(buf[2],buf1[2],10)!=0)
       flag = 1;

   clear_lcd(3,1);
   if(!flag)break;
   delayms(10000);
  
   }
   if(flag)
    {
      memset(tempbuf,0,30);
     strcpy(tempbuf,"RAM检测错误");
     lcd_disp(3,0,tempbuf);
      
	}
   else
   { 
   memset(tempbuf,0,30);
   strcpy(tempbuf,"RAM检测正常");
   lcd_disp(3,0,tempbuf);
      
   }

⌨️ 快捷键说明

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