美团亮灯 bug 修复

This commit is contained in:
zzh 2025-12-08 11:32:44 +08:00
parent 6eb5df592e
commit ebdd4cd187

99
main.c
View File

@ -38,6 +38,7 @@ pthread_t pt_keycheck;
pthread_t pt_mqtt_status;
pthread_t pt_station_heartbeat;
pthread_t pt_simulate_light;
pthread_t pt_all_light;
uart_utils_t uartSend = {0};
uart_utils_t uartRecvData = {0};
uart_utils_t uartRecvBack = {0};
@ -53,6 +54,11 @@ bool isBindTag=false;
bool isSendComEnd=true;
bool isStopBroadcast=false;
bool isStopBroadcastBegin=false;
bool isAllLightOn=false; // 全场亮灯标志
uint8_t allLightColor=4; // 全场亮灯颜色,默认红色
uint8_t allLightFlash=3; // 全场亮灯闪烁模式,默认闪烁
uint8_t allLightSound=0; // 全场亮灯蜂鸣,默认关闭
int allLightDuration=30; // 全场亮灯持续时间(秒)
bool isOtaEnable=false;
jt_only_tag_t onlyTags[200]={0};
int tagCount=0;
@ -135,6 +141,7 @@ void *thread_mqtt_status_check(void *arg);
void *thread_station_heartbeat(void *arg);
void *thread_heartbeat_check(void *arg);
void *thread_simulate_light(void *arg);
void *thread_all_light(void *arg);
void update_lightbar_heartbeat(uint32_t tagCode);
void report_lightbar_login(uint32_t tagCode);
void report_lightbar_logout(uint32_t tagCode);
@ -325,6 +332,76 @@ void *thread_simulate_light(void *arg){
pthread_exit(NULL);
}
/*================================================================================*/
// 全场亮灯线程 - 从/root/all_light文件读取配置并触发全场亮灯
void *thread_all_light(void *arg){
LOG_I("thread_all_light started\n");
char all_light_payload[256] = {0};
while(1){
sleep(5); // 每5秒检查一次
// 从/root/all_light文件读取内容
FILE *fp = fopen("/root/all_light", "r");
if(fp == NULL){
continue;
}
memset(all_light_payload, 0, sizeof(all_light_payload));
if(fgets(all_light_payload, sizeof(all_light_payload), fp) != NULL){
// 去掉换行符
int len = strlen(all_light_payload);
if(len > 0 && all_light_payload[len-1] == '\n'){
all_light_payload[len-1] = '\0';
}
// 解析配置: 格式为 "color,flash,sound,duration" 例如 "4,3,0,30"
// color: 0=不亮,1=蓝,2=绿,3=青,4=红,5=紫,6=黄,7=白
// flash: 1=常亮,3=闪烁
// sound: 0=关闭,1=开启
// duration: 持续时间(秒)
int color=4, flash=3, sound=0, duration=30;
if(sscanf(all_light_payload, "%d,%d,%d,%d", &color, &flash, &sound, &duration) >= 1){
LOG_I("all_light: color=%d, flash=%d, sound=%d, duration=%d\n", color, flash, sound, duration);
// 设置全场亮灯参数
allLightColor = color;
allLightFlash = flash;
allLightSound = sound;
allLightDuration = duration;
// 等待上一个命令完成
while(!isSendComEnd){
usleep(100*1000);
}
// 清空串口缓冲区
tcflush(uartSend.uart_fd, TCIOFLUSH);
// 设置全场亮灯标志
isSendComEnd = false;
isLightOnByGroup = false;
isLightOnById = false;
isLightOn = false;
isBindTag = false;
isAllLightOn = true;
// 发送按ID范围点亮命令 '*' 表示按ID点亮
// timeout单位是5秒所以 duration(秒) / 5 = timeout
uart_data_send_head(&uartSend, '*', 5, duration/5, 0);
LOG_I("all_light: command sent\n");
}
}
fclose(fp);
// 删除文件,避免重复触发
remove("/root/all_light");
}
pthread_exit(NULL);
}
/*================================================================================*/
void doCommand_help(int argc, char *argv[])
{
@ -1581,6 +1658,20 @@ void *thread_uart_recv_ack(void *arg){
uart_data_send_lighton_by_group(&uartSend,groups,1);
isLightOnByGroup=false;
}
if(isAllLightOn){
// 全场亮灯 - 使用ID范围0x00000000到0xFFFFFFFF点亮所有灯条
jt_led_or_group_package_t all_led_ctrl={
.s.color=allLightColor,
.s.sound=allLightSound,
.s.single=0,
.s.flash=allLightFlash,
};
uart_data_send_lighton_by_id(&uartSend, 0x00, 0xFF, 0x00000000, 0xFFFFFFFF, all_led_ctrl, 0x0000);
isAllLightOn=false;
LOG_I("all_light: id range command sent, color=%d, flash=%d, sound=%d\n",
allLightColor, allLightFlash, allLightSound);
}
}else if(parm_ack==0x4646){
isSendComEnd=true;
}else if(parm_ack==0x5252){
@ -2393,6 +2484,14 @@ int main(int argc, char *argv[])
LOG_I("pthread_create simulate_light success\n");
pthread_detach(pt_simulate_light);
}
ret = pthread_create(&pt_all_light,NULL,thread_all_light,NULL);
if(ret!=0){
LOG_I("pthread_create all_light fail\n");
}else{
LOG_I("pthread_create all_light success\n");
pthread_detach(pt_all_light);
}
#endif
#if 0
readresult=file_to_buffer("mqttRawPassword",&len);