From efacf3eaa895dd1bf3470e622e5af36a31b375af Mon Sep 17 00:00:00 2001 From: ypc <15051963820@163.com> Date: Tue, 14 Jul 2026 13:25:18 +0800 Subject: [PATCH] =?UTF-8?q?log:=20=E5=85=A8=E6=A8=A1=E5=9D=97=20MY=5FLOG?= =?UTF-8?q?=20=E2=86=92=20LOG=20=E8=BF=81=E7=A7=BB=20+=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=8D=B3=E6=97=B6=E8=BE=93=E5=87=BA=20+=20=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit liblog: - worker_thread 改为一次加锁取完立即输出,去掉凑批延迟 - 内部 printf 均加时间戳 (fmt_time) - 删除废弃的 q_pop 函数 myBase.h: - MY_LOG 宏加时间戳 (gettimeofday + localtime) - 新增 sys/time.h + time.h 头文件 comm 模块: - comm_internal.h 补 #include myLog.h - 全模块 MY_LOG_I/E → LOG_I/E 迁移 (6 文件) system 模块: - app_sys / com_router / libiec / modbus_m / plc / self_ptl - MY_LOG_I/E → LOG_I/E 迁移,统一日志格式 webserver: - 清理 ws_method.cpp 多余空行 - MY_LOG → LOG 迁移 --- release/inc/myBase.h | 13 ++- src/public/libcomm/inc/comm_internal.h | 1 + src/public/libcomm/src/comm_core.cpp | 16 +-- src/public/libcomm/src/comm_tcp.cpp | 10 +- src/public/libcomm/src/comm_uart.cpp | 8 +- src/public/libcomm/src/comm_udp.cpp | 6 +- src/public/liblog/src/myLog.c | 120 ++++++++++---------- src/system/RTU/src/app_sys.cpp | 52 ++++----- src/system/libcom_router/src/com_router.cpp | 6 +- src/system/libiec/src/iec104.cpp | 16 +-- src/system/libmodbus_m/src/modbus_m.cpp | 12 +- src/system/libplc/src/plc.cpp | 10 +- src/system/libself_ptl/src/self_ptl.cpp | 2 +- src/system/libweb_server/src/web_server.cpp | 10 +- src/system/libweb_server/src/ws_method.cpp | 16 --- 15 files changed, 145 insertions(+), 153 deletions(-) diff --git a/release/inc/myBase.h b/release/inc/myBase.h index 10a2c5d..0e50dac 100644 --- a/release/inc/myBase.h +++ b/release/inc/myBase.h @@ -17,6 +17,8 @@ #include #include #include +#include +#include #ifdef __cplusplus extern "C" @@ -44,8 +46,15 @@ extern "C" #define MY_LOG(color, level, fmt, ...) \ do \ { \ - printf("%s[%s] [%s, %u] " fmt COLOR_RESET "\n", \ - color, level, __SHORT_FILE__, __LINE__, ##__VA_ARGS__); \ + struct timeval _tv; \ + gettimeofday(&_tv, NULL); \ + struct tm *_tm = localtime(&_tv.tv_sec); \ + printf("%s[%04d-%02d-%02d %02d:%02d:%02d.%03d] [%s] [%s, %u] " fmt COLOR_RESET "\n", \ + color, \ + _tm ? _tm->tm_year + 1900 : 0, _tm ? _tm->tm_mon + 1 : 0, _tm ? _tm->tm_mday : 0, \ + _tm ? _tm->tm_hour : 0, _tm ? _tm->tm_min : 0, _tm ? _tm->tm_sec : 0, \ + (int)(_tv.tv_usec / 1000), \ + level, __SHORT_FILE__, __LINE__, ##__VA_ARGS__); \ } while (0) #define MY_LOG_I(fmt, ...) MY_LOG(COLOR_WHITE, "INFO", fmt, ##__VA_ARGS__) diff --git a/src/public/libcomm/inc/comm_internal.h b/src/public/libcomm/inc/comm_internal.h index eb0efcd..ea99ae6 100644 --- a/src/public/libcomm/inc/comm_internal.h +++ b/src/public/libcomm/inc/comm_internal.h @@ -8,6 +8,7 @@ #define _COMM_INTERNAL_H_ #include "myComm.h" +#include "myLog.h" #include #include diff --git a/src/public/libcomm/src/comm_core.cpp b/src/public/libcomm/src/comm_core.cpp index 328c8e0..4ad9b95 100644 --- a/src/public/libcomm/src/comm_core.cpp +++ b/src/public/libcomm/src/comm_core.cpp @@ -169,7 +169,7 @@ void handle_error(stru_comm_instance *inst, int fd) if (inst->debug) { - MY_LOG_E("comm[%d] fd=%d error: %s", inst->id, fd, strerror(error)); + LOG_E("comm[%d] fd=%d error: %s", inst->id, fd, strerror(error)); } notify_state(inst, fd, COMM_STATE_ERROR); @@ -201,7 +201,7 @@ LOCAL void handle_tcp_read(stru_comm_instance *inst, int fd) { if (inst->debug) { - MY_LOG_I("comm[%d] fd=%d connection closed by peer", inst->id, fd); + LOG_I("comm[%d] fd=%d connection closed by peer", inst->id, fd); } close_client_fd(inst, fd); break; @@ -217,7 +217,7 @@ LOCAL void handle_tcp_read(stru_comm_instance *inst, int fd) { if (inst->debug) { - MY_LOG_E("comm[%d] fd=%d recv error: %s", inst->id, fd, strerror(errno)); + LOG_E("comm[%d] fd=%d recv error: %s", inst->id, fd, strerror(errno)); } close_client_fd(inst, fd); } @@ -311,14 +311,14 @@ LOCAL void worker_loop(void) if (inst->debug) { - MY_LOG_I("comm[%d] TCP client connected fd=%d", inst->id, fd); + LOG_I("comm[%d] TCP client connected fd=%d", inst->id, fd); } } else { if (inst->debug) { - MY_LOG_E("comm[%d] TCP connect failed: %s", inst->id, strerror(error)); + LOG_E("comm[%d] TCP connect failed: %s", inst->id, strerror(error)); } epoll_del_fd(fd); close(fd); @@ -437,7 +437,7 @@ int comm_create(int type, int debug, const union_comm_para *para) if (debug) { - MY_LOG_I("comm[%d] created type=%d", inst->id, type); + LOG_I("comm[%d] created type=%d", inst->id, type); } return inst->id; @@ -551,7 +551,7 @@ int comm_disconnect(int id) if (inst->debug) { - MY_LOG_I("comm[%d] disconnected", inst->id); + LOG_I("comm[%d] disconnected", inst->id); } return COMM_OK; @@ -594,7 +594,7 @@ int comm_send(int id, int fd, const unsigned char *data, int len) if (inst->debug) { - MY_LOG_E("comm[%d] fd=%d send error: %s", inst->id, fd, strerror(errno)); + LOG_E("comm[%d] fd=%d send error: %s", inst->id, fd, strerror(errno)); } return COMM_ERR_SEND; diff --git a/src/public/libcomm/src/comm_tcp.cpp b/src/public/libcomm/src/comm_tcp.cpp index b16900c..f58d61d 100644 --- a/src/public/libcomm/src/comm_tcp.cpp +++ b/src/public/libcomm/src/comm_tcp.cpp @@ -33,7 +33,7 @@ void handle_accept(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_E("comm[%d] accept error: %s", inst->id, strerror(errno)); + LOG_E("comm[%d] accept error: %s", inst->id, strerror(errno)); } break; } @@ -57,7 +57,7 @@ void handle_accept(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_I("comm[%d] TCP client connected: %s:%d fd=%d", + LOG_I("comm[%d] TCP client connected: %s:%d fd=%d", inst->id, ip_str, ntohs(client_addr.sin_port), client_fd); } @@ -121,7 +121,7 @@ int tcp_server_bind(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_I("comm[%d] TCP server listening on %s:%d", + LOG_I("comm[%d] TCP server listening on %s:%d", inst->id, inst->local_ip, inst->local_port); } @@ -163,7 +163,7 @@ int tcp_client_connect(stru_comm_instance *inst) { if (inst->debug) { - MY_LOG_E("comm[%d] TCP client local bind failed: %s", inst->id, strerror(errno)); + LOG_E("comm[%d] TCP client local bind failed: %s", inst->id, strerror(errno)); } } } @@ -207,7 +207,7 @@ int tcp_client_connect(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_I("comm[%d] TCP client connecting to %s:%d", + LOG_I("comm[%d] TCP client connecting to %s:%d", inst->id, inst->remote_ip, inst->remote_port); } diff --git a/src/public/libcomm/src/comm_uart.cpp b/src/public/libcomm/src/comm_uart.cpp index 4407e3b..105a3c1 100644 --- a/src/public/libcomm/src/comm_uart.cpp +++ b/src/public/libcomm/src/comm_uart.cpp @@ -134,7 +134,7 @@ int uart_open(stru_comm_instance *inst) { if (inst->debug) { - MY_LOG_E("comm[%d] UART open %s failed: %s", + LOG_E("comm[%d] UART open %s failed: %s", inst->id, inst->uart_device, strerror(errno)); } @@ -145,7 +145,7 @@ int uart_open(stru_comm_instance *inst) { if (inst->debug) { - MY_LOG_E("comm[%d] UART configure failed: %s", + LOG_E("comm[%d] UART configure failed: %s", inst->id, strerror(errno)); } close(fd); @@ -164,7 +164,7 @@ int uart_open(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_I("comm[%d] UART opened %s baud=%d databits=%d stopbits=%d parity=%c", + LOG_I("comm[%d] UART opened %s baud=%d databits=%d stopbits=%d parity=%c", inst->id, inst->uart_device, inst->uart_baudrate, inst->uart_data_bits, inst->uart_stop_bits, inst->uart_parity); } @@ -218,7 +218,7 @@ void handle_uart_read(stru_comm_instance *inst, int fd) { if (inst->debug) { - MY_LOG_E("comm[%d] UART fd=%d read error: %s", + LOG_E("comm[%d] UART fd=%d read error: %s", inst->id, fd, strerror(errno)); } } diff --git a/src/public/libcomm/src/comm_udp.cpp b/src/public/libcomm/src/comm_udp.cpp index e4c6bca..2ec1bbe 100644 --- a/src/public/libcomm/src/comm_udp.cpp +++ b/src/public/libcomm/src/comm_udp.cpp @@ -42,7 +42,7 @@ void handle_udp_read(stru_comm_instance *inst, int fd) { if (inst->debug) { - MY_LOG_E("comm[%d] fd=%d recvfrom error: %s", + LOG_E("comm[%d] fd=%d recvfrom error: %s", inst->id, fd, strerror(errno)); } } @@ -98,7 +98,7 @@ int udp_bind(stru_comm_instance *inst) if (inst->debug) { - MY_LOG_I("comm[%d] UDP bound to %s:%d", + LOG_I("comm[%d] UDP bound to %s:%d", inst->id, inst->local_ip, inst->local_port); } @@ -123,7 +123,7 @@ int udp_sendto(stru_comm_instance *inst, int fd, const unsigned char *data, int { if (inst->debug) { - MY_LOG_E("comm[%d] fd=%d sendto error: %s", inst->id, fd, strerror(errno)); + LOG_E("comm[%d] fd=%d sendto error: %s", inst->id, fd, strerror(errno)); } return COMM_ERR_SEND; diff --git a/src/public/liblog/src/myLog.c b/src/public/liblog/src/myLog.c index bc63d87..6c46ad5 100644 --- a/src/public/liblog/src/myLog.c +++ b/src/public/liblog/src/myLog.c @@ -186,55 +186,6 @@ LOCAL void q_push(stru_log_msg *m) pthread_cond_signal(&g_log.q.cond_pop); pthread_mutex_unlock(&g_log.q.lock); } - -/** - * @brief 出队(消费者端) - * @detail 队列空且线程运行中时阻塞等待 - * @return 成功返回消息指针,线程停止返回 NULL - */ -LOCAL stru_log_msg *q_pop(void) -{ - pthread_mutex_lock(&g_log.q.lock); - - while (g_log.q.count == 0 && g_log.running) - { - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_nsec += FLUSH_MS * 1000000; - if (ts.tv_nsec >= 1000000000) - { - ts.tv_sec += 1; - ts.tv_nsec -= 1000000000; - } - - pthread_cond_timedwait(&g_log.q.cond_pop, &g_log.q.lock, &ts); - } - - if (g_log.q.count == 0) - { - pthread_mutex_unlock(&g_log.q.lock); - - return NULL; - } - - /* 头摘 */ - stru_log_msg *m = g_log.q.head; - - g_log.q.head = m->next; - - if (!g_log.q.head) - { - g_log.q.tail = NULL; - } - - g_log.q.count--; - - pthread_cond_signal(&g_log.q.cond_push); - pthread_mutex_unlock(&g_log.q.lock); - - return m; -} - /* ========== 文件管理 ========== */ /** @@ -476,30 +427,48 @@ LOCAL void output_batch(stru_log_msg **batch, int cnt) * @brief 日志消费线程主循环 * @detail 批量从队列取消息 → 输出 → 归还消息池 */ +/** + * @brief 日志消费线程主循环 + * @detail 一次加锁取完队列中所有消息 → 立即输出 → 归还消息池。 + * 队列空时短暂休眠,有消息到达时由 q_push 的 cond_signal 唤醒。 + * 不等待凑批——有多少输出多少,确保日志及时可见。 + */ LOCAL void *worker_thread(void *arg) { (void)arg; - printf("[INFO] [myLog.c, %u] liblog: worker_thread started\n", __LINE__); + { + char ts[64]; + fmt_time(ts, sizeof(ts)); + printf("[%s] [INFO] [myLog.c, %u] liblog: worker_thread started\n", ts, __LINE__); + } while (g_log.running) { stru_log_msg *batch[BATCH_MAX]; int cnt = 0; - /* 批量取消息 */ - for (int i = 0; i < BATCH_MAX; i++) - { - stru_log_msg *m = q_pop(); + /* 一次加锁,取完队列中所有消息(最多 BATCH_MAX 条防止饿死) */ + pthread_mutex_lock(&g_log.q.lock); - if (!m) + while (cnt < BATCH_MAX && g_log.q.count > 0) + { + stru_log_msg *m = g_log.q.head; + + g_log.q.head = m->next; + + if (!g_log.q.head) { - break; + g_log.q.tail = NULL; } + g_log.q.count--; batch[cnt++] = m; } + pthread_cond_broadcast(&g_log.q.cond_push); + pthread_mutex_unlock(&g_log.q.lock); + if (cnt > 0) { output_batch(batch, cnt); @@ -510,12 +479,35 @@ LOCAL void *worker_thread(void *arg) pool_free(batch[i]); } } - /* q_pop 已内置 FLUSH_MS 超时,无需额外 sleep */ + else + { + /* 队列空,等待新消息(带超时避免死等) */ + pthread_mutex_lock(&g_log.q.lock); + + if (g_log.q.count == 0 && g_log.running) + { + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_nsec += FLUSH_MS * 1000000; + + if (ts.tv_nsec >= 1000000000) + { + ts.tv_sec += 1; + ts.tv_nsec -= 1000000000; + } + + pthread_cond_timedwait(&g_log.q.cond_pop, &g_log.q.lock, &ts); + } + + pthread_mutex_unlock(&g_log.q.lock); + } } return NULL; } + /* ========== 全局初始化(pthread_once) ========== */ /** @@ -542,13 +534,21 @@ LOCAL void global_init(void) if (ret != 0) { - printf("[ERROR] [myLog.c, %u] liblog: pthread_create failed (err=%d)\n", __LINE__, ret); + { + char ts[64]; + fmt_time(ts, sizeof(ts)); + printf("[%s] [ERROR] [myLog.c, %u] liblog: pthread_create failed (err=%d)\n", ts, __LINE__, ret); + } g_log.running = 0; } else { - printf("[INFO] [myLog.c, %u] liblog: async worker thread started, to_console=%d, to_file=%d\n", - __LINE__, g_log.to_console, g_log.to_file); + { + char ts[64]; + fmt_time(ts, sizeof(ts)); + printf("[%s] [INFO] [myLog.c, %u] liblog: async worker thread started, to_console=%d, to_file=%d\n", + ts, __LINE__, g_log.to_console, g_log.to_file); + } } } diff --git a/src/system/RTU/src/app_sys.cpp b/src/system/RTU/src/app_sys.cpp index 93063d7..a998920 100644 --- a/src/system/RTU/src/app_sys.cpp +++ b/src/system/RTU/src/app_sys.cpp @@ -58,9 +58,9 @@ static int app_mq_create(void) { stru_app_msg_queue *mq = &g_app_mq[i]; mq->p_msg_queue = task_msg_queue_create(mq->name, mq->msg_size, mq->msg_num); - if(NULL == mq->p_msg_queue) { MY_LOG_E("app_mq_create: failed for %s", mq->name); return -1; } + if(NULL == mq->p_msg_queue) { LOG_E("app_mq_create: failed for %s", mq->name); return -1; } } - MY_LOG_I("app_mq_create: %d queues created", ENUM_MQ_MAX); + LOG_I("app_mq_create: %d queues created", ENUM_MQ_MAX); return 0; } @@ -97,7 +97,7 @@ static std::string get_system_config_path(void) /* fallback: 从可执行文件路径推导(本地调试用) */ if (0 != func_proc_self_dir(buf, sizeof(buf))) { - MY_LOG_E("func_proc_self_dir failed"); + LOG_E("func_proc_self_dir failed"); return ""; } @@ -123,7 +123,7 @@ static int app_config_load(void) if (!buf) { /* 配置文件不存在时不视为错误——默认启用所有模块 */ - MY_LOG_I("app_config.json not found, enabling all modules by default"); + LOG_I("app_config.json not found, enabling all modules by default"); for (size_t i = 0; i < g_vec_app.size(); i++) { @@ -138,7 +138,7 @@ static int app_config_load(void) if (!root) { - MY_LOG_E("cJSON_Parse failed for app_config.json"); + LOG_E("cJSON_Parse failed for app_config.json"); return -1; } @@ -147,7 +147,7 @@ static int app_config_load(void) if (!apps || !cJSON_IsArray(apps)) { - MY_LOG_E("app_config.json missing 'apps' array"); + LOG_E("app_config.json missing 'apps' array"); cJSON_Delete(root); return -1; @@ -175,11 +175,11 @@ static int app_config_load(void) if (enable && cJSON_IsTrue(enable)) { g_enabled_apps.insert(std::string(name->valuestring)); - MY_LOG_I("app enabled: %s", name->valuestring); + LOG_I("app enabled: %s", name->valuestring); } else { - MY_LOG_I("app disabled: %s", name->valuestring); + LOG_I("app disabled: %s", name->valuestring); } } @@ -187,7 +187,7 @@ static int app_config_load(void) if (g_enabled_apps.empty()) { - MY_LOG_E("no apps enabled in config"); + LOG_E("no apps enabled in config"); return -1; } @@ -247,7 +247,7 @@ static int app_timer_create(stru_app *p_app) if (!p_app->p_timer[i]) { - MY_LOG_E("timer%d create failed for %s", i + 1, p_app->name); + LOG_E("timer%d create failed for %s", i + 1, p_app->name); return -1; } @@ -275,14 +275,14 @@ static int app_init(void) if (!is_app_enabled(p->name)) { - MY_LOG_I("app skipped (disabled): %s", p->name); + LOG_I("app skipped (disabled): %s", p->name); continue; } if (0 != p->app_init1((void *)p)) { - MY_LOG_E("app_init1 failed: %s", p->name); + LOG_E("app_init1 failed: %s", p->name); return -1; } @@ -300,20 +300,20 @@ static int app_init(void) if (!is_app_enabled(p->name)) { - MY_LOG_I("app skipped (disabled): %s", p->name); + LOG_I("app skipped (disabled): %s", p->name); continue; } if (0 != p->app_init2((void *)p)) { - MY_LOG_E("app_init2 failed: %s", p->name); + LOG_E("app_init2 failed: %s", p->name); return -1; } } - if(0 != app_mq_create()) { MY_LOG_E("app_mq_create"); return -1; } + if(0 != app_mq_create()) { LOG_E("app_mq_create"); return -1; } /* 创建事件 + 定时器 + 启动线程 */ for (i = 0; i < g_vec_app.size(); i++) @@ -327,7 +327,7 @@ static int app_init(void) p->p_event = task_event_create(ev_name.c_str()); if (!p->p_event) { - MY_LOG_E("task_event_create failed: %s", ev_name.c_str()); + LOG_E("task_event_create failed: %s", ev_name.c_str()); return -1; } @@ -336,14 +336,14 @@ static int app_init(void) if (0 != app_timer_create(p)) { - MY_LOG_E("app_timer_create failed: %s", p->name); + LOG_E("app_timer_create failed: %s", p->name); return -1; } if (!is_app_enabled(p->name)) { - MY_LOG_I("app skipped (disabled): %s", p->name); + LOG_I("app skipped (disabled): %s", p->name); continue; } @@ -352,14 +352,14 @@ static int app_init(void) if (0 != pthread_create(&thread, NULL, p->fun_cb, p->arg)) { - MY_LOG_E("pthread_create failed: %s", p->name); + LOG_E("pthread_create failed: %s", p->name); return -1; } g_threads.push_back(thread); - MY_LOG_I("thread started: %s", p->name); + LOG_I("thread started: %s", p->name); task_sleep_ms(10); } @@ -372,14 +372,14 @@ int app_sys_init(void) { if (0 != app_config_load()) { - MY_LOG_E("app_config_load failed"); + LOG_E("app_config_load failed"); return -1; } if (g_vec_app.size() != (size_t)ENUM_APP_MAX) { - MY_LOG_E("g_vec_app size mismatch: %zu vs ENUM %d", + LOG_E("g_vec_app size mismatch: %zu vs ENUM %d", g_vec_app.size(), ENUM_APP_MAX); return -1; @@ -387,7 +387,7 @@ int app_sys_init(void) if (0 != app_init()) { - MY_LOG_E("app_init failed"); + LOG_E("app_init failed"); return -1; } @@ -402,7 +402,7 @@ int app_sys_init(void) */ void app_sys_stop(void) { - MY_LOG_I("stopping all app modules..."); + LOG_I("stopping all app modules..."); for (size_t i = 0; i < g_vec_app.size(); i++) { @@ -416,14 +416,14 @@ void app_sys_stop(void) task_sleep_ms(2000); - MY_LOG_I("app_sys_stop done"); + LOG_I("app_sys_stop done"); } stru_app *app_get_ptr(uint32_t app_id) { if (app_id >= ENUM_APP_MAX) { - MY_LOG_E("app_id out of range: %u max %d", app_id, ENUM_APP_MAX); + LOG_E("app_id out of range: %u max %d", app_id, ENUM_APP_MAX); return NULL; } diff --git a/src/system/libcom_router/src/com_router.cpp b/src/system/libcom_router/src/com_router.cpp index 4f548a6..dd947b4 100644 --- a/src/system/libcom_router/src/com_router.cpp +++ b/src/system/libcom_router/src/com_router.cpp @@ -654,7 +654,7 @@ void *app_com_router(void *arg) /* 已断开, 仅第一次打印 */ if(last_state[i] >= 0) { - MY_LOG_I("com_router: %s disconnected", ch->key); + LOG_I("com_router: %s disconnected", ch->key); last_state[i] = -1; } } @@ -662,7 +662,7 @@ void *app_com_router(void *arg) { if(last_state[i] <= 0) { - MY_LOG_I("com_router: %s connected", ch->key); + LOG_I("com_router: %s connected", ch->key); } last_state[i] = 1; } @@ -697,7 +697,7 @@ void *app_com_router(void *arg) if(EV_STOP & event) { - MY_LOG_I("app_com_router: received EV_STOP, exiting"); + LOG_I("app_com_router: received EV_STOP, exiting"); break; } } diff --git a/src/system/libiec/src/iec104.cpp b/src/system/libiec/src/iec104.cpp index 431480c..0f52ba3 100644 --- a/src/system/libiec/src/iec104.cpp +++ b/src/system/libiec/src/iec104.cpp @@ -1260,23 +1260,23 @@ int app_iec_init1(void *arg) if (0 != func_proc_self_dir(dir, sizeof(dir))) { - MY_LOG_E("app_iec_init1: get_exe_dir failed"); + LOG_E("app_iec_init1: get_exe_dir failed"); return -1; } std::string path = std::string(dir) + "/config/IEC60870/iec1014.xml"; - MY_LOG_I("app_iec_init1: cfg path: %s", path.c_str()); + LOG_I("app_iec_init1: cfg path: %s", path.c_str()); if (0 != iec_cfg_parse(path.c_str())) { - MY_LOG_E("app_iec_init1: cfg parse failed: %s", path.c_str()); + LOG_E("app_iec_init1: cfg parse failed: %s", path.c_str()); return -1; } stru_app *p_app = (stru_app *)arg; dc_signal_out("iec.run_cnt", "iec.run_cnt", DATA_TYPE_U32, &p_app->run_cnt, "iec104"); - MY_LOG_I("app_iec_init1: ok"); + LOG_I("app_iec_init1: ok"); return 0; } @@ -1286,11 +1286,11 @@ int app_iec_init2(void *arg) if (0 != iec104_point_init()) { - MY_LOG_E("app_iec_init2: iec104_point_init failed"); + LOG_E("app_iec_init2: iec104_point_init failed"); return -1; } - MY_LOG_I("app_iec_init2: ok"); + LOG_I("app_iec_init2: ok"); return 0; } @@ -1302,7 +1302,7 @@ void *app_iec(void *arg) if (NULL == arg) { - MY_LOG_E("app_iec: NULL arg"); + LOG_E("app_iec: NULL arg"); return NULL; } @@ -1345,7 +1345,7 @@ void *app_iec(void *arg) /* 停止信号 */ if (event & EV_STOP) { - MY_LOG_I("app_iec: received EV_STOP, exiting"); + LOG_I("app_iec: received EV_STOP, exiting"); break; } } diff --git a/src/system/libmodbus_m/src/modbus_m.cpp b/src/system/libmodbus_m/src/modbus_m.cpp index 5526c7f..8b7073e 100644 --- a/src/system/libmodbus_m/src/modbus_m.cpp +++ b/src/system/libmodbus_m/src/modbus_m.cpp @@ -956,7 +956,7 @@ int app_modbus_m_init1(void *arg) std::string base_path = get_base_path(); if (base_path.empty()) { - MY_LOG_E("get_base_path failed"); + LOG_E("get_base_path failed"); return -1; } g_modbus_m_base_path = base_path + "config/MODBUS/"; @@ -964,13 +964,13 @@ int app_modbus_m_init1(void *arg) std::string cfg_path = g_modbus_m_base_path + "modbus_m.xml"; if (0 != modbus_m_cfg_parse(cfg_path)) { - MY_LOG_E("modbus_m_cfg_parse failed: %s", cfg_path.c_str()); + LOG_E("modbus_m_cfg_parse failed: %s", cfg_path.c_str()); return -1; } if (0 != modbus_m_init()) { - MY_LOG_E("modbus_m_init failed"); + LOG_E("modbus_m_init failed"); return -1; } @@ -986,7 +986,7 @@ void *app_modbus_m(void *arg) { if (NULL == arg) { - MY_LOG_E("app_modbus_m arg null"); + LOG_E("app_modbus_m arg null"); return NULL; } @@ -999,7 +999,7 @@ void *app_modbus_m(void *arg) // 预构建轮询分组 build_poll_groups(g_modbus_m_cfg.point.st_vec, st_groups); build_poll_groups(g_modbus_m_cfg.point.mx_vec, mx_groups); - MY_LOG_I("poll groups: st=%zu, mx=%zu", st_groups.size(), mx_groups.size()); + LOG_I("poll groups: st=%zu, mx=%zu", st_groups.size(), mx_groups.size()); while (1) { @@ -1030,7 +1030,7 @@ void *app_modbus_m(void *arg) if(EV_STOP & event) { - MY_LOG_I("app_modbus_m: received EV_STOP, exiting"); + LOG_I("app_modbus_m: received EV_STOP, exiting"); break; } } diff --git a/src/system/libplc/src/plc.cpp b/src/system/libplc/src/plc.cpp index 9955959..18cf15a 100644 --- a/src/system/libplc/src/plc.cpp +++ b/src/system/libplc/src/plc.cpp @@ -1739,7 +1739,7 @@ int app_plc_init1(void *arg) stru_app *p_app = (stru_app *)arg; if (NULL == p_app) { - MY_LOG_E("app_plc_init1 arg null"); + LOG_E("app_plc_init1 arg null"); return -1; } @@ -1765,14 +1765,14 @@ int app_plc_init1(void *arg) if (ret != 0) { - MY_LOG_E("app_plc_init1 dc_signal_out failed"); + LOG_E("app_plc_init1 dc_signal_out failed"); return -1; } p_plc_cfg = self_ptl_cfg_get(); if (nullptr == p_plc_cfg) { - MY_LOG_E("app_plc_init1 self_ptl_cfg_get failed"); + LOG_E("app_plc_init1 self_ptl_cfg_get failed"); return -1; } @@ -1801,7 +1801,7 @@ int app_plc_init2(void *arg) } if (ret != 0) { - MY_LOG_E("app_plc_init2 dc_signal_in failed"); + LOG_E("app_plc_init2 dc_signal_in failed"); return -1; } return 0; @@ -1811,7 +1811,7 @@ void *app_plc(void *arg) { if (NULL == arg) { - MY_LOG_E("app_plc arg null"); + LOG_E("app_plc arg null"); return NULL; } diff --git a/src/system/libself_ptl/src/self_ptl.cpp b/src/system/libself_ptl/src/self_ptl.cpp index 7ece67e..fc6e556 100644 --- a/src/system/libself_ptl/src/self_ptl.cpp +++ b/src/system/libself_ptl/src/self_ptl.cpp @@ -662,7 +662,7 @@ void *app_self_ptl(void *arg) /* EV_STOP: 优雅退出 */ if(EV_STOP & event) { - MY_LOG_I("app_self_ptl: received EV_STOP, exiting"); + LOG_I("app_self_ptl: received EV_STOP, exiting"); break; } } diff --git a/src/system/libweb_server/src/web_server.cpp b/src/system/libweb_server/src/web_server.cpp index 1eff6fb..4aecd28 100644 --- a/src/system/libweb_server/src/web_server.cpp +++ b/src/system/libweb_server/src/web_server.cpp @@ -384,7 +384,7 @@ int app_web_server_init1(void *arg) mg_mgr_init(&s_ws_mgr); mg_http_listen(&s_ws_mgr, WS_LISTEN_ON, ws_event_handler, NULL); - MY_LOG_I("web_server listening on %s, ws=%s, root=%s", + LOG_I("web_server listening on %s, ws=%s, root=%s", WS_LISTEN_ON, WS_UPGRADE_URI, g_web_root.c_str()); return 0; @@ -400,7 +400,7 @@ void *app_web_server(void *arg) { if (!arg) { - MY_LOG_E("app_web_server arg null"); + LOG_E("app_web_server arg null"); return NULL; } @@ -419,7 +419,7 @@ void *app_web_server(void *arg) if (event & EV_STOP) { - MY_LOG_I("web_server stopping"); + LOG_I("web_server stopping"); break; } @@ -440,14 +440,12 @@ void *app_web_server(void *arg) { cnt_1s++; p_app->run_cnt++; - - LOG_I("web_server run_cnt=%u", p_app->run_cnt); } } mg_mgr_free(&s_ws_mgr); - MY_LOG_I("web_server stopped, total 1s cycles=%u", cnt_1s); + LOG_I("web_server stopped, total 1s cycles=%u", cnt_1s); return NULL; } diff --git a/src/system/libweb_server/src/ws_method.cpp b/src/system/libweb_server/src/ws_method.cpp index a2a4f60..7318bed 100644 --- a/src/system/libweb_server/src/ws_method.cpp +++ b/src/system/libweb_server/src/ws_method.cpp @@ -528,22 +528,6 @@ void ws_recv(struct mg_connection *c, const char *p_rx, uint16_t rx_len) sub++; } - /* 导出 out 信号 XML(PLC Config 页面依赖) */ - if (0 == strcmp(sub, "out") || 0 == strncmp(sub, "out ", 4) - || 0 == strcmp(sub, "all") || 0 == strncmp(sub, "all ", 4)) - { - char resolved[512]; - char proc_dir[256] = {0}; - - if (0 == func_proc_self_dir(proc_dir, sizeof(proc_dir))) - { - snprintf(resolved, sizeof(resolved), - "%sconfig/SYSTEM/datacenter_out.xml", proc_dir); - dc_save_out_signals_xml(resolved); - LOG_I("datacenter_out.xml saved to %s", resolved); - } - } - /* 构建信号元数据 JSON */ const char *dc_types[5]; int dc_type_count = 0;