myUART.cpp
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:26k
- #include "My_head.h"
- #include "MyProtocol.h"
- #include "carddef.h"
- #include "DS_addr.h"
- /****************************************************/
- #define DE_RE P3_6
- #define UARTBUF_SIZE 180
- //===================================================
- BYTE code TieUpBus_Ordors[4]={0xAA,0X55,0x55,0xAA};
- BYTE xdata uartSbuf[UARTBUF_SIZE];
- BYTE pdata uartRbuf[UARTBUF_SIZE];
- static BYTE uartRbuf_count = 0;
- bit my_ti = FALSE;
- bit dowith_receive_flag = FALSE;
- BYTE idata receive_head[4];
- BYTE receive_head_counte =0;
- BYTE receive_timer = 0;
- BYTE enble_send_count = 0;
- //===================================================
- void Uart_Int(void) interrupt 4 using 2
- {
- bit no_my_data_flag= FALSE;
- register BYTE ch;
- if(RI)
- {
- RI = FALSE;enble_send_count = 2;
- ch = SBUF;
- /**************** test ***********
- if(uartRbuf_count<UARTBUF_SIZE)
- {
- uartRbuf[uartRbuf_count++] = ch;
- }
- if(uartRbuf_count>ORDOR_PLACE)
- {
- dowith_receive_flag = TRUE; //this is a test!
- }
- /**********************************/
- if(!receive_timer)
- {
- receive_timer=2;
- receive_head_counte=0;
- }
- if(receive_timer<3)
- {
- receive_head[receive_head_counte]=ch;
- if(++receive_head_counte>3)
- {
- if( (receive_head[0]!=TieUpBus_Ordors[0])
- ||(receive_head[1]!=TieUpBus_Ordors[1])
- ||(receive_head[2]!=TieUpBus_Ordors[2])
- ||(receive_head[3]!=TieUpBus_Ordors[3]))
- {
- receive_timer=0;
- //receive_head_counte=0;
- }
- else{
- receive_timer=45;
- uartRbuf_count=0;
- //receive_head_counte=0;
- //dowith_receive_flag = TRUE; //for test.
- }
- }
- return;
- }
- if((receive_timer<10)||(receive_timer>45))
- {
- receive_timer=0;
- return;
- }
- //=================================================================
- if(uartRbuf_count<UARTBUF_SIZE)
- {
- uartRbuf[uartRbuf_count++] = ch;
- ch = uartRbuf_count-1;
- }
- else ch = uartRbuf_count;
- switch(ch)
- {
- case ASP_PLACE:
- if(uartRbuf[ch] != DOWN_ASP)
- {
- no_my_data_flag = TRUE;
- }
- break;
- case TYPE_PLACE:
- if(uartRbuf[ch] != equip_addr.ntype)
- {
- no_my_data_flag = TRUE;
- }
- //dowith_receive_flag = TRUE; //this is a test!
- break;
- case NUMBER_PLACE1:
- if(uartRbuf[ch] != ((BYTE *)(&equip_addr.number_addr))[0])
- {
- no_my_data_flag = TRUE;
- }
- break;
- case NUMBER_PLACE2:
- if(uartRbuf[ch] != ((BYTE *)(&equip_addr.number_addr))[1])
- {
- no_my_data_flag = TRUE;
- }
- break;
- case DATLENGTH_PLACE:
- if((uartRbuf[ch]<FRAMELENGTH_MIN)||(uartRbuf[ch]>FRAMELENGTH_MAX))
- {
- no_my_data_flag = TRUE;
- }
- break;
- default:
- if((ch>ORDOR_PLACE) && (ch>=uartRbuf[DATLENGTH_PLACE]))
- {
- REN = FALSE; //for run-time!
- dowith_receive_flag = TRUE;
- }
- break;
- }
- if(no_my_data_flag)
- {
- REN=FALSE; //for run-time!
- receive_timer=1;
- receive_head_counte=0; //MUST!!
- //uartRbuf_count=0;
- }
- /********************************/
- }
- if(TI){my_ti=TI=FALSE;}
- }
- /*************************************************************/
- /* uart_send */
- /*************************************************************/
- void Uart_Putc(BYTE ch)
- {
- while(my_ti);
- SBUF = ch;
- my_ti= TRUE;
- }
- bit SendStr(BYTE *ptr,int count) //"BYTE" modiry to "int" by 2004-6-18
- { //"void" modify "bit" by 2004-07-08
- int i;
- //if(count>512)return;
- Set_Timer20ms(5);
- while(enble_send_count)if(!Get_Timer20ms())return(FALSE);
- REN = FALSE;
- DE_RE = 0;
- TB8 = 1;
- for(i=0;i<count;i++)
- {
- //Save_My_TestData(ptr[i]);
- Uart_Putc(ptr[i]);
- }
- delay_ms(2);//must for RS485!
- DE_RE = 1;
- REN = TRUE;
- return(TRUE);
- }
- /*************************************************************/
- void UartBuf_Clear(void)
- {
- BYTE i=0;
- for(;i<UARTBUF_SIZE;i++)uartRbuf[i]=0;
- uartRbuf_count=0;
- dowith_receive_flag = FALSE;
- my_ti = FALSE;
- }
- void Uart_Init(void)
- {
- TR1 = 0;
- IP |= 0X10; // ES优先级1
- //SCON = 0x50; // 8位UART,波特率可变 REN=1
- SCON = 0xF0,TB8=1; // 9位UART,波特率可变 REN=1,摸停止位。
- TMOD &= 0x0f; // 方式寄存器
- TMOD |= 0x20; // T1设为自动再装入8位计数器,或者分成2个8位计数器
- ES = 1; //(ES为串行口中断允许位)
- TH1=TL1=0xFA; // 0xfA--9600bps(22.1184Mhz)
- PCON |= 0x80; // PCON.7为波特率加倍,PCON的其他位为掉电控制位
- // 2004-7-21改为波特率19200
- TR1 = 1; // TCON |= 0x40;
- #if(MCU_IC==SST564) //EXTRAM = AUXR^2;
- AUXR &= ~0x02; //0: Internal Expanded RAM access.
- #elif(MCU_IC==SM5964)//OME = SCONF^2;
- SCONF |= 0x02; //1: default is enable.
- #endif
- DE_RE = 1;
- UartBuf_Clear();
- //delay_ms(1);
- }
- /*---------------------------------------------------*/
- bit close_dis_led = FALSE;
- bit Check_Uart_Event(void)
- {
- if(dowith_receive_flag)
- {
- PostMessage(MY_UART_EVENT,0);
- dowith_receive_flag = FALSE;
- return(TRUE);
- }
- if(receive_timer && !close_dis_led)
- {
- Dis_Comming_Led(TRUE);//0-close;1--open.
- close_dis_led = TRUE; //for time and spi bus.
- }
- else if(close_dis_led)
- {
- Dis_Comming_Led(FALSE);//0-close;1--open.
- close_dis_led = FALSE; //for time and spi bus.
- }
- return(FALSE);
- }
- bit Check_BCCsum(BYTE *buf)
- {
- BYTE len,BCC_sum;//ii;
- for(BCC_sum=0,len=0;len<buf[DATLENGTH_PLACE];len++)
- {
- BCC_sum ^= buf[len];
- }
- if(~BCC_sum != buf[len])return(FALSE); //CRCERR;
- return(TRUE);
- }
- void Set_BCCsum(BYTE *buf,BYTE nCount)
- {
- BYTE ii;
- for(buf[nCount]=0,ii=0;ii<nCount;ii++)
- {
- buf[nCount]^=buf[ii];
- }
- buf[nCount]=~buf[nCount];
- }
- BYTE Do_Uart_Event(BYTE dat) //这样可以把uartSbuf节约出来?
- {
- BYTE len;//,BCC_sum;//ii;
- //while(enble_send_count);
- //SendStr(receive_head,4);
- //SendStr(uartRbuf,uartRbuf_count); //for test.
- //SendStr(&equip_addr.ntype,1);
- //SendStr((BYTE *)(&equip_addr.number_addr),2);
- //for(len=0;len<uartRbuf_count;len++)uartSbuf[len]=uartRbuf[len];
- memcpy(uartSbuf,uartRbuf,uartRbuf_count);
- len=uartRbuf_count,uartRbuf_count = 0;
- receive_timer = 45; //for continue!
- REN = TRUE;
- if(uartSbuf[FRAMECODE_PLACE]&THELAST_FRAME)
- {
- receive_timer = 0; //for renew the head str!
- }
- /***********this is a test!!************************
- Set_BCCsum(uartSbuf,uartSbuf[DATLENGTH_PLACE]);
- SendStr(uartSbuf,len);//REN = TRUE;
- /***************************************************/
- if(!Check_BCCsum(uartSbuf))return(FALSE);//CRCERR;
- //SendStr("OK",2);
- switch(uartSbuf[ORDOR_PLACE])
- {
- case CHECKEQUIP_ORDOR:// 0x50
- Do_CheckEquip();
- break;
- case SetNumber_ORDOR:// 0x52
- Do_SetNumber();
- break;
- case SetConParam_ORDOR:// 0X53
- Do_SetConParam();
- break;
- case GetConParam_ORDOR:// 0x55
- Do_GetConParam();
- break;
- case ClearConParam_ORDOR:// 0x57
- Do_ClearConParam();
- break;
- case SetBh_Money_ORDOR:// 0x58
- Do_SetBh_Money();
- break;
- case GetBh_Money_ORDOR:// 0x59
- Do_GetBh_Money();
- break;
- case SendDcpeoples_ORDOR:// 0x5A
- Do_SendDcpeoples();
- break;
- case SetCardClass_Para_ORDOR:// 0x5C
- Do_SetCardClass_Para();
- break;
- case GetCardClass_Para_ORDOR:// 0x5D
- Do_GetCardClass_Para();
- break;
- case SetSystemTime_ORDOR:// 0x60
- Do_SetSystemTime();
- break;
- case GetSystemTime_ORDOR:// 0x61
- Do_GetSystemTime();
- break;
- case SendCardStatus_ORDOR:// 0x62
- //Do_SendCardStatus();
- break;
- case SetLostCardTime_ORDOR:// 0x63
- //Do_SetLostCardTime();
- break;
- case GetLossCardsTime_ORDOR:// 0x64
- //Do_GetLossCardsTime();
- break;
- case GetCardStatus_ORDOR:// 0x65
- //Do_GetCardStatus();
- break;
- case ReadConData_ORDOR:// 0x70
- Do_ReadConData();
- break;
- case SetConRecode_ORDOR:// 0x71
- Do_SetConRecode();
- break;
- case SendCardGain_ORDOR:// 0x72
- //Do_SendCardGain();
- break;
- case GetCardGain_ORDOR:// 0x73
- //Do_GetCardGain();
- break;
- case GetConStatusInfo_ORDOR:// 0x75
- Do_GetConStatusInfo();
- break;
- case GetEquipVersionInfo_ORDOR:// 0x76
- Do_GetEquipVersionInfo();
- break;
- /**************************************/
- case GetCardLevel_ORDOR:// 0x80
- //Do_GetCardLevel();
- break;
- case SetSeedCard_ORDOR:// 0x81
- //Do_SetSeedCard();
- break;
- case GetUserCardInfo_ORDOR:// 0x82
- //Do_GetUserCardInfo();
- break;
- case SetUserCardInfo_ORDOR:// 0x83
- //Do_SetUserCardInfo();
- break;
- /**************************************/
- case SetOpUserInfo_ORDOR:// 0x90
- Do_SetOpUserInfo();
- break;
- case GetCurOpUserInfo:// 0x91
- Do_GetCurOpUserInfo();
- break;
- case GetOpUserInfo:// 0x92
- //Do_GetOpUserInfo();
- break;
- default:break;
- }
- dat=dat;
- return(TRUE); //len
- }
- void Do_CheckEquip(void)
- {
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = EQUIPANSWER_ORDOR;//0x51,所有重要数据都对方需要回答
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = Equip_CurStatus; //最近运行情况。
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetConParam(void)
- {
- BYTE nCount = ASP_PLACE;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(Con_param_Info))
- {
- dat = FORMAT_ERR;
- }
- else
- {
- memcpy(&con_param_Info,&uartSbuf[DATAST_PLACE],sizeof(Con_param_Info));
- dat=Saveparam_To_Mem();
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- //Dis_ConMode();
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_ClearConParam(void)
- {
- BYTE nCount,dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE != 0)
- {
- dat = FORMAT_ERR;
- }
- else
- {
- dat=ClearConParam_From_Mem(); //恢复到初始出厂状态。
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- //Dis_ConMode();
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_GetConParam(void)
- {
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- //dat=restoreparam_from_Mem();
- memcpy(&uartSbuf[DATAST_PLACE],&con_param_Info,sizeof(Con_param_Info));
- nCount+=sizeof(Con_param_Info);
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetSystemTime(void)
- {
- BYTE buf[7];// = {0x00,0x45,0x23,0x16,0x06,0x03,0x04};
- BYTE nCount;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE != 6)
- {
- dat = FORMAT_ERR;
- }
- else
- {
- nCount=DATAST_PLACE;
- buf[YEAR_ADDR]=uartSbuf[nCount++];
- buf[MOM_ADDR] =uartSbuf[nCount++];
- buf[DATE_ADDR]=uartSbuf[nCount++];
- buf[HOUR_ADDR]=uartSbuf[nCount++];
- buf[MIN_ADDR] =uartSbuf[nCount++];
- buf[SEC_ADDR] =uartSbuf[nCount++];
- Do_WriteClock(buf);
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_GetSystemTime(void)
- {
- BYTE buf[7];// = {0x00,0x45,0x23,0x16,0x06,0x03,0x04};
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- Do_ReadClock(buf);
- nCount = DATAST_PLACE;
- uartSbuf[nCount++]=buf[YEAR_ADDR];
- uartSbuf[nCount++]=buf[MOM_ADDR];
- uartSbuf[nCount++]=buf[DATE_ADDR];
- uartSbuf[nCount++]=buf[HOUR_ADDR];
- uartSbuf[nCount++]=buf[MIN_ADDR];
- uartSbuf[nCount++]=buf[SEC_ADDR];
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_ReadConData(void)
- {
- Con_Record pdata con_record;
- BYTE ii,dat,nCount = ASP_PLACE;
- //SendStr(uartSbuf,10);//for test.
- if((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 1)return; //err.
- if((dat=uartSbuf[DATAST_PLACE])==0)return;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- while(dat--)
- {
- if((ii=Read_ConData_From_Memory(&con_record))==SUCCESS)
- {
- memcpy(&uartSbuf[nCount],&con_record,sizeof(Con_Record));
- nCount += sizeof(Con_Record);
- if((con_record.mark==CONSUME_FLAG)&&(con_statusinfo.con_records>0))
- {
- con_statusinfo.con_records--;
- con_statusinfo.con_allmoney-=con_record.con_Money;
- }
- }
- else if(ii==NO_CON_RECORD)
- {
- uartSbuf[FRAMECODE_PLACE] |= THELAST_FRAME;
- receive_timer = 0; //must!
- break;
- }
- else
- {
- Equip_CurStatus=ii;
- Do_CheckEquip();
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- }
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetConRecode(void)
- {
- }
- void Do_SetCardClass_Para(void)
- {
- Card_Class_Para pdata card_class;
- BYTE nCount = ASP_PLACE;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(Card_Class_Para))
- {
- dat = FORMAT_ERR;
- }
- else
- {
- memcpy(&card_class,&uartSbuf[DATAST_PLACE],sizeof(Card_Class_Para));
- dat=SaveCardClass_To_Mem(&card_class);
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_GetCardClass_Para(void)
- {
- Card_Class_Para pdata card_class;
- BYTE nCount = ASP_PLACE,dat;
- if((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 1)return; //err.
- if((dat=uartSbuf[DATAST_PLACE])<1 || dat>8)return;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- card_class.card_class=dat; //must.
- if((dat=ReadCardClass_from_Mem(&card_class))!=SUCCESS)
- {
- Equip_CurStatus=dat;
- Do_CheckEquip();
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- memcpy(&uartSbuf[DATAST_PLACE],&card_class,sizeof(Card_Class_Para));
- nCount += sizeof(Card_Class_Para);
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetBh_Money(void)
- {
- BYTE nCount,dat=uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE;
- if((dat<sizeof(Bh_Money))||(dat>DATLENGTH_MAX))
- {
- dat=FORMAT_ERR;
- }
- else
- {
- if(uartSbuf[FRAMECODE_PLACE]&FRAMES_MAX == 0)
- {//这就决定了编号只能一次下载下去!否则只保留最后一次的。
- if((dat=DelAllBh_Money())!=SUCCESS)goto SKIP;
- }
- dat = uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE;
- dat = SaveBh_Money_To_Mem(&uartSbuf[DATAST_PLACE],dat);
- }
- SKIP:
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- #define FRAME_BHSTRUCT_S (DATLENGTH_MAX/sizeof(Bh_Money))
- void Do_GetBh_Money(void)
- {
- Bh_Money pdata bh_money;
- BYTE ii,dat,nCount,frame=uartSbuf[FRAMECODE_PLACE]&FRAMES_MAX;
- //SendStr(uartSbuf,10);//for test.
- if((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 1)return; //err.
- if(((dat=uartSbuf[DATAST_PLACE])<1)||(dat>FRAME_BHSTRUCT_S))return;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- for(ii=frame*FRAME_BHSTRUCT_S,frame=ii+dat;ii<frame;ii++)
- {
- if((dat=ReadBh_Money_From_Memory(&bh_money,ii))==SUCCESS)
- {
- if(bh_money.Bh_code==0xffff)
- {
- bh_money.Bh_code=ii,bh_money.money=0;
- }
- memcpy(&uartSbuf[nCount],&bh_money,sizeof(Bh_Money));
- nCount += sizeof(Bh_Money);
- }
- else if(dat==KEY_VALERR_CODE)
- {
- uartSbuf[FRAMECODE_PLACE] |= THELAST_FRAME;
- receive_timer = 0; //must!
- break;
- }
- else
- {
- Equip_CurStatus=dat;
- Do_CheckEquip();
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- }
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetNumber(void)
- {
- BYTE nCount = ASP_PLACE;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(Equip_Addr))
- {
- dat = FORMAT_ERR;
- }
- else if((con_statusinfo.con_records>0))
- {
- dat= OP_UNALLOWED;//可能还有消费数据
- }
- else
- {
- memcpy(&equip_addr,&uartSbuf[DATAST_PLACE],sizeof(Equip_Addr));
- dat=Saveparam_To_Mem();
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_SendDcpeoples(void)
- {
- BYTE nCount,dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(Dc_Peoples))
- {
- dat = FORMAT_ERR;
- }
- else
- {
- memcpy(&dc_peoples,&uartSbuf[DATAST_PLACE],sizeof(Dc_Peoples));
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_GetConStatusInfo(void)
- {
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- //dat=restoreparam_from_Mem();
- memcpy(&uartSbuf[nCount],&con_statusinfo,sizeof(Con_StatusInfo));
- nCount += sizeof(Con_StatusInfo);
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- extern const BYTE code YsnOysFlag_Str[];
- extern const BYTE code MyReVision_Str[];
- extern const BYTE code Con_Types_Str[];
- void Do_GetEquipVersionInfo(void)
- {
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- memcpy(&uartSbuf[nCount],Con_Types_Str,strlen(Con_Types_Str));
- nCount+=strlen(Con_Types_Str);
- memcpy(&uartSbuf[nCount],",",1);
- nCount+=1;
- memcpy(&uartSbuf[nCount],MyReVision_Str,strlen(MyReVision_Str));
- nCount+=strlen(MyReVision_Str);
- memcpy(&uartSbuf[nCount],&YsnOysFlag_Str[3],strlen(YsnOysFlag_Str)-2);
- nCount+=strlen(YsnOysFlag_Str)-2;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetOpUserInfo(void)
- {
- BYTE nCount,dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(Op_User_Info))
- {
- dat = FORMAT_ERR;
- }
- else
- {
- memcpy(&op_user_info,&uartSbuf[DATAST_PLACE],sizeof(Op_User_Info));
- dat=Saveparam_To_Mem();
- }
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- uartSbuf[nCount++] = dat;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- if(dat==SUCCESS)
- {
- do_buzzer(BUZZER_WAIT);
- }
- }
- void Do_GetCurOpUserInfo(void)
- {
- BYTE nCount = ASP_PLACE;
- uartSbuf[ASP_PLACE] = UP_ASP;
- uartSbuf[TYPE_PLACE] = equip_addr.ntype;
- uartSbuf[NUMBER_PLACE1] = ((BYTE*)&(equip_addr.number_addr))[0];
- uartSbuf[NUMBER_PLACE2] = ((BYTE*)&(equip_addr.number_addr))[1];
- //uartSbuf[DATLENGTH_PLACE]=
- //uartSbuf[FRAMECODE_PLACE]= THELAST_FRAME;//保持原来下传的不变。
- uartSbuf[ORDOR_PLACE] = AckSetGet_ORDOR;
- nCount = DATAST_PLACE;
- //dat=restoreparam_from_Mem();
- memcpy(&uartSbuf[nCount],&op_user_info,sizeof(Op_User_Info));
- nCount += sizeof(Op_User_Info);
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }