From 141bcbcaa3c81d2a66875c95b39ecab01c0bb74a Mon Sep 17 00:00:00 2001 From: zzh Date: Thu, 12 Jun 2025 14:33:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E6=89=80=E6=9C=89=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E7=A8=8B=E5=90=8D=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E4=BE=BF=E6=8E=92=E6=9F=A5=E5=93=AA=E4=BA=9B=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E8=B5=84=E6=BA=90=E8=BE=83=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 27 ++++++++++++++++++++------- mqtt_utils/mqtt_utils.c | 28 +++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 2eb51bc..ac2db5e 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #define DBG_TAG "main" #define DBG_LVL DBG_INFO #include "debug_print.h" +#include #if 0 #include #include @@ -1163,30 +1164,37 @@ error: /*================================================================================*/ void *thread_ota(void *arg){ + prctl(PR_SET_NAME, "ota"); checkOtaKey(); } void *thread_mqtt(void *arg){ + prctl(PR_SET_NAME, "mqtt"); mqtt_init(); } void *thread_removelog(void *arg){ + prctl(PR_SET_NAME, "removelog"); removeLog(); } void *thread_reboot(void *arg){ + prctl(PR_SET_NAME, "reboot"); rebootSystem(); } void *thread_feed_watchdog(void *arg){ + prctl(PR_SET_NAME, "watchdog"); feedWatchDog(); } void *thread_readqr(void *arg){ + prctl(PR_SET_NAME, "readqr"); readQrcode(); } void *thread_tag_search_send(void *arg){ + prctl(PR_SET_NAME, "tag_search"); while(1){ if(isSearchLabelOn){ //uart_data_send_head_search(&uartSend,5); @@ -1204,6 +1212,7 @@ void *thread_tag_search_send(void *arg){ } void *thread_do_ota(void *arg){ + prctl(PR_SET_NAME, "do_ota"); while(1){ if(isOtaEnable && isSendComEnd && !isLEDOtaSuccess){ sleep(1); @@ -1221,6 +1230,7 @@ void *thread_do_ota(void *arg){ //char *tag_4="00A04C11"; //char *tag_5="00A04CD0"; void *thread_uart_recv_ack(void *arg){ + prctl(PR_SET_NAME, "uart_ack"); uint16_t parm_ack; int ret=0; while(1){ @@ -1376,6 +1386,7 @@ void *thread_uart_recv_ack(void *arg){ } void *thread_uart_recv_data(void *arg){ + prctl(PR_SET_NAME, "uart_data"); uint16_t parmAck; uint32_t tagCode; uint8_t tagSignal; @@ -1398,6 +1409,7 @@ void *thread_uart_recv_data(void *arg){ } void *thread_uart_recv_back(void *arg){ + prctl(PR_SET_NAME, "uart_back"); uint16_t parmAck; uint32_t tagCode; uint8_t tagSignal; @@ -1552,6 +1564,7 @@ void addOnlyTag(uint32_t tagname,uint16_t battery){ } void *thread_remove_duplicate_tag(void *arg){ + prctl(PR_SET_NAME, "rm_dup_tag"); uint32_t tagname=0; uint16_t battery=0; while(1){ @@ -1565,6 +1578,7 @@ void *thread_remove_duplicate_tag(void *arg){ } void *thread_mqtt_recv(void *arg){ + prctl(PR_SET_NAME, "mqtt_recv"); char payload[1024]={0}; char msg_body_value[1024] ={0}; char msg_body[1024] = {0}; @@ -1578,7 +1592,7 @@ void *thread_mqtt_recv(void *arg){ if(isSendComEnd){ if(GetDataFromMQueue(payload)==0){ //getPayloadTime=120*1000; - //LOG_I("payload:%s\n",payload); + LOG_I("payload:%s\n",payload); get_string_from_json_string_by_key_unescape(payload,"messageId",mqtt_parm.msg_messageId,sizeof(mqtt_parm.msg_messageId)); //LOG_I("messageId:%s\n",mqtt_parm.msg_messageId); if(isSearchLabelOn){ @@ -1658,7 +1672,7 @@ void *thread_mqtt_recv(void *arg){ searchTimeOld=getCurrentTime(); LOG_I("searchTimeOld:%d\n",searchTimeOld); isSearchLabelOn=true; - }else if(strcmp(mqtt_parm.msg_type,"3016")==0){ + }else if(strcmp(mqtt_parm.msg_type,"3015")==0){ LOG_I("3015 light on\n"); get_string_from_json_string_by_key_unescape(msg_data, "scene", mqtt_parm.msg_scene, sizeof(mqtt_parm.msg_scene)); LOG_I("scene:%s\n",mqtt_parm.msg_scene); @@ -1781,26 +1795,25 @@ void *thread_mqtt_recv(void *arg){ }else{ mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"labelconfig is empty",0,productid); } - }else if(strcmp(mqtt_parm.msg_type,"3015")==0){ + }else if(strcmp(mqtt_parm.msg_type,"3027")==0){ LOG_I("3027 All light on/off 广播点亮\n"); get_string_from_json_string_by_key_unescape(msg_data, "color", mqtt_parm.msg_color, sizeof(mqtt_parm.msg_color)); - strcpy(mqtt_parm.msg_color, "1"); // 默认关闭颜色 + //strcpy(mqtt_parm.msg_color, "1"); // 默认关闭颜色 LOG_I("color:%s\n",mqtt_parm.msg_color); get_string_from_json_string_by_key_unescape(msg_data, "sound", mqtt_parm.msg_sound, sizeof(mqtt_parm.msg_sound)); - strcpy(mqtt_parm.msg_sound, "0"); // 默认关闭声音 + //strcpy(mqtt_parm.msg_sound, "0"); // 默认关闭声音 LOG_I("sound:%s\n",mqtt_parm.msg_sound); get_string_from_json_string_by_key_unescape(msg_data, "flash", mqtt_parm.msg_flash, sizeof(mqtt_parm.msg_flash)); - strcpy(mqtt_parm.msg_flash, "0"); // 默认关闭闪烁 + //strcpy(mqtt_parm.msg_flash, "0"); // 默认关闭闪烁 LOG_I("flash:%s\n",mqtt_parm.msg_flash); get_string_from_json_string_by_key_unescape(msg_data, "flashInterval", mqtt_parm.msg_flashInterval, sizeof(mqtt_parm.msg_flashInterval)); LOG_I("flashInterval:%s\n",mqtt_parm.msg_flashInterval); get_string_from_json_string_by_key_unescape(msg_data, "lightDuration", mqtt_parm.msg_lightDuration, sizeof(mqtt_parm.msg_lightDuration)); - strcpy(mqtt_parm.msg_lightDuration, "300"); // 点亮300秒 LOG_I("lightDuration:%s\n",mqtt_parm.msg_lightDuration); if(isLightEnable){ diff --git a/mqtt_utils/mqtt_utils.c b/mqtt_utils/mqtt_utils.c index a0cfb24..9075837 100644 --- a/mqtt_utils/mqtt_utils.c +++ b/mqtt_utils/mqtt_utils.c @@ -19,6 +19,8 @@ #include #endif +#include +#include #include #include #include @@ -248,6 +250,28 @@ void mqtt_utils_delivery_complete(void *context, MQTTAsync_token token){ //LOG_I("%s\n",__func__); } +static int led_running = 1; +static pthread_t led_thread; + +void* led_blink_thread(void* arg) { + prctl(PR_SET_NAME, "led_blink"); + int fd = open("/sys/class/gpio/gpio113/value", O_WRONLY); + if (fd < 0) { + LOG_I("Failed to open GPIO\n"); + return NULL; + } + + while(led_running) { + write(fd, "1", 1); + usleep(500000); + write(fd, "0", 1); + usleep(500000); + } + + close(fd); + return NULL; +} + void mqtt_utils_connected(void *context, char *cause){ if (cause != NULL) { LOG_I("%s cause:%s\n",__func__, cause); @@ -256,7 +280,9 @@ void mqtt_utils_connected(void *context, char *cause){ } connect_failure_times=0; mqtt_utils_subscribe(mqtt_conf,nativeInvokTopicName,2); - system("echo 1 > /sys/class/gpio/gpio113/value");//yellow ok + //system("echo 1 > /sys/class/gpio/gpio113/value");//yellow ok + led_running = 1; + pthread_create(&led_thread, NULL, led_blink_thread, NULL); char myid[32]={0}; myrand(myid,19); updateStationInfo(myid);