WLG/main.cpp

154 lines
4.0 KiB
C++
Raw Permalink Normal View History

2024-10-19 16:02:41 +08:00
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <boost/thread.hpp>
2024-10-23 09:58:35 +08:00
#include <zlog.h>
#include "platform/platform_init.hpp"
#include "common/common_func.hpp"
#include "common/global.hpp"
#include "threadfunc/thread_func.hpp"
#include "utility/secure.hpp"
#include "utility/aes.h"
#include "dbaccess/sql_db.hpp"
#include "uart/uart.hpp"
2024-10-29 20:35:17 +08:00
#include "minilzo/minilzo.h"
2024-10-23 09:58:35 +08:00
2024-10-19 16:02:41 +08:00
extern std::vector<RecvData> g_VecWaveDataX;
extern std::vector<RecvData> g_VecWaveDataY;
extern std::vector<RecvData> g_VecWaveDataZ;
2024-10-23 09:58:35 +08:00
zlog_category_t *zct = NULL;
zlog_category_t *zbt = NULL;
int main(int argc, char *argv[]) {
2024-10-29 20:35:17 +08:00
int rc = zlog_init("/opt/configenv/wlg.conf");
2024-10-23 09:58:35 +08:00
if (rc) {
printf("init failed\n");
return -1;
2024-10-19 16:02:41 +08:00
}
2024-10-23 09:58:35 +08:00
zct = zlog_get_category("wlg");
zbt = zlog_get_category("cfg");
if (!zct || !zbt) {
printf("get category fail\n");
zlog_fini();
return -2;
}
2024-10-29 20:35:17 +08:00
zlog_info(zbt, " Firmware compile time:%s %s,version %s", __DATE__, __TIME__, GlobalConfig::Version.c_str());
zlog_info(zbt, "####CIDNSOFT start####");
2024-10-23 09:58:35 +08:00
2024-10-19 16:02:41 +08:00
g_VecWaveDataX.reserve(1000);
g_VecWaveDataY.reserve(1000);
2024-10-23 09:58:35 +08:00
g_VecWaveDataZ.reserve(1500);
2024-10-19 16:02:41 +08:00
boost::thread::attributes attrs;
2024-10-23 09:58:35 +08:00
attrs.set_stack_size(1024 * 1024);
PlatformInit::Init();
2024-10-19 16:02:41 +08:00
2024-10-22 20:56:21 +08:00
sqlite_db_ctrl::instance().InintGateway();
2024-10-21 18:34:30 +08:00
2024-10-24 16:01:21 +08:00
uart_inst::instance().InitZigbeeHW();
2024-10-19 16:02:41 +08:00
// UDP接收客户端发来的组播消息用于外接 QT 专家系统,屏蔽之
boost::thread searchT(SearchThread);
searchT.detach();
2024-10-23 09:58:35 +08:00
// 串口处理线程,用于与 ZigBee 模块通信通过ZigBee无线通信技术与无线传感器通信
2024-10-19 16:02:41 +08:00
boost::thread uartReadTh(UartStart);
uartReadTh.detach();
boost::thread uartTestReadTh(TestUart);
uartReadTh.detach();
2024-11-14 18:48:45 +08:00
// boost::thread InitModuleReadTh(InitModule);
// InitModuleReadTh.detach();
InitModule();
2024-10-21 18:34:30 +08:00
2024-10-19 16:02:41 +08:00
// 休眠2秒等待串口线程初始化完毕
sleep(2);
// 串口数据处理,读取传感器原始波形数据
boost::thread uartWaveReadTh(UartStartWave);
uartWaveReadTh.detach();
#ifdef NR5G_MODULE
print_info("NR5G_MODULE \n");
2024-10-23 09:58:35 +08:00
// 5G
2024-10-19 16:02:41 +08:00
boost::thread startCSQ(GetCSQ);
startCSQ.detach();
#ifndef NR5G_MEIGE
boost::thread startDial(Dial5G);
startDial.detach();
#endif
#endif
2024-10-23 09:58:35 +08:00
#ifdef Q4G_MODULE
2024-10-19 16:02:41 +08:00
boost::thread startCSQ(GetCSQ);
startCSQ.detach();
print_info("4G_MODULE \n");
#endif
#ifdef WIFI_MODULE
print_info("WiFi_MODULE \n");
#endif
//通过UDP接收数据
2024-10-19 16:02:41 +08:00
boost::thread StartConnectSys(attrs, StartUdpSys);
StartConnectSys.detach();
2024-10-23 09:58:35 +08:00
2024-10-19 16:02:41 +08:00
//循环检测线程
2024-10-23 09:58:35 +08:00
boost::thread normalCheckThread(attrs, CheckThread);
2024-10-19 16:02:41 +08:00
normalCheckThread.detach();
//启动cgi server
2024-10-23 09:58:35 +08:00
boost::thread startTcpCgi(attrs, StartCgiServer);
2024-10-19 16:02:41 +08:00
startTcpCgi.detach();
sleep(5);
2024-10-24 16:01:21 +08:00
uart_inst::instance().ZigbeeParameterConfig();
2024-10-19 16:02:41 +08:00
sleep(1);
2024-10-22 19:04:25 +08:00
uart_inst::instance().UpdateZigbeeInfoCtrl();
2024-10-19 16:02:41 +08:00
//启动 mqtt客户端
boost::thread startMqtt(StartMqttClient);
startMqtt.detach();
//启动 mqtt 心跳
boost::thread startHeart(HeartRep);
startHeart.detach();
2024-11-05 15:15:51 +08:00
boost::thread DiskCheck(attrs, DiskSpaceCheck);
DiskCheck.detach();
2024-10-23 09:58:35 +08:00
if (lzo_init() != LZO_E_OK) {
zlog_error(zbt, "internal error - lzo_init() failed !!!");
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
2024-10-19 16:02:41 +08:00
}
//int fd = OpenWatchDog();
2024-10-19 16:02:41 +08:00
int count = 0;
while (GlobalConfig::QuitFlag_G) {
//WriteWatchDog(fd);
2024-10-19 16:02:41 +08:00
sleep(20);
2024-10-23 09:58:35 +08:00
if (GlobalConfig::threadStatus == 0) {
count++;
} else if (GlobalConfig::threadStatus == 1) {
2024-10-19 16:02:41 +08:00
GlobalConfig::threadStatus = 0;
count = 0;
}
2024-10-23 09:58:35 +08:00
if (count >= 30) {
zlog_error(zbt, "===========threadStatus ========failed");
2024-10-19 16:02:41 +08:00
break;
}
}
return 0;
}