178 lines
4.9 KiB
C++
178 lines
4.9 KiB
C++
#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();
|
||
}
|
||
extern std::vector<RecvData> g_VecWaveDataX;
|
||
extern std::vector<RecvData> g_VecWaveDataY;
|
||
extern std::vector<RecvData> g_VecWaveDataZ;
|
||
int main(int argc, char *argv[])
|
||
{
|
||
printf(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
||
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
|
||
log_init(SOFTWARE_RUN_LOG, 1380, 1000 * 1024);
|
||
LOG_INFO("####CIDNSOFT start####\n");
|
||
LOG_INFO(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
||
// 查看版本信息
|
||
if (CheckFileVersion(argc, argv)) {
|
||
return 0;
|
||
}
|
||
|
||
g_VecWaveDataX.reserve(1000);
|
||
g_VecWaveDataY.reserve(1000);
|
||
g_VecWaveDataZ.reserve (1500);
|
||
// 设置线程属性之栈空间大小
|
||
boost::thread::attributes attrs;
|
||
attrs.set_stack_size(1024*1024);//2M
|
||
|
||
// 初始化平台配置文件
|
||
platform->PlatFormInit();
|
||
|
||
sql_ctl->InintGateway();
|
||
//sql_ctl->CalculateData();
|
||
//sql_ctl->CalculateBattery();
|
||
pUart->InitZigbee();
|
||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||
boost::thread searchT(SearchThread);
|
||
searchT.detach();
|
||
|
||
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||
boost::thread uartReadTh(UartStart);
|
||
uartReadTh.detach();
|
||
|
||
boost::thread uartTestReadTh(TestUart);
|
||
uartReadTh.detach();
|
||
|
||
// boost::thread InitModuleReadTh(InitModule);
|
||
// InitModuleReadTh.detach();
|
||
|
||
InitModule();
|
||
// 休眠2秒,等待串口线程初始化完毕
|
||
sleep(2);
|
||
|
||
// 串口数据处理,读取传感器原始波形数据
|
||
boost::thread uartWaveReadTh(UartStartWave);
|
||
uartWaveReadTh.detach();
|
||
|
||
|
||
#ifdef G2UL_GATEWAY
|
||
//启动 RUN LED
|
||
boost::thread startRunLED(RunLED);
|
||
startRunLED.detach();
|
||
#endif
|
||
|
||
#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
|
||
|
||
// 通过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();
|
||
|
||
//启动CMT server
|
||
boost::thread startTcpCmt(attrs, StartCMTServer);
|
||
startTcpCmt.detach();
|
||
|
||
sleep(5);
|
||
pUart->ZigbeeInit();
|
||
sleep(1);
|
||
pUart->UpdateZigbeeInfoCtrl();
|
||
|
||
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]);
|
||
}*/
|
||
|
||
//启动 mqtt客户端
|
||
boost::thread startMqtt(StartMqttClient);
|
||
startMqtt.detach();
|
||
|
||
//启动 mqtt 心跳
|
||
boost::thread startHeart(HeartRep);
|
||
startHeart.detach();
|
||
|
||
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");
|
||
}
|
||
|
||
int fd = OpenWatchDog();
|
||
int count = 0;
|
||
while (GlobalConfig::QuitFlag_G) {
|
||
#ifdef G2UL_GATEWAY
|
||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,1);
|
||
usleep(20000);
|
||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,0);
|
||
#endif
|
||
WriteWatchDog(fd);
|
||
sleep(20);
|
||
if(GlobalConfig::threadStatus == 0){
|
||
count ++;
|
||
}else if(GlobalConfig::threadStatus == 1){
|
||
GlobalConfig::threadStatus = 0;
|
||
count = 0;
|
||
}
|
||
if(count >= 30){
|
||
LOG_ERROR("===========threadStatus ========failed \n");
|
||
break;
|
||
}
|
||
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|