/* * uart_rcv.c * * Created on: 2022年4月20日 * Author: dell */ #include #include #include #include #include "onechip_include_header.h" #define ENV_ADJ_THRESHOLD 27.0 #define DEBUG_BUF_SIZE (512) // 调试串口缓冲区长度 #define BUF_SIZE (512) // 调试串口缓冲区长度 enum SLAVE_MCU_Ctr_cmd_type { SLAVE_MCU_CMD_PARAM = 0x01, SLAVE_MCU_CMD_HEAT = 0x02, SLAVE_MCU_CMD_LIGHT_CTR= 0X03, SLAVE_MCU_CMD_QRSCANNER_CTR= 0X04, SLAVE_MCU_CMD_FAN= 0X05, SLAVE_MCU_CMD_CARD_ST= 0X06, SLAVE_MCU_CMD_PID = 0x20, }; enum SLAVE_MCU_Ctr_UP_type { SLAVE_MCU_UP_HEAT = 0x10, SLAVE_MCU_UP_QR_PARAM= 0X11, SLAVE_MCU_UP_QR = 0x12, SLAVE_MCU_INFO, //异常信息 }; uint8_t g_uart2_rcv_start = 0; uint8_t g_uart2_rcv_complete_flg = 0; uint8_t g_uart2_rx_buf[DEBUG_BUF_SIZE] = {0}; uint8_t g_uart2_tx_buf[BUF_SIZE] = {0}; uint16_t g_uart2_rx_len = 0; str_hole_info_t hole1 = {0}; str_hole_info_t hole2 = {0}; str_hole_info_t hole3 = {0}; str_hole_info_t hole4 = {0}; str_hole_info_t hole5 = {0}; str_hole_info_t hole6 = {0}; str_hole_info_t hole7 = {0}; str_hole_info_t hole8 = {0}; str_hole_info_t hole9 = {0}; str_hole_info_t hole10 = {0}; str_card_param_info_t m_str_card_param_info = {0}; unsigned int haveheaderflag = 0; uint32_t qr_check_delay = QR_CHECH_STATE_FIRST; /*1s定时器里面,大于0,每s减1*/ extern void DelayMS(uint32_t ms); extern void QRparam_upload(str_card_param_info_t *p_str_card_param_info); extern uint8_t sys_info[40]; uint32_t received_len; /******************************************************************** * bcd_to_hex() * *描述:BCD转HEX *参数:无 *返回:无 *其他:无 *-------------------------------------------------------------------- *记录: ********************************************************************/ uint8_t bcd_to_hex(uint8_t val) { return ((val / 10) << 4) + val % 10; } void svanner_receive_Rec_IDLE(UART_HandleTypeDef *huart) { if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET)) { __HAL_UART_CLEAR_IDLEFLAG(huart); received_len = DEBUG_BUF_SIZE - __HAL_DMA_GET_COUNTER(huart->hdmarx); HAL_UART_DMAStop(huart); HAL_UART_Receive_DMA(huart, g_uart2_rx_buf, DEBUG_BUF_SIZE); } } void svanner_receive_analysis(void) { if(received_len){ Van_Device_Printf(VAN_LOG_CRITICAL, "rec QR inif %d \n\r",received_len); unsigned filter = 0; /*while('{' != g_uart2_rx_buf[filter] && filterpid, pid, 10); item = cJSON_GetObjectItem(root, "t"); if (item == NULL) { /*消息不合格*/ cJSON_Delete(root); return -1; } double t = item->valuedouble; // printf("t=%f \r\n", t); info->temp[0] = (uint8_t)t; info->temp[1] = (uint8_t)((t -(uint8_t)t)* 100); // 获取数组item item = cJSON_GetObjectItem(root, "e"); if (item == NULL) { /*消息不合格*/ cJSON_Delete(root); return -1; } int test_arry_size = cJSON_GetArraySize(item); for (int i = 0; i < test_arry_size; i++) { // 打印数组里的所有item cJSON *sub_array = cJSON_GetArrayItem(item, i); cJSON *sub = cJSON_GetObjectItem(sub_array, "i"); id = sub->valueint; // printf("id=%d \r\n", id); if(id > 0) { sub = cJSON_GetObjectItemCaseSensitive(sub_array, "T"); Tt = sub->valuedouble; // printf("Tt=%f \r\n", Tt); sub = cJSON_GetObjectItemCaseSensitive(sub_array, "t"); Tt1 = sub->valuedouble; // printf("Tt1=%f \r\n", Tt1); } else { Tt = 0; Tt1 = 0; } info->hole_info[i].item = id; info->hole_info[i].TtMax[0] = (uint8_t)Tt; info->hole_info[i].TtMax[1] = (uint8_t)((Tt -(uint8_t)Tt)* 100); info->hole_info[i].TtMin[0] = (uint8_t)Tt1; info->hole_info[i].TtMin[1] = (uint8_t)((Tt1 -(uint8_t)Tt1)* 100); } // 记得删除json cJSON_Delete(root); return 0; } void svanner_receive_Rec_Start(UART_HandleTypeDef *huart){ __HAL_UART_CLEAR_IDLEFLAG(huart); memset((char *)g_uart2_rx_buf,0,DEBUG_BUF_SIZE); HAL_UART_Receive_DMA(huart, g_uart2_rx_buf, DEBUG_BUF_SIZE); __HAL_UART_ENABLE_IT(huart, UART_IT_IDLE); }