去掉合包亮灯的锁,防止无法写入

This commit is contained in:
zzh 2025-07-18 10:54:41 +08:00
parent e8670b0775
commit ad4da8ea92

23
main.c
View File

@ -59,7 +59,7 @@ int fd;
int UPCASE=0; int UPCASE=0;
int count_value=0; int count_value=0;
int getPayloadTime=120*1000;//usecond int getPayloadTime=120*1000;//usecond
char softwareVersion[16]="1.1.20"; char softwareVersion[16]="1.1.22";
char stationsn[16]="TJ251372224247";//TJ250995217957 char stationsn[16]="TJ251372224247";//TJ250995217957
char productid[8]="10045"; char productid[8]="10045";
char appKey[32]="fdhQmhqhvbL1cf1K9mUqt"; char appKey[32]="fdhQmhqhvbL1cf1K9mUqt";
@ -1912,7 +1912,7 @@ void *thread_mqtt_recv(void *arg){
system("mv /userdata/tx_ota /userdata/ota"); system("mv /userdata/tx_ota /userdata/ota");
system("mv /userdata/ota/ustart.sh /userdata"); system("mv /userdata/ota/ustart.sh /userdata");
system("sync"); system("sync");
sleep(1); sleep(15);
system("reboot"); system("reboot");
}else if(strcmp(mqtt_parm.msg_type,"5003")==0){ }else if(strcmp(mqtt_parm.msg_type,"5003")==0){
LOG_I("5003 need report station info\n"); LOG_I("5003 need report station info\n");
@ -2047,7 +2047,7 @@ void *thread_mqtt_recv(void *arg){
if(strcmp(msg_labelconfig_value,"")!=0){ if(strcmp(msg_labelconfig_value,"")!=0){
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"ok",1,productid); mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"ok",1,productid);
isSendComEnd=false; isSendComEnd=false;
isLightOn=false; isLightOn=false;
isLightOnByRule=true; isLightOnByRule=true;
isLabelUp=false; isLabelUp=false;
//isSearchLabel=false; //isSearchLabel=false;
@ -2539,7 +2539,7 @@ int main(int argc, char *argv[])
{ {
// 先检查标准输入是否可用 // 先检查标准输入是否可用
if (feof(stdin) || ferror(stdin)) { if (feof(stdin) || ferror(stdin)) {
LOG_I("stdin error or EOF, sleeping for 1 second\n"); //LOG_I("stdin error or EOF, sleeping for 1 second\n");
sleep(1); sleep(1);
continue; continue;
} }
@ -2592,17 +2592,21 @@ void *thread_timeout_check(void *arg) {
// 合并点亮线程 // 合并点亮线程
void *thread_3015_lighton_merge(void *arg) { void *thread_3015_lighton_merge(void *arg) {
while (1) { int total_all = 0;
while (1) {
pthread_mutex_lock(&lightsn_buffer_mutex); pthread_mutex_lock(&lightsn_buffer_mutex);
if (is_3015_collecting) { if (is_3015_collecting) {
time_t now = time(NULL); time_t now = time(NULL);
if ((now - first_3015_time >= 3) || (lightsn_buffer_count >= MAX_LIGHTSN_BUFFER)) { if ((now - first_3015_time >= 3) || (lightsn_buffer_count >= MAX_LIGHTSN_BUFFER)) {
int total = lightsn_buffer_count; int total = lightsn_buffer_count;
int batch_size = 10; total_all += total;
int batch_size = 10;
int sent = 0; int sent = 0;
while (sent < total) { while (sent < total) {
int this_batch = (total - sent > batch_size) ? batch_size : (total - sent); int this_batch = (total - sent > batch_size) ? batch_size : (total - sent);
if (isLightEnable && this_batch > 0) { LOG_I("-------total:%d, sent:%d, this batch: %d------\n", total, sent, this_batch);
if (isLightEnable && this_batch > 0) {
isLightOn = true; isLightOn = true;
isLightOnByRule = false; isLightOnByRule = false;
isLabelUp = false; isLabelUp = false;
@ -2673,11 +2677,12 @@ void *thread_3015_lighton_merge(void *arg) {
} }
sent += this_batch; sent += this_batch;
if (sent < total) { if (sent < total) {
pthread_mutex_unlock(&lightsn_buffer_mutex); // 释放锁等待
sleep(3); sleep(3);
pthread_mutex_lock(&lightsn_buffer_mutex); // 重新加锁
} }
LOG_I("total_all: %d\n", total_all);
} }
// 不要立即清空buffer等待isLightOn处理完成 // 不要立即清空buffer等待isLightOn处理完成
is_3015_collecting = false; is_3015_collecting = false;
first_3015_time = 0; first_3015_time = 0;