112 lines
4.7 KiB
C
112 lines
4.7 KiB
C
|
/***************************************************************
|
|||
|
Copyright © huijue Network Co., Ltd. 1998-2129. All rights reserved.
|
|||
|
Copyright © 上海汇珏网络通信设备股份有限公司 1998-2129. All rights reserved.
|
|||
|
文件名 : MainProcess.c
|
|||
|
作者 : kooloo
|
|||
|
版本 : V1.0
|
|||
|
描述 : 动环监控/边缘网关FSU 守护进程 POSIX 内存共享 队列消息等定义初始化
|
|||
|
硬件平台 : iMX6ULL
|
|||
|
内核版本 : linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7
|
|||
|
编译器版本 :gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
|
|||
|
日志 : 初版V1.0 2023/7/15 kooloo创建
|
|||
|
***************************************************************/
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
#include <errno.h>
|
|||
|
#include <unistd.h>
|
|||
|
#include "public.h" //公共函数头文件
|
|||
|
#include <sys/mman.h> //posix 内存共享 消息队列
|
|||
|
#include <sys/stat.h>
|
|||
|
#include <fcntl.h>
|
|||
|
#include "mslog.h"
|
|||
|
#include "SystemTimeFunc.h"
|
|||
|
#include "ProcessisRunning.h"
|
|||
|
#include<mqueue.h>
|
|||
|
#include <time.h>
|
|||
|
#include "cJSON.h" //
|
|||
|
#include <linux/watchdog.h> //增加看门狗 kooloo add 20240311
|
|||
|
|
|||
|
#define WDOG_DEV_ONOFF 1 //=0 关闭 =1 开启
|
|||
|
|
|||
|
int main(int argc, char *argv[])
|
|||
|
{
|
|||
|
int ret,wdog_fd; //临时变量
|
|||
|
int op;
|
|||
|
struct timespec Sleep_t;
|
|||
|
int timeout=WDOG_DEV_TIMEOUT;
|
|||
|
|
|||
|
Sleep_t.tv_nsec=0;
|
|||
|
Sleep_t.tv_sec=1; //时间基准间隔1s 判断依据宏定义 设置的大小 kooloo add 202311
|
|||
|
//设置日志级别为more;打开标准输出、打印所在行数和函数名、文件日志功能;
|
|||
|
//设置日志目录为:/tmp/mslog;
|
|||
|
//设置日志文件为:mslog_sample.txt;
|
|||
|
//FLAG为LOG_API_TEST或TAG_TEST2的日志,不进行打印;
|
|||
|
// mslog_api_init((mslog_level_warn|mslog_enable_stdprint|mslog_enable_linefunc|mslog_enable_filelog),
|
|||
|
// "/tmp/mslog","mslog_fsu.txt","LOG_API_TEST|TAG_TEST2");
|
|||
|
mslog_api_init(C_MSLOG_FLAG_MP,S_MSLOGDIR_PATH,S_MSLOGFILE_NAME_MP,"LOG_API_TEST|TAG_TEST2");
|
|||
|
printf("MainProcessApp \n"); //开机 程序打印信息 做区分使用
|
|||
|
|
|||
|
#if WDOG_DEV_ONOFF //看门狗 方便折叠 kooloo add 20240311
|
|||
|
/* 打开看门狗 */
|
|||
|
wdog_fd = open(WDOG_DEV, O_RDWR);
|
|||
|
if (0 > wdog_fd)
|
|||
|
{
|
|||
|
ms_error1("open error: %s: %s\n", WDOG_DEV, strerror(errno));
|
|||
|
exit(EXIT_FAILURE);
|
|||
|
}
|
|||
|
/* 打开之后看门狗计时器会开启、先停止它 */
|
|||
|
op = WDIOS_DISABLECARD;
|
|||
|
if (0 > ioctl(wdog_fd, WDIOC_SETOPTIONS, &op))
|
|||
|
{
|
|||
|
ms_error1("ioctl error: WDIOC_SETOPTIONS: %s\n", strerror(errno));
|
|||
|
close(wdog_fd);
|
|||
|
exit(EXIT_FAILURE);
|
|||
|
}
|
|||
|
|
|||
|
/* 设置超时时间 */
|
|||
|
if (0 > ioctl(wdog_fd, WDIOC_SETTIMEOUT, &timeout)) {
|
|||
|
ms_error1("ioctl error: WDIOC_SETTIMEOUT: %s\n", strerror(errno));
|
|||
|
close(wdog_fd);
|
|||
|
exit(EXIT_FAILURE);
|
|||
|
}
|
|||
|
/* 开启看门狗计时器 */
|
|||
|
op = WDIOS_ENABLECARD;
|
|||
|
if (0 > ioctl(wdog_fd, WDIOC_SETOPTIONS, &op)) {
|
|||
|
ms_error1("ioctl error: WDIOC_SETOPTIONS: %s\n", strerror(errno));
|
|||
|
close(wdog_fd);
|
|||
|
exit(EXIT_FAILURE);
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
SystemIpc_Init(); //申请共享内存和队列 kooloo add 202311
|
|||
|
SystemInfo_PrintLog(); //开机信息打印 及相关参数获取 kooloo add 202311
|
|||
|
Systemtimer_Iint(); //滴答时钟初始化 kooloo add 202311
|
|||
|
SystemInterval_Iint(); //变量初始化 kooloo add 202311
|
|||
|
|
|||
|
SystemProcess_Iint(); //启动相关进程 kooloo add 202311 执行和判断相关子程序时,切换到指定路径下 kooloo add 202312
|
|||
|
|
|||
|
while(1)
|
|||
|
{
|
|||
|
#if WDOG_DEV_ONOFF //看门狗 方便折叠 kooloo add 20240311
|
|||
|
ioctl(wdog_fd, WDIOC_KEEPALIVE, NULL); //喂狗时间设置us微秒、在超时时间到来前100ms喂狗 定时喂狗 kooloo add 20240311
|
|||
|
#endif
|
|||
|
//判断开机时长 判断是否需要更新时间
|
|||
|
if(Timer_getDiffValueTicks(pSysPara->g_TimeUpdateCounter)>C_SYSTEMTIME_UPDATE_PERIOD)
|
|||
|
{
|
|||
|
SystemProcess_Exe(S_TimeAlignedApp_PATH_EXE); //启动获取时间的子进程
|
|||
|
pSysPara->g_TimeUpdateCounter=Timer_getNowTicks();
|
|||
|
|
|||
|
}
|
|||
|
//判断子进程是否运行 间隔判断
|
|||
|
if(Timer_getDiffValueTicks(pSysPara->g_ExeIsRunningCounter)>C_PRCESS_ISRUNNING_CYCLE_PERIOD)
|
|||
|
{
|
|||
|
ProcessIsRunning_ServiceLoop(); //判断子进程是否正常运行 kooloo add 202311
|
|||
|
pSysPara->g_ExeIsRunningCounter=Timer_getNowTicks();
|
|||
|
}
|
|||
|
nanosleep(&Sleep_t, NULL); //高精度休眠时间 kooloo add 202311
|
|||
|
}
|
|||
|
munmap(pSysPara,C_SYSDATASHARE_LEN); //系统调用解除指定地址范围内的映射 kooloo add 202311 退出主进程 解除映射
|
|||
|
mslog_api_deinit();//退出释放日志资源;
|
|||
|
exit(0);
|
|||
|
}
|