uart_rcv.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * uart_rcv.c
  3. *
  4. * Created on: 2022年4月20日
  5. * Author: dell
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <ctype.h>
  11. #include "NuMicro.h"
  12. #include "cfg_param_record.h"
  13. #include "uart_rcv.h"
  14. #include "usr_pid.h"
  15. #include "cJSON.h"
  16. #include "ws2812.h"
  17. #define ENV_ADJ_THRESHOLD 27.0
  18. enum SLAVE_MCU_Ctr_cmd_type
  19. {
  20. SLAVE_MCU_CMD_PARAM = 0x01,
  21. SLAVE_MCU_CMD_HEAT = 0x02,
  22. SLAVE_MCU_CMD_LIGHT_CTR= 0X03,
  23. SLAVE_MCU_CMD_QRSCANNER_CTR= 0X04,
  24. SLAVE_MCU_CMD_FAN= 0X05,
  25. SLAVE_MCU_CMD_CARD_ST= 0X06,
  26. SLAVE_MCU_CMD_PID = 0x20,
  27. };
  28. enum SLAVE_MCU_Ctr_UP_type
  29. {
  30. SLAVE_MCU_UP_HEAT = 0x10,
  31. SLAVE_MCU_UP_QR_PARAM= 0X11,
  32. SLAVE_MCU_UP_QR = 0x12,
  33. SLAVE_MCU_INFO, //异常信息
  34. };
  35. #define combine_cmdMessage(msg,header,seqer,cmder,tailer) { \
  36. msg.head = header; \
  37. msg.seq = seqer; \
  38. msg.cmd = cmder; \
  39. msg.tail = tailer; \
  40. }
  41. uint8_t g_uart2_rcv_start = 0;
  42. uint8_t g_uart2_rcv_complete_flg = 0;
  43. uint16_t g_uart2_rx_len = 0;
  44. uint8_t g_uart2_frame_overtime_cnt = 0;
  45. uint16_t g_uart2_rcv_cmd = 0;
  46. uint16_t g_uart2_cmd_overtime_secs = 0;
  47. uint32_t g_uart2_cmd_overtime_cnt = 0;
  48. uint8_t g_param_set_mode = 0; // 参数设置模式
  49. uint8_t g_uart1_rcv_start = 0;
  50. uint8_t g_uart1_rcv_complete_flg = 0;
  51. uint8_t g_uart1_tx_buf[BUF_SIZE] = {0};
  52. uint8_t g_uart1_rx_buf[BUF_SIZE] = {0};
  53. uint8_t g_uart1_rx_len = 0;
  54. uint8_t g_uart1_frame_overtime_cnt = 0;
  55. uint8_t g_uart0_rcv_start = 0;
  56. uint8_t g_uart0_rcv_complete_flg = 0;
  57. uint8_t g_uart0_tx_buf[DEBUG_BUF_SIZE] = {0};
  58. uint8_t g_uart0_rx_buf[BUF_SIZE] = {0};
  59. uint8_t g_uart0_rx_len = 0;
  60. uint8_t g_uart0_frame_overtime_cnt = 0;
  61. uint32_t uart0_header = 0;
  62. uint32_t uart0_last = 0;
  63. unsigned int haveheaderflag = 0;
  64. heat_ctrl_struct g_heat_ctrl = {0};
  65. // card_param_struct card = {0};
  66. str_hole_info_t hole1 = {0};
  67. str_hole_info_t hole2 = {0};
  68. str_hole_info_t hole3 = {0};
  69. str_hole_info_t hole4 = {0};
  70. str_hole_info_t hole5 = {0};
  71. str_hole_info_t hole6 = {0};
  72. str_hole_info_t hole7 = {0};
  73. str_hole_info_t hole8 = {0};
  74. str_hole_info_t hole9 = {0};
  75. str_hole_info_t hole10 = {0};
  76. str_card_param_info_t m_str_card_param_info = {0};
  77. uint32_t qr_check_delay = QR_CHECH_STATE_FIRST; /*1s定时器里面,大于0,每s减1*/
  78. extern void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
  79. extern uint8_t sys_info[40];
  80. /********************************************************************
  81. * bcd_to_hex()
  82. *
  83. *描述:BCD转HEX
  84. *参数:无
  85. *返回:无
  86. *其他:无
  87. *--------------------------------------------------------------------
  88. *记录:
  89. ********************************************************************/
  90. uint8_t bcd_to_hex(uint8_t val)
  91. {
  92. return ((val / 10) << 4) + val % 10;
  93. }
  94. /********************************************************************
  95. * debug_receive_int_handle()
  96. *
  97. *描述:调试串口接收中断数据处理
  98. *参数:无
  99. *返回:无
  100. *其他:无
  101. *--------------------------------------------------------------------
  102. *记录:
  103. ********************************************************************/
  104. void debug_receive_int_handle0(void)
  105. {
  106. if (UART_GET_INT_FLAG(UART0, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk))
  107. {
  108. /* UART receive data available flag */
  109. /* Move the data from Rx FIFO to sw buffer (RAM). */
  110. /* Every time leave 1 byte data in FIFO for Rx timeout */
  111. while (UART_GET_RX_EMPTY(UART0) == 0)
  112. {
  113. if (uart0_last == BUF_SIZE)uart0_last = 0;
  114. g_uart0_rx_buf[uart0_last] = UART_READ(UART0);
  115. uart0_last++;
  116. }
  117. }
  118. }
  119. void debug_receive_int_handle1(void)
  120. {
  121. while (UART_GET_RX_EMPTY(UART1) == 0)
  122. {
  123. if (g_uart1_rx_len >= BUF_SIZE)
  124. g_uart1_rx_len = 0;
  125. g_uart1_rx_buf[g_uart1_rx_len] = UART_READ(UART1);
  126. g_uart1_rx_len++;
  127. }
  128. }
  129. /********************************************************************
  130. * UART02_IRQHandler()
  131. *
  132. *描述:串口接收中断
  133. *参数:无
  134. *返回:无
  135. *其他:无
  136. *--------------------------------------------------------------------
  137. *记录:
  138. ********************************************************************/
  139. void UART02_IRQHandler(void)
  140. {
  141. if (UART_GET_INT_FLAG(UART0, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
  142. {
  143. debug_receive_int_handle0();
  144. }
  145. else if (UART_GET_INT_FLAG(UART0,UART_INTSTS_BUFERRIF_Msk) )
  146. {
  147. debug_receive_int_handle0();
  148. UART_ClearIntFlag(UART0,UART_INTSTS_BUFERRINT_Msk);
  149. }
  150. else if (UART_GET_INT_FLAG(UART0,UART_INTSTS_RLSINT_Msk) )
  151. {
  152. UART_ClearIntFlag(UART0,UART_INTSTS_RLSINT_Msk);
  153. }
  154. if (UART_GET_INT_FLAG(UART2, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
  155. {
  156. debug_receive_int_handle2();
  157. }
  158. else if (UART_GET_INT_FLAG(UART2,UART_INTSTS_BUFERRIF_Msk) )
  159. {
  160. debug_receive_int_handle2();
  161. UART_ClearIntFlag(UART2,UART_INTSTS_BUFERRINT_Msk);
  162. }
  163. else if (UART_GET_INT_FLAG(UART2,UART_INTSTS_RLSINT_Msk) )
  164. {
  165. UART_ClearIntFlag(UART2,UART_INTSTS_RLSINT_Msk);
  166. }
  167. }
  168. /********************************************************************
  169. * UART13_IRQHandler()
  170. *
  171. *描述:串口接收中断
  172. *参数:无
  173. *返回:无
  174. *其他:无
  175. *--------------------------------------------------------------------
  176. *记录:
  177. ********************************************************************/
  178. void UART13_IRQHandler(void)
  179. {
  180. if (UART_GET_INT_FLAG(UART1, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
  181. {
  182. debug_receive_int_handle1();
  183. }
  184. else if (UART_GET_INT_FLAG(UART1,UART_INTSTS_BUFERRIF_Msk) )
  185. {
  186. debug_receive_int_handle1();
  187. UART_ClearIntFlag(UART1,UART_INTSTS_BUFERRINT_Msk);
  188. }
  189. else if (UART_GET_INT_FLAG(UART1,UART_INTSTS_RLSINT_Msk) )
  190. {
  191. UART_ClearIntFlag(UART1,UART_INTSTS_RLSINT_Msk);
  192. }
  193. }
  194. void sendMsgtoMasterMcu(struct CmdMessage *pmsg)
  195. {
  196. static uint8_t sedbuf[DEBUG_BUF_SIZE];
  197. uint16_t checksum = 0;
  198. *(unsigned short *)sedbuf = pmsg->head;
  199. sedbuf[2] = pmsg->seq;
  200. sedbuf[3] = pmsg->cmd;
  201. *(unsigned short *)(sedbuf+4) = pmsg->len;
  202. for(int i=0; i < pmsg->len; i++){
  203. sedbuf[6+i] = pmsg->data[i];
  204. }
  205. for(int i=2; i < (pmsg->len + 6); i++){
  206. checksum += sedbuf[i];
  207. }
  208. sedbuf[6+pmsg->len] = checksum&0xff;/*结尾标记高位*/
  209. sedbuf[7+pmsg->len ] = checksum>>8 ;/*结尾标记低位*/
  210. UART_Write(UART0, sedbuf, (8+pmsg->len));
  211. }
  212. uint16_t checkSum(const uint8_t *pInBuffer, int uLen)
  213. {
  214. uint32_t sum = 0;
  215. for(int i = 0; i < uLen; i++)
  216. {
  217. sum += pInBuffer[i];
  218. }
  219. return (sum);
  220. }
  221. /********************************************************************
  222. * int Decode(const char *pInBuffer, int uLen)
  223. *
  224. *描述:对串口数据进行解码成结构体
  225. *参数:pInBuffer 接收缓冲区
  226. *uheader 当前头位置
  227. ulast 当前头尾位置
  228. maxlen 缓冲区长度
  229. pMessage 命令结构体
  230. pdata 命令数据
  231. *返回:1解码成功,0解码失败
  232. *其他:无
  233. *--------------------------------------------------------------------
  234. *记录:
  235. ********************************************************************/
  236. int DecodeNew(struct CmdMessage *pMessage, uint8_t *pdata, const uint8_t *pInBuffer, uint32_t* pheader,uint32_t ulast,uint32_t maxlen)
  237. {
  238. uint32_t bufRealLen;
  239. uint32_t sizeofMessage = MINI7_MASSAGE_SIZE;
  240. uint32_t header = *pheader;
  241. uint32_t i = 0;
  242. if (NULL == pInBuffer || NULL == pMessage || NULL == pdata || NULL == pheader)
  243. {
  244. /*空指针判断*/
  245. return 0;
  246. }
  247. /*缓冲区有效数据长度,缓冲区循环处理,会出现头大于未情况*/
  248. bufRealLen = (ulast > header)?(ulast - header):(ulast + maxlen - header);
  249. if(bufRealLen < sizeofMessage){
  250. /*长度过段,跳过*/
  251. return 0;
  252. }
  253. bufRealLen -= sizeofMessage; /*最大有效数据长度*/
  254. for(; i<=bufRealLen;){
  255. uint32_t headerflag = pInBuffer[(header + i)%maxlen];
  256. headerflag += pInBuffer[(header + i + 1)%maxlen] <<8;
  257. if(headerflag != MINI7_HEADER_FALG){
  258. i += 1;
  259. // header = (header + 1)%maxlen;
  260. continue;
  261. }
  262. uint32_t messagelen = pInBuffer[(header + i + 4)%maxlen];
  263. messagelen += pInBuffer[(header + i + 5)%maxlen] <<8;
  264. if(messagelen > (maxlen- sizeofMessage)){
  265. /*长度超长 跳过2个字节*/
  266. i += 1;
  267. // header = (header + 1)%maxlen;
  268. continue;
  269. }
  270. if(messagelen >bufRealLen){
  271. /*当前起始点可能存在数据,跳出循环,*/
  272. i++; /*for采样小于等于判断,循环次数多1,此处加1便于后续处理*/
  273. break;
  274. }
  275. uint16_t checkesum = 0;
  276. uint16_t recsum = 0;
  277. if((header + i + 6 + messagelen) < maxlen){
  278. checkesum = checkSum(pInBuffer + header + i + 2, messagelen+4);
  279. }else{
  280. checkesum = checkSum(pInBuffer + header + i + 2, (maxlen - (header + i + 2)));
  281. checkesum += checkSum(pInBuffer, (header + i + 6 + messagelen)%maxlen);
  282. }
  283. recsum = *(pInBuffer + (header + i + 6 + messagelen)%maxlen ) ;
  284. recsum += *(pInBuffer + (header + i + 7 + messagelen)%maxlen) << 8;
  285. /*固定结尾预留做调试用*/
  286. if(checkesum != recsum && recsum>>8 != MINI7_TAIL_FALG){
  287. i += 1;
  288. // ? ? ? ? ?header = (header + 1)%maxlen;
  289. }else{
  290. /*解析成功,拷贝消息结构体*/
  291. uint8_t * pCharMessage = (uint8_t *)pMessage;
  292. for(unsigned copyi=0;copyi<(sizeofMessage-2);copyi++){
  293. *pCharMessage++ = pInBuffer[(header + i+ copyi)%maxlen];
  294. }
  295. (*pMessage).tail = MINI7_TAIL_FALG;
  296. /*解析成功,拷贝数据结构体*/
  297. for(unsigned copyi=0;copyi<messagelen;copyi++){
  298. *pdata++ = pInBuffer[(header + i + 6 + copyi)%maxlen];
  299. }
  300. *pheader = (header + messagelen + i + sizeofMessage - 2)%maxlen;
  301. return 1;
  302. }
  303. }
  304. *pheader = (header + i - 1)%maxlen;
  305. return 0;
  306. }
  307. /********************************************************************
  308. * heater_state_upload()
  309. *
  310. *描述:上传加热、风扇状态及加热体温度
  311. *参数:无
  312. *返回:0/1:设置失败/成功
  313. *其他:无
  314. *--------------------------------------------------------------------
  315. *记录:包含上报和应答处理
  316. ********************************************************************/
  317. void heater_state_upload(uint32_t upenv)
  318. {
  319. struct CmdMessage msg;
  320. uint8_t databuf[7]={0};
  321. combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_UP_HEAT,MINI7_TAIL_FALG)
  322. if(upenv){
  323. msg.len = sizeof(databuf);
  324. }else{
  325. msg.len = sizeof(databuf)-2;
  326. }
  327. msg.data = databuf;
  328. databuf[0] = g_heat_ctrl.heat_state;
  329. databuf[1] = g_heat_ctrl.temp_stable_sta;
  330. databuf[2] = (uint8_t)pid1.ActualTemp;
  331. databuf[3] = (uint8_t)((pid1.ActualTemp - (uint8_t)pid1.ActualTemp) * 100);
  332. databuf[4] = g_heat_ctrl.fan_state;
  333. databuf[5] = (uint8_t)pid1.cabinTem;
  334. databuf[6] = (uint8_t)((pid1.cabinTem - (uint8_t)pid1.cabinTem) * 100);
  335. sendMsgtoMasterMcu(&msg);
  336. }
  337. void sendInfoMasterMcu(uint8_t *data, uint16_t len)
  338. {
  339. struct CmdMessage msg;
  340. combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_INFO,MINI7_TAIL_FALG)
  341. msg.len = len;
  342. msg.data = data;
  343. sendMsgtoMasterMcu(&msg);
  344. }
  345. /********************************************************************
  346. * uart2_rcv_frame_analysis()
  347. *
  348. *描述:接收帧解析
  349. *参数:无
  350. *返回:无
  351. *其他:无
  352. *--------------------------------------------------------------------
  353. *记录:
  354. ********************************************************************/
  355. void send_param(void){
  356. struct CmdMessage msg;
  357. combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_UP_QR_PARAM,MINI7_TAIL_FALG)
  358. msg.len = sizeof(m_str_card_param_info);
  359. msg.data = (char*)&m_str_card_param_info;
  360. sendMsgtoMasterMcu(&msg);
  361. }
  362. /********************************************************************
  363. * trigmode_select_sensor()
  364. *
  365. *描述:切换为感应触发模式
  366. *参数:无
  367. *返回:0/1:设置失败/成功
  368. *其他:无
  369. *--------------------------------------------------------------------
  370. *记录:包含上报和应答处理
  371. ********************************************************************/
  372. void trigmode_select_sensor(void)
  373. {
  374. memset(g_uart2_tx_buf, 0, sizeof(g_uart2_tx_buf));
  375. // memset(g_uart2_rx_buf, 0, sizeof(g_uart2_rx_buf));
  376. g_uart2_tx_buf[0] = 0x7E; // 帧头
  377. g_uart2_tx_buf[1] = 0x00; // 帧头
  378. g_uart2_tx_buf[2] = 0x08; // 命令标识
  379. g_uart2_tx_buf[3] = 0x01; // 命令标识
  380. g_uart2_tx_buf[4] = 0x00;
  381. g_uart2_tx_buf[5] = 0x00;
  382. g_uart2_tx_buf[6] = 0xD7;
  383. // g_uart2_tx_buf[6] = 0xEF;
  384. g_uart2_tx_buf[7] = 0xAB;
  385. g_uart2_tx_buf[8] = 0xCD;
  386. UART_Write(UART2, g_uart2_tx_buf, 9);
  387. }
  388. /********************************************************************
  389. * data_out_oragin()
  390. *
  391. *描述:切换为原始数据输出
  392. *参数:无
  393. *返回:0/1:设置失败/成功
  394. *其他:无
  395. *--------------------------------------------------------------------
  396. *记录:包含上报和应答处理
  397. ********************************************************************/
  398. void data_out_original(void)
  399. {
  400. memset(g_uart2_tx_buf, 0, sizeof(g_uart2_tx_buf));
  401. g_uart2_tx_buf[0] = 0x7E; // 帧头
  402. g_uart2_tx_buf[1] = 0x00; // 帧头
  403. g_uart2_tx_buf[2] = 0x08; // 命令标识
  404. g_uart2_tx_buf[3] = 0x01; // 命令标识
  405. g_uart2_tx_buf[4] = 0x00;
  406. g_uart2_tx_buf[5] = 0x0D;
  407. // g_uart0_tx_buf[6] = 0xD7;
  408. g_uart2_tx_buf[6] = 0xCA;
  409. g_uart2_tx_buf[7] = 0xAB;
  410. g_uart2_tx_buf[8] = 0xCD;
  411. UART_Write(UART2, g_uart2_tx_buf, 9);
  412. HAL_Delay(100);
  413. }
  414. int parse_qrcode_info(str_card_param_info_t *info, char *qrcode_str)
  415. {
  416. int id = 0;
  417. double Tt = 0;
  418. double Tt1 = 0;
  419. if (info == 0)
  420. {
  421. return -1;
  422. }
  423. cJSON *root = cJSON_Parse(qrcode_str);
  424. if (root == NULL)
  425. { /*消息不合格*/
  426. return -1;
  427. }
  428. cJSON *item = cJSON_GetObjectItem(root, "p");
  429. if (item == NULL)
  430. { /*消息不合格*/
  431. cJSON_Delete(root);
  432. return -1;
  433. }
  434. char *pid = cJSON_GetStringValue(item);
  435. // printf("pid=%s \r\n", pid);
  436. memcpy(info->pid, pid, 10);
  437. item = cJSON_GetObjectItem(root, "t");
  438. if (item == NULL)
  439. { /*消息不合格*/
  440. cJSON_Delete(root);
  441. return -1;
  442. }
  443. double t = item->valuedouble;
  444. // printf("t=%f \r\n", t);
  445. info->temp[0] = (uint8_t)t;
  446. info->temp[1] = (uint8_t)((t -(uint8_t)t)* 100);
  447. // 获取数组item
  448. item = cJSON_GetObjectItem(root, "e");
  449. if (item == NULL)
  450. { /*消息不合格*/
  451. cJSON_Delete(root);
  452. return -1;
  453. }
  454. int test_arry_size = cJSON_GetArraySize(item);
  455. for (int i = 0; i < test_arry_size; i++)
  456. {
  457. // 打印数组里的所有item
  458. cJSON *sub_array = cJSON_GetArrayItem(item, i);
  459. cJSON *sub = cJSON_GetObjectItem(sub_array, "i");
  460. id = sub->valueint;
  461. // printf("id=%d \r\n", id);
  462. if(id > 0)
  463. {
  464. sub = cJSON_GetObjectItemCaseSensitive(sub_array, "T");
  465. Tt = sub->valuedouble;
  466. // printf("Tt=%f \r\n", Tt);
  467. sub = cJSON_GetObjectItemCaseSensitive(sub_array, "t");
  468. Tt1 = sub->valuedouble;
  469. // printf("Tt1=%f \r\n", Tt1);
  470. }
  471. else
  472. {
  473. Tt = 0;
  474. Tt1 = 0;
  475. }
  476. info->hole_info[i].item = id;
  477. info->hole_info[i].TtMax[0] = (uint8_t)Tt;
  478. info->hole_info[i].TtMax[1] = (uint8_t)((Tt -(uint8_t)Tt)* 100);
  479. info->hole_info[i].TtMin[0] = (uint8_t)Tt1;
  480. info->hole_info[i].TtMin[1] = (uint8_t)((Tt1 -(uint8_t)Tt1)* 100);
  481. }
  482. // 记得删除json
  483. cJSON_Delete(root);
  484. return 0;
  485. }
  486. /********************************************************************
  487. * QRparam_upload()
  488. *
  489. *描述:上传二维码扫码参数
  490. *参数:无
  491. *返回:无
  492. *其他:无
  493. *--------------------------------------------------------------------
  494. *记录:包含上报和应答处理
  495. ********************************************************************/
  496. void QRparam_upload(str_card_param_info_t *p_str_card_param_info)
  497. {
  498. memset(g_uart0_tx_buf, 0, sizeof(g_uart0_tx_buf));
  499. // int QR_param_pid = 0;
  500. // QR_param_pid = atoi(&m_str_card_param_info.pid[0]);
  501. g_uart0_tx_buf[0] = 0xAA; // 帧头
  502. g_uart0_tx_buf[1] = 0x55; // 帧头
  503. g_uart0_tx_buf[2] = 0x0A; // 命令标识
  504. g_uart0_tx_buf[3] = 0x11; // 命令标识
  505. #if 0
  506. /*卡盒编号*/
  507. g_uart0_tx_buf[4] = (uint8_t)m_str_card_param_info.pid[0] - 48;
  508. g_uart0_tx_buf[5] = (uint8_t)m_str_card_param_info.pid[1] - 48;
  509. g_uart0_tx_buf[6] = (uint8_t)m_str_card_param_info.pid[2] - 48;
  510. g_uart0_tx_buf[7] = (uint8_t)m_str_card_param_info.pid[3] - 48;
  511. g_uart0_tx_buf[8] = (uint8_t)m_str_card_param_info.pid[4] - 48;
  512. g_uart0_tx_buf[9] = (uint8_t)m_str_card_param_info.pid[5] - 48;
  513. /*卡槽工作温度(整数+小数)*/
  514. g_uart0_tx_buf[10] = (uint8_t)(m_str_card_param_info.temp);
  515. g_uart0_tx_buf[11] = (uint8_t)((m_str_card_param_info.temp-(uint8_t)(m_str_card_param_info.temp))*100);
  516. /*孔1检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  517. g_uart0_tx_buf[12] = (uint8_t)(m_str_card_param_info.hole_info[0].item);
  518. g_uart0_tx_buf[13] = (uint8_t)(m_str_card_param_info.hole_info[0].TtMax);
  519. g_uart0_tx_buf[14] = (uint8_t)((m_str_card_param_info.hole_info[0].TtMax-(uint8_t)(m_str_card_param_info.hole_info[0].TtMax))*100);
  520. g_uart0_tx_buf[15] = (uint8_t)(m_str_card_param_info.hole_info[0].TtMin);
  521. g_uart0_tx_buf[16] = (uint8_t)((m_str_card_param_info.hole_info[0].TtMin-(uint8_t)(m_str_card_param_info.hole_info[0].TtMin))*100);
  522. /*孔2检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  523. g_uart0_tx_buf[17] = (uint8_t)(m_str_card_param_info.hole_info[1].item);
  524. g_uart0_tx_buf[18] = (uint8_t)(m_str_card_param_info.hole_info[1].TtMax);
  525. g_uart0_tx_buf[19] = (uint8_t)((m_str_card_param_info.hole_info[1].TtMax-(uint8_t)(m_str_card_param_info.hole_info[1].TtMax))*100);
  526. g_uart0_tx_buf[20] = (uint8_t)(m_str_card_param_info.hole_info[1].TtMin);
  527. g_uart0_tx_buf[21] = (uint8_t)((m_str_card_param_info.hole_info[1].TtMin-(uint8_t)(m_str_card_param_info.hole_info[1].TtMin))*100);
  528. /*孔3检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  529. g_uart0_tx_buf[22] = (uint8_t)(m_str_card_param_info.hole_info[2].item);
  530. g_uart0_tx_buf[23] = (uint8_t)(m_str_card_param_info.hole_info[2].TtMax);
  531. g_uart0_tx_buf[24] = (uint8_t)((m_str_card_param_info.hole_info[2].TtMax-(uint8_t)(m_str_card_param_info.hole_info[2].TtMax))*100);
  532. g_uart0_tx_buf[25] = (uint8_t)(m_str_card_param_info.hole_info[2].TtMin);
  533. g_uart0_tx_buf[26] = (uint8_t)((m_str_card_param_info.hole_info[2].TtMin-(uint8_t)(m_str_card_param_info.hole_info[2].TtMin))*100);
  534. /*孔4检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  535. g_uart0_tx_buf[27] = (uint8_t)(m_str_card_param_info.hole_info[3].item);
  536. g_uart0_tx_buf[28] = (uint8_t)(m_str_card_param_info.hole_info[3].TtMax);
  537. g_uart0_tx_buf[29] = (uint8_t)((m_str_card_param_info.hole_info[3].TtMax-(uint8_t)(m_str_card_param_info.hole_info[3].TtMax))*100);
  538. g_uart0_tx_buf[30] = (uint8_t)(m_str_card_param_info.hole_info[3].TtMin);
  539. g_uart0_tx_buf[31] = (uint8_t)((m_str_card_param_info.hole_info[3].TtMin-(uint8_t)(m_str_card_param_info.hole_info[3].TtMin))*100);
  540. /*孔5检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  541. g_uart0_tx_buf[32] = (uint8_t)(m_str_card_param_info.hole_info[4].item);
  542. g_uart0_tx_buf[33] = (uint8_t)(m_str_card_param_info.hole_info[4].TtMax);
  543. g_uart0_tx_buf[34] = (uint8_t)((m_str_card_param_info.hole_info[4].TtMax-(uint8_t)(m_str_card_param_info.hole_info[4].TtMax))*100);
  544. g_uart0_tx_buf[35] = (uint8_t)(m_str_card_param_info.hole_info[4].TtMin);
  545. g_uart0_tx_buf[36] = (uint8_t)((m_str_card_param_info.hole_info[4].TtMin-(uint8_t)(m_str_card_param_info.hole_info[4].TtMin))*100);
  546. /*孔6检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  547. g_uart0_tx_buf[37] = (uint8_t)(m_str_card_param_info.hole_info[5].item);
  548. g_uart0_tx_buf[38] = (uint8_t)(m_str_card_param_info.hole_info[5].TtMax);
  549. g_uart0_tx_buf[39] = (uint8_t)((m_str_card_param_info.hole_info[5].TtMax-(uint8_t)(m_str_card_param_info.hole_info[5].TtMax))*100);
  550. g_uart0_tx_buf[40] = (uint8_t)(m_str_card_param_info.hole_info[5].TtMin);
  551. g_uart0_tx_buf[41] = (uint8_t)((m_str_card_param_info.hole_info[5].TtMin-(uint8_t)(m_str_card_param_info.hole_info[5].TtMin))*100);
  552. /*孔7检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  553. g_uart0_tx_buf[42] = (uint8_t)(m_str_card_param_info.hole_info[6].item);
  554. g_uart0_tx_buf[43] = (uint8_t)(m_str_card_param_info.hole_info[6].TtMax);
  555. g_uart0_tx_buf[44] = (uint8_t)((m_str_card_param_info.hole_info[6].TtMax-(uint8_t)(m_str_card_param_info.hole_info[6].TtMax))*100);
  556. g_uart0_tx_buf[45] = (uint8_t)(m_str_card_param_info.hole_info[6].TtMin);
  557. g_uart0_tx_buf[46] = (uint8_t)((m_str_card_param_info.hole_info[6].TtMin-(uint8_t)(m_str_card_param_info.hole_info[6].TtMin))*100);
  558. /*孔8检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  559. g_uart0_tx_buf[47] = (uint8_t)(m_str_card_param_info.hole_info[7].item);
  560. g_uart0_tx_buf[48] = (uint8_t)(m_str_card_param_info.hole_info[7].TtMax);
  561. g_uart0_tx_buf[49] = (uint8_t)((m_str_card_param_info.hole_info[7].TtMax-(uint8_t)(m_str_card_param_info.hole_info[7].TtMax))*100);
  562. g_uart0_tx_buf[50] = (uint8_t)(m_str_card_param_info.hole_info[7].TtMin);
  563. g_uart0_tx_buf[51] = (uint8_t)((m_str_card_param_info.hole_info[7].TtMin-(uint8_t)(m_str_card_param_info.hole_info[7].TtMin))*100);
  564. /*孔9检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  565. g_uart0_tx_buf[52] = (uint8_t)(m_str_card_param_info.hole_info[8].item);
  566. g_uart0_tx_buf[53] = (uint8_t)(m_str_card_param_info.hole_info[8].TtMax);
  567. g_uart0_tx_buf[54] = (uint8_t)((m_str_card_param_info.hole_info[8].TtMax-(uint8_t)(m_str_card_param_info.hole_info[8].TtMax))*100);
  568. g_uart0_tx_buf[55] = (uint8_t)(m_str_card_param_info.hole_info[8].TtMin);
  569. g_uart0_tx_buf[56] = (uint8_t)((m_str_card_param_info.hole_info[8].TtMin-(uint8_t)(m_str_card_param_info.hole_info[8].TtMin))*100);
  570. /*孔10检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
  571. g_uart0_tx_buf[57] = (uint8_t)(m_str_card_param_info.hole_info[9].item);
  572. g_uart0_tx_buf[58] = (uint8_t)(m_str_card_param_info.hole_info[9].TtMax);
  573. g_uart0_tx_buf[59] = (uint8_t)((m_str_card_param_info.hole_info[9].TtMax-(uint8_t)(m_str_card_param_info.hole_info[9].TtMax))*100);
  574. g_uart0_tx_buf[60] = (uint8_t)(m_str_card_param_info.hole_info[9].TtMin);
  575. g_uart0_tx_buf[61] = (uint8_t)((m_str_card_param_info.hole_info[9].TtMin-(uint8_t)(m_str_card_param_info.hole_info[9].TtMin))*100);
  576. #endif
  577. memcpy(g_uart0_tx_buf + 4, (uint8_t*)p_str_card_param_info, sizeof(str_card_param_info_t));
  578. g_uart0_tx_buf[62] = 0x55; // 帧尾
  579. g_uart0_tx_buf[63] = 0xBB; // 帧尾
  580. UART_Write(UART0, g_uart0_tx_buf, 64);
  581. }