123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- #include <rtthread.h>
- #include "main.h"
- #include "flash.h"
- #include "buffer.h"
- #include "button.h"
- #include "usart.h"
- #include <stdlib.h>
- #include "weight.h"
- #include "display.h"
- #include "plan.h"
- #include "xBeeAppEscapingMode.h"
- union frameinit_t dataframehead = {0x7E,0x00,0x01,0x01};
- unsigned char WeightConst_product[40] = {0xD2,0xBB,0xBA,0xC5,0xC5,0xA3,0xC9,0xE1,0x20,0x20};
- union plan_comp_t plan_comp = {0,0,0,0,0,0};
- union pf_comp_t pf_comp = {0,0,0,0,0};
- unsigned char WeightConst_Product_JS=0;
- unsigned char WeightConst_Product_Run=0;
- unsigned short WeightConst_Product_Run_time=0;
- unsigned char WeightConst_Run=0;
- unsigned char WeightConst_Stop = 0;
- unsigned char WeightConst_PlantempList[40];
- unsigned char WeightConst_Nextfeed[40];
- signed short WeightConst_NextWeightTarget;
- unsigned char WeightConst_feed[40];
- signed short WeightConst_WeightTargetTemp;
-
- signed short WeightConst_WeightTarget;
- unsigned char CompleteTarget_order = 0xFD;
- signed short WeightConst_WeightTargetAllowMin;
- signed short WeightConst_WeightTargetAllowMax;
- unsigned char WeightConst_WeightHaveBegin = 0;
- unsigned short WeightConst_DELAYTIME;
- unsigned short WeightConst_DELAYON = 0;
- unsigned char XbeeConst_lastsort;
- unsigned char XbeeConst_lastinorout;
- unsigned char XbeeConst_FrameNum = 0;
- unsigned char XbeeConst_CanSend=1;
- unsigned char getPlaning=0;
- static unsigned char XbeeConst_needRetry=0;
- rt_sem_t pop_product_sem = RT_NULL;
- rt_sem_t delay_key_sem = RT_NULL;
- unsigned char delayKeying = 0;
- union TimeConst_t TimeConst={
- .data.year = 1,
- .data.month = 0,
- .data.date = 32,
- .data.hh = 0,
- .data.mm = 0,
- .data.ss = 0
- };
- static rt_thread_t tdelay_key_id = RT_NULL;
- static void delay_key_entry(void *parameter)
- {
- while(1)
- {
- rt_sem_take(delay_key_sem, RT_WAITING_FOREVER);
- delayKeying =1;
- rt_thread_mdelay(3000);
- delayKeying =0;
- }
- }
- void delay_key_thread(void)
- {
- tdelay_key_id = rt_thread_create("delay_key",
- delay_key_entry, RT_NULL,
- 0x100, 6, 5);
-
- if (tdelay_key_id != RT_NULL) rt_thread_startup(tdelay_key_id);
- }
- void setSendFrame_t(unsigned char Broadcast,unsigned char Radius,unsigned char TO) {
- userSendFrame_t.frameHead = 0x7E;
- userSendFrame_t.frameLen = 0;
- userSendFrame_t.frameType = 0x10;
- userSendFrame_t.frameID = 0x01;
- if (Broadcast == 1) {
- userSendFrame_t.des64DeviceAdd[0] = 0x00;
- userSendFrame_t.des64DeviceAdd[1] = 0x00;
- userSendFrame_t.des64DeviceAdd[2] = 0x00;
- userSendFrame_t.des64DeviceAdd[3] = 0x00;
- userSendFrame_t.des64DeviceAdd[4] = 0x00;
- userSendFrame_t.des64DeviceAdd[5] = 0x00;
- userSendFrame_t.des64DeviceAdd[6] = 0xFF;
- userSendFrame_t.des64DeviceAdd[7] = 0xFF;
- }
- else if (Broadcast == 2) {
- for (int i = 0; i < 8; i++)
- userSendFrame_t.des64DeviceAdd[i] = XbeeConst_CCAddress[i];
- }
- else {
- for (int i = 0; i < 8; i++)
- userSendFrame_t.des64DeviceAdd[i] = XbeeConst_CenterAddress[i];
- }
- userSendFrame_t.des16NetAdd = 0xFFFE ;
- userSendFrame_t.broadcastRadius = Radius;
- userSendFrame_t.transmitOptions = TO;
- }
- rt_sem_t setTIME_lock = RT_NULL;
- static void setTIME_entry(void *parameter) {
- while (1) {
-
- rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
- if ((TimeConst.data.date == 29) && (TimeConst.data.month == 2) && (TimeConst.data.year % 4)>0 ) {
- TimeConst.data.date = 1;
- TimeConst.data.month ++;
- }
- else if ((TimeConst.data.date == 30) && (TimeConst.data.month == 2) && (TimeConst.data.year % 4) == 0 ) {
- TimeConst.data.date = 1;
- TimeConst.data.month ++;
- }
- else if ((TimeConst.data.date == 31) && ((TimeConst.data.month == 4) || (TimeConst.data.month == 6) ||
- (TimeConst.data.month == 9) || (TimeConst.data.month == 11)) ) {
- TimeConst.data.date = 1;
- TimeConst.data.month ++;
- }
- else if (TimeConst.data.date == 32) {
- TimeConst.data.date = 1;
- TimeConst.data.month ++;
- }
- if (TimeConst.data.month == 13) {
- TimeConst.data.month = 1;
- TimeConst.data.year ++;
- }
-
- TimeConst.data.ss++;
- if (TimeConst.data.ss==60) {
- TimeConst.data.ss = 0;
- TimeConst.data.mm ++;
- }
- if (TimeConst.data.mm==60) {
- TimeConst.data.mm = 0;
- TimeConst.data.hh ++;
- }
- if (TimeConst.data.hh==24) {
- TimeConst.data.hh = 0;
- TimeConst.data.date ++;
- }
-
- rt_sem_release(setTIME_lock);
- rt_thread_mdelay(998);
- }
- }
- static rt_thread_t tTimeid = RT_NULL;
- void setTIME_thread(void)
- {
- tTimeid = rt_thread_create("Timer", setTIME_entry, RT_NULL, 0x200, 2, 5);
-
- if (tTimeid != RT_NULL) rt_thread_startup(tTimeid);
- }
- extern unsigned char iscowweight;
- void setWeightConst_initProduct(void) {
- rt_memset(WeightConst_product,0x20,40);
- rt_memset(WeightConst_feed,0x20,40);
- rt_memset(WeightConst_Nextfeed,0x20,40);
- if (WeightConst_SBType==1||WeightConst_SBType==6) {
-
- if (iscowweight==1)
- {
- WeightConst_feed[0]=0xCE;
- WeightConst_feed[1]=0xDE;
- WeightConst_feed[2]=0xB6;
- WeightConst_feed[3]=0xFA;
- WeightConst_feed[4]=0xB1;
- WeightConst_feed[5]=0xEA;
- WeightConst_feed[6]=0x20;
- WeightConst_feed[7]=0x20;
- }
- else if (!isWeight)
- {
- WeightConst_feed[0]=0xC7;
- WeightConst_feed[1]=0xEB;
- WeightConst_feed[2]=0xC8;
- WeightConst_feed[3]=0xA1;
- WeightConst_feed[4]=0xBC;
- WeightConst_feed[5]=0xC6;
- WeightConst_feed[6]=0xBB;
- WeightConst_feed[7]=0xAE;
- }
- else
- {
- WeightConst_feed[0]=0xD6;
- WeightConst_feed[1]=0xD8;
- WeightConst_feed[2]=0xC1;
- WeightConst_feed[3]=0xBF;
- WeightConst_feed[4]=0x20;
- WeightConst_feed[5]=0x20;
- WeightConst_feed[6]=0x20;
- WeightConst_feed[7]=0x20;
- }
- }
- else if (WeightConst_SBType==3) {
- WeightConst_feed[0]=0xC7;
- WeightConst_feed[1]=0xEB;
- WeightConst_feed[2]=0xC8;
- WeightConst_feed[3]=0xA1;
- WeightConst_feed[4]=0xBC;
- WeightConst_feed[5]=0xC6;
- WeightConst_feed[6]=0xBB;
- WeightConst_feed[7]=0xAE;
- }
-
- plan_comp.data.incount = 0;
- plan_comp.data.outcount = 0;
- plan_comp.data.reget = 0;
- plan_comp.data.swpos = 0;
- plan_comp.data.sumweight = 0;
- plan_comp.data.shifts = 0;
-
-
- WeightConst_WeightTarget = 0;
-
-
- pf_comp.data.addorout = 0;
- pf_comp.data.tw_pos = 0;
- pf_comp.data.az_pos = 0;
- pf_comp.data.autosecond = 0;
- pf_comp.data.autozone = 0; ;
- pf_comp.data.needBegin = 0;
- pf_comp.data.pfsort = 0xFE;
- pf_comp.data.delaytime = 0;
- pf_comp.data.JMP = 0;
-
- WeightConst_Product_Run = 0;
- XbeeConst_lastsort = 0;
- XbeeConst_lastinorout = 0;
- if (WeightConst_SBType>2 && WeightConst_SBType<7) {
- rt_event_send(&display_event, EVENT_clearall);
- rt_event_send(&display_event, EVENT_Current_noweight);
- }
- }
- void pop_product_entry(void *parameter) {
- while(1)
- {
- rt_sem_take(pop_product_sem, RT_WAITING_FOREVER);
-
- for (int CheckWeight_i = 0; CheckWeight_i < 30; CheckWeight_i++) {
- WeightConst_AutoSingleNSecondNum[CheckWeight_i][0]=0;
- WeightConst_AutoSingleNSecondNum[CheckWeight_i][1]=0;
- WeightConst_AutoSingleNSecondNum[CheckWeight_i][2]=0;
- }
-
- while(1){
- WeightConst_WeightHaveBegin=0;
- if (tsdb_recordcount('p')>0) {
- findplan();
- unsigned char setWeightConst_length=0;
- setWeightConst_length = WeightConst_PlantempList[1];
- WeightConst_Run = 1;
- if (WeightConst_PlantempList[3]==0x12) {
- save_read_ts('p');
- rt_sem_take(display_lock, RT_WAITING_FOREVER);
- setWeightConst_initProduct();
- rt_memset(WeightConst_product,0x20,40);
- rt_memset(WeightConst_feed,0x20,40);
- for (int i = 0; i <= setWeightConst_length-10; i++) {
- WeightConst_product[i] = WeightConst_PlantempList[i+4];
- if (WeightConst_SBType==1||WeightConst_SBType==6) {
- WeightConst_feed[i] = WeightConst_product[i];
- }
- }
- plan_comp.Buffer[0] = WeightConst_PlantempList[setWeightConst_length-5+1];
- plan_comp.Buffer[1] = WeightConst_PlantempList[setWeightConst_length-5];
- for (int i = 2; i < 6; i++) {
- plan_comp.Buffer[i] = WeightConst_PlantempList[setWeightConst_length-5+i];
- }
- WeightConst_Product_Run_time = (plan_comp.data.incount<<8) || plan_comp.data.outcount;
- pf_comp.data.pfsort = 0xFD;
- WeightConst_Stop = 0;
- if (WeightConst_SBType>2 && WeightConst_SBType<7) {
- rt_event_send(&display_event, EVENT_PlanName);
- }
- rt_sem_release(display_lock);
- rt_thread_mdelay(1000);
- }
- else if (WeightConst_PlantempList[3]==0x15) {
- rt_sem_take(display_lock, RT_WAITING_FOREVER);
- rt_memset(WeightConst_feed,0x20,40);
- for (int i = 0; i <= setWeightConst_length-11; i++)
- WeightConst_feed[i] = WeightConst_PlantempList[i+4];
-
- WeightConst_WeightTarget = WeightConst_PlantempList[setWeightConst_length-6]<<8 ;
- WeightConst_WeightTarget = WeightConst_WeightTarget | WeightConst_PlantempList[setWeightConst_length-5];
-
- WeightConst_WeightTargetTemp = WeightConst_WeightTarget;
-
- for (int i = 0; i < 5; i++)
- pf_comp.Buffer[i] = WeightConst_PlantempList[setWeightConst_length-4 + i];
- if ( pf_comp.data.tW_minus ==1)
- WeightConst_WeightTarget = WeightConst_WeightTarget * -1;
- WeightConst_Product_Run = (pf_comp.data.pfsort<253);
- WeightConst_DELAYTIME = 0;
- WeightConst_DELAYON = 0;
- CanButton = 0x01;
- WeightConst_oksum=0;
- WeightConst_WeightOK = 0;
- if (pf_comp.data.firstReget) {
- pf_comp.data.needBegin = 0;
- plan_comp.data.reget = 0;
- WeightConst_Product_JS = 0;
- }
- else WeightConst_Product_JS = 1;
- if (pf_comp.data.needBegin == 1 && isTag==0 && pf_comp.data.addorout==1)
- {
- CompleteTarget_order = pf_comp.data.pfsort;
- write_Flash("completeorder", &CompleteTarget_order, sizeof(CompleteTarget_order));
- }
-
- if (pf_comp.data.needBegin == 0 || CompleteTarget_order == pf_comp.data.pfsort
- || (pf_comp.data.needBegin == 1 && isTag==0 && pf_comp.data.addorout==1))
- getTargetWeight();
-
- rt_sem_release(display_lock);
-
- if (pf_comp.data.pfsort>=253)
- {
- reset_read_ts('p');
-
- }
-
- if (WeightConst_SBType>2 && WeightConst_SBType<7) {
-
-
- if (WeightConst_Product_Run)
- {
- if (plan_comp.data.reget>0)
- rt_event_send(&display_event, EVENT_Current_noweight);
- else
- rt_event_send(&display_event, EVENT_Current);
- }
- else
- {
- rt_event_send(&display_event, EVENT_clearall);
- rt_event_send(&display_event, EVENT_Current_noweight);
- }
- if (findNextplan()>0)
- rt_event_send(&display_event, EVENT_Next);
- }
- break;
- }
- }
-
- rt_thread_mdelay(10);
- }
- }
- }
- void sendgetTime(void) {
-
-
- unsigned char buf[6] ;
- unsigned char CRCNum=0;
- buf[0]= 0x7E;
- buf[1]= 0x04;
- buf[2]= XbeeConst_DeviceAddress;
-
- buf[3]= 0xF8;
- buf[4] = XbeeConst_FrameNum++;
- for (int i=0; i< 5; i++) CRCNum+=buf[i];
- buf[5] = 0xff - CRCNum;
-
- if(READ_BIT(RCC->CSR, RCC_CSR_IWDGRSTF) == RESET)
- {
- ts_pushArrary(&ts_keydb, buf, buf[1]+2);
- }
- if (tsdb_recordcount('p') > 0) {
- findF12();
- rt_event_send(&display_event, EVENT_PlanName);
- rt_thread_mdelay(1000);
- rt_sem_release(pop_product_sem);
- }
- __HAL_RCC_CLEAR_RESET_FLAGS();
- }
- void sendkey2(int BtnType) {
-
- unsigned char buf[17];
- unsigned char CRCNum;
- union timekeyweight_t xBytes;
- CRCNum = 0;
- xBytes = getTimeWeight(2);
- buf[0]= 0x7E;
- buf[1]= 0x0F;
- buf[2]= XbeeConst_DeviceAddress;
- buf[3]= BtnType;
-
- for (int i=9; i >0; i--) buf[i+3]= xBytes.Buffer[9-i];
- if (BtnType==0xF4) {
- beep();
- XbeeConst_lastsort=0xFD;
- buf[13] = 0x00;
- buf[14] = 0x00;
- }
- else {
- buf[13] = XbeeConst_lastsort;
- buf[14] = XbeeConst_lastinorout;
- }
- buf[15] = XbeeConst_FrameNum ++;
- for (int i=0; i< 16; i++) CRCNum+=buf[i];
- buf[16] = 0xff - CRCNum;
- ts_pushArrary(&ts_keydb, buf, buf[1]+2);
- if (BtnType==0xF4) {
-
- getPlaning = 1;
- rt_sem_take(weight_lock, RT_WAITING_FOREVER);
- WeightConst_WeightBegin = WeightConst_WeightCur;
- rt_sem_release(weight_lock);
- rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
- write_Flash("begintime", &TimeConst, sizeof(TimeConst));
- rt_sem_release(setTIME_lock);
- write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
- write_Flash("TimeConst", &TimeConst, sizeof(TimeConst));
- }
- }
- void sendkey1(int BtnType, int remote) {
-
- unsigned char buf[17];
- unsigned char CRCNum;
- union timekeyweight_t xBytes;
- CRCNum = 0;
- xBytes = getTimeWeight(BtnType);
- buf[0]= 0x7E;
- buf[1]= 0x0F;
- if (isCC)
- buf[2]= ((remote<< 4) & 0x0f) | (XbeeConst_DeviceAddress& 0x0f);
- else
- buf[2]= XbeeConst_DeviceAddress & 0x0f;
- buf[3]= BtnType;
- for (int i=9; i >0; i--) buf[i+3]= xBytes.Buffer[9-i];
- buf[13]= pf_comp.data.pfsort;
- buf[14]= 0x00;
- buf[15] = XbeeConst_FrameNum ++;
- for (int i=0; i< 16; i++)
- CRCNum+=buf[i];
- buf[16]= 0xff - CRCNum;
- ts_pushArrary(&ts_keydb, buf, buf[1]+2);
-
- CompleteTarget_order = pf_comp.data.pfsort;
- rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
- write_Flash("TimeConst", &TimeConst, sizeof(TimeConst));
- rt_sem_release(setTIME_lock);
- save_read_ts('p');
- beep();
- alarm_off();
- if (pf_comp.data.pfsort == 0xFE) {
- rt_sem_take(display_lock, RT_WAITING_FOREVER);
- setWeightConst_initProduct();
- WeightConst_Product_Run_time=0;
- rt_sem_release(display_lock);
- }
- else
- {
- WeightConst_Product_Run_time++;
- rt_sem_take(weight_lock, RT_WAITING_FOREVER);
- WeightConst_WeightBegin = WeightConst_WeightCur;
- rt_sem_release(weight_lock);
- rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
- write_Flash("begintime", &TimeConst, sizeof(TimeConst));
- rt_sem_release(setTIME_lock);
- write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
- if (pf_comp.data.delaytime)
- WeightConst_DELAYON = 1;
- else
- {
-
- rt_sem_release(pop_product_sem);
- WeightConst_DELAYON = 0;
- }
- }
- }
- void getTargetWeight(void)
- {
- WeightConst_WeightHaveBegin = 1;
- if (pf_comp.data.tw_pos > WeightConst_WeightWS) {
- WeightConst_WeightTarget = WeightConst_WeightTarget/mypow(10,pf_comp.data.tw_pos - WeightConst_WeightWS);
- pf_comp.data.tw_pos = WeightConst_WeightWS;
- }
- else if (pf_comp.data.tw_pos < WeightConst_WeightWS) {
- WeightConst_WeightTarget = WeightConst_WeightTarget*mypow(10,WeightConst_WeightWS - pf_comp.data.tw_pos);
- pf_comp.data.tw_pos = WeightConst_WeightWS;
- }
- if (WeightConst_Product_JS == 1) {
- rt_sem_take(weight_lock, RT_WAITING_FOREVER);
- if (WeightConst_WeightBegin == -30000)
- WeightConst_WeightBegin = WeightConst_WeightCur;
- rt_sem_release(weight_lock);
-
- if (pf_comp.data.addorout == 0)
- WeightConst_WeightTarget = WeightConst_WeightBegin + WeightConst_WeightTarget;
- else
- WeightConst_WeightTarget = WeightConst_WeightBegin - WeightConst_WeightTarget;
- }
- else
- WeightConst_WeightBegin=-30000;
-
- if (pf_comp.data.az_pos > pf_comp.data.tw_pos) {
- pf_comp.data.autozone = pf_comp.data.autozone/mypow(10,pf_comp.data.az_pos-pf_comp.data.tw_pos);
- pf_comp.data.az_pos = pf_comp.data.tw_pos;
- }
- else if (pf_comp.data.az_pos < pf_comp.data.tw_pos) {
- pf_comp.data.autozone = pf_comp.data.autozone*mypow(10,pf_comp.data.tw_pos-pf_comp.data.az_pos);
- pf_comp.data.az_pos = pf_comp.data.tw_pos;
- }
- WeightConst_WeightTargetAllowMin = WeightConst_WeightTarget - pf_comp.data.autozone;
- WeightConst_WeightTargetAllowMax = WeightConst_WeightTarget + pf_comp.data.autozone;
- WeightConst_AutoSingleNSecondPoint=0;
- WeightConst_oksum = 0;
- WeightConst_allsum = 0;
- if (WeightConst_SBType>2 && WeightConst_SBType<7) {
- rt_event_send(&display_event, EVENT_Stop);
- }
-
- }
- void SendWifi_entry(void *parameter) {
- while (1)
- {
- if ((XbeeConst_needRetry>(40+XbeeConst_DeviceAddress)) && XbeeConst_CanSend==0) {
- if ((XbeeConst_FTxBuf0[4]&0xF0) == 0xF0) {
- XbeeConst_FTxBuf0[4]=XbeeConst_FTxBuf0[4]-16;
- XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]] = 0;
- for (int i=1; i< XbeeConst_FTxBuf0[0]; i++){
- XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]] += XbeeConst_FTxBuf0[i];
- }
- XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]] = 0xff - XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]];
- }
- if (XbeeConst_UseAPI>0) {
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- setSendFrame_t(XbeeConst_FTxBuf0[4]==0xF8 || XbeeConst_FTxBuf0[4]==0xE8,0x00,0xC0);
-
- XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FTxBuf0);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_PTxBuf0[SendWifi_i];
-
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- else{
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_FTxBuf0[SendWifi_i];
-
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- XbeeConst_needRetry = 0;
- XbeeConst_FrameNumLast = XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]-1];
- }
- else if (XbeeConst_CanSend==1 && tsdb_recordcount('k')>0) {
- if (findkey()<0xFFFFFFFF)
- {
- XbeeConst_CanSend = 0;
- XbeeConst_needRetry = 0;
- XbeeConst_FrameNumLast = XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]-1];
- if (XbeeConst_UseAPI>0) {
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- setSendFrame_t(XbeeConst_FTxBuf0[4]==0xF8,0x00,0xC0);
- XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FTxBuf0);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_PTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- else
- {
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_FTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- }
- }
- else if (XbeeConst_CanSend==1 && tsdb_recordcount('w')>=4) {
- if (findweight()>3){
- XbeeConst_CanSend = 0;
- XbeeConst_needRetry = 0;
- XbeeConst_FrameNumLast = XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]-1];
- if (XbeeConst_UseAPI>0) {
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- setSendFrame_t(XbeeConst_FTxBuf0[4]==0xF8,0x00,0xC0);
- XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FTxBuf0);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_PTxBuf0[SendWifi_i];
-
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- else{
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_FTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FTxBuf0[0]);
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- }
- }
- else if (XbeeConst_CanSend==1 && rb_full_count(SendWeightQueue)>0 && rb_peek(SendWeightQueue)==0x7e && iscowweight==1) {
- XbeeConst_FTxBuf0[1] = rb_remove(SendWeightQueue);
- XbeeConst_FTxBuf0[2] = rb_remove(SendWeightQueue);
- XbeeConst_FTxBuf0[0] = XbeeConst_FTxBuf0[2] + 2;
- for (int SendWifi_i = 3; SendWifi_i <= XbeeConst_FTxBuf0[0]; SendWifi_i++)
- XbeeConst_FTxBuf0[SendWifi_i] = rb_remove(SendWeightQueue);
-
- XbeeConst_CanSend = 0;
- XbeeConst_needRetry = 0;
- XbeeConst_FrameNumLast = XbeeConst_FTxBuf0[XbeeConst_FTxBuf0[0]-1];
- rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
- if (XbeeConst_UseAPI>0) {
- setSendFrame_t(XbeeConst_FTxBuf0[4]==0xF8,0x00,0xC0);
- XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FTxBuf0);
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_PTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
- }
- else
- {
- for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FTxBuf0[0]; SendWifi_i++)
- usart2_send_data[SendWifi_i-1] = XbeeConst_FTxBuf0[SendWifi_i];
- HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FTxBuf0[0]);
- }
- rt_thread_mdelay(50);
- rt_sem_release(uart2_lock);
- }
- XbeeConst_needRetry++;
- rt_thread_mdelay(100);
- }
- }
- static rt_thread_t SendWifiid = RT_NULL;
- void SendWifi_thread(void)
- {
- SendWifiid = rt_thread_create("SendWifi", SendWifi_entry, RT_NULL, 0x300,5, 5);
-
- if (SendWifiid != RT_NULL) rt_thread_startup(SendWifiid);
- }
- static rt_thread_t pop_productid = RT_NULL;
- void pop_product_thread(void)
- {
- pop_productid = rt_thread_create("popproduct", pop_product_entry, RT_NULL, 0x400, 5, 5);
-
- if (pop_productid != RT_NULL) rt_thread_startup(pop_productid);
- }
|