do_rfic.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:6k
- #include "my_head.h"
- #include "carddef.h"
- #include "Rf500fun.c"
- #include "sendcard.h"
- /***********************************************************/
- BYTE code Nkey_a[6] = {'Y', 's','n', 'O', 'y', 's'};
- BYTE code Nkey_b[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- //===========================================================
- void Init_Rfic(void)
- {
- Rf_Init();
- mifs_config();
- //mifs_clr_control_bit();
- //mifs_set_control_bit();
- //mifs_load_key(KEYA,5,Nkey_b);
- //mifs_get_info(bankdata);
- }
- BYTE Fill_data(BYTE bankdata[],long *val,BYTE into_flag)
- {
- BYTE i;
- long *ll=(long *)bankdata;
- BYTE *temp=(BYTE *)val;
- i=bankdata[0];bankdata[0]=bankdata[3];bankdata[3]=i;
- i=bankdata[1];bankdata[1]=bankdata[2];bankdata[2]=i;
- if(READCARD_FALG == into_flag)
- {
- *val = *ll; //for return(val);
- return(SUCCESS);
- }
- else if(TEST_WRITE_FLAG == into_flag)
- {
- *ll=*val;
- }
- else
- {
- if((*ll<0)||(*ll>10000000))return(CARD_VALERR_CODE);
- if(CONSUME_FLAG== into_flag)*ll -= *val;
- else if(INCREMENT_FLAG == into_flag)*ll += *val;
- else return(OTHERERR);
- if(*ll < 0)return(CARDVAL_NOFOR_CONSUME); //卡上金额不足以本次消费!!
- if(*ll > 10000000)return(KEY_VALERR_CODE);//输入值无效或卡上金额太大
- *val = *ll; //for return(val);
- }
- i=bankdata[0];bankdata[0]=bankdata[3];bankdata[3]=i;
- i=bankdata[1];bankdata[1]=bankdata[2];bankdata[2]=i;
- /*/
- for(i=0;i<4;i++)
- {
- bankdata[4+i]=~bankdata[i];
- bankdata[8+i]=bankdata[i];
- }
- bankdata[12]=bankdata[14]=0x14;
- bankdata[13]=bankdata[15]=~0x14;
- /*/
- return(SUCCESS);
- }
- BYTE Do_RfIC(long *val,BYTE into_flag)
- {
- Con_Record pdata con_record;
- BYTE size, i;
- BYTE idata tt[2];
- BYTE idata card_snr[4];
- BYTE idata bankdata[16];
- BYTE idata keydata[6];
- //BYTE idata testdata[16];
- if(Equip_CurStatus == MEM_FULL_ARALM)return(MEM_FULL_ARALM);
- mifs_reset(15);
- for(i=25;--i;)
- {
- if(mifs_request(IDLE_CARD,tt))continue;
- if(mifs_anticoll(0,card_snr))continue;
- if(memcmp(&mycard.card_id,card_snr,4))return(CARD_NO_FINED);
- if(mifs_select(card_snr,&size))continue;
- Count_Sector_PWD(keydata,card_snr,CONSUME_TYPE_SECTOR);
- if(mifs_authKey(KEYA,CONSUME_TYPE_SECTOR,keydata))continue;
- //if(mifs_read(CONSUME_LIMIT_SECT,bankdata))continue;
- //memcpy(savedata,bankdata,16);
- if(mifs_read(CONSUME_MONEY_SECT,bankdata))continue;
- break;
- }
- if(!i)return(CARD_READERR_CODE);
- //===================================================
- con_record.con_Money = *val;
- if((con_param_info.con_mode != JC_MODE))//--计次模式
- {
- if((i=Fill_data(bankdata,val,into_flag)) != SUCCESS)return(i);
- }
- con_record.balance= *val; //余额
- if(READCARD_FALG == into_flag)
- {
- mifs_halt();
- return(SUCCESS);
- }
- if(CONSUME_FLAG != into_flag)
- {
- mifs_halt();
- return(OP_UNALLOWED);
- }
- //==========================================================
- if(*((WORD*)(&bankdata[DAYMAX_MONEY_ADDR])) > 0x7fff)
- {
- *((WORD*)(&bankdata[DAYMAX_MONEY_ADDR])) = con_record.con_Money;
- }
- else
- {
- *((WORD*)(&bankdata[DAYMAX_MONEY_ADDR]))=*((WORD*)(&bankdata[DAYMAX_MONEY_ADDR]))+con_record.con_Money;
- }
- bankdata[CONTIMES_COUNTS_ADDR+con_param_info.period]++;//为下次限次
- //===========================================================
- for(i=10;--i;)
- {
- if(mifs_request(IDLE_CARD,tt))continue;
- if(mifs_anticoll(0,card_snr))continue;
- if(memcmp(&mycard.card_id,card_snr,4))return(CARD_NO_FINED);
- if(mifs_select(card_snr,&size))continue;
- Count_Sector_PWD(keydata,card_snr,CONSUME_TYPE_SECTOR);
- if(mifs_authKey(KEYA,CONSUME_TYPE_SECTOR,keydata))continue;
- //if(con_param_info.con_mode != JC_MODE)
- {//--因为计次模式不扣卡上金额!
- if(mifs_write(CONSUME_MONEY_SECT,bankdata))continue;
- //if(mifs_check_write(card_snr,KEYA,CONSUME_MONEY_SECT,bankdata))continue;
- //mifs_read(CONSUME_MONEY_SECT,testdata);
- }
- //if(mifs_write(CONSUME_LIMIT_SECT,savedata))continue;
- //if(mifs_check_write(card_snr,KEYA,CONSUME_LIMIT_SECT,savedata))continue;
- break;
- }
- if(!i)return(CARD_WRITEERR_CODE);
- //mycard.counts; //本卡总共使用次数;有何用??
- mifs_halt();
- con_record.mark = into_flag;
- if((con_param_info.con_mode == JC_MODE)) //--计次模式
- {
- con_record.mark = JZJC_CON_FLAG;
- }
- memcpy(con_record.card,mycard.card_code,3);//"x12x34x56",3);//for test.
- memcpy(con_record.con_time,seedcard_info.date,6);
- if((i=Save_ConData_to_Memory(&con_record))!=SUCCESS)
- {
- return(i);
- }
- con_statusinfo.con_records++;
- con_statusinfo.con_dayrecords++;
- con_statusinfo.con_bootrecords++;
- con_statusinfo.con_allmoney+=con_record.con_Money;
- con_statusinfo.con_daymoney+=con_record.con_Money;
- con_statusinfo.con_bootmoney+=con_record.con_Money;
- Save_My_All_Data();
- //SendStr(card_snr,4);//for test!
- //SendStr(bankdata,16);//for test!
- return(SUCCESS);
- }
- BYTE Do_TestCardWrite_Event_6(BYTE Dat)
- {
- BYTE i;
- //long val = thekey.key_val;//为防止卡操作过程中出错!
- //if((i=Do_RfIC(&val,TEST_WRITE_FLAG)) != SUCCESS) //进入开户测试!
- //if((i=Do_RfIC(&val,INCREMENT_FLAG)) != SUCCESS) //进入充值测试!
- if((i=GetSEEDCardTest(&seedcard_info)) != SUCCESS) //用子卡初始化测试!
- {
- do_buzzer(BUZZER_ERROR);
- Dis_Err(i);
- mifs_halt();
- }
- else
- {
- equip_addr.ntype = seedcard_info.fuc_type;
- if((i=Saveparam_To_Mem())==SUCCESS)do_buzzer(BUZZER_SUCCESS);
- else
- {
- equip_addr.ntype = 0; //must.
- do_buzzer(BUZZER_ERROR);
- }
- //thekey.key_val = val;
- //KeyVal_Tobuf();
- //Dis_KeyBuf();
- Dis_Err(i);
- }
- //SendStr("T:",2);SendStr(&i,1);
- Stop_Timer(DISPLAY_DELAYEVENT_Tevent);//msut!!
- Set_TimerEvent(DISPLAY_DELAYEVENT_Tevent,DISPLAY_DELAYEVENT_TIME);
- Do_DisLed_Flash(0x00,0x00,200);
- Set_TimerEvent(WAIT_CARD_Tevent,WAIT_CARDCONSUME_TIME);//(1)
- SetCurState(IDEL_STATUS);//ActiveState(INIT_STATUS);
- Dat=Dat;
- return(i);
- }
- BYTE Check_Card_Event(BYTE cardmode)
- {
- BYTE idata tt[2];
- if(cardmode)
- {
- if(mifs_request(ALL_CARD,tt))return(1);
- }
- else
- {
- if(mifs_request(IDLE_CARD,tt))return(1);
- }
- Stop_Timer(DIS_CLOCKEVENT_Tevent);//must!
- Stop_Timer(WAIT_CARD_Tevent);
- PostMessage(FIND_CARD_EVENT,0);
- return(0);
- }