灯带分组合包

This commit is contained in:
zzh 2025-06-18 15:22:18 +08:00
parent d315d63d27
commit 3e214f7739

31
main.c
View File

@ -1977,10 +1977,37 @@ void *thread_mqtt_recv(void *arg){
isLightOnByRule=false;
isLabelUp=true;
//isSearchLabel=false;
uart_data_send_head_lableup(&uartSend,5,1);
// 分组信息缓存与批量处理
typedef struct {
char label1[64];
char label2[64];
char label3[64];
char sn[64];
} GroupInfo;
#define GROUP_MAX 20
static GroupInfo group_buffer[GROUP_MAX];
static int group_count = 0;
static time_t last_write_time = 0;
// 保存一次分组信息
strncpy(group_buffer[group_count].label1, mqtt_parm.msg_label1, sizeof(group_buffer[group_count].label1));
strncpy(group_buffer[group_count].label2, mqtt_parm.msg_label2, sizeof(group_buffer[group_count].label2));
strncpy(group_buffer[group_count].label3, mqtt_parm.msg_label3, sizeof(group_buffer[group_count].label3));
strncpy(group_buffer[group_count].sn, mqtt_parm.msg_sn, sizeof(group_buffer[group_count].sn));
group_count++;
if (group_count == 1) {
last_write_time = time(NULL);
}
time_t now = time(NULL);
if (group_count >= GROUP_MAX || (now - last_write_time) >= 180) {
for (int i = 0; i < group_count; i++) {
uart_data_send_head_lableup(&uartSend, 5, 1);
}
group_count = 0;
last_write_time = now;
}
}else{
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"sn is empty",0,productid);
}
}
}else if(strcmp(mqtt_parm.msg_type,"3023")==0){
LOG_I("3023 light on by rule\n");
get_string_from_json_string_by_key_unescape(msg_data, "labelConfig", msg_labelconfig_value, sizeof(msg_labelconfig_value));