log: 全模块 MY_LOG → LOG 迁移 + 日志即时输出 + 时间戳统一
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 迁移
This commit is contained in:
parent
370be09926
commit
efacf3eaa8
|
|
@ -17,6 +17,8 @@
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|
@ -44,8 +46,15 @@ extern "C"
|
||||||
#define MY_LOG(color, level, fmt, ...) \
|
#define MY_LOG(color, level, fmt, ...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
printf("%s[%s] [%s, %u] " fmt COLOR_RESET "\n", \
|
struct timeval _tv; \
|
||||||
color, level, __SHORT_FILE__, __LINE__, ##__VA_ARGS__); \
|
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)
|
} while (0)
|
||||||
|
|
||||||
#define MY_LOG_I(fmt, ...) MY_LOG(COLOR_WHITE, "INFO", fmt, ##__VA_ARGS__)
|
#define MY_LOG_I(fmt, ...) MY_LOG(COLOR_WHITE, "INFO", fmt, ##__VA_ARGS__)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#define _COMM_INTERNAL_H_
|
#define _COMM_INTERNAL_H_
|
||||||
|
|
||||||
#include "myComm.h"
|
#include "myComm.h"
|
||||||
|
#include "myLog.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ void handle_error(stru_comm_instance *inst, int fd)
|
||||||
|
|
||||||
if (inst->debug)
|
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);
|
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)
|
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);
|
close_client_fd(inst, fd);
|
||||||
break;
|
break;
|
||||||
|
|
@ -217,7 +217,7 @@ LOCAL void handle_tcp_read(stru_comm_instance *inst, int fd)
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
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);
|
close_client_fd(inst, fd);
|
||||||
}
|
}
|
||||||
|
|
@ -311,14 +311,14 @@ LOCAL void worker_loop(void)
|
||||||
|
|
||||||
if (inst->debug)
|
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
|
else
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
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);
|
epoll_del_fd(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -437,7 +437,7 @@ int comm_create(int type, int debug, const union_comm_para *para)
|
||||||
|
|
||||||
if (debug)
|
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;
|
return inst->id;
|
||||||
|
|
@ -551,7 +551,7 @@ int comm_disconnect(int id)
|
||||||
|
|
||||||
if (inst->debug)
|
if (inst->debug)
|
||||||
{
|
{
|
||||||
MY_LOG_I("comm[%d] disconnected", inst->id);
|
LOG_I("comm[%d] disconnected", inst->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return COMM_OK;
|
return COMM_OK;
|
||||||
|
|
@ -594,7 +594,7 @@ int comm_send(int id, int fd, const unsigned char *data, int len)
|
||||||
|
|
||||||
if (inst->debug)
|
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;
|
return COMM_ERR_SEND;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ void handle_accept(stru_comm_instance *inst)
|
||||||
|
|
||||||
if (inst->debug)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ void handle_accept(stru_comm_instance *inst)
|
||||||
|
|
||||||
if (inst->debug)
|
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);
|
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)
|
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);
|
inst->id, inst->local_ip, inst->local_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ int tcp_client_connect(stru_comm_instance *inst)
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
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)
|
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);
|
inst->id, inst->remote_ip, inst->remote_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ int uart_open(stru_comm_instance *inst)
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
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));
|
inst->id, inst->uart_device, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ int uart_open(stru_comm_instance *inst)
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
if (inst->debug)
|
||||||
{
|
{
|
||||||
MY_LOG_E("comm[%d] UART configure failed: %s",
|
LOG_E("comm[%d] UART configure failed: %s",
|
||||||
inst->id, strerror(errno));
|
inst->id, strerror(errno));
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -164,7 +164,7 @@ int uart_open(stru_comm_instance *inst)
|
||||||
|
|
||||||
if (inst->debug)
|
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->id, inst->uart_device, inst->uart_baudrate,
|
||||||
inst->uart_data_bits, inst->uart_stop_bits, inst->uart_parity);
|
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)
|
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));
|
inst->id, fd, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ void handle_udp_read(stru_comm_instance *inst, int fd)
|
||||||
{
|
{
|
||||||
if (inst->debug)
|
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));
|
inst->id, fd, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +98,7 @@ int udp_bind(stru_comm_instance *inst)
|
||||||
|
|
||||||
if (inst->debug)
|
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);
|
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)
|
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;
|
return COMM_ERR_SEND;
|
||||||
|
|
|
||||||
|
|
@ -186,55 +186,6 @@ LOCAL void q_push(stru_log_msg *m)
|
||||||
pthread_cond_signal(&g_log.q.cond_pop);
|
pthread_cond_signal(&g_log.q.cond_pop);
|
||||||
pthread_mutex_unlock(&g_log.q.lock);
|
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 日志消费线程主循环
|
* @brief 日志消费线程主循环
|
||||||
* @detail 批量从队列取消息 → 输出 → 归还消息池
|
* @detail 批量从队列取消息 → 输出 → 归还消息池
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @brief 日志消费线程主循环
|
||||||
|
* @detail 一次加锁取完队列中所有消息 → 立即输出 → 归还消息池。
|
||||||
|
* 队列空时短暂休眠,有消息到达时由 q_push 的 cond_signal 唤醒。
|
||||||
|
* 不等待凑批——有多少输出多少,确保日志及时可见。
|
||||||
|
*/
|
||||||
LOCAL void *worker_thread(void *arg)
|
LOCAL void *worker_thread(void *arg)
|
||||||
{
|
{
|
||||||
(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)
|
while (g_log.running)
|
||||||
{
|
{
|
||||||
stru_log_msg *batch[BATCH_MAX];
|
stru_log_msg *batch[BATCH_MAX];
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
/* 批量取消息 */
|
/* 一次加锁,取完队列中所有消息(最多 BATCH_MAX 条防止饿死) */
|
||||||
for (int i = 0; i < BATCH_MAX; i++)
|
pthread_mutex_lock(&g_log.q.lock);
|
||||||
{
|
|
||||||
stru_log_msg *m = q_pop();
|
|
||||||
|
|
||||||
if (!m)
|
while (cnt < BATCH_MAX && g_log.q.count > 0)
|
||||||
{
|
{
|
||||||
break;
|
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--;
|
||||||
batch[cnt++] = m;
|
batch[cnt++] = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_cond_broadcast(&g_log.q.cond_push);
|
||||||
|
pthread_mutex_unlock(&g_log.q.lock);
|
||||||
|
|
||||||
if (cnt > 0)
|
if (cnt > 0)
|
||||||
{
|
{
|
||||||
output_batch(batch, cnt);
|
output_batch(batch, cnt);
|
||||||
|
|
@ -510,12 +479,35 @@ LOCAL void *worker_thread(void *arg)
|
||||||
pool_free(batch[i]);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========== 全局初始化(pthread_once) ========== */
|
/* ========== 全局初始化(pthread_once) ========== */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -542,13 +534,21 @@ LOCAL void global_init(void)
|
||||||
|
|
||||||
if (ret != 0)
|
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;
|
g_log.running = 0;
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@ static int app_mq_create(void)
|
||||||
{
|
{
|
||||||
stru_app_msg_queue *mq = &g_app_mq[i];
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ static std::string get_system_config_path(void)
|
||||||
/* fallback: 从可执行文件路径推导(本地调试用) */
|
/* fallback: 从可执行文件路径推导(本地调试用) */
|
||||||
if (0 != func_proc_self_dir(buf, sizeof(buf)))
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ static int app_config_load(void)
|
||||||
if (!buf)
|
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++)
|
for (size_t i = 0; i < g_vec_app.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -138,7 +138,7 @@ static int app_config_load(void)
|
||||||
|
|
||||||
if (!root)
|
if (!root)
|
||||||
{
|
{
|
||||||
MY_LOG_E("cJSON_Parse failed for app_config.json");
|
LOG_E("cJSON_Parse failed for app_config.json");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,7 @@ static int app_config_load(void)
|
||||||
|
|
||||||
if (!apps || !cJSON_IsArray(apps))
|
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);
|
cJSON_Delete(root);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -175,11 +175,11 @@ static int app_config_load(void)
|
||||||
if (enable && cJSON_IsTrue(enable))
|
if (enable && cJSON_IsTrue(enable))
|
||||||
{
|
{
|
||||||
g_enabled_apps.insert(std::string(name->valuestring));
|
g_enabled_apps.insert(std::string(name->valuestring));
|
||||||
MY_LOG_I("app enabled: %s", name->valuestring);
|
LOG_I("app enabled: %s", name->valuestring);
|
||||||
}
|
}
|
||||||
else
|
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())
|
if (g_enabled_apps.empty())
|
||||||
{
|
{
|
||||||
MY_LOG_E("no apps enabled in config");
|
LOG_E("no apps enabled in config");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +247,7 @@ static int app_timer_create(stru_app *p_app)
|
||||||
|
|
||||||
if (!p_app->p_timer[i])
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -275,14 +275,14 @@ static int app_init(void)
|
||||||
|
|
||||||
if (!is_app_enabled(p->name))
|
if (!is_app_enabled(p->name))
|
||||||
{
|
{
|
||||||
MY_LOG_I("app skipped (disabled): %s", p->name);
|
LOG_I("app skipped (disabled): %s", p->name);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != p->app_init1((void *)p))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -300,20 +300,20 @@ static int app_init(void)
|
||||||
|
|
||||||
if (!is_app_enabled(p->name))
|
if (!is_app_enabled(p->name))
|
||||||
{
|
{
|
||||||
MY_LOG_I("app skipped (disabled): %s", p->name);
|
LOG_I("app skipped (disabled): %s", p->name);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != p->app_init2((void *)p))
|
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;
|
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++)
|
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());
|
p->p_event = task_event_create(ev_name.c_str());
|
||||||
if (!p->p_event)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -336,14 +336,14 @@ static int app_init(void)
|
||||||
|
|
||||||
if (0 != app_timer_create(p))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_app_enabled(p->name))
|
if (!is_app_enabled(p->name))
|
||||||
{
|
{
|
||||||
MY_LOG_I("app skipped (disabled): %s", p->name);
|
LOG_I("app skipped (disabled): %s", p->name);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -352,14 +352,14 @@ static int app_init(void)
|
||||||
|
|
||||||
if (0 != pthread_create(&thread, NULL, p->fun_cb, p->arg))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_threads.push_back(thread);
|
g_threads.push_back(thread);
|
||||||
|
|
||||||
MY_LOG_I("thread started: %s", p->name);
|
LOG_I("thread started: %s", p->name);
|
||||||
task_sleep_ms(10);
|
task_sleep_ms(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,14 +372,14 @@ int app_sys_init(void)
|
||||||
{
|
{
|
||||||
if (0 != app_config_load())
|
if (0 != app_config_load())
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_config_load failed");
|
LOG_E("app_config_load failed");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_vec_app.size() != (size_t)ENUM_APP_MAX)
|
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);
|
g_vec_app.size(), ENUM_APP_MAX);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -387,7 +387,7 @@ int app_sys_init(void)
|
||||||
|
|
||||||
if (0 != app_init())
|
if (0 != app_init())
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_init failed");
|
LOG_E("app_init failed");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -402,7 +402,7 @@ int app_sys_init(void)
|
||||||
*/
|
*/
|
||||||
void app_sys_stop(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++)
|
for (size_t i = 0; i < g_vec_app.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -416,14 +416,14 @@ void app_sys_stop(void)
|
||||||
|
|
||||||
task_sleep_ms(2000);
|
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)
|
stru_app *app_get_ptr(uint32_t app_id)
|
||||||
{
|
{
|
||||||
if (app_id >= ENUM_APP_MAX)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -654,7 +654,7 @@ void *app_com_router(void *arg)
|
||||||
/* 已断开, 仅第一次打印 */
|
/* 已断开, 仅第一次打印 */
|
||||||
if(last_state[i] >= 0)
|
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;
|
last_state[i] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -662,7 +662,7 @@ void *app_com_router(void *arg)
|
||||||
{
|
{
|
||||||
if(last_state[i] <= 0)
|
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;
|
last_state[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -697,7 +697,7 @@ void *app_com_router(void *arg)
|
||||||
|
|
||||||
if(EV_STOP & event)
|
if(EV_STOP & event)
|
||||||
{
|
{
|
||||||
MY_LOG_I("app_com_router: received EV_STOP, exiting");
|
LOG_I("app_com_router: received EV_STOP, exiting");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1260,23 +1260,23 @@ int app_iec_init1(void *arg)
|
||||||
|
|
||||||
if (0 != func_proc_self_dir(dir, sizeof(dir)))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path = std::string(dir) + "/config/IEC60870/iec1014.xml";
|
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()))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stru_app *p_app = (stru_app *)arg;
|
stru_app *p_app = (stru_app *)arg;
|
||||||
dc_signal_out("iec.run_cnt", "iec.run_cnt", DATA_TYPE_U32, &p_app->run_cnt, "iec104");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1286,11 +1286,11 @@ int app_iec_init2(void *arg)
|
||||||
|
|
||||||
if (0 != iec104_point_init())
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MY_LOG_I("app_iec_init2: ok");
|
LOG_I("app_iec_init2: ok");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1302,7 +1302,7 @@ void *app_iec(void *arg)
|
||||||
|
|
||||||
if (NULL == arg)
|
if (NULL == arg)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_iec: NULL arg");
|
LOG_E("app_iec: NULL arg");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1345,7 +1345,7 @@ void *app_iec(void *arg)
|
||||||
/* 停止信号 */
|
/* 停止信号 */
|
||||||
if (event & EV_STOP)
|
if (event & EV_STOP)
|
||||||
{
|
{
|
||||||
MY_LOG_I("app_iec: received EV_STOP, exiting");
|
LOG_I("app_iec: received EV_STOP, exiting");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -956,7 +956,7 @@ int app_modbus_m_init1(void *arg)
|
||||||
std::string base_path = get_base_path();
|
std::string base_path = get_base_path();
|
||||||
if (base_path.empty())
|
if (base_path.empty())
|
||||||
{
|
{
|
||||||
MY_LOG_E("get_base_path failed");
|
LOG_E("get_base_path failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
g_modbus_m_base_path = base_path + "config/MODBUS/";
|
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";
|
std::string cfg_path = g_modbus_m_base_path + "modbus_m.xml";
|
||||||
if (0 != modbus_m_cfg_parse(cfg_path))
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != modbus_m_init())
|
if (0 != modbus_m_init())
|
||||||
{
|
{
|
||||||
MY_LOG_E("modbus_m_init failed");
|
LOG_E("modbus_m_init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -986,7 +986,7 @@ void *app_modbus_m(void *arg)
|
||||||
{
|
{
|
||||||
if (NULL == arg)
|
if (NULL == arg)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_modbus_m arg null");
|
LOG_E("app_modbus_m arg null");
|
||||||
return 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.st_vec, st_groups);
|
||||||
build_poll_groups(g_modbus_m_cfg.point.mx_vec, mx_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)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
@ -1030,7 +1030,7 @@ void *app_modbus_m(void *arg)
|
||||||
|
|
||||||
if(EV_STOP & event)
|
if(EV_STOP & event)
|
||||||
{
|
{
|
||||||
MY_LOG_I("app_modbus_m: received EV_STOP, exiting");
|
LOG_I("app_modbus_m: received EV_STOP, exiting");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1739,7 +1739,7 @@ int app_plc_init1(void *arg)
|
||||||
stru_app *p_app = (stru_app *)arg;
|
stru_app *p_app = (stru_app *)arg;
|
||||||
if (NULL == p_app)
|
if (NULL == p_app)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_plc_init1 arg null");
|
LOG_E("app_plc_init1 arg null");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1765,14 +1765,14 @@ int app_plc_init1(void *arg)
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_plc_init1 dc_signal_out failed");
|
LOG_E("app_plc_init1 dc_signal_out failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_plc_cfg = self_ptl_cfg_get();
|
p_plc_cfg = self_ptl_cfg_get();
|
||||||
if (nullptr == p_plc_cfg)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1801,7 +1801,7 @@ int app_plc_init2(void *arg)
|
||||||
}
|
}
|
||||||
if (ret != 0)
|
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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1811,7 +1811,7 @@ void *app_plc(void *arg)
|
||||||
{
|
{
|
||||||
if (NULL == arg)
|
if (NULL == arg)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_plc arg null");
|
LOG_E("app_plc arg null");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -662,7 +662,7 @@ void *app_self_ptl(void *arg)
|
||||||
/* EV_STOP: 优雅退出 */
|
/* EV_STOP: 优雅退出 */
|
||||||
if(EV_STOP & event)
|
if(EV_STOP & event)
|
||||||
{
|
{
|
||||||
MY_LOG_I("app_self_ptl: received EV_STOP, exiting");
|
LOG_I("app_self_ptl: received EV_STOP, exiting");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -384,7 +384,7 @@ int app_web_server_init1(void *arg)
|
||||||
mg_mgr_init(&s_ws_mgr);
|
mg_mgr_init(&s_ws_mgr);
|
||||||
mg_http_listen(&s_ws_mgr, WS_LISTEN_ON, ws_event_handler, NULL);
|
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());
|
WS_LISTEN_ON, WS_UPGRADE_URI, g_web_root.c_str());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -400,7 +400,7 @@ void *app_web_server(void *arg)
|
||||||
{
|
{
|
||||||
if (!arg)
|
if (!arg)
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_web_server arg null");
|
LOG_E("app_web_server arg null");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -419,7 +419,7 @@ void *app_web_server(void *arg)
|
||||||
|
|
||||||
if (event & EV_STOP)
|
if (event & EV_STOP)
|
||||||
{
|
{
|
||||||
MY_LOG_I("web_server stopping");
|
LOG_I("web_server stopping");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -440,14 +440,12 @@ void *app_web_server(void *arg)
|
||||||
{
|
{
|
||||||
cnt_1s++;
|
cnt_1s++;
|
||||||
p_app->run_cnt++;
|
p_app->run_cnt++;
|
||||||
|
|
||||||
LOG_I("web_server run_cnt=%u", p_app->run_cnt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mg_mgr_free(&s_ws_mgr);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -528,22 +528,6 @@ void ws_recv(struct mg_connection *c, const char *p_rx, uint16_t rx_len)
|
||||||
sub++;
|
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 */
|
/* 构建信号元数据 JSON */
|
||||||
const char *dc_types[5];
|
const char *dc_types[5];
|
||||||
int dc_type_count = 0;
|
int dc_type_count = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue