ems/ems_c/main.c

109 lines
3.0 KiB
C
Raw Normal View History

2025-05-13 17:49:49 +08:00
/*****************************************************************************
* @copyright 2024-2024, . POWER SUPPLY CO., LTD.
* @file main.c
* @brief
* @author Gary
* @date 2024/08/30
* @remark
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include "argparse.h"
#include "daemon.h"
#include "app_task_regedit.h"
#include "mw_schedule_handle.h"
/*****************************************************************************
* @brief
* @param[in] argc
* @param[in] argv
* @return
*****************************************************************************/
int main(int argc, char *argv[])
{
void *arg = NULL; // 初始化参数
int ret = 0; // 返回值
cli_args_t args = {0}; // 命令行参数结构体初始化
// 解析命令行参数
cliArgsInit(argc, argv, &args);
// 是否开启进程守护
if (args.daemonized)
{
daemonize();
}
// 加锁,防止重复运行
if (checkDaemonRunning() == 1)
{
// 是否执行停止命令
if (args.stop)
{
ret = stop_daemon();
if (ret == 0)
{
KITPTF(LOG_DAEMON_EN, INFO_EN, "_EMS_C_V1.0.0 停止成功。");
}
else
{
KITPTF(LOG_DAEMON_EN, INFO_EN, "_EMS_C_V1.0.0 停止失败。");
}
}
else
{
KITPTF(LOG_DAEMON_EN, INFO_EN, "_EMS_C_V1.0.0 进程已经在运行中,不可重复运行,已退出。");
ret = 1;
}
goto main_end;
}
else
{
if (args.stop)
{
ret = 0;
printf("_EMS_C_V1.0.0 不在运行中,停止失败。\n");
goto main_end;
}
}
// EMS初始化
ret = initEmsSystem(arg);
// 设置SIGPIPE信号处理函数为忽略
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
{
printf("设置SIGPIPE信号的处理行为为SIG_IGN失败\n");
}
else
{
printf("设置SIGPIPE信号的处理行为为SIG_IGN即忽略。\n");
}
// 注册线程入口
if (ret == 0)
regeditThreadEntry(arg);
// 启动Ems的Api
// if (ret == 0)
// runEmsWebApi();
// 主循环,保持进程运行
while (1)
{
/*测试模式*/
#ifdef RELEASE_DEBUG
// setRtdbPointValue(rtdbType, kDev_Type_EMS, 0, kEms_TcpLog_Enable, 1.0);
// setRtdbPointValue(rtdbType, kDev_Type_EMS, 0, kEms_UartLog_Enable, 1.0);
// setRtdbPointValue(rtdbType, kDev_Type_EMS, 0, kEms_ModBusLog_Enable, 1.0);
#endif
sleep(5); // 每60秒检查一次
}
main_end:
return ret; // 返回状态
}