buffer.c 41 KB

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