do_rfic.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:6k
源码类别:

RFID编程

开发平台:

C/C++

  1. #include  "my_head.h"
  2. #include  "carddef.h"
  3. #include  "Rf500fun.c"
  4. #include  "sendcard.h"
  5. /***********************************************************/
  6. BYTE  code  Nkey_a[6] = {'Y', 's','n', 'O', 'y', 's'};
  7. BYTE  code  Nkey_b[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  8. //===========================================================
  9. void  Init_Rfic(void)
  10. {
  11.   Rf_Init();
  12.   mifs_config();
  13.   //mifs_clr_control_bit();
  14.   //mifs_set_control_bit();
  15.   //mifs_load_key(KEYA,5,Nkey_b);
  16.   //mifs_get_info(bankdata);
  17. }
  18. BYTE  Fill_data(BYTE  bankdata[],long *val,BYTE  into_flag)
  19. {
  20.     BYTE  i;
  21. long  *ll=(long  *)bankdata;
  22. BYTE  *temp=(BYTE *)val;
  23. i=bankdata[0];bankdata[0]=bankdata[3];bankdata[3]=i;
  24. i=bankdata[1];bankdata[1]=bankdata[2];bankdata[2]=i;
  25. if(READCARD_FALG == into_flag)
  26.   {
  27.    *val = *ll; //for return(val);
  28.    return(SUCCESS);
  29.   }
  30. else if(TEST_WRITE_FLAG == into_flag)
  31.   {
  32.    *ll=*val;
  33.   }
  34. else
  35.  {
  36.       if((*ll<0)||(*ll>10000000))return(CARD_VALERR_CODE);
  37.       if(CONSUME_FLAG== into_flag)*ll -= *val;
  38.   else if(INCREMENT_FLAG == into_flag)*ll += *val;
  39.   else return(OTHERERR);
  40.   if(*ll < 0)return(CARDVAL_NOFOR_CONSUME); //卡上金额不足以本次消费!!
  41.   if(*ll > 10000000)return(KEY_VALERR_CODE);//输入值无效或卡上金额太大
  42.       *val = *ll; //for  return(val);
  43.  }
  44. i=bankdata[0];bankdata[0]=bankdata[3];bankdata[3]=i;
  45. i=bankdata[1];bankdata[1]=bankdata[2];bankdata[2]=i;
  46. /*/
  47. for(i=0;i<4;i++)
  48.  {
  49.   bankdata[4+i]=~bankdata[i];
  50.   bankdata[8+i]=bankdata[i];
  51.  }
  52. bankdata[12]=bankdata[14]=0x14;
  53. bankdata[13]=bankdata[15]=~0x14;
  54. /*/
  55. return(SUCCESS);
  56. }
  57. BYTE  Do_RfIC(long  *val,BYTE  into_flag)
  58. {
  59.     Con_Record   pdata  con_record;
  60. BYTE  size,  i;
  61. BYTE  idata  tt[2];
  62. BYTE  idata  card_snr[4];
  63. BYTE  idata  bankdata[16];
  64. BYTE  idata  keydata[6];
  65. //BYTE  idata  testdata[16];
  66.     if(Equip_CurStatus == MEM_FULL_ARALM)return(MEM_FULL_ARALM);
  67.     mifs_reset(15);
  68. for(i=25;--i;)
  69.   {
  70.    if(mifs_request(IDLE_CARD,tt))continue;
  71.    if(mifs_anticoll(0,card_snr))continue;
  72.    if(memcmp(&mycard.card_id,card_snr,4))return(CARD_NO_FINED);
  73.    if(mifs_select(card_snr,&size))continue;
  74.        Count_Sector_PWD(keydata,card_snr,CONSUME_TYPE_SECTOR);
  75.    if(mifs_authKey(KEYA,CONSUME_TYPE_SECTOR,keydata))continue;
  76.        //if(mifs_read(CONSUME_LIMIT_SECT,bankdata))continue;
  77.    //memcpy(savedata,bankdata,16);
  78.       if(mifs_read(CONSUME_MONEY_SECT,bankdata))continue;
  79.    break;
  80.   }
  81. if(!i)return(CARD_READERR_CODE);
  82.     //===================================================
  83. con_record.con_Money = *val;
  84.     if((con_param_info.con_mode != JC_MODE))//--计次模式
  85.   {
  86.    if((i=Fill_data(bankdata,val,into_flag)) != SUCCESS)return(i);
  87.   }
  88.     con_record.balance= *val;   //余额
  89. if(READCARD_FALG == into_flag)
  90.   {
  91.        mifs_halt();
  92.    return(SUCCESS);
  93.   }
  94.     if(CONSUME_FLAG != into_flag)
  95.   {
  96.        mifs_halt();
  97.    return(OP_UNALLOWED);
  98.   }
  99.     //==========================================================
  100. if(*((WORD*)(&bankdata[DAYMAX_MONEY_ADDR])) > 0x7fff)
  101.   {
  102.    *((WORD*)(&bankdata[DAYMAX_MONEY_ADDR])) = con_record.con_Money;
  103.   }
  104.     else
  105.   {
  106.        *((WORD*)(&bankdata[DAYMAX_MONEY_ADDR]))=*((WORD*)(&bankdata[DAYMAX_MONEY_ADDR]))+con_record.con_Money;
  107.   }
  108. bankdata[CONTIMES_COUNTS_ADDR+con_param_info.period]++;//为下次限次
  109.     //===========================================================
  110.     for(i=10;--i;)
  111.   {
  112.       if(mifs_request(IDLE_CARD,tt))continue;
  113.    if(mifs_anticoll(0,card_snr))continue;
  114.    if(memcmp(&mycard.card_id,card_snr,4))return(CARD_NO_FINED);
  115.    if(mifs_select(card_snr,&size))continue;
  116.        Count_Sector_PWD(keydata,card_snr,CONSUME_TYPE_SECTOR);
  117.    if(mifs_authKey(KEYA,CONSUME_TYPE_SECTOR,keydata))continue;
  118.    //if(con_param_info.con_mode != JC_MODE)
  119.      {//--因为计次模式不扣卡上金额!
  120.       if(mifs_write(CONSUME_MONEY_SECT,bankdata))continue;
  121.       //if(mifs_check_write(card_snr,KEYA,CONSUME_MONEY_SECT,bankdata))continue;
  122.   //mifs_read(CONSUME_MONEY_SECT,testdata);
  123.  }
  124.    //if(mifs_write(CONSUME_LIMIT_SECT,savedata))continue;
  125.        //if(mifs_check_write(card_snr,KEYA,CONSUME_LIMIT_SECT,savedata))continue;
  126.    break;
  127.   }
  128.     if(!i)return(CARD_WRITEERR_CODE);
  129. //mycard.counts; //本卡总共使用次数;有何用??
  130.     mifs_halt();
  131.     con_record.mark  = into_flag;
  132.     if((con_param_info.con_mode == JC_MODE))   //--计次模式
  133.       {
  134.    con_record.mark  = JZJC_CON_FLAG;
  135.   }
  136. memcpy(con_record.card,mycard.card_code,3);//"x12x34x56",3);//for test.
  137. memcpy(con_record.con_time,seedcard_info.date,6);
  138. if((i=Save_ConData_to_Memory(&con_record))!=SUCCESS)
  139.   {
  140.    return(i);
  141.   }
  142.     con_statusinfo.con_records++;
  143.     con_statusinfo.con_dayrecords++;
  144.     con_statusinfo.con_bootrecords++;
  145.     con_statusinfo.con_allmoney+=con_record.con_Money;
  146.     con_statusinfo.con_daymoney+=con_record.con_Money;
  147.     con_statusinfo.con_bootmoney+=con_record.con_Money;
  148. Save_My_All_Data();
  149.     //SendStr(card_snr,4);//for test!
  150.     //SendStr(bankdata,16);//for test!
  151. return(SUCCESS);
  152. }
  153. BYTE  Do_TestCardWrite_Event_6(BYTE  Dat)
  154. {
  155.     BYTE  i;
  156. //long  val = thekey.key_val;//为防止卡操作过程中出错!
  157. //if((i=Do_RfIC(&val,TEST_WRITE_FLAG)) != SUCCESS)  //进入开户测试!
  158. //if((i=Do_RfIC(&val,INCREMENT_FLAG)) != SUCCESS)   //进入充值测试!
  159.     if((i=GetSEEDCardTest(&seedcard_info)) != SUCCESS)  //用子卡初始化测试!
  160.  {
  161.       do_buzzer(BUZZER_ERROR);
  162.       Dis_Err(i);
  163.       mifs_halt();
  164.  }
  165.     else
  166.  {
  167.       equip_addr.ntype = seedcard_info.fuc_type;
  168.   if((i=Saveparam_To_Mem())==SUCCESS)do_buzzer(BUZZER_SUCCESS);
  169.   else 
  170.   {
  171.         equip_addr.ntype = 0; //must.
  172.     do_buzzer(BUZZER_ERROR); 
  173.   }
  174.       //thekey.key_val = val;
  175.       //KeyVal_Tobuf();
  176.       //Dis_KeyBuf();
  177.       Dis_Err(i);
  178.  }
  179.     //SendStr("T:",2);SendStr(&i,1);
  180. Stop_Timer(DISPLAY_DELAYEVENT_Tevent);//msut!!
  181.     Set_TimerEvent(DISPLAY_DELAYEVENT_Tevent,DISPLAY_DELAYEVENT_TIME);
  182. Do_DisLed_Flash(0x00,0x00,200);
  183.     Set_TimerEvent(WAIT_CARD_Tevent,WAIT_CARDCONSUME_TIME);//(1)
  184. SetCurState(IDEL_STATUS);//ActiveState(INIT_STATUS);
  185.     Dat=Dat;
  186.     return(i);
  187. }
  188. BYTE  Check_Card_Event(BYTE  cardmode)
  189. {
  190.     BYTE  idata  tt[2];
  191. if(cardmode)
  192.   {
  193.    if(mifs_request(ALL_CARD,tt))return(1);
  194.   }
  195. else
  196.   {
  197.    if(mifs_request(IDLE_CARD,tt))return(1);
  198.   }
  199. Stop_Timer(DIS_CLOCKEVENT_Tevent);//must!
  200. Stop_Timer(WAIT_CARD_Tevent);
  201.     PostMessage(FIND_CARD_EVENT,0);
  202.     return(0);
  203. }