buffer.c 40 KB

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