buffer.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. #include "ring_buffer.h"
  2. #include <rtthread.h>
  3. #include "usart.h"
  4. #include "weight.h"
  5. #include "flash.h"
  6. #include "plan.h"
  7. #include "display.h"
  8. #include "button.h"
  9. #include "xBeeAppEscapingMode.h"
  10. rt_sem_t thread_EmptyBuffer_sem = RT_NULL;
  11. rt_sem_t uart1_lock = RT_NULL;
  12. rt_sem_t uart2_lock = RT_NULL;
  13. rt_sem_t uart3_lock = RT_NULL;
  14. rt_sem_t uart4_lock = RT_NULL;
  15. rt_sem_t uart5_lock = RT_NULL;
  16. #define BUF_SIZE 256
  17. ring_buffer usart1_buf,usart2_buf,usart3_buf,uart4_buf,uart5_buf;
  18. ring_buffer *rb_usart1,*rb_usart2,*rb_usart3,*rb_uart4,*rb_uart5;
  19. unsigned char rb_buffer1[BUF_SIZE],rb_buffer2[BUF_SIZE*4],rb_buffer3[BUF_SIZE],rb_buffer4[BUF_SIZE],rb_buffer5[BUF_SIZE];
  20. ring_buffer display_buf;
  21. ring_buffer *rb_display;
  22. unsigned char rb_display_buffer[BUF_SIZE];
  23. ring_buffer _SendWeightQueue,_XbeeQueue,_XbeeAPIQueue,_RemoteQueue;
  24. ring_buffer *SendWeightQueue,*XbeeQueue,*XbeeAPIQueue,*RemoteQueue;
  25. unsigned char SendWeightQueue_bf[BUF_SIZE*4],XbeeQueue_bf[BUF_SIZE*2],XbeeAPIQueue_bf[BUF_SIZE*4],RemoteQueue_bf[BUF_SIZE*2];
  26. ring_buffer _RecWeightQueue;
  27. ring_buffer *RecWeightQueue;
  28. uint8_t RecWeightQueue_bf[128];
  29. uint8_t usart1_send_data[64];
  30. uint8_t usart2_send_data[256];
  31. uint8_t usart3_send_data[64];
  32. uint8_t uart4_send_data[256];
  33. uint8_t flag_uart1_send = 0;
  34. uint8_t flag_uart2_send = 0;
  35. uint8_t flag_uart3_send = 0;
  36. uint8_t flag_uart4_send = 0;
  37. unsigned char XbeeConst_CenterAddress[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF}; //开始地址 0xFF
  38. unsigned char XbeeConst_CCAddress[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF}; //开始地址 0xFF //开始地址 0x10
  39. unsigned char XbeeConst_RemoteAddress = 0x01; // 远程TMR地址
  40. static unsigned char XbeeConst_FRxBufAPI[100]; //处理无线临时表
  41. unsigned char XbeeConst_ReadAPINum = 0;
  42. static unsigned char XbeeConst_needEscape=0;
  43. unsigned char XbeeConst_FRemoteTxBuf[]= {0x00,0x7E,0x15,0x00,0xF1,0x7E,0x45,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  48. }; //处理铲车临时表
  49. static unsigned char XbeeConst_FRxBuf0[100]; //处理完整无线临时表
  50. static unsigned char XbeeConst_FRxBuf0_Remote[100]; //处理完整铲车无线临时表
  51. static unsigned char XbeeConst_FrameLength0 = 0;
  52. static unsigned char XbeeConst_ReadNum0 = 0;
  53. static unsigned char XbeeConst_FrameLength0_Remote = 0, XbeeConst_ReadNum0_Remote = 0;
  54. unsigned char XbeeConst_FrameNumLast=0; //上次发送的帧编号
  55. unsigned char RemoteFrameNumLast = 0xFF; //铲车接收的上次帧编号
  56. unsigned char XbeeConst_FTxBuf0[50]; //处理发送无线临时表
  57. unsigned char* XbeeConst_PTxBuf0; //处理发送无线临时表
  58. unsigned char* XbeeConst_PRemoteTxBuf0; //处理发送远程显示临时表
  59. unsigned char ccsend = 0;
  60. extern unsigned char iscowweight;
  61. unsigned char readyPop = 0;
  62. static unsigned char XbeeConst_FRxBuf12[100]; //处理完整无线临时表
  63. char b[40] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U'};
  64. unsigned char* BleApp2MakeFrame(unsigned short dist,unsigned char cmd,unsigned char type,unsigned char* buf)//返回一个处理完成后的数组的首地址
  65. {
  66. unsigned char len = buf[0];
  67. unsigned char BLEMakeFrame[100];//makeFrame保存转义完成后的数据
  68. unsigned char l;
  69. unsigned char xLen = 1;//处理后的数组长度,放在数组的第一位
  70. BLEMakeFrame[xLen++] = 0x41;
  71. BLEMakeFrame[xLen++] = 0x54;
  72. BLEMakeFrame[xLen++] = 0x2b;
  73. BLEMakeFrame[xLen++] = 0x4d;
  74. BLEMakeFrame[xLen++] = 0x45;
  75. BLEMakeFrame[xLen++] = 0x53;
  76. BLEMakeFrame[xLen++] = 0x48;
  77. BLEMakeFrame[xLen++] = cmd;
  78. BLEMakeFrame[xLen++] = (dist>>8)&0xFF;
  79. BLEMakeFrame[xLen++] = dist&0xFF;
  80. if (type==0)
  81. {
  82. BLEMakeFrame[xLen++] = type;
  83. for(l = 4; l < 15; l++) BLEMakeFrame[xLen++] = buf[l];
  84. }
  85. else{
  86. BLEMakeFrame[xLen++] = type;
  87. for(l = 4; l < 7; l++) BLEMakeFrame[xLen++] = buf[l];
  88. for(l = 15; l < 23; l++) BLEMakeFrame[xLen++] = buf[l];
  89. }
  90. BLEMakeFrame[xLen++] = 0x0D;
  91. BLEMakeFrame[xLen++] = 0x0A;
  92. BLEMakeFrame[0] = xLen - 1;
  93. return BLEMakeFrame;//返回最终数组
  94. }
  95. void RB_init(void)
  96. {
  97. rb_usart1 = &usart1_buf;
  98. rb_init(rb_usart1, sizeof(rb_buffer1)/sizeof(rb_buffer1[0]), rb_buffer1);
  99. rb_usart2 = &usart2_buf;
  100. rb_init(rb_usart2, sizeof(rb_buffer2)/sizeof(rb_buffer2[0]), rb_buffer2);
  101. rb_usart3 = &usart3_buf;
  102. rb_init(rb_usart3, sizeof(rb_buffer3)/sizeof(rb_buffer3[0]), rb_buffer3);
  103. rb_uart4 = &uart4_buf;
  104. rb_init(rb_uart4, sizeof(rb_buffer4)/sizeof(rb_buffer4[0]), rb_buffer4);
  105. rb_uart5 = &uart5_buf;
  106. rb_init(rb_uart5, sizeof(rb_buffer5)/sizeof(rb_buffer5[0]), rb_buffer5);
  107. // if (WeightConst_SBType==4||WeightConst_SBType==6) {
  108. rb_display = &display_buf;
  109. rb_init(rb_display, sizeof(rb_display_buffer)/sizeof(rb_display_buffer[0]), rb_display_buffer);
  110. // }
  111. SendWeightQueue = &_SendWeightQueue;
  112. rb_init(SendWeightQueue, sizeof(SendWeightQueue_bf)/sizeof(SendWeightQueue_bf[0]), SendWeightQueue_bf);
  113. XbeeQueue = &_XbeeQueue;
  114. rb_init(XbeeQueue, sizeof(XbeeQueue_bf)/sizeof(XbeeQueue_bf[0]), XbeeQueue_bf);
  115. XbeeAPIQueue = &_XbeeAPIQueue;
  116. rb_init(XbeeAPIQueue, sizeof(XbeeAPIQueue_bf)/sizeof(XbeeAPIQueue_bf[0]), XbeeAPIQueue_bf);
  117. RecWeightQueue = &_RecWeightQueue;
  118. rb_init(RecWeightQueue, sizeof(RecWeightQueue_bf)/sizeof(RecWeightQueue_bf[0]), RecWeightQueue_bf);
  119. RemoteQueue = &_RemoteQueue;
  120. rb_init(RemoteQueue, sizeof(RemoteQueue_bf)/sizeof(RemoteQueue_bf[0]), RemoteQueue_bf);
  121. }
  122. void USART_Push(unsigned char address, unsigned char data)
  123. {
  124. if (address==1)
  125. {
  126. rb_push_insert(rb_usart1, data);
  127. }
  128. else if (address==2)
  129. {
  130. rb_push_insert(rb_usart2, data);
  131. }
  132. else if (address==3)
  133. {
  134. rb_push_insert(rb_usart3, data);
  135. }
  136. else if (address==4)
  137. {
  138. rb_push_insert(rb_uart4, data);
  139. }
  140. else if (address==5)
  141. {
  142. rb_push_insert(rb_uart5, data);
  143. }
  144. }
  145. void RX_API(void) {
  146. unsigned char tempval, checksum = 0;
  147. if (rb_full_count(XbeeAPIQueue)> 0) {
  148. tempval = rb_remove(XbeeAPIQueue); //继续存数据
  149. // rt_kprintf(" %02X",tempval);
  150. switch (XbeeConst_ReadAPINum) {
  151. case 0:
  152. if (tempval == 0x7e) { //协议头前面1个7E判断
  153. XbeeConst_FRxBufAPI[0] = tempval;
  154. XbeeConst_ReadAPINum = 1;
  155. }
  156. break;
  157. case 1:
  158. if (tempval == 0x7e) { //协议头前面1个7E判断
  159. XbeeConst_FRxBufAPI[0] = tempval;
  160. XbeeConst_ReadAPINum = 1;
  161. }
  162. else {
  163. if (tempval == 0x7D) XbeeConst_needEscape = 1;
  164. else
  165. {
  166. if (XbeeConst_needEscape) {
  167. XbeeConst_needEscape=0;
  168. tempval = tempval^0x20;
  169. }
  170. XbeeConst_FRxBufAPI[XbeeConst_ReadAPINum++] = tempval;
  171. }
  172. }
  173. break;
  174. case 2:
  175. if (tempval == 0x7e) { //协议头前面1个7E判断
  176. XbeeConst_FRxBufAPI[0] = tempval;
  177. XbeeConst_ReadAPINum = 1;
  178. }
  179. else {
  180. if (tempval == 0x7D) XbeeConst_needEscape = 1;
  181. else
  182. {
  183. if (XbeeConst_needEscape) {
  184. XbeeConst_needEscape=0;
  185. tempval = tempval^0x20;
  186. }
  187. XbeeConst_FRxBufAPI[XbeeConst_ReadAPINum++] = tempval;
  188. }
  189. }
  190. break;
  191. default:
  192. if (tempval == 0x7e) { //协议头前面1个7E判断
  193. XbeeConst_FRxBufAPI[0] = tempval;
  194. XbeeConst_ReadAPINum = 1;
  195. }
  196. else {
  197. if (tempval == 0x7D) XbeeConst_needEscape = 1;
  198. else
  199. {
  200. if (XbeeConst_needEscape) {
  201. XbeeConst_needEscape=0;
  202. tempval = tempval^0x20;
  203. }
  204. XbeeConst_FRxBufAPI[XbeeConst_ReadAPINum++] = tempval;
  205. }
  206. }
  207. if (XbeeConst_ReadAPINum > XbeeConst_FRxBufAPI[2]+3) { //读完已知长度的数据
  208. // rt_kprintf("\n");
  209. for (unsigned short i = 3; i < XbeeConst_FRxBufAPI[2]+3; i++)
  210. checksum += XbeeConst_FRxBufAPI[i];
  211. if (((0xff - checksum)&0xFF) == XbeeConst_FRxBufAPI[XbeeConst_FRxBufAPI[2]+3]) //校验成功
  212. {
  213. if (XbeeConst_FRxBufAPI[3] == 0x90) {
  214. if((XbeeConst_FRxBufAPI[18]&0xF0) == 0xA0 || (XbeeConst_FRxBufAPI[18]) == 0x14) //铲车数据
  215. {
  216. if ((XbeeConst_FRxBufAPI[18] == 0xA1 && WeightConst_SBType == 2) ||
  217. (XbeeConst_FRxBufAPI[18] != 0xA1 ))
  218. for (unsigned short i = 15; i < XbeeConst_FRxBufAPI[2]+3; i++)
  219. rb_push_insert(RemoteQueue, XbeeConst_FRxBufAPI[i]); //赋值数据到数组
  220. }
  221. else if (XbeeConst_FRxBufAPI[18] == 0xB2 && XbeeConst_FRxBufAPI[19] == 0x03) //收到设置铲车定向
  222. {
  223. for (unsigned short i = 0; i < 8; i++) XbeeConst_CCAddress[i] = XbeeConst_FRxBufAPI[i+4];
  224. ccsend = (XbeeConst_FRxBufAPI[17] == XbeeConst_DeviceAddress);
  225. }
  226. else if (XbeeConst_FRxBufAPI[17] == XbeeConst_DeviceAddress || XbeeConst_FRxBufAPI[17] == 0xFF)
  227. for (unsigned short i = 15; i < XbeeConst_FRxBufAPI[2]+3; i++)
  228. rb_push_insert(XbeeQueue, XbeeConst_FRxBufAPI[i]); //赋值数据到数组
  229. if(XbeeConst_FRxBufAPI[18]==0x18)
  230. for (unsigned short i = 0; i < 8; i++)
  231. XbeeConst_CenterAddress[i] = XbeeConst_FRxBufAPI[i+4];
  232. }
  233. }
  234. XbeeConst_ReadAPINum = 0; //循环计数清零
  235. }
  236. break;
  237. }
  238. }
  239. }
  240. static unsigned char planreget_save,planreget = 0;
  241. static uint8_t foundlastplan_ ;
  242. void RX(void) {
  243. unsigned char tempval, checksum = 0;
  244. if (rb_full_count(XbeeQueue)> 0) {
  245. tempval = rb_remove(XbeeQueue); //继续存数据
  246. switch (XbeeConst_ReadNum0) {
  247. case 0:
  248. if (tempval == 0x7e) { //协议头前面1个7E判断
  249. XbeeConst_FRxBuf0[XbeeConst_ReadNum0] = tempval;
  250. XbeeConst_ReadNum0++;
  251. }
  252. break;
  253. case 1:
  254. XbeeConst_FRxBuf0[XbeeConst_ReadNum0] = tempval; //这个字节为帧长度
  255. XbeeConst_ReadNum0++;
  256. XbeeConst_FrameLength0 = XbeeConst_FRxBuf0[1] + 1; //算出帧长度
  257. break;
  258. default:
  259. XbeeConst_FRxBuf0[XbeeConst_ReadNum0] = tempval; //读数据
  260. if (XbeeConst_ReadNum0 >= XbeeConst_FrameLength0) { //读完已知长度的数据
  261. for (unsigned short i = 0; i < XbeeConst_FrameLength0; i++)
  262. checksum += XbeeConst_FRxBuf0[i];
  263. if ((0xff - checksum) == XbeeConst_FRxBuf0[XbeeConst_FrameLength0]) //校验成功
  264. {
  265. rt_strncpy(dataframehead.Buffer, XbeeConst_FRxBuf0, 4);
  266. if ((dataframehead.data.addr&0x1F) == XbeeConst_DeviceAddress || dataframehead.data.addr == 0xFF) { //收到本设备的数据,不是本设备的不处理
  267. if (dataframehead.data.frameType == 0x10) { //实时重量
  268. if (XbeeConst_FRxBuf0[XbeeConst_FrameLength0-1] == XbeeConst_FrameNumLast) {
  269. save_read_ts('w');
  270. XbeeConst_CanSend=0x01;//取消无线发送锁定
  271. }
  272. }
  273. else if (dataframehead.data.frameType == 0xAA && isnewLora==1) { //1号键回复
  274. rt_sem_release(displayRemote_lock);
  275. rt_sem_release(sendLora_lock);
  276. }
  277. else if (dataframehead.data.frameType == 0x11 ) { //1号键回复
  278. if (XbeeConst_FRxBuf0[XbeeConst_FrameLength0-1] == XbeeConst_FrameNumLast) {
  279. save_read_ts('k');
  280. XbeeConst_CanSend=0x01;//取消无线发送锁定
  281. }
  282. }
  283. else if (dataframehead.data.frameType == 0x12 || dataframehead.data.frameType == 0x15) { //2号键内容
  284. // rt_kprintf("%02X//////////////////////////%02X \n",dataframehead.data.frameType,XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  285. if (dataframehead.data.frameType == 0x12)
  286. {
  287. // if(isn==1) {
  288. // clearScreenAll_();
  289. // delay_ms(100);
  290. // }
  291. if (getPlaning==1)
  292. {
  293. planreget_save = 0;
  294. readyPop = 1;
  295. for (int i=0;i<XbeeConst_FRxBuf0[1]+2;i++)
  296. XbeeConst_FRxBuf12[i] = XbeeConst_FRxBuf0[i];
  297. }
  298. //setWeightConst_initProduct();
  299. // rt_sem_release(pop_product_sem);//需要弹出最新内容
  300. }
  301. else if (dataframehead.data.frameType == 0x15)
  302. {
  303. // rt_kprintf("--XbeeConst_lastsort:%02X \n", XbeeConst_lastsort);
  304. // rt_kprintf("0x15 ------index:%02X \n",XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  305. if (XbeeConst_lastsort==0xFD && XbeeConst_lastsort < XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  306. reset_read_ts('p');
  307. if (readyPop==1 && getPlaning==1)
  308. {
  309. // readyPop = 0;
  310. getPlaning=0;
  311. planreget = XbeeConst_FRxBuf12[XbeeConst_FRxBuf12[1]-3]&0x01;
  312. reset_read_ts('p');
  313. ts_pushArrary(&ts_plandb, XbeeConst_FRxBuf12, XbeeConst_FRxBuf12[1]+2);
  314. // rt_kprintf("\n");
  315. // rt_kprintf("\n");
  316. // rt_kprintf("\n");
  317. // rt_kprintf("0x12-----------------------------\n");
  318. // rt_kprintf("pop index:%02X \n",XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  319. rt_sem_release(pop_product_sem);//需要弹出最新内容
  320. }
  321. if (planreget_save==0 && planreget==1){
  322. XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-2] = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-2] | 0x01;
  323. }
  324. planreget_save =1;
  325. foundlastplan_ = 0xF0;
  326. foundlastplan_ = findlastplan();
  327. if ((XbeeConst_lastsort != XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]
  328. && foundlastplan_ != XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  329. || XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]>0xFD)
  330. ts_pushArrary(&ts_plandb, XbeeConst_FRxBuf0, XbeeConst_FRxBuf0[1]+2);
  331. save_read_ts('k');
  332. XbeeConst_CanSend=0x01;//取消无线发送锁定
  333. if (XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]<0xFD && getPlaning==0) { //如果没有结束,则发送05协议
  334. XbeeConst_lastsort = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1];
  335. XbeeConst_lastinorout = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-3]>>7;
  336. // rt_kprintf("XbeeConst_lastsort get:%02X \n", XbeeConst_lastsort);
  337. sendkey2(0xF5);
  338. }
  339. else if (XbeeConst_lastsort==0xFD && readyPop==0 && XbeeConst_lastsort < XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  340. {
  341. rt_sem_release(pop_product_sem);//如果直接收到15,如全天结束或空计划,需要弹出最新内容
  342. }
  343. if (readyPop==1) readyPop = 0;
  344. }
  345. }
  346. else if (dataframehead.data.frameType == 0x14) { //无线按键处理
  347. RemoteSendDisplay = 0;
  348. if (isCC)
  349. checksum =0x7E + 0x05 + ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 4 ) | XbeeConst_DeviceAddress
  350. + 0xA4 + XbeeConst_FRxBuf0[4] + XbeeConst_FRxBuf0[5];
  351. else
  352. checksum =0x7E + 0x05 + XbeeConst_DeviceAddress + 0xA4 + XbeeConst_FRxBuf0[4] + XbeeConst_FRxBuf0[5];
  353. XbeeConst_FRemoteTxBuf[0] = 0x07;
  354. XbeeConst_FRemoteTxBuf[1] = 0x7E;
  355. XbeeConst_FRemoteTxBuf[2] = 0x05;
  356. if (isCC)
  357. XbeeConst_FRemoteTxBuf[3] = ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 4 ) | XbeeConst_DeviceAddress;
  358. else
  359. XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
  360. XbeeConst_FRemoteTxBuf[4] = 0xA4;
  361. XbeeConst_FRemoteTxBuf[5] = XbeeConst_FRxBuf0[4];
  362. XbeeConst_FRemoteTxBuf[6] = XbeeConst_FRxBuf0[5];
  363. XbeeConst_FRemoteTxBuf[7] = 0xff - checksum;
  364. if (XbeeConst_UseAPI>0) {
  365. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  366. setSendFrame_t(0x01,0x01,0xC1);
  367. XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
  368. for (int i = 1; i <= XbeeConst_PTxBuf0[0]; i++) //将缓冲区发出
  369. usart2_send_data[i - 1] = XbeeConst_PTxBuf0[i];
  370. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
  371. rt_sem_release(uart2_lock);
  372. }
  373. else {
  374. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  375. for (int i = 1; i <= XbeeConst_FRemoteTxBuf[0]; i++) //将缓冲区发出
  376. usart2_send_data[i - 1] = XbeeConst_FRemoteTxBuf[i];
  377. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FRemoteTxBuf[0]);
  378. rt_sem_release(uart2_lock);
  379. }
  380. RemoteSendDisplay = 1;
  381. if (XbeeConst_FRxBuf0[4]==0x01 && button_state.b1 ==0 && delayKeying == 0)
  382. {
  383. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  384. {
  385. rt_sem_release(delay_key_sem); //收到1号键
  386. sendkey1(0xF3, ((XbeeConst_FRxBuf0_Remote[2] >> 4) & 0x0F) );
  387. WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  388. WeightConst_oksum = 0;
  389. WeightConst_joksum = 0;
  390. WeightConst_allsum = 0;
  391. button_state.b1=1; //5秒内不可按键
  392. }
  393. }
  394. else if (XbeeConst_FRxBuf0[4]==0x02 && button_state.b2==0) //收到2号键
  395. // sendkey2(0xF4);
  396. if(WeightConst_DELAYON==0)
  397. {
  398. if (tsdb_recordcount('k')==0)
  399. {
  400. sendkey2(0xF4);
  401. // WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  402. // WeightConst_oksum = 0;
  403. // WeightConst_allsum = 0;
  404. }
  405. }
  406. button_state.b2=1; //5秒内不可按键
  407. }
  408. else if (dataframehead.data.frameType == 0xA1) { //铲车显示处理
  409. for (unsigned short i=4; i < 22; i++) { //显示重量
  410. uart4_send_data[i - 4] = XbeeConst_FRxBuf0[i];
  411. uart4_send_data[18]=0;
  412. for (int i = 2; i <18; i++) //校验和
  413. uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
  414. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  415. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  416. rt_sem_release(uart4_lock);
  417. }
  418. }
  419. else if (dataframehead.data.frameType == 0xA4) { //无线按键成功处理
  420. beep();
  421. }
  422. else if (dataframehead.data.frameType == 0x16) { //设置无线模式
  423. XbeeConst_UseAPI = XbeeConst_FRxBuf0[4];
  424. write_Flash("API", &XbeeConst_UseAPI, sizeof(XbeeConst_UseAPI));
  425. setAPI();
  426. beep();
  427. }
  428. else if (dataframehead.data.frameType == 0x17) { //设置屏幕类型
  429. WeightConst_SBType = XbeeConst_FRxBuf0[4];
  430. write_Flash("PM", &WeightConst_SBType, sizeof(WeightConst_SBType));
  431. beep();
  432. }
  433. else if (dataframehead.data.frameType == 0x19) { //设置地址
  434. XbeeConst_DeviceAddress = XbeeConst_FRxBuf0[4];
  435. write_Flash("CH", &XbeeConst_DeviceAddress, sizeof(XbeeConst_DeviceAddress));
  436. beep();
  437. }
  438. else if (dataframehead.data.frameType == 0x1A) { //设置提取类型
  439. WeightConst_TQ = XbeeConst_FRxBuf0[4];
  440. write_Flash("TQ", &WeightConst_TQ, sizeof(WeightConst_TQ));
  441. //---------- USART_Configuration();
  442. beep();
  443. }
  444. else if (dataframehead.data.frameType == 0x1B) { //设置网络编号
  445. beep();
  446. XbeeConst_NetAddress = XbeeConst_FRxBuf0[4];
  447. write_Flash("WL", &XbeeConst_NetAddress, sizeof(XbeeConst_NetAddress));
  448. setNetAddress();
  449. beep();
  450. }
  451. else if (dataframehead.data.frameType == 0x18) { //设置时间
  452. XbeeConst_CanSend=0x01;//取消无线发送锁定
  453. TimeConst.Buffer[0] = XbeeConst_FRxBuf0[7];
  454. TimeConst.Buffer[1] = XbeeConst_FRxBuf0[6];
  455. TimeConst.Buffer[2] = XbeeConst_FRxBuf0[5];
  456. TimeConst.Buffer[3] = XbeeConst_FRxBuf0[4];
  457. save_read_ts('k');
  458. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  459. write_Flash("TimeConst", &TimeConst, sizeof(TimeConst));
  460. rt_sem_release(setTIME_lock);
  461. CanButton = 0x01;
  462. beep();
  463. }
  464. }
  465. }
  466. XbeeConst_ReadNum0 = 0; //循环计数清零
  467. XbeeConst_FrameLength0 = 0;
  468. } else {
  469. XbeeConst_ReadNum0++; //小于帧长度
  470. if (XbeeConst_ReadNum0>90)
  471. {
  472. XbeeConst_ReadNum0 = 0; //循环计数清零
  473. XbeeConst_FrameLength0 = 0;
  474. }
  475. }
  476. break;
  477. }
  478. }
  479. }
  480. void RX_Remote(void) {
  481. unsigned char tempval, checksum = 0;
  482. if (rb_full_count(RemoteQueue) > 0) {
  483. tempval = rb_remove(RemoteQueue); //继续存数据
  484. switch (XbeeConst_ReadNum0_Remote) {
  485. case 0:
  486. if (tempval == 0x7e) { //协议头前面1个7E判断
  487. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval;
  488. XbeeConst_ReadNum0_Remote++;
  489. }
  490. break;
  491. case 1:
  492. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval; //这个字节为帧长度
  493. XbeeConst_ReadNum0_Remote++;
  494. XbeeConst_FrameLength0_Remote= XbeeConst_FRxBuf0_Remote[1] + 1; //算出帧长度
  495. break;
  496. default:
  497. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval; //读数据
  498. if (XbeeConst_ReadNum0_Remote >= XbeeConst_FrameLength0_Remote) { //读完已知长度的数据
  499. for (unsigned short i = 0; i < XbeeConst_FrameLength0_Remote; i++)
  500. checksum += XbeeConst_FRxBuf0_Remote[i];
  501. if ((0xff - checksum) == XbeeConst_FRxBuf0_Remote[XbeeConst_FrameLength0_Remote]) //校验成功
  502. {
  503. if (
  504. (((XbeeConst_FRxBuf0_Remote[2] & 0x1F) == XbeeConst_RemoteAddress && (WeightConst_SBType == 2 || WeightConst_SBType == 7))
  505. ||
  506. ((XbeeConst_FRxBuf0_Remote[2] & 0x1F) == XbeeConst_DeviceAddress && (WeightConst_SBType != 2 && WeightConst_SBType != 7)))
  507. ||
  508. (XbeeConst_RemoteAddress==0 && XbeeConst_FRxBuf0_Remote[2]==0x0A)) { //收到本设备的数据,不是本设备的不处理
  509. if ((XbeeConst_FRxBuf0_Remote[3] == 0xA1 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  510. || (XbeeConst_FRxBuf0_Remote[3] == 0xF1 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  511. )
  512. { //铲车显示处理
  513. if (XbeeConst_FRxBuf0_Remote[14]==0xC8 && XbeeConst_FRxBuf0_Remote[15]==0xB7) //确认开始
  514. {
  515. XbeeConst_FRxBuf0_Remote[21] = 0x20;
  516. XbeeConst_FRxBuf0_Remote[20] = 0x20;
  517. XbeeConst_FRxBuf0_Remote[19] = 0x20;
  518. XbeeConst_FRxBuf0_Remote[18] = 0x20;
  519. XbeeConst_FRxBuf0_Remote[17] = 0x20;
  520. XbeeConst_FRxBuf0_Remote[16] = 0x20;
  521. XbeeConst_FRxBuf0_Remote[15] = 0x20;
  522. XbeeConst_FRxBuf0_Remote[14] = b[XbeeConst_RemoteAddress];
  523. }
  524. else
  525. {
  526. XbeeConst_FRxBuf0_Remote[17] = XbeeConst_FRxBuf0_Remote[16];
  527. XbeeConst_FRxBuf0_Remote[16] = XbeeConst_FRxBuf0_Remote[15];
  528. XbeeConst_FRxBuf0_Remote[15] = XbeeConst_FRxBuf0_Remote[14];
  529. XbeeConst_FRxBuf0_Remote[14] = b[XbeeConst_RemoteAddress];
  530. }
  531. for (unsigned short i=4; i < 22; i++) //显示重量
  532. uart4_send_data[i - 4] = XbeeConst_FRxBuf0_Remote[i];
  533. uart4_send_data[18]=0;
  534. for (int i = 2; i <18; i++) //校验和
  535. uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
  536. // if (WeightConst_SBType == 7)
  537. // {
  538. // for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  539. // WeightConst_feed[SendDisplay_i] = uart4_send_data[2+SendDisplay_i] ;
  540. // WeightConst_Weight_display[7-SendDisplay_i] = uart4_send_data[10+SendDisplay_i] ;
  541. // WeightConst_Weight_display[7] = 0x20;
  542. // }
  543. // get_msg(4,//Xstart
  544. // 8,//Ystart
  545. // 1,//size
  546. // 0,//reset
  547. // 0,//speed
  548. // 8,//字符个数
  549. // 3,//界面数
  550. // 0,//id
  551. // 0x5B,//Xend
  552. // 0,
  553. // &WeightConst_feed[0]//字码
  554. // );
  555. // delay_ms(200);
  556. // get_msg(92,//Xstart
  557. // 4,//Ystart
  558. // 2,//size
  559. // 0,//reset
  560. // 0,//speed
  561. // 8,//字符个数
  562. // 3,//界面数
  563. // 1,//id
  564. // 0xBF,//Xend
  565. // 1,
  566. // &WeightConst_Weight_display[0]//字码
  567. // );
  568. // }
  569. // else
  570. {
  571. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  572. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  573. rt_thread_mdelay(50);
  574. rt_sem_release(uart4_lock);
  575. }
  576. }
  577. else if (XbeeConst_FRxBuf0_Remote[3] == 0xA4 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  578. { //铲车收到无线按键成功处理
  579. beep();
  580. }
  581. else if (
  582. (XbeeConst_FRxBuf0_Remote[3] == 0xA2 || XbeeConst_FRxBuf0_Remote[3] == 0x14)
  583. && (WeightConst_SBType != 2 && WeightConst_SBType != 7) && XbeeConst_FRxBuf0_Remote[1] == 0x05
  584. // (XbeeConst_FRxBuf0_Remote[3] == 0xA2 && WeightConst_SBType != 2 && XbeeConst_UseAPI)
  585. // || (XbeeConst_FRxBuf0_Remote[3] == 0x14 && WeightConst_SBType != 2 && !XbeeConst_UseAPI)
  586. ) { //TMR收到无线按键处理
  587. RemoteSendDisplay = 0;
  588. XbeeConst_FRemoteTxBuf[0] = 7;
  589. XbeeConst_FRemoteTxBuf[1] = 0x7E;
  590. XbeeConst_FRemoteTxBuf[2] = 0x05;
  591. if (isCC)
  592. XbeeConst_FRemoteTxBuf[3] = ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 5 ) | (XbeeConst_DeviceAddress&0x1F);
  593. else
  594. XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
  595. XbeeConst_FRemoteTxBuf[4] = 0xA4;
  596. XbeeConst_FRemoteTxBuf[5] = XbeeConst_FRxBuf0_Remote[4];
  597. XbeeConst_FRemoteTxBuf[6] = XbeeConst_FRxBuf0_Remote[5];
  598. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0;
  599. for (int i = 1; i < XbeeConst_FRemoteTxBuf[0]; i++)
  600. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] =
  601. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]+XbeeConst_FRemoteTxBuf[i];
  602. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0xFF - XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]];
  603. if (XbeeConst_UseAPI>0) {
  604. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  605. setSendFrame_t(0x01,0x01,0xC1);
  606. XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
  607. for (int i = 1; i <= XbeeConst_PTxBuf0[0]; i++) //将缓冲区发出
  608. usart2_send_data[i - 1] = XbeeConst_PTxBuf0[i];
  609. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
  610. rt_thread_mdelay(50);
  611. rt_sem_release(uart2_lock);
  612. }
  613. else
  614. {
  615. if (iscowweight<1 )
  616. {
  617. rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
  618. for (int i = 1; i <= XbeeConst_FRemoteTxBuf[0]; i++) //将缓冲区发出
  619. usart3_send_data[i - 1] = XbeeConst_FRemoteTxBuf[i];
  620. HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]);
  621. rt_thread_mdelay(50);
  622. rt_sem_release(uart3_lock);
  623. }
  624. }
  625. RemoteSendDisplay = 1;
  626. if (XbeeConst_FRxBuf0_Remote[4]==0x01 && button_state.b1==0
  627. && RemoteFrameNumLast != XbeeConst_FRxBuf0_Remote[XbeeConst_FRxBuf0_Remote[1]])//收到1号键
  628. {
  629. if (pf_comp.data.needBegin == 1 && WeightConst_WeightHaveBegin==0)
  630. {
  631. beep();
  632. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  633. WeightConst_WeightBegin = WeightConst_WeightCur;
  634. rt_sem_release(weight_lock);
  635. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  636. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  637. rt_sem_release(setTIME_lock);
  638. write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  639. getTargetWeight();
  640. }
  641. else if (pf_comp.data.pfsort != 0xFE && delayKeying == 0)
  642. {
  643. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  644. {
  645. rt_sem_release(delay_key_sem);
  646. sendkey1(0xF3, ((XbeeConst_FRxBuf0_Remote[2] >> 4) & 0x0F));
  647. WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  648. WeightConst_oksum = 0;
  649. WeightConst_joksum = 0;
  650. WeightConst_allsum = 0;
  651. button_state.b1=1; //5秒内不可按键
  652. }
  653. }
  654. }
  655. else if (XbeeConst_FRxBuf0_Remote[4]==0x02 && button_state.b2==0
  656. && RemoteFrameNumLast != XbeeConst_FRxBuf0_Remote[XbeeConst_FRxBuf0_Remote[1]]) //收到2号键
  657. {
  658. if(!WeightConst_DELAYON>0)
  659. {
  660. if (tsdb_recordcount('k')==0)
  661. sendkey2(0xF4);
  662. }
  663. // WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  664. // WeightConst_oksum = 0;
  665. // WeightConst_allsum = 0;
  666. button_state.b2=1; //5秒内不可按键
  667. }
  668. }
  669. }
  670. RemoteFrameNumLast = XbeeConst_FRxBuf0_Remote[XbeeConst_FRxBuf0_Remote[1]];
  671. }
  672. XbeeConst_ReadNum0_Remote = 0; //循环计数清零
  673. XbeeConst_FrameLength0_Remote = 0;
  674. } else {
  675. XbeeConst_ReadNum0_Remote++; //小于帧长度
  676. if (XbeeConst_ReadNum0_Remote>90)
  677. {
  678. XbeeConst_ReadNum0_Remote = 0; //循环计数清零
  679. XbeeConst_FrameLength0_Remote = 0;
  680. }
  681. }
  682. break;
  683. }
  684. }
  685. }
  686. static unsigned char Rec_watchTag[50]; //接收标签
  687. unsigned char Rec_watchTag_point=0; //接收标签
  688. unsigned char ReadTag_state=0; //读标签状态 0 没读或已读成功,1 开始读 ,2 正在读
  689. unsigned char WriteTag_state=0; //写标签状态 0 没写或已写成功,1 开始写 ,2 正在写
  690. void ReadTag(unsigned char x) { //发送标签
  691. unsigned char sendchar;
  692. sendchar=0x7E;
  693. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  694. sendchar=0x03;
  695. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  696. sendchar=XbeeConst_DeviceAddress;
  697. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  698. sendchar=0xB2;
  699. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  700. sendchar=x;
  701. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  702. sendchar = 0x7E + 03 + XbeeConst_DeviceAddress + 0xB2 + x;
  703. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  704. if (x==1) ReadTag_state=1;
  705. else ReadTag_state=0;
  706. }
  707. void WriteTag(void) { //发送标签
  708. unsigned char sendchar;
  709. sendchar=0x7E;
  710. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  711. sendchar=0x0A;
  712. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  713. sendchar=XbeeConst_DeviceAddress;
  714. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  715. sendchar=0xB1;
  716. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  717. sendchar = 0x7E + 0x0A + XbeeConst_DeviceAddress + 0xB1;
  718. for (int i = 0; i < 8; i++) {
  719. sendchar = sendchar + WeightConst_feed[i];
  720. HAL_UART_Transmit(&huart5, (uint8_t *)&WeightConst_feed[i], 1, 1);
  721. }
  722. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  723. WriteTag_state = 1;
  724. }
  725. void watchTag(){
  726. unsigned char tempval, checksum = 0;
  727. tempval = rb_remove(rb_uart5);
  728. //HAL_UART_Transmit(&huart5, &tempval, 1,1);
  729. if (tempval==0x7e || Rec_watchTag_point>49){ //头 过长回头
  730. Rec_watchTag_point=0;
  731. }
  732. Rec_watchTag[Rec_watchTag_point++] = tempval;
  733. if (Rec_watchTag_point>1 && Rec_watchTag_point>(Rec_watchTag[1]+2) ){ //符合长度
  734. Rec_watchTag_point=0;
  735. for (int i = 0; i < Rec_watchTag[1]+2; i++)
  736. {
  737. checksum = checksum + Rec_watchTag[i];
  738. if (checksum== Rec_watchTag[Rec_watchTag[1]+2] && Rec_watchTag[2]==XbeeConst_DeviceAddress)
  739. {//校验通过
  740. if (Rec_watchTag[3]==0xB2)
  741. {
  742. if (Rec_watchTag[1]==2 && ReadTag_state==1)
  743. { //收到唤醒回复
  744. ReadTag_state=2;
  745. }else if (ReadTag_state==2){//收到标签
  746. ReadTag_state=0;
  747. for (int j = 0; j < 8; j++) {
  748. if (WeightConst_feed[j] != Rec_watchTag[4+j]) ReadTag_state=2;
  749. }
  750. if (ReadTag_state ==0 && pf_comp.data.needBegin==1 && WeightConst_WeightHaveBegin==0)
  751. {
  752. beep();
  753. WeightConst_WeightBegin = WeightConst_WeightCur;
  754. // FLKey_SaveQPOrder(pf_comp.data.pfsort);
  755. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  756. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  757. rt_sem_release(setTIME_lock);
  758. write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  759. getTargetWeight();
  760. ReadTag(0);//关闭唤醒
  761. }
  762. beep();
  763. }
  764. }
  765. else if (Rec_watchTag[3]==0xB1 && WriteTag_state>0){
  766. if (Rec_watchTag[1]==2){ //收到写入回复
  767. WriteTag_state=2;
  768. }else if(WriteTag_state==2){//写入成功
  769. beep();
  770. ReadTag(1);//kai唤醒
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. extern uint8_t rDataBuffer;
  778. static void threadEmptyBuffer_entry(void *parameter)
  779. {
  780. unsigned char tempval;
  781. // if (isTag >0 )
  782. // HAL_UART_Receive_IT(&huart5, &rDataBuffer, 1);
  783. while(1)
  784. {
  785. rt_sem_take(thread_EmptyBuffer_sem, RT_WAITING_FOREVER); //等待串口消息
  786. while (rb_full_count(rb_usart1) > 0) {
  787. ReadWeight();
  788. }
  789. while (rb_full_count(rb_usart2) > 0) {
  790. if (XbeeConst_UseAPI>0) {
  791. rb_push_insert(XbeeAPIQueue,rb_remove(rb_usart2));
  792. RX_API();
  793. }
  794. else
  795. rb_push_insert(XbeeQueue,rb_remove(rb_usart2));
  796. while(rb_full_count(XbeeQueue)>0) RX();
  797. while(rb_full_count(RemoteQueue)>0) RX_Remote();
  798. }
  799. while (rb_full_count(rb_usart3) > 0) {
  800. if (XbeeConst_UseAPI>0) {
  801. if (WeightConst_BLE==1 || WeightConst_BLE== 3)
  802. {
  803. rb_push_insert(rb_usart1, rb_remove(rb_usart3));
  804. }
  805. else {
  806. rb_remove(rb_usart3);
  807. } //不能删除,用于清空3号串口
  808. }
  809. else
  810. {
  811. rb_push_insert(RemoteQueue, rb_remove(rb_usart3));
  812. while(rb_full_count(RemoteQueue)>0) RX_Remote();
  813. }
  814. }
  815. while (rb_full_count(rb_uart4) > 0) {
  816. tempval = rb_remove(rb_uart4); //继续存数据
  817. //if (tempval==0x59 && finish_send==0) finish_send=1;
  818. }
  819. while (rb_full_count(rb_uart5) > 0) {
  820. watchTag();
  821. }
  822. }
  823. }
  824. static rt_thread_t uart_tid = RT_NULL;
  825. void threadUart_init(void)
  826. {
  827. uart_tid = rt_thread_create("EmptyBuf",
  828. threadEmptyBuffer_entry, RT_NULL,
  829. 0x500,
  830. 4, 5);
  831. /* 如果获得线程控制块,启动这个线程 */
  832. if (uart_tid != RT_NULL) rt_thread_startup(uart_tid);
  833. }