uart.C
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:28k
- #include "My_head.h"
- #include "MyProtocol.h"
- #include "carddef.h"
- #include "DS_addr.h"
- #include "DataFlash.H"
- /****************************************************/
- #define DE_RE P3_6
- #define UARTBUF_SIZE 180
- //===================================================
- BYTE code TieUpBus_Ordors[4]={0xAA,0X55,0x55,0xAA};
- BYTE code BoardCast_ADDR[2]={0xAA,0xFF};
- 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])
- &&(uartRbuf[ch] != BoardCast_ADDR[0]))//并且不等于广播地址
- {
- no_my_data_flag = TRUE;
- }
- break;
- case NUMBER_PLACE2:
- if((uartRbuf[ch] != ((BYTE *)(&equip_addr.number_addr))[1])
- &&(uartRbuf[ch] != BoardCast_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 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节约出来?
- {
- PostMessage(MY_UART_EVENT,0);
- dowith_receive_flag = FALSE;
- return(TRUE);
- }
- /*---------------------------------------------------*/
- bit close_dis_led = FALSE;
- bit Check_Uart_Event(void)
- {
- BYTE len;//,BCC_sum;//ii;
- if(!dowith_receive_flag)
- {
- 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);
- }
- memcpy(uartSbuf,uartRbuf,uartRbuf_count);
- len=uartRbuf_count,uartRbuf_count = 0;
- dowith_receive_flag = FALSE;
- 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;
- do_buzzer(1);
- /***************************************************/
- if(!Check_BCCsum(uartSbuf))return(FALSE);//CRCERR;
- //do_buzzer(1);
- //SendStr("OK",2);
- switch(uartSbuf[ORDOR_PLACE])
- {
- case CHECKEQUIP_ORDOR:// 0x50
- Do_CheckEquip(Equip_CurStatus);
- break;
- case SetNumber_ORDOR:// 0x52
- Do_SetNumber();
- break;
- case GetNumber_ORDOR:// 0x99
- Do_GetNumber();
- break;
-
- //自动充值数据
- case SetAutoGainCards_ORDOR:// 0xC5
- Do_SetAutoGainCards();
- break;
- case GetAutoGainCards_ORDOR:// 0xC6
- Do_GetAutoGainCards();
- break;
- //自动充值限制
- case SetAutoGainParam_ORDOR:// 0xC7
- Do_SetAutoGainParam();
- break;
- case GetAutoGainParam_ORDOR:// 0xC8
- Do_GetAutoGainParam();
- 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 SetSystemTime_ORDOR:// 0x60
- Do_SetSystemTime();
- break;
- case GetSystemTime_ORDOR:// 0x61
- Do_GetSystemTime();
- break;
- case SetLostCardTime_ORDOR:// 0x63
- //Do_SetLostCardTime();
- break;
- case GetLossCardsTime_ORDOR:// 0x64
- // Do_GetLossCardsTime();
- break;
- /************************************/
- case SendCardStatus_ORDOR:// 0x62
- Do_SendCardStatus();
- 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;
- }
- return(TRUE); //len
- }
- void Do_CheckEquip(BYTE dat)
- {
- 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++] = dat;//Equip_CurStatus; //最近运行情况。
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- //恢复设备到初始出厂状态。
- 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_SetAutoGainParam(void)
- {
- BYTE nCount = ASP_PLACE;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE<sizeof(sttFillLimitInfo))
- dat = FORMAT_ERR;
- else
- dat=WriteFillLimitInfo((sttFillLimitInfo*)&uartSbuf[DATAST_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;
- 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_GetAutoGainParam(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;
- ReadFillLimitInfo((sttFillLimitInfo*)&uartSbuf[DATAST_PLACE]);
- //dat=restoreparam_from_Mem();
- //memcpy(&uartSbuf[DATAST_PLACE],&stOrderDinnerTimeList,sizeof(stOrderDinnerTimeList));
- nCount+=sizeof(sttFillLimitInfo);
- 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 != 7)
- {
- 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++];
- buf[DAY_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)
- {
- DisplayDate();
- 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[nCount++]=buf[DAY_ADDR];
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- #define FRAME_CONSTRUCT_S (DATLENGTH_MAX/sizeof(Con_Record))
- void Do_ReadConData(void)
- {
- Con_Record xdata con_record;
- BYTE ii,dat,nCount;
- //SendStr(uartSbuf,10);//for test.
- if( ((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 1)
- ||((dat=uartSbuf[DATAST_PLACE])<1 )
- ||( dat > FRAME_CONSTRUCT_S )
- )
- {
- Do_CheckEquip(FORMAT_ERR);
- 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;
- if((uartSbuf[FRAMECODE_PLACE]&FRAMES_MAX)==0)
- {
- //do_buzzer(1);//Dis_Err(ii);
- //SendStr((BYTE *)&myall_savedata.lread_page,2);
- //SendStr((BYTE *)&myall_savedata.conread_page,2);
- //SendStr((BYTE *)&myall_savedata.lread_byte,2);
- //SendStr((BYTE *)&myall_savedata.conread_byte,2);
- myall_savedata.lread_page = myall_savedata.conread_page;
- myall_savedata.lread_byte = myall_savedata.conread_byte;
- }
- while(dat--)
- {
- if((ii=Read_ConData_From_Memory(&con_record))==SUCCESS)
- {
- memcpy(&uartSbuf[nCount],&con_record,sizeof(Con_Record));
- nCount += sizeof(Con_Record);
- //if(nCount>FRAMELENGTH_MAX)break;
- }
- else if(ii==NO_CON_RECORD)
- {
- uartSbuf[FRAMECODE_PLACE] |= THELAST_FRAME;
- receive_timer = 0; //must!
- break;
- }
- else
- {
- Equip_CurStatus=ii;
- Do_CheckEquip(ii);
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- }
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- /*
- if(uartSbuf[FRAMECODE_PLACE]&THELAST_FRAME)
- {
- do_buzzer(2);//Dis_Err(ii);
- myall_savedata.lread_page = myall_savedata.conread_page;
- myall_savedata.lread_byte = myall_savedata.conread_byte;
- }
- */
- }
- void Do_SetConRecode(void)
- {
- Con_Record xdata con_record;
- bit renew_del_flag=FALSE;
- signed short dat;
- BYTE ii,nCount;
- //SendStr(uartSbuf,10);//for test.
- dat = *(signed short*)(&uartSbuf[DATAST_PLACE]);
- //*((BYTE *)(&dat+1))=uartSbuf[DATAST_PLACE+1];
- if(((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 2)
- ||(dat==0)||(dat>+250)||(dat<-250))
- {
- Do_CheckEquip(FORMAT_ERR);
- 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;
- if(dat<0)
- {
- renew_del_flag=TRUE; //TRUE:恢复
- dat=-dat;
- }
- //=============================================================
- if(renew_del_flag)for(nCount=0;nCount<dat;nCount++) //TRUE:恢复
- {
- if((ii=Renew_ConData_From_Memory(&con_record))==SUCCESS)
- {
- 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(ii);
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- }
- //-----------------------------------------------------------
- else for(nCount=0;nCount<dat;nCount++)
- {
- if((ii=Del_ConData_From_Memory(&con_record))==SUCCESS)
- {
- if((con_statusinfo.con_records>0))//&&(con_record.mark==CONSUME_FLAG))
- {
- con_statusinfo.con_records--;
- con_statusinfo.con_allmoney-=con_record.con_Money;
- if(con_statusinfo.con_allmoney<0)con_statusinfo.con_allmoney=0L;
- }
- }
- else if(ii==NO_CON_RECORD)
- {
- con_statusinfo.con_records = 0; //理论上不必要!
- con_statusinfo.con_allmoney= 0L; //理论上不必要!
- uartSbuf[FRAMECODE_PLACE] |= THELAST_FRAME;
- receive_timer = 0; //must!
- break;
- }
- else
- {
- Equip_CurStatus=ii;
- Do_CheckEquip(ii);
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- }
- //============================================================
- if(nCount)Save_My_All_Data();//防乱掉电用。
- uartSbuf[DATAST_PLACE] = nCount; //成功删除或恢复的记录个数。
- nCount=DATAST_PLACE+1;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- //设置自动充值数据
- void Do_SetAutoGainCards(void)
- {
- WORD PageIndex=uartSbuf[DATAST_PLACE] * 0x100 + uartSbuf[DATAST_PLACE+1];
- BYTE RecordCount=uartSbuf[DATAST_PLACE+2];
- BYTE nCount,dat;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE < (sizeof(sttFillPara)*RecordCount + 3))
- {
- dat = FORMAT_ERR;
- }
- else
- {
- //memcpy(stOrderDinnerParaList,&uartSbuf[DATAST_PLACE+2],Len);
- dat=WriteFillPara(PageIndex,RecordCount,(sttFillPara*)&uartSbuf[DATAST_PLACE+3]);
- }
- 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_GetAutoGainCards(void)
- {
- WORD PageIndex=uartSbuf[DATAST_PLACE] * 0x100 + uartSbuf[DATAST_PLACE+1];
- BYTE RecordCount=uartSbuf[DATAST_PLACE+2];
- BYTE nCount = ASP_PLACE,dat;
- if((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 3)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;
- if(dat=ReadFillPara(PageIndex,RecordCount,(sttFillPara*)&uartSbuf[DATAST_PLACE])!=SUCCESS)
- {
- Equip_CurStatus=dat;
- Do_CheckEquip(dat);
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- //memcpy(&uartSbuf[DATAST_PLACE],&card_class,sizeof(sttOrderDinnerParameter)*RecordCount);
- nCount += sizeof(sttFillPara)*RecordCount;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- void Do_SetNumber(void) //modify 2004-09-05
- {
- BYTE nCount = ASP_PLACE;
- BYTE dat = SUCCESS;
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE != 2)
- {
- dat = FORMAT_ERR;
- }
- else if(con_statusinfo.con_records>0)
- {
- dat= OP_UNALLOWED;//可能还有消费数据
- }
- else
- {
- //memcpy(&equip_addr,&uartSbuf[DATAST_PLACE],sizeof(Equip_Addr));
- equip_addr.number_addr=*(WORD *)&uartSbuf[DATAST_PLACE];
- 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_GetNumber(void)//and 2004-09-5
- {
- BYTE nCount;
- 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],&equip_addr,sizeof(Equip_Addr));
- nCount += sizeof(Equip_Addr);
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }
- 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_SendCardStatus(void)
- {
- WORD PageIndex;
- BYTE Count=uartSbuf[DATAST_PLACE+2];
- BYTE Status=uartSbuf[DATAST_PLACE+3];
- BYTE nCount,dat;
- memcpy(&PageIndex,&uartSbuf[DATAST_PLACE],2); //包序号。
- if(uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE < (4*Count + 4))
- dat = FORMAT_ERR;
- else
- dat=SaveCardStatusTable(PageIndex,&uartSbuf[DATAST_PLACE+4],Count,Status);
- 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_GetCardStatus(void)
- {
- WORD PageIndex;
- //BYTE Count=uartSbuf[DATAST_PLACE+2];
- BYTE Status=uartSbuf[DATAST_PLACE+2];
- BYTE nCount,dat;
- memcpy(&PageIndex,&uartSbuf[DATAST_PLACE],2);
- if((uartSbuf[DATLENGTH_PLACE]-DATAST_PLACE) != 3)return; //err.
- 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;
- if(dat=ReadCardStatusTable(PageIndex,&uartSbuf[DATAST_PLACE],33,Status)!=SUCCESS)
- {
- Equip_CurStatus=dat;
- Do_CheckEquip(dat);
- do_buzzer(BUZZER_ALARM);//Dis_Err(ii);
- return;
- }
- //memcpy(&uartSbuf[DATAST_PLACE],&card_class,sizeof(sttOrderDinnerParameter)*RecordCount);
- nCount += 4 * 33;
- uartSbuf[DATLENGTH_PLACE] = nCount;
- Set_BCCsum(uartSbuf,nCount);
- if(!SendStr(uartSbuf,nCount+1))Dis_Err(COMMERR);
- }