buffer.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  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 == 0x11 ) { //1号键回复
  273. if (XbeeConst_FRxBuf0[XbeeConst_FrameLength0-1] == XbeeConst_FrameNumLast) {
  274. save_read_ts('k');
  275. XbeeConst_CanSend=0x01;//取消无线发送锁定
  276. }
  277. }
  278. else if (dataframehead.data.frameType == 0x12 || dataframehead.data.frameType == 0x15) { //2号键内容
  279. // rt_kprintf("%02X//////////////////////////%02X \n",dataframehead.data.frameType,XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  280. if (dataframehead.data.frameType == 0x12)
  281. {
  282. // if(isn==1) {
  283. // clearScreenAll_();
  284. // delay_ms(100);
  285. // }
  286. if (getPlaning==1)
  287. {
  288. planreget_save = 0;
  289. readyPop = 1;
  290. for (int i=0;i<XbeeConst_FRxBuf0[1]+2;i++)
  291. XbeeConst_FRxBuf12[i] = XbeeConst_FRxBuf0[i];
  292. }
  293. //setWeightConst_initProduct();
  294. // rt_sem_release(pop_product_sem);//需要弹出最新内容
  295. }
  296. else if (dataframehead.data.frameType == 0x15)
  297. {
  298. // rt_kprintf("--XbeeConst_lastsort:%02X \n", XbeeConst_lastsort);
  299. // rt_kprintf("0x15 ------index:%02X \n",XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  300. if (XbeeConst_lastsort==0xFD && XbeeConst_lastsort < XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  301. reset_read_ts('p');
  302. if (readyPop==1 && getPlaning==1)
  303. {
  304. // readyPop = 0;
  305. getPlaning=0;
  306. planreget = XbeeConst_FRxBuf12[XbeeConst_FRxBuf12[1]-3]&0x01;
  307. reset_read_ts('p');
  308. ts_pushArrary(&ts_plandb, XbeeConst_FRxBuf12, XbeeConst_FRxBuf12[1]+2);
  309. // rt_kprintf("\n");
  310. // rt_kprintf("\n");
  311. // rt_kprintf("\n");
  312. // rt_kprintf("0x12-----------------------------\n");
  313. // rt_kprintf("pop index:%02X \n",XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]);
  314. rt_sem_release(pop_product_sem);//需要弹出最新内容
  315. }
  316. if (planreget_save==0 && planreget==1){
  317. XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-2] = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-2] | 0x01;
  318. }
  319. planreget_save =1;
  320. foundlastplan_ = 0xF0;
  321. foundlastplan_ = findlastplan();
  322. if ((XbeeConst_lastsort != XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]
  323. && foundlastplan_ != XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  324. || XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]>0xFD)
  325. ts_pushArrary(&ts_plandb, XbeeConst_FRxBuf0, XbeeConst_FRxBuf0[1]+2);
  326. save_read_ts('k');
  327. XbeeConst_CanSend=0x01;//取消无线发送锁定
  328. if (XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1]<0xFD && getPlaning==0) { //如果没有结束,则发送05协议
  329. XbeeConst_lastsort = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1];
  330. XbeeConst_lastinorout = XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-3]>>7;
  331. // rt_kprintf("XbeeConst_lastsort get:%02X \n", XbeeConst_lastsort);
  332. sendkey2(0xF5);
  333. }
  334. else if (XbeeConst_lastsort==0xFD && readyPop==0 && XbeeConst_lastsort < XbeeConst_FRxBuf0[XbeeConst_FRxBuf0[1]-1])
  335. {
  336. rt_sem_release(pop_product_sem);//如果直接收到15,如全天结束或空计划,需要弹出最新内容
  337. }
  338. if (readyPop==1) readyPop = 0;
  339. }
  340. }
  341. else if (dataframehead.data.frameType == 0x14) { //无线按键处理
  342. RemoteSendDisplay = 0;
  343. if (isCC)
  344. checksum =0x7E + 0x05 + ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 4 ) | XbeeConst_DeviceAddress
  345. + 0xA4 + XbeeConst_FRxBuf0[4] + XbeeConst_FRxBuf0[5];
  346. else
  347. checksum =0x7E + 0x05 + XbeeConst_DeviceAddress + 0xA4 + XbeeConst_FRxBuf0[4] + XbeeConst_FRxBuf0[5];
  348. XbeeConst_FRemoteTxBuf[0] = 0x07;
  349. XbeeConst_FRemoteTxBuf[1] = 0x7E;
  350. XbeeConst_FRemoteTxBuf[2] = 0x05;
  351. if (isCC)
  352. XbeeConst_FRemoteTxBuf[3] = ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 4 ) | XbeeConst_DeviceAddress;
  353. else
  354. XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
  355. XbeeConst_FRemoteTxBuf[4] = 0xA4;
  356. XbeeConst_FRemoteTxBuf[5] = XbeeConst_FRxBuf0[4];
  357. XbeeConst_FRemoteTxBuf[6] = XbeeConst_FRxBuf0[5];
  358. XbeeConst_FRemoteTxBuf[7] = 0xff - checksum;
  359. if (XbeeConst_UseAPI>0) {
  360. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  361. setSendFrame_t(0x01,0x01,0xC1);
  362. XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
  363. for (int i = 1; i <= XbeeConst_PTxBuf0[0]; i++) //将缓冲区发出
  364. usart2_send_data[i - 1] = XbeeConst_PTxBuf0[i];
  365. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
  366. rt_sem_release(uart2_lock);
  367. }
  368. else {
  369. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  370. for (int i = 1; i <= XbeeConst_FRemoteTxBuf[0]; i++) //将缓冲区发出
  371. usart2_send_data[i - 1] = XbeeConst_FRemoteTxBuf[i];
  372. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_FRemoteTxBuf[0]);
  373. rt_sem_release(uart2_lock);
  374. }
  375. RemoteSendDisplay = 1;
  376. if (XbeeConst_FRxBuf0[4]==0x01 && button_state.b1 ==0 && delayKeying == 0)
  377. {
  378. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  379. {
  380. rt_sem_release(delay_key_sem); //收到1号键
  381. sendkey1(0xF3, ((XbeeConst_FRxBuf0_Remote[2] >> 4) & 0x0F) );
  382. WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  383. WeightConst_oksum = 0;
  384. WeightConst_joksum = 0;
  385. WeightConst_allsum = 0;
  386. button_state.b1=1; //5秒内不可按键
  387. }
  388. }
  389. else if (XbeeConst_FRxBuf0[4]==0x02 && button_state.b2==0) //收到2号键
  390. // sendkey2(0xF4);
  391. if(WeightConst_DELAYON==0)
  392. {
  393. if (tsdb_recordcount('k')==0)
  394. {
  395. sendkey2(0xF4);
  396. // WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  397. // WeightConst_oksum = 0;
  398. // WeightConst_allsum = 0;
  399. }
  400. }
  401. button_state.b2=1; //5秒内不可按键
  402. }
  403. else if (dataframehead.data.frameType == 0xA1) { //铲车显示处理
  404. for (unsigned short i=4; i < 22; i++) { //显示重量
  405. uart4_send_data[i - 4] = XbeeConst_FRxBuf0[i];
  406. uart4_send_data[18]=0;
  407. for (int i = 2; i <18; i++) //校验和
  408. uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
  409. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  410. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  411. rt_sem_release(uart4_lock);
  412. }
  413. }
  414. else if (dataframehead.data.frameType == 0xA4) { //无线按键成功处理
  415. beep();
  416. }
  417. else if (dataframehead.data.frameType == 0x16) { //设置无线模式
  418. XbeeConst_UseAPI = XbeeConst_FRxBuf0[4];
  419. write_Flash("API", &XbeeConst_UseAPI, sizeof(XbeeConst_UseAPI));
  420. setAPI();
  421. beep();
  422. }
  423. else if (dataframehead.data.frameType == 0x17) { //设置屏幕类型
  424. WeightConst_SBType = XbeeConst_FRxBuf0[4];
  425. write_Flash("PM", &WeightConst_SBType, sizeof(WeightConst_SBType));
  426. beep();
  427. }
  428. else if (dataframehead.data.frameType == 0x19) { //设置地址
  429. XbeeConst_DeviceAddress = XbeeConst_FRxBuf0[4];
  430. write_Flash("CH", &XbeeConst_DeviceAddress, sizeof(XbeeConst_DeviceAddress));
  431. beep();
  432. }
  433. else if (dataframehead.data.frameType == 0x1A) { //设置提取类型
  434. WeightConst_TQ = XbeeConst_FRxBuf0[4];
  435. write_Flash("TQ", &WeightConst_TQ, sizeof(WeightConst_TQ));
  436. //---------- USART_Configuration();
  437. beep();
  438. }
  439. else if (dataframehead.data.frameType == 0x1B) { //设置网络编号
  440. beep();
  441. XbeeConst_NetAddress = XbeeConst_FRxBuf0[4];
  442. write_Flash("WL", &XbeeConst_NetAddress, sizeof(XbeeConst_NetAddress));
  443. setNetAddress();
  444. beep();
  445. }
  446. else if (dataframehead.data.frameType == 0x18) { //设置时间
  447. XbeeConst_CanSend=0x01;//取消无线发送锁定
  448. TimeConst.Buffer[0] = XbeeConst_FRxBuf0[7];
  449. TimeConst.Buffer[1] = XbeeConst_FRxBuf0[6];
  450. TimeConst.Buffer[2] = XbeeConst_FRxBuf0[5];
  451. TimeConst.Buffer[3] = XbeeConst_FRxBuf0[4];
  452. save_read_ts('k');
  453. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  454. write_Flash("TimeConst", &TimeConst, sizeof(TimeConst));
  455. rt_sem_release(setTIME_lock);
  456. CanButton = 0x01;
  457. beep();
  458. }
  459. }
  460. }
  461. XbeeConst_ReadNum0 = 0; //循环计数清零
  462. XbeeConst_FrameLength0 = 0;
  463. } else {
  464. XbeeConst_ReadNum0++; //小于帧长度
  465. if (XbeeConst_ReadNum0>90)
  466. {
  467. XbeeConst_ReadNum0 = 0; //循环计数清零
  468. XbeeConst_FrameLength0 = 0;
  469. }
  470. }
  471. break;
  472. }
  473. }
  474. }
  475. void RX_Remote(void) {
  476. unsigned char tempval, checksum = 0;
  477. if (rb_full_count(RemoteQueue) > 0) {
  478. tempval = rb_remove(RemoteQueue); //继续存数据
  479. switch (XbeeConst_ReadNum0_Remote) {
  480. case 0:
  481. if (tempval == 0x7e) { //协议头前面1个7E判断
  482. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval;
  483. XbeeConst_ReadNum0_Remote++;
  484. }
  485. break;
  486. case 1:
  487. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval; //这个字节为帧长度
  488. XbeeConst_ReadNum0_Remote++;
  489. XbeeConst_FrameLength0_Remote= XbeeConst_FRxBuf0_Remote[1] + 1; //算出帧长度
  490. break;
  491. default:
  492. XbeeConst_FRxBuf0_Remote[XbeeConst_ReadNum0_Remote] = tempval; //读数据
  493. if (XbeeConst_ReadNum0_Remote >= XbeeConst_FrameLength0_Remote) { //读完已知长度的数据
  494. for (unsigned short i = 0; i < XbeeConst_FrameLength0_Remote; i++)
  495. checksum += XbeeConst_FRxBuf0_Remote[i];
  496. if ((0xff - checksum) == XbeeConst_FRxBuf0_Remote[XbeeConst_FrameLength0_Remote]) //校验成功
  497. {
  498. if (
  499. (((XbeeConst_FRxBuf0_Remote[2] & 0x1F) == XbeeConst_RemoteAddress && (WeightConst_SBType == 2 || WeightConst_SBType == 7))
  500. ||
  501. ((XbeeConst_FRxBuf0_Remote[2] & 0x1F) == XbeeConst_DeviceAddress && (WeightConst_SBType != 2 && WeightConst_SBType != 7)))
  502. ||
  503. (XbeeConst_RemoteAddress==0 && XbeeConst_FRxBuf0_Remote[2]==0x0A)) { //收到本设备的数据,不是本设备的不处理
  504. if ((XbeeConst_FRxBuf0_Remote[3] == 0xA1 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  505. || (XbeeConst_FRxBuf0_Remote[3] == 0xF1 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  506. )
  507. { //铲车显示处理
  508. if (XbeeConst_FRxBuf0_Remote[14]==0xC8 && XbeeConst_FRxBuf0_Remote[15]==0xB7) //确认开始
  509. {
  510. XbeeConst_FRxBuf0_Remote[21] = 0x20;
  511. XbeeConst_FRxBuf0_Remote[20] = 0x20;
  512. XbeeConst_FRxBuf0_Remote[19] = 0x20;
  513. XbeeConst_FRxBuf0_Remote[18] = 0x20;
  514. XbeeConst_FRxBuf0_Remote[17] = 0x20;
  515. XbeeConst_FRxBuf0_Remote[16] = 0x20;
  516. XbeeConst_FRxBuf0_Remote[15] = 0x20;
  517. XbeeConst_FRxBuf0_Remote[14] = b[XbeeConst_RemoteAddress];
  518. }
  519. else
  520. {
  521. XbeeConst_FRxBuf0_Remote[17] = XbeeConst_FRxBuf0_Remote[16];
  522. XbeeConst_FRxBuf0_Remote[16] = XbeeConst_FRxBuf0_Remote[15];
  523. XbeeConst_FRxBuf0_Remote[15] = XbeeConst_FRxBuf0_Remote[14];
  524. XbeeConst_FRxBuf0_Remote[14] = b[XbeeConst_RemoteAddress];
  525. }
  526. for (unsigned short i=4; i < 22; i++) //显示重量
  527. uart4_send_data[i - 4] = XbeeConst_FRxBuf0_Remote[i];
  528. uart4_send_data[18]=0;
  529. for (int i = 2; i <18; i++) //校验和
  530. uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i];
  531. // if (WeightConst_SBType == 7)
  532. // {
  533. // for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  534. // WeightConst_feed[SendDisplay_i] = uart4_send_data[2+SendDisplay_i] ;
  535. // WeightConst_Weight_display[7-SendDisplay_i] = uart4_send_data[10+SendDisplay_i] ;
  536. // WeightConst_Weight_display[7] = 0x20;
  537. // }
  538. // get_msg(4,//Xstart
  539. // 8,//Ystart
  540. // 1,//size
  541. // 0,//reset
  542. // 0,//speed
  543. // 8,//字符个数
  544. // 3,//界面数
  545. // 0,//id
  546. // 0x5B,//Xend
  547. // 0,
  548. // &WeightConst_feed[0]//字码
  549. // );
  550. // delay_ms(200);
  551. // get_msg(92,//Xstart
  552. // 4,//Ystart
  553. // 2,//size
  554. // 0,//reset
  555. // 0,//speed
  556. // 8,//字符个数
  557. // 3,//界面数
  558. // 1,//id
  559. // 0xBF,//Xend
  560. // 1,
  561. // &WeightConst_Weight_display[0]//字码
  562. // );
  563. // }
  564. // else
  565. {
  566. rt_sem_take(uart4_lock, RT_WAITING_FOREVER);
  567. HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19);
  568. rt_thread_mdelay(50);
  569. rt_sem_release(uart4_lock);
  570. }
  571. }
  572. else if (XbeeConst_FRxBuf0_Remote[3] == 0xA4 && (WeightConst_SBType == 2 || WeightConst_SBType == 7) )
  573. { //铲车收到无线按键成功处理
  574. beep();
  575. }
  576. else if (
  577. (XbeeConst_FRxBuf0_Remote[3] == 0xA2 || XbeeConst_FRxBuf0_Remote[3] == 0x14)
  578. && (WeightConst_SBType != 2 && WeightConst_SBType != 7) && XbeeConst_FRxBuf0_Remote[1] == 0x05
  579. // (XbeeConst_FRxBuf0_Remote[3] == 0xA2 && WeightConst_SBType != 2 && XbeeConst_UseAPI)
  580. // || (XbeeConst_FRxBuf0_Remote[3] == 0x14 && WeightConst_SBType != 2 && !XbeeConst_UseAPI)
  581. ) { //TMR收到无线按键处理
  582. RemoteSendDisplay = 0;
  583. XbeeConst_FRemoteTxBuf[0] = 7;
  584. XbeeConst_FRemoteTxBuf[1] = 0x7E;
  585. XbeeConst_FRemoteTxBuf[2] = 0x05;
  586. if (isCC)
  587. XbeeConst_FRemoteTxBuf[3] = ((XbeeConst_FRxBuf0_Remote[2] & 0x0F) << 5 ) | (XbeeConst_DeviceAddress&0x1F);
  588. else
  589. XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress;
  590. XbeeConst_FRemoteTxBuf[4] = 0xA4;
  591. XbeeConst_FRemoteTxBuf[5] = XbeeConst_FRxBuf0_Remote[4];
  592. XbeeConst_FRemoteTxBuf[6] = XbeeConst_FRxBuf0_Remote[5];
  593. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0;
  594. for (int i = 1; i < XbeeConst_FRemoteTxBuf[0]; i++)
  595. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] =
  596. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]+XbeeConst_FRemoteTxBuf[i];
  597. XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0xFF - XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]];
  598. if (XbeeConst_UseAPI>0) {
  599. rt_sem_take(uart2_lock, RT_WAITING_FOREVER);
  600. setSendFrame_t(0x01,0x01,0xC1);
  601. XbeeConst_PTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf);
  602. for (int i = 1; i <= XbeeConst_PTxBuf0[0]; i++) //将缓冲区发出
  603. usart2_send_data[i - 1] = XbeeConst_PTxBuf0[i];
  604. HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PTxBuf0[0]);
  605. rt_thread_mdelay(50);
  606. rt_sem_release(uart2_lock);
  607. }
  608. else
  609. {
  610. if (iscowweight<1 )
  611. {
  612. rt_sem_take(uart3_lock, RT_WAITING_FOREVER);
  613. for (int i = 1; i <= XbeeConst_FRemoteTxBuf[0]; i++) //将缓冲区发出
  614. usart3_send_data[i - 1] = XbeeConst_FRemoteTxBuf[i];
  615. HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]);
  616. rt_thread_mdelay(50);
  617. rt_sem_release(uart3_lock);
  618. }
  619. }
  620. RemoteSendDisplay = 1;
  621. if (XbeeConst_FRxBuf0_Remote[4]==0x01 && button_state.b1==0)//收到1号键
  622. {
  623. if (pf_comp.data.needBegin == 1 && WeightConst_WeightHaveBegin==0)
  624. {
  625. beep();
  626. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  627. WeightConst_WeightBegin = WeightConst_WeightCur;
  628. rt_sem_release(weight_lock);
  629. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  630. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  631. rt_sem_release(setTIME_lock);
  632. write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  633. getTargetWeight();
  634. }
  635. else if (pf_comp.data.pfsort != 0xFE && delayKeying == 0)
  636. {
  637. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  638. {
  639. rt_sem_release(delay_key_sem);
  640. sendkey1(0xF3, ((XbeeConst_FRxBuf0_Remote[2] >> 4) & 0x0F));
  641. WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  642. WeightConst_oksum = 0;
  643. WeightConst_joksum = 0;
  644. WeightConst_allsum = 0;
  645. button_state.b1=1; //5秒内不可按键
  646. }
  647. }
  648. }
  649. else if (XbeeConst_FRxBuf0_Remote[4]==0x02 && button_state.b2==0) //收到2号键
  650. {
  651. if(!WeightConst_DELAYON>0)
  652. {
  653. if (tsdb_recordcount('k')==0)
  654. sendkey2(0xF4);
  655. }
  656. // WeightConst_AutoSingleNSecondPoint=0; // 防止自动跳转,重置自动记录指针
  657. // WeightConst_oksum = 0;
  658. // WeightConst_allsum = 0;
  659. button_state.b2=1; //5秒内不可按键
  660. }
  661. }
  662. }
  663. }
  664. XbeeConst_ReadNum0_Remote = 0; //循环计数清零
  665. XbeeConst_FrameLength0_Remote = 0;
  666. } else {
  667. XbeeConst_ReadNum0_Remote++; //小于帧长度
  668. if (XbeeConst_ReadNum0_Remote>90)
  669. {
  670. XbeeConst_ReadNum0_Remote = 0; //循环计数清零
  671. XbeeConst_FrameLength0_Remote = 0;
  672. }
  673. }
  674. break;
  675. }
  676. }
  677. }
  678. static unsigned char Rec_watchTag[50]; //接收标签
  679. unsigned char Rec_watchTag_point=0; //接收标签
  680. unsigned char ReadTag_state=0; //读标签状态 0 没读或已读成功,1 开始读 ,2 正在读
  681. unsigned char WriteTag_state=0; //写标签状态 0 没写或已写成功,1 开始写 ,2 正在写
  682. void ReadTag(unsigned char x) { //发送标签
  683. unsigned char sendchar;
  684. sendchar=0x7E;
  685. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  686. sendchar=0x03;
  687. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  688. sendchar=XbeeConst_DeviceAddress;
  689. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  690. sendchar=0xB2;
  691. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  692. sendchar=x;
  693. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  694. sendchar = 0x7E + 03 + XbeeConst_DeviceAddress + 0xB2 + x;
  695. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  696. if (x==1) ReadTag_state=1;
  697. else ReadTag_state=0;
  698. }
  699. void WriteTag(void) { //发送标签
  700. unsigned char sendchar;
  701. sendchar=0x7E;
  702. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  703. sendchar=0x0A;
  704. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  705. sendchar=XbeeConst_DeviceAddress;
  706. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  707. sendchar=0xB1;
  708. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  709. sendchar = 0x7E + 0x0A + XbeeConst_DeviceAddress + 0xB1;
  710. for (int i = 0; i < 8; i++) {
  711. sendchar = sendchar + WeightConst_feed[i];
  712. HAL_UART_Transmit(&huart5, (uint8_t *)&WeightConst_feed[i], 1, 1);
  713. }
  714. HAL_UART_Transmit(&huart5, (uint8_t *)&sendchar, 1, 1);
  715. WriteTag_state = 1;
  716. }
  717. void watchTag(){
  718. unsigned char tempval, checksum = 0;
  719. tempval = rb_remove(rb_uart5);
  720. //HAL_UART_Transmit(&huart5, &tempval, 1,1);
  721. if (tempval==0x7e || Rec_watchTag_point>49){ //头 过长回头
  722. Rec_watchTag_point=0;
  723. }
  724. Rec_watchTag[Rec_watchTag_point++] = tempval;
  725. if (Rec_watchTag_point>1 && Rec_watchTag_point>(Rec_watchTag[1]+2) ){ //符合长度
  726. Rec_watchTag_point=0;
  727. for (int i = 0; i < Rec_watchTag[1]+2; i++)
  728. {
  729. checksum = checksum + Rec_watchTag[i];
  730. if (checksum== Rec_watchTag[Rec_watchTag[1]+2] && Rec_watchTag[2]==XbeeConst_DeviceAddress)
  731. {//校验通过
  732. if (Rec_watchTag[3]==0xB2)
  733. {
  734. if (Rec_watchTag[1]==2 && ReadTag_state==1)
  735. { //收到唤醒回复
  736. ReadTag_state=2;
  737. }else if (ReadTag_state==2){//收到标签
  738. ReadTag_state=0;
  739. for (int j = 0; j < 8; j++) {
  740. if (WeightConst_feed[j] != Rec_watchTag[4+j]) ReadTag_state=2;
  741. }
  742. if (ReadTag_state ==0 && pf_comp.data.needBegin==1 && WeightConst_WeightHaveBegin==0)
  743. {
  744. beep();
  745. WeightConst_WeightBegin = WeightConst_WeightCur;
  746. // FLKey_SaveQPOrder(pf_comp.data.pfsort);
  747. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  748. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  749. rt_sem_release(setTIME_lock);
  750. write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  751. getTargetWeight();
  752. ReadTag(0);//关闭唤醒
  753. }
  754. beep();
  755. }
  756. }
  757. else if (Rec_watchTag[3]==0xB1 && WriteTag_state>0){
  758. if (Rec_watchTag[1]==2){ //收到写入回复
  759. WriteTag_state=2;
  760. }else if(WriteTag_state==2){//写入成功
  761. beep();
  762. ReadTag(1);//kai唤醒
  763. }
  764. }
  765. }
  766. }
  767. }
  768. }
  769. extern uint8_t rDataBuffer;
  770. static void threadEmptyBuffer_entry(void *parameter)
  771. {
  772. unsigned char tempval;
  773. // if (isTag >0 )
  774. // HAL_UART_Receive_IT(&huart5, &rDataBuffer, 1);
  775. while(1)
  776. {
  777. rt_sem_take(thread_EmptyBuffer_sem, RT_WAITING_FOREVER); //等待串口消息
  778. while (rb_full_count(rb_usart1) > 0) {
  779. ReadWeight();
  780. }
  781. while (rb_full_count(rb_usart2) > 0) {
  782. if (XbeeConst_UseAPI>0) {
  783. rb_push_insert(XbeeAPIQueue,rb_remove(rb_usart2));
  784. RX_API();
  785. }
  786. else
  787. rb_push_insert(XbeeQueue,rb_remove(rb_usart2));
  788. while(rb_full_count(XbeeQueue)>0) RX();
  789. while(rb_full_count(RemoteQueue)>0) RX_Remote();
  790. }
  791. while (rb_full_count(rb_usart3) > 0) {
  792. if (XbeeConst_UseAPI>0) {
  793. if (WeightConst_BLE==1 || WeightConst_BLE== 3)
  794. {
  795. rb_push_insert(rb_usart1, rb_remove(rb_usart3));
  796. }
  797. else {
  798. rb_remove(rb_usart3);
  799. } //不能删除,用于清空3号串口
  800. }
  801. else
  802. {
  803. rb_push_insert(RemoteQueue, rb_remove(rb_usart3));
  804. while(rb_full_count(RemoteQueue)>0) RX_Remote();
  805. }
  806. }
  807. while (rb_full_count(rb_uart4) > 0) {
  808. tempval = rb_remove(rb_uart4); //继续存数据
  809. //if (tempval==0x59 && finish_send==0) finish_send=1;
  810. }
  811. while (rb_full_count(rb_uart5) > 0) {
  812. watchTag();
  813. }
  814. }
  815. }
  816. static rt_thread_t uart_tid = RT_NULL;
  817. void threadUart_init(void)
  818. {
  819. uart_tid = rt_thread_create("EmptyBuf",
  820. threadEmptyBuffer_entry, RT_NULL,
  821. 0x500,
  822. 4, 5);
  823. /* 如果获得线程控制块,启动这个线程 */
  824. if (uart_tid != RT_NULL) rt_thread_startup(uart_tid);
  825. }