2021-09-18 13:45:24 +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>
|
|
|
|
|
#include "platform/SH_PlatformInit.hpp"
|
|
|
|
|
#include "common/SH_CommonFunc.hpp"
|
|
|
|
|
#include "API_log/SH_log.h"
|
|
|
|
|
#include "common/SH_global.h"
|
|
|
|
|
#include "threadfunc/SH_ThreadFunc.hpp"
|
|
|
|
|
#include "secure/SH_Secure.hpp"
|
|
|
|
|
#include "aes/aes.h"
|
|
|
|
|
#include "dbaccess/SH_SqlDB.hpp"
|
|
|
|
|
#include "uart/SH_Uart.hpp"
|
|
|
|
|
|
|
|
|
|
namespace{
|
|
|
|
|
PlatformInit *platform = PlatformInit::instance();
|
|
|
|
|
Uart *pUart = Uart::instance();
|
|
|
|
|
}
|
2024-09-22 18:59:52 +08:00
|
|
|
|
extern std::vector<RecvData> g_VecWaveDataX;
|
|
|
|
|
extern std::vector<RecvData> g_VecWaveDataY;
|
|
|
|
|
extern std::vector<RecvData> g_VecWaveDataZ;
|
2021-09-18 13:45:24 +08:00
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2024-08-05 10:25:50 +08:00
|
|
|
|
printf(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
2021-09-18 13:45:24 +08:00
|
|
|
|
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
|
2024-09-05 10:48:31 +08:00
|
|
|
|
log_init(SOFTWARE_RUN_LOG, 1380, 160 * 1024 * 2);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
LOG_INFO("####CIDNSOFT start####\n");
|
|
|
|
|
|
|
|
|
|
// 查看版本信息
|
|
|
|
|
if (CheckFileVersion(argc, argv)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 20:59:55 +08:00
|
|
|
|
g_VecWaveDataX.reserve(300000);
|
|
|
|
|
g_VecWaveDataY.reserve(300000);
|
|
|
|
|
g_VecWaveDataZ.reserve (500000);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
// 设置线程属性之栈空间大小
|
|
|
|
|
boost::thread::attributes attrs;
|
2024-09-20 20:09:03 +08:00
|
|
|
|
attrs.set_stack_size(1024*1024*2);//2M
|
2021-09-18 13:45:24 +08:00
|
|
|
|
|
|
|
|
|
// 初始化平台配置文件
|
|
|
|
|
platform->PlatFormInit();
|
2024-08-05 10:25:50 +08:00
|
|
|
|
|
2024-07-09 09:49:42 +08:00
|
|
|
|
sql_ctl->InintGateway();
|
2024-09-24 19:18:16 +08:00
|
|
|
|
//sql_ctl->CalculateData();
|
2024-08-12 09:45:22 +08:00
|
|
|
|
//sql_ctl->CalculateBattery();
|
2024-07-09 09:49:42 +08:00
|
|
|
|
pUart->InitZigbee();
|
2021-09-18 13:45:24 +08:00
|
|
|
|
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
2024-07-09 09:49:42 +08:00
|
|
|
|
boost::thread searchT(SearchThread);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
searchT.detach();
|
|
|
|
|
|
|
|
|
|
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
|
|
|
|
boost::thread uartReadTh(UartStart);
|
|
|
|
|
uartReadTh.detach();
|
|
|
|
|
|
2024-07-09 09:49:42 +08:00
|
|
|
|
boost::thread uartTestReadTh(TestUart);
|
|
|
|
|
uartReadTh.detach();
|
|
|
|
|
|
|
|
|
|
boost::thread InitModuleReadTh(InitModule);
|
|
|
|
|
InitModuleReadTh.detach();
|
|
|
|
|
//boost::thread uartWatchDogReadTh(WatchDog);
|
|
|
|
|
//uartWatchDogReadTh.detach();
|
|
|
|
|
|
2021-09-18 13:45:24 +08:00
|
|
|
|
// 休眠2秒,等待串口线程初始化完毕
|
2024-07-09 09:49:42 +08:00
|
|
|
|
sleep(2);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
|
|
|
|
|
// 串口数据处理,读取传感器原始波形数据
|
|
|
|
|
boost::thread uartWaveReadTh(UartStartWave);
|
|
|
|
|
uartWaveReadTh.detach();
|
|
|
|
|
|
2024-08-05 10:25:50 +08:00
|
|
|
|
|
|
|
|
|
#ifdef G2UL_GATEWAY
|
|
|
|
|
//启动 RUN LED
|
2024-07-09 09:49:42 +08:00
|
|
|
|
boost::thread startRunLED(RunLED);
|
|
|
|
|
startRunLED.detach();
|
2024-08-05 10:25:50 +08:00
|
|
|
|
#endif
|
2024-07-09 09:49:42 +08:00
|
|
|
|
|
|
|
|
|
#ifdef NR5G_MODULE
|
|
|
|
|
print_info("NR5G_MODULE \n");
|
|
|
|
|
//5G
|
|
|
|
|
boost::thread startCSQ(GetCSQ);
|
|
|
|
|
startCSQ.detach();
|
|
|
|
|
#ifndef NR5G_MEIGE
|
|
|
|
|
boost::thread startDial(Dial5G);
|
|
|
|
|
startDial.detach();
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef Q4G_MODULE
|
|
|
|
|
boost::thread startCSQ(GetCSQ);
|
|
|
|
|
startCSQ.detach();
|
|
|
|
|
print_info("4G_MODULE \n");
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef WIFI_MODULE
|
|
|
|
|
print_info("WiFi_MODULE \n");
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-18 13:45:24 +08:00
|
|
|
|
// 通过UDP接收数据
|
|
|
|
|
boost::thread StartConnectSys(attrs, StartUdpSys);
|
|
|
|
|
StartConnectSys.detach();
|
|
|
|
|
|
|
|
|
|
//循环检测线程
|
|
|
|
|
boost::thread normalCheckThread(attrs,CheckThread);
|
|
|
|
|
normalCheckThread.detach();
|
|
|
|
|
|
|
|
|
|
//启动软件升级线程
|
|
|
|
|
boost::thread StartDownloadThread(attrs, RecvUpdateFile);
|
|
|
|
|
StartDownloadThread.detach();
|
|
|
|
|
|
|
|
|
|
//启动cgi server
|
|
|
|
|
boost::thread startTcpCgi(attrs,StartCgiServer);
|
|
|
|
|
startTcpCgi.detach();
|
|
|
|
|
|
2024-07-09 09:49:42 +08:00
|
|
|
|
|
|
|
|
|
sleep(5);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
pUart->ZigbeeInit();
|
2024-07-09 09:49:42 +08:00
|
|
|
|
sleep(1);
|
2021-09-18 13:45:24 +08:00
|
|
|
|
pUart->UpdateZigbeeInfoCtrl();
|
2024-07-09 09:49:42 +08:00
|
|
|
|
|
|
|
|
|
bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
|
|
|
|
print_info("===========status ======== %d\n",status);
|
|
|
|
|
|
|
|
|
|
/* char * szRes = sql_ctl->GetDataChar(T_SENSOR_INFO(TNAME), "dataNodeName", "dataNodeNo = '074cfd0000158d00'");
|
|
|
|
|
printf("szRes = %s\n",szRes);
|
|
|
|
|
for(int i = 0; i < 64;i++){
|
|
|
|
|
printf("temp = %02x ",szRes[i]);
|
|
|
|
|
}*/
|
|
|
|
|
|
2024-08-05 10:25:50 +08:00
|
|
|
|
//启动 mqtt客户端
|
|
|
|
|
boost::thread startMqtt(StartMqttClient);
|
|
|
|
|
startMqtt.detach();
|
|
|
|
|
|
|
|
|
|
//启动 mqtt 心跳
|
|
|
|
|
boost::thread startHeart(HeartRep);
|
|
|
|
|
startHeart.detach();
|
2024-07-15 19:02:49 +08:00
|
|
|
|
|
2024-09-22 18:59:52 +08:00
|
|
|
|
if (lzo_init() != LZO_E_OK)
|
|
|
|
|
{
|
|
|
|
|
printf("internal error - lzo_init() failed !!!\n");
|
|
|
|
|
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 20:59:55 +08:00
|
|
|
|
int fd = OpenWatchDog();
|
2024-08-27 12:15:32 +08:00
|
|
|
|
int count = 0;
|
2021-09-18 13:45:24 +08:00
|
|
|
|
while (GlobalConfig::QuitFlag_G) {
|
2024-08-05 10:25:50 +08:00
|
|
|
|
#ifdef G2UL_GATEWAY
|
2024-07-09 09:49:42 +08:00
|
|
|
|
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,1);
|
|
|
|
|
usleep(20000);
|
|
|
|
|
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,0);
|
2024-08-05 10:25:50 +08:00
|
|
|
|
#endif
|
2024-09-23 20:59:55 +08:00
|
|
|
|
WriteWatchDog(fd);
|
2024-07-09 09:49:42 +08:00
|
|
|
|
sleep(20);
|
2024-08-27 12:15:32 +08:00
|
|
|
|
if(GlobalConfig::threadStatus == 0){
|
|
|
|
|
count ++;
|
|
|
|
|
}else if(GlobalConfig::threadStatus == 1){
|
|
|
|
|
GlobalConfig::threadStatus = 0;
|
|
|
|
|
count = 0;
|
|
|
|
|
}
|
2024-09-20 17:30:40 +08:00
|
|
|
|
if(count >= 30){
|
2024-08-27 12:15:32 +08:00
|
|
|
|
LOG_ERROR("===========threadStatus ========failed \n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-09-18 13:45:24 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|