修复串口缓冲区数据错乱
This commit is contained in:
parent
700c4bf9fb
commit
ae32d60119
17
main.c
17
main.c
@ -175,7 +175,7 @@ void report_lightbar_login(uint32_t tagCode) {
|
|||||||
LOG_I("Lightbar login report - payload: %s\n", payload);
|
LOG_I("Lightbar login report - payload: %s\n", payload);
|
||||||
|
|
||||||
// 发送MQTT消息
|
// 发送MQTT消息
|
||||||
//mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================================*/
|
/*================================================================================*/
|
||||||
@ -217,7 +217,7 @@ void report_lightbar_logout(uint32_t tagCode) {
|
|||||||
LOG_I("Lightbar logout report - payload: %s\n", payload);
|
LOG_I("Lightbar logout report - payload: %s\n", payload);
|
||||||
|
|
||||||
// 发送MQTT消息
|
// 发送MQTT消息
|
||||||
//mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
mqtt_utils_publish(&mqtt_config, topic, 0, payload, strlen(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================================*/
|
/*================================================================================*/
|
||||||
@ -1344,6 +1344,11 @@ void *thread_uart_recv_ack(void *arg){
|
|||||||
uint16_t parm_ack;
|
uint16_t parm_ack;
|
||||||
int ret=0;
|
int ret=0;
|
||||||
while(1){
|
while(1){
|
||||||
|
// 只有在发送命令后才等待ACK,避免读取残留数据
|
||||||
|
if(isSendComEnd){
|
||||||
|
usleep(100*1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ret=uart_data_receive_ack(&uartSend,&parm_ack);
|
ret=uart_data_receive_ack(&uartSend,&parm_ack);
|
||||||
if(ret>0){
|
if(ret>0){
|
||||||
LOG_I("ack:%x\n",parm_ack);
|
LOG_I("ack:%x\n",parm_ack);
|
||||||
@ -1947,7 +1952,10 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
get_int_from_json_string_by_key(msg_colors,"B",&b_enable);
|
get_int_from_json_string_by_key(msg_colors,"B",&b_enable);
|
||||||
|
|
||||||
// 根据RGB组合设置颜色
|
// 根据RGB组合设置颜色
|
||||||
if(r_enable && !g_enable && !b_enable){
|
if(!r_enable && !g_enable && !b_enable){
|
||||||
|
changecolor = 0; // 不亮
|
||||||
|
break;
|
||||||
|
}else if(r_enable && !g_enable && !b_enable){
|
||||||
changecolor = 4; // 红色
|
changecolor = 4; // 红色
|
||||||
break;
|
break;
|
||||||
}else if(!r_enable && g_enable && !b_enable){
|
}else if(!r_enable && g_enable && !b_enable){
|
||||||
@ -2008,6 +2016,9 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
// 正常处理
|
// 正常处理
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清空串口缓冲区,避免残留数据干扰
|
||||||
|
tcflush(uartSend.uart_fd, TCIOFLUSH);
|
||||||
|
|
||||||
isSendComEnd = false;
|
isSendComEnd = false;
|
||||||
isLightOnByGroup = false;
|
isLightOnByGroup = false;
|
||||||
isLightOnById = false;
|
isLightOnById = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user