add zlog.
This commit is contained in:
parent
9b7ce05eb4
commit
ea5dbf1313
@ -77,8 +77,6 @@
|
|||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="minilzo-2.10"/>
|
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
@ -117,6 +115,7 @@
|
|||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/WLG"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/WLG"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/zlog/include"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include"/>
|
||||||
@ -129,6 +128,7 @@
|
|||||||
<option id="gnu.cpp.link.option.paths.1792108116" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
|
<option id="gnu.cpp.link.option.paths.1792108116" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/lib"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/lib"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/ssl/lib"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/ssl/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/zlog/lib"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/lib"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/lib"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp"/>
|
||||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/mqtt1410/lib"/>
|
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/mqtt1410/lib"/>
|
||||||
@ -137,6 +137,7 @@
|
|||||||
</option>
|
</option>
|
||||||
<option id="gnu.cpp.link.option.libs.2006599708" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
<option id="gnu.cpp.link.option.libs.2006599708" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||||
<listOptionValue builtIn="false" value="sqlite3"/>
|
<listOptionValue builtIn="false" value="sqlite3"/>
|
||||||
|
<listOptionValue builtIn="false" value="zlog"/>
|
||||||
<listOptionValue builtIn="false" value="boost_system"/>
|
<listOptionValue builtIn="false" value="boost_system"/>
|
||||||
<listOptionValue builtIn="false" value="pthread"/>
|
<listOptionValue builtIn="false" value="pthread"/>
|
||||||
<listOptionValue builtIn="false" value="boost_thread"/>
|
<listOptionValue builtIn="false" value="boost_thread"/>
|
||||||
@ -161,8 +162,6 @@
|
|||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="minilzo-2.10|wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="minilzo-2.10"/>
|
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
#include <boost/xpressive/xpressive_dynamic.hpp>
|
#include <boost/xpressive/xpressive_dynamic.hpp>
|
||||||
|
#include <zlog.h>
|
||||||
#include "global.hpp"
|
#include "global.hpp"
|
||||||
#include "dbaccess/sql_db.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
|
|
||||||
@ -33,7 +34,10 @@ char sendpacket[PACKET_SIZE];
|
|||||||
char recvpacket[PACKET_SIZE];
|
char recvpacket[PACKET_SIZE];
|
||||||
|
|
||||||
static boost::mutex s_config_mu;
|
static boost::mutex s_config_mu;
|
||||||
Mutex g_tDbMutex;
|
|
||||||
|
zlog_category_t *zct;
|
||||||
|
zlog_category_t *zbt;
|
||||||
|
|
||||||
string GetLocalTimeWithMs(void) {
|
string GetLocalTimeWithMs(void) {
|
||||||
string defaultTime = "19700101000000000";
|
string defaultTime = "19700101000000000";
|
||||||
try {
|
try {
|
||||||
@ -56,6 +60,7 @@ string GetLocalTimeWithMs(void) {
|
|||||||
return defaultTime;
|
return defaultTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int code_convert(const char *from_charset, const char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen) {
|
int code_convert(const char *from_charset, const char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen) {
|
||||||
iconv_t cd;
|
iconv_t cd;
|
||||||
char **pin = &inbuf;
|
char **pin = &inbuf;
|
||||||
@ -112,6 +117,7 @@ std::string UTFtoGBK(const char *utf8) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string convertEncoding(const std::string &input, const char *fromEncoding, const char *toEncoding) {
|
std::string convertEncoding(const std::string &input, const char *fromEncoding, const char *toEncoding) {
|
||||||
iconv_t conv = iconv_open(toEncoding, fromEncoding);
|
iconv_t conv = iconv_open(toEncoding, fromEncoding);
|
||||||
if (conv == (iconv_t)-1) {
|
if (conv == (iconv_t)-1) {
|
||||||
|
|||||||
109
main.cpp
109
main.cpp
@ -8,45 +8,49 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include "platform/SH_PlatformInit.hpp"
|
#include <zlog.h>
|
||||||
#include "common/SH_CommonFunc.hpp"
|
#include "platform/platform_init.hpp"
|
||||||
#include "API_log/SH_log.h"
|
#include "common/common_func.hpp"
|
||||||
#include "common/SH_global.h"
|
#include "common/global.hpp"
|
||||||
#include "threadfunc/SH_ThreadFunc.hpp"
|
#include "threadfunc/thread_func.hpp"
|
||||||
#include "secure/SH_Secure.hpp"
|
#include "utility/secure.hpp"
|
||||||
#include "aes/aes.h"
|
#include "utility/aes.h"
|
||||||
#include "dbaccess/SH_SqlDB.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
#include "uart/SH_Uart.hpp"
|
#include "uart/uart.hpp"
|
||||||
|
|
||||||
namespace{
|
|
||||||
PlatformInit *platform = PlatformInit::instance();
|
|
||||||
Uart *pUart = Uart::instance();
|
|
||||||
}
|
|
||||||
extern std::vector<RecvData> g_VecWaveDataX;
|
extern std::vector<RecvData> g_VecWaveDataX;
|
||||||
extern std::vector<RecvData> g_VecWaveDataY;
|
extern std::vector<RecvData> g_VecWaveDataY;
|
||||||
extern std::vector<RecvData> g_VecWaveDataZ;
|
extern std::vector<RecvData> g_VecWaveDataZ;
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
zlog_category_t *zct = NULL;
|
||||||
printf(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
zlog_category_t *zbt = NULL;
|
||||||
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
|
|
||||||
log_init(SOFTWARE_RUN_LOG, 1380, 1000 * 1024);
|
int main(int argc, char *argv[]) {
|
||||||
LOG_INFO("####CIDNSOFT start####\n");
|
int rc = zlog_init("/opt/wlg.conf");
|
||||||
LOG_INFO(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
|
if (rc) {
|
||||||
// 查看版本信息
|
printf("init failed\n");
|
||||||
if (CheckFileVersion(argc, argv)) {
|
return -1;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zct = zlog_get_category("wlg");
|
||||||
|
zbt = zlog_get_category("cfg");
|
||||||
|
if (!zct || !zbt) {
|
||||||
|
printf("get category fail\n");
|
||||||
|
zlog_fini();
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
zlog_info(zbt, " Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__, GlobalConfig::Version.c_str());
|
||||||
|
zlog_info(zbt, "####CIDNSOFT start####\n");
|
||||||
|
|
||||||
g_VecWaveDataX.reserve(1000);
|
g_VecWaveDataX.reserve(1000);
|
||||||
g_VecWaveDataY.reserve(1000);
|
g_VecWaveDataY.reserve(1000);
|
||||||
g_VecWaveDataZ.reserve (1500);
|
g_VecWaveDataZ.reserve(1500);
|
||||||
// 设置线程属性之栈空间大小
|
|
||||||
boost::thread::attributes attrs;
|
boost::thread::attributes attrs;
|
||||||
attrs.set_stack_size(1024*1024);//2M
|
attrs.set_stack_size(1024 * 1024);
|
||||||
|
|
||||||
|
PlatformInit::Init();
|
||||||
|
|
||||||
// 初始化平台配置文件
|
|
||||||
platform->PlatFormInit();
|
|
||||||
|
|
||||||
sqlite_db_ctrl::instance().InintGateway();
|
sqlite_db_ctrl::instance().InintGateway();
|
||||||
|
|
||||||
uart_inst::instance().InitZigbee();
|
uart_inst::instance().InitZigbee();
|
||||||
@ -54,7 +58,7 @@ int main(int argc, char *argv[])
|
|||||||
boost::thread searchT(SearchThread);
|
boost::thread searchT(SearchThread);
|
||||||
searchT.detach();
|
searchT.detach();
|
||||||
|
|
||||||
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||||||
boost::thread uartReadTh(UartStart);
|
boost::thread uartReadTh(UartStart);
|
||||||
uartReadTh.detach();
|
uartReadTh.detach();
|
||||||
|
|
||||||
@ -64,7 +68,6 @@ int main(int argc, char *argv[])
|
|||||||
boost::thread InitModuleReadTh(InitModule);
|
boost::thread InitModuleReadTh(InitModule);
|
||||||
InitModuleReadTh.detach();
|
InitModuleReadTh.detach();
|
||||||
|
|
||||||
|
|
||||||
// 休眠2秒,等待串口线程初始化完毕
|
// 休眠2秒,等待串口线程初始化完毕
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
@ -72,7 +75,6 @@ int main(int argc, char *argv[])
|
|||||||
boost::thread uartWaveReadTh(UartStartWave);
|
boost::thread uartWaveReadTh(UartStartWave);
|
||||||
uartWaveReadTh.detach();
|
uartWaveReadTh.detach();
|
||||||
|
|
||||||
|
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
//启动 RUN LED
|
//启动 RUN LED
|
||||||
boost::thread startRunLED(RunLED);
|
boost::thread startRunLED(RunLED);
|
||||||
@ -81,7 +83,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifdef NR5G_MODULE
|
#ifdef NR5G_MODULE
|
||||||
print_info("NR5G_MODULE \n");
|
print_info("NR5G_MODULE \n");
|
||||||
//5G
|
// 5G
|
||||||
boost::thread startCSQ(GetCSQ);
|
boost::thread startCSQ(GetCSQ);
|
||||||
startCSQ.detach();
|
startCSQ.detach();
|
||||||
#ifndef NR5G_MEIGE
|
#ifndef NR5G_MEIGE
|
||||||
@ -90,7 +92,7 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q4G_MODULE
|
#ifdef Q4G_MODULE
|
||||||
boost::thread startCSQ(GetCSQ);
|
boost::thread startCSQ(GetCSQ);
|
||||||
startCSQ.detach();
|
startCSQ.detach();
|
||||||
print_info("4G_MODULE \n");
|
print_info("4G_MODULE \n");
|
||||||
@ -103,19 +105,18 @@ int main(int argc, char *argv[])
|
|||||||
// 通过UDP接收数据
|
// 通过UDP接收数据
|
||||||
boost::thread StartConnectSys(attrs, StartUdpSys);
|
boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||||
StartConnectSys.detach();
|
StartConnectSys.detach();
|
||||||
|
|
||||||
//循环检测线程
|
//循环检测线程
|
||||||
boost::thread normalCheckThread(attrs,CheckThread);
|
boost::thread normalCheckThread(attrs, CheckThread);
|
||||||
normalCheckThread.detach();
|
normalCheckThread.detach();
|
||||||
|
|
||||||
//启动软件升级线程
|
//启动软件升级线程
|
||||||
boost::thread StartDownloadThread(attrs, RecvUpdateFile);
|
boost::thread StartDownloadThread(attrs, RecvUpdateFile);
|
||||||
StartDownloadThread.detach();
|
StartDownloadThread.detach();
|
||||||
|
|
||||||
//启动cgi server
|
|
||||||
boost::thread startTcpCgi(attrs,StartCgiServer);
|
|
||||||
startTcpCgi.detach();
|
|
||||||
|
|
||||||
|
//启动cgi server
|
||||||
|
boost::thread startTcpCgi(attrs, StartCgiServer);
|
||||||
|
startTcpCgi.detach();
|
||||||
|
|
||||||
sleep(5);
|
sleep(5);
|
||||||
uart_inst::instance().ZigbeeInit();
|
uart_inst::instance().ZigbeeInit();
|
||||||
@ -130,35 +131,31 @@ int main(int argc, char *argv[])
|
|||||||
boost::thread startHeart(HeartRep);
|
boost::thread startHeart(HeartRep);
|
||||||
startHeart.detach();
|
startHeart.detach();
|
||||||
|
|
||||||
if (lzo_init() != LZO_E_OK)
|
if (lzo_init() != LZO_E_OK) {
|
||||||
{
|
zlog_error(zbt, "internal error - lzo_init() failed !!!");
|
||||||
printf("internal error - lzo_init() failed !!!\n");
|
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
|
||||||
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = OpenWatchDog();
|
int fd = OpenWatchDog();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (GlobalConfig::QuitFlag_G) {
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,1);
|
gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 1);
|
||||||
usleep(20000);
|
usleep(20000);
|
||||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,0);
|
gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0);
|
||||||
#endif
|
#endif
|
||||||
WriteWatchDog(fd);
|
WriteWatchDog(fd);
|
||||||
sleep(20);
|
sleep(20);
|
||||||
if(GlobalConfig::threadStatus == 0){
|
if (GlobalConfig::threadStatus == 0) {
|
||||||
count ++;
|
count++;
|
||||||
}else if(GlobalConfig::threadStatus == 1){
|
} else if (GlobalConfig::threadStatus == 1) {
|
||||||
GlobalConfig::threadStatus = 0;
|
GlobalConfig::threadStatus = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
if(count >= 30){
|
if (count >= 30) {
|
||||||
LOG_ERROR("===========threadStatus ========failed \n");
|
zlog_error(zbt, "===========threadStatus ========failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,15 +4,13 @@
|
|||||||
#include "common/global.hpp"
|
#include "common/global.hpp"
|
||||||
#include "dbaccess/sql_db.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
|
|
||||||
|
|
||||||
/*********************全局变量声明***********************/
|
/*********************全局变量声明***********************/
|
||||||
int GlobalConfig::RUN_MODE = 0;
|
int GlobalConfig::RUN_MODE = 0;
|
||||||
int GlobalConfig::QuitFlag_G = 1;
|
int GlobalConfig::QuitFlag_G = 1;
|
||||||
int GlobalConfig::LinkStatus_G = 0;
|
int GlobalConfig::LinkStatus_G = 0;
|
||||||
int GlobalConfig::LinkCount = 0;
|
int GlobalConfig::LinkCount = 0;
|
||||||
int GlobalConfig::net0Status = 1;
|
int GlobalConfig::net0Status = 1;
|
||||||
|
|
||||||
|
|
||||||
std::string GlobalConfig::Version = "3.2.5";
|
std::string GlobalConfig::Version = "3.2.5";
|
||||||
std::string GlobalConfig::MacAddr_G = "";
|
std::string GlobalConfig::MacAddr_G = "";
|
||||||
std::string GlobalConfig::MacAddr_G2 = "";
|
std::string GlobalConfig::MacAddr_G2 = "";
|
||||||
@ -27,104 +25,93 @@ int GlobalConfig::ServerPort = 0;
|
|||||||
int GlobalConfig::threadStatus = 1;
|
int GlobalConfig::threadStatus = 1;
|
||||||
int GlobalConfig::day = 0;
|
int GlobalConfig::day = 0;
|
||||||
|
|
||||||
extern map<string,compressWaveChannel> g_mapCompress;
|
extern map<string, compressWaveChannel> g_mapCompress;
|
||||||
|
|
||||||
TopicList GlobalConfig::Topic_G;
|
TopicList GlobalConfig::Topic_G;
|
||||||
ZigbeeInfo GlobalConfig::ZigbeeInfo_G;
|
ZigbeeInfo GlobalConfig::ZigbeeInfo_G;
|
||||||
ZIGBEE GlobalConfig::Zigbee_G;
|
ZIGBEE GlobalConfig::Zigbee_G;
|
||||||
GPIOInfo GlobalConfig::GPIO_G;
|
GPIOInfo GlobalConfig::GPIO_G;
|
||||||
std::string GlobalConfig::DbName_G = "/opt/configenv/cidn.db"; //数据库名称
|
std::string GlobalConfig::DbName_G = "/opt/configenv/cidn.db"; //数据库名称
|
||||||
std::string GlobalConfig::Config_G = "/opt/configenv/config.ini";
|
std::string GlobalConfig::Config_G = "/opt/configenv/config.ini";
|
||||||
std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
|
std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
|
||||||
|
|
||||||
// 处理ZigBee网络接收过程的PanID切换
|
// 处理ZigBee网络接收过程的PanID切换
|
||||||
enumZigBeeTransmitStatus GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
enumZigBeeTransmitStatus GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||||
int GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
int GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||||
|
|
||||||
PlatformInit::PlatformInit()
|
PlatformInit::PlatformInit() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
PlatformInit::~PlatformInit() {}
|
||||||
|
|
||||||
PlatformInit::~PlatformInit()
|
void PlatformInit::Init() {
|
||||||
{
|
try {
|
||||||
}
|
GlobalConfig::MacAddr_G = GetLocalMac("eth0");
|
||||||
|
GlobalConfig::MacAddr_G2 = GetLocalMac("eth1");
|
||||||
|
transform(GlobalConfig::MacAddr_G.begin(), GlobalConfig::MacAddr_G.end(), GlobalConfig::MacAddr_G.begin(), ::toupper);
|
||||||
|
transform(GlobalConfig::MacAddr_G2.begin(), GlobalConfig::MacAddr_G2.end(), GlobalConfig::MacAddr_G2.begin(), ::toupper);
|
||||||
|
GlobalConfig::IpAddr_G = IpAddrInit();
|
||||||
|
print_info("GlobalConfig::IpAddr_G : %s\n", GlobalConfig::IpAddr_G.c_str());
|
||||||
|
this->ConfigFileCheck();
|
||||||
|
print_info("ConfigFileCheck\n");
|
||||||
|
this->TopicInit();
|
||||||
|
print_info("TopicInit\n");
|
||||||
|
this->ServerIpInit();
|
||||||
|
print_info("TopicInit\n");
|
||||||
|
this->Sqlite3Init();
|
||||||
|
this->GPIOInit();
|
||||||
|
|
||||||
void PlatformInit::PlatFormInit()
|
print_info("ServerIP : %s \n", GlobalConfig::ServerIP.c_str());
|
||||||
{
|
std::string strMac = sqlite_db_ctrl::instance().GetData("t_gateway_info", "gatewayMAC", NULL);
|
||||||
try{
|
if (strMac == "60294D208517") {
|
||||||
GlobalConfig::MacAddr_G = GetLocalMac("eth0");
|
char szUpdateSql[100] = {0x00};
|
||||||
GlobalConfig::MacAddr_G2 = GetLocalMac("eth1");
|
sprintf(szUpdateSql, "gatewayMAC = '%s'", GlobalConfig::MacAddr_G.c_str());
|
||||||
transform(GlobalConfig::MacAddr_G.begin(), GlobalConfig::MacAddr_G.end(), GlobalConfig::MacAddr_G.begin(), ::toupper);
|
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL);
|
||||||
transform(GlobalConfig::MacAddr_G2.begin(), GlobalConfig::MacAddr_G2.end(), GlobalConfig::MacAddr_G2.begin(), ::toupper);
|
} else if (strMac != GlobalConfig::MacAddr_G) {
|
||||||
GlobalConfig::IpAddr_G = IpAddrInit();
|
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n", strMac.c_str(), GlobalConfig::MacAddr_G.c_str());
|
||||||
print_info("GlobalConfig::IpAddr_G : %s\n", GlobalConfig::IpAddr_G.c_str());
|
strMac.insert(2, ":");
|
||||||
this->ConfigFileCheck();
|
strMac.insert(5, ":");
|
||||||
print_info("ConfigFileCheck\n");
|
strMac.insert(8, ":");
|
||||||
this->TopicInit();
|
strMac.insert(11, ":");
|
||||||
print_info("TopicInit\n");
|
strMac.insert(14, ":");
|
||||||
this->ServerIpInit();
|
ModifyMac((char*)strMac.c_str());
|
||||||
print_info("TopicInit\n");
|
// system("reboot");
|
||||||
this->Sqlite3Init();
|
}
|
||||||
this->GPIOInit();
|
|
||||||
|
|
||||||
print_info("ServerIP : %s \n", GlobalConfig::ServerIP.c_str());
|
|
||||||
std::string strMac = sqlite_db_ctrl::instance().GetData("t_gateway_info","gatewayMAC",NULL);
|
|
||||||
if(strMac == "60294D208517"){
|
|
||||||
char szUpdateSql[100]={0x00};
|
|
||||||
sprintf(szUpdateSql,"gatewayMAC = '%s'",GlobalConfig::MacAddr_G.c_str());
|
|
||||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
|
||||||
}
|
|
||||||
else if(strMac != GlobalConfig::MacAddr_G ){
|
|
||||||
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n",strMac.c_str(),GlobalConfig::MacAddr_G.c_str());
|
|
||||||
strMac.insert(2,":");
|
|
||||||
strMac.insert(5,":");
|
|
||||||
strMac.insert(8,":");
|
|
||||||
strMac.insert(11,":");
|
|
||||||
strMac.insert(14,":");
|
|
||||||
ModifyMac((char*)strMac.c_str());
|
|
||||||
//system("reboot");
|
|
||||||
}
|
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info","MAC2",NULL);
|
std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info", "MAC2", NULL);
|
||||||
if(strMac2 == "60294D208518"){
|
if (strMac2 == "60294D208518") {
|
||||||
char szUpdateSql[100]={0x00};
|
char szUpdateSql[100] = {0x00};
|
||||||
sprintf(szUpdateSql,"MAC2 = '%s'",GlobalConfig::MacAddr_G2.c_str());
|
sprintf(szUpdateSql, "MAC2 = '%s'", GlobalConfig::MacAddr_G2.c_str());
|
||||||
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL);
|
||||||
}
|
} else if (strMac2 != GlobalConfig::MacAddr_G2) {
|
||||||
else if(strMac2 != GlobalConfig::MacAddr_G2 ){
|
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n", strMac2.c_str(), GlobalConfig::MacAddr_G2.c_str());
|
||||||
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n",strMac2.c_str(),GlobalConfig::MacAddr_G2.c_str());
|
strMac2.insert(2, ":");
|
||||||
strMac2.insert(2,":");
|
strMac2.insert(5, ":");
|
||||||
strMac2.insert(5,":");
|
strMac2.insert(8, ":");
|
||||||
strMac2.insert(8,":");
|
strMac2.insert(11, ":");
|
||||||
strMac2.insert(11,":");
|
strMac2.insert(14, ":");
|
||||||
strMac2.insert(14,":");
|
ModifyMac((char*)strMac2.c_str());
|
||||||
ModifyMac((char*)strMac2.c_str());
|
// system("reboot");
|
||||||
//system("reboot");
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// sleep(10);
|
// sleep(10);
|
||||||
} catch(...){
|
} catch (...) {
|
||||||
print_error("PlatFormInit exception happend.\n");
|
print_error("PlatFormInit exception happend.\n");
|
||||||
std::string errorinfo = "系统初始化异常";
|
std::string errorinfo = "系统初始化异常";
|
||||||
}
|
}
|
||||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME)," zigbeeShortAddr ",NULL);
|
vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL);
|
||||||
for (size_t i = 0; i < vecResult.size(); i++)
|
for (size_t i = 0; i < vecResult.size(); i++) {
|
||||||
{
|
|
||||||
compressWaveChannel tempchannel;
|
compressWaveChannel tempchannel;
|
||||||
g_mapCompress.insert(std::make_pair(vecResult[0],tempchannel));
|
g_mapCompress.insert(std::make_pair(vecResult[0], tempchannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit::TopicInit()
|
void PlatformInit::TopicInit() {
|
||||||
{
|
|
||||||
GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G;//
|
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G; //
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfo/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfo/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
@ -132,15 +119,14 @@ void PlatformInit::TopicInit()
|
|||||||
|
|
||||||
GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G;//
|
GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G; //
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G;//
|
GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G; //
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G;
|
GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
|
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver";
|
GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver";
|
||||||
@ -151,93 +137,85 @@ void PlatformInit::TopicInit()
|
|||||||
|
|
||||||
GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger";
|
GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger";
|
||||||
|
|
||||||
GlobalConfig::Topic_G.mPubLocalCmd= "up/" + GlobalConfig::MacAddr_G + "/recive/cmd";
|
GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformInit::ConfigFileCheck() {
|
||||||
void PlatformInit::ConfigFileCheck()
|
if (access(SYSTEMINFOFILE, 0) < 0) {
|
||||||
{
|
|
||||||
if (access(SYSTEMINFOFILE, 0) < 0) {
|
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", "");
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", "");
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", "");
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate", "");
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "timezone", "UTC+8");
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "timezone", "UTC+8");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayNo", GlobalConfig::MacAddr_G);
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayNo", GlobalConfig::MacAddr_G);
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "Area", "countryId", "");
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "countryId", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", "");
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", "");
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", "");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "Uint", "uint", "ST");
|
WriteStr2Config(SYSTEMINFOFILE, "Uint", "uint", "ST");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(NETWORKCONFIG, 0) < 0) {
|
if (access(NETWORKCONFIG, 0) < 0) {
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "dnsName", " ");
|
WriteStr2Config(NETWORKCONFIG, "Net", "dnsName", " ");
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "networkPortStatus", "DHCP");
|
WriteStr2Config(NETWORKCONFIG, "Net", "networkPortStatus", "DHCP");
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "gateway", "0.0.0.0");
|
WriteStr2Config(NETWORKCONFIG, "Net", "gateway", "0.0.0.0");
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "subnetMask", "0.0.0.0");
|
WriteStr2Config(NETWORKCONFIG, "Net", "subnetMask", "0.0.0.0");
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "ipAddress", "0.0.0.0");
|
WriteStr2Config(NETWORKCONFIG, "Net", "ipAddress", "0.0.0.0");
|
||||||
WriteStr2Config(NETWORKCONFIG, "Net", "hostName", "0.0.0.0");
|
WriteStr2Config(NETWORKCONFIG, "Net", "hostName", "0.0.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(SERVERCONFIG, 0) < 0) {
|
if (access(SERVERCONFIG, 0) < 0) {
|
||||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0");
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0");
|
||||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", "51613");
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", "51613");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlatformInit::ServerIpInit()
|
int PlatformInit::ServerIpInit() {
|
||||||
{
|
|
||||||
if (access(SERVERCONFIG, 0) >= 0) {
|
if (access(SERVERCONFIG, 0) >= 0) {
|
||||||
GlobalConfig::ServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
GlobalConfig::ServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||||
GlobalConfig::ServerPort = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
GlobalConfig::ServerPort = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit::Sqlite3Init()
|
void PlatformInit::Sqlite3Init() {
|
||||||
{
|
|
||||||
sqlite_db_ctrl::instance().OpenDB(GlobalConfig::DbName_G.c_str());
|
sqlite_db_ctrl::instance().OpenDB(GlobalConfig::DbName_G.c_str());
|
||||||
char szValue[10] = {0x00};
|
char szValue[10] = {0x00};
|
||||||
int nType = readIntValue( "Update", "type",(char*)GlobalConfig::Config_G.c_str());
|
int nType = readIntValue("Update", "type", (char*)GlobalConfig::Config_G.c_str());
|
||||||
if(nType== 1){
|
if (nType == 1) {
|
||||||
sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
||||||
writeIntValue("Update", "type",0,(char*)GlobalConfig::Config_G.c_str());
|
writeIntValue("Update", "type", 0, (char*)GlobalConfig::Config_G.c_str());
|
||||||
}
|
}
|
||||||
print_info("szValue = %d\n",nType);
|
print_info("szValue = %d\n", nType);
|
||||||
sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str());
|
sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||||
print_info("Sqlite3Init \n");
|
print_info("Sqlite3Init \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit::GPIOInit()
|
void PlatformInit::GPIOInit() {
|
||||||
{
|
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
GlobalConfig::GPIO_G.zigAckrep = 507;
|
GlobalConfig::GPIO_G.zigAckrep = 507;
|
||||||
GlobalConfig::GPIO_G.zigAckreset = 499;
|
GlobalConfig::GPIO_G.zigAckreset = 499;
|
||||||
GlobalConfig::GPIO_G.zigReset = 496;
|
GlobalConfig::GPIO_G.zigReset = 496;
|
||||||
GlobalConfig::GPIO_G.commPower = 363;
|
GlobalConfig::GPIO_G.commPower = 363;
|
||||||
GlobalConfig::GPIO_G.vol3_8 = 498;
|
GlobalConfig::GPIO_G.vol3_8 = 498;
|
||||||
GlobalConfig::GPIO_G.commRest = 466;
|
GlobalConfig::GPIO_G.commRest = 466;
|
||||||
GlobalConfig::GPIO_G.wifiPower = 488;
|
GlobalConfig::GPIO_G.wifiPower = 488;
|
||||||
GlobalConfig::GPIO_G.wifiReset = 474;
|
GlobalConfig::GPIO_G.wifiReset = 474;
|
||||||
GlobalConfig::GPIO_G.hardWatchDog = 497;
|
GlobalConfig::GPIO_G.hardWatchDog = 497;
|
||||||
GlobalConfig::GPIO_G.zigDef = 408;
|
GlobalConfig::GPIO_G.zigDef = 408;
|
||||||
GlobalConfig::GPIO_G.runLed = 409;
|
GlobalConfig::GPIO_G.runLed = 409;
|
||||||
GlobalConfig::GPIO_G.errorLed = 410;
|
GlobalConfig::GPIO_G.errorLed = 410;
|
||||||
GlobalConfig::GPIO_G.netResetNet0 = 489;
|
GlobalConfig::GPIO_G.netResetNet0 = 489;
|
||||||
#else if IMX6UL_GATEWAY
|
#else if IMX6UL_GATEWAY
|
||||||
GlobalConfig::GPIO_G.zigAckrep = 119;
|
GlobalConfig::GPIO_G.zigAckrep = 119;
|
||||||
GlobalConfig::GPIO_G.zigAckreset = 120;
|
GlobalConfig::GPIO_G.zigAckreset = 120;
|
||||||
GlobalConfig::GPIO_G.zigReset = 116;
|
GlobalConfig::GPIO_G.zigReset = 116;
|
||||||
GlobalConfig::GPIO_G.wifiReset = 8;
|
GlobalConfig::GPIO_G.wifiReset = 8;
|
||||||
GlobalConfig::GPIO_G.commRest = 8;
|
GlobalConfig::GPIO_G.commRest = 8;
|
||||||
GlobalConfig::GPIO_G.power = 9;
|
GlobalConfig::GPIO_G.power = 9;
|
||||||
GlobalConfig::GPIO_G.errorLed = 130;
|
GlobalConfig::GPIO_G.errorLed = 130;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void PlatformInit::SystemInfoInit()
|
void PlatformInit::SystemInfoInit() {
|
||||||
{
|
std::ifstream ifileOut(SYSTEMINFOFILE);
|
||||||
std::ifstream ifileOut(SYSTEMINFOFILE);
|
|
||||||
Json::Reader recvReader;
|
Json::Reader recvReader;
|
||||||
Json::Value Systeminfo;
|
Json::Value Systeminfo;
|
||||||
//从配置文件中读取json数据
|
//从配置文件中读取json数据
|
||||||
@ -248,11 +226,11 @@ void PlatformInit::SystemInfoInit()
|
|||||||
if (ifileOut.is_open()) {
|
if (ifileOut.is_open()) {
|
||||||
ifileOut.close();
|
ifileOut.close();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ifileOut.close();
|
ifileOut.close();
|
||||||
|
|
||||||
Systeminfo["dataWatchIpAddress"] = GlobalConfig::IpAddr_G;
|
Systeminfo["dataWatchIpAddress"] = GlobalConfig::IpAddr_G;
|
||||||
Systeminfo["softVersion"] = GlobalConfig::Version;
|
Systeminfo["softVersion"] = GlobalConfig::Version;
|
||||||
|
|
||||||
@ -263,115 +241,105 @@ void PlatformInit::SystemInfoInit()
|
|||||||
std::ofstream os;
|
std::ofstream os;
|
||||||
os.open(SYSTEMINFOFILE);
|
os.open(SYSTEMINFOFILE);
|
||||||
os << sw.write(Systeminfo);
|
os << sw.write(Systeminfo);
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformInit::UserInit() {
|
||||||
void PlatformInit::UserInit()
|
|
||||||
{
|
|
||||||
std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName");
|
std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName");
|
||||||
if (userName.length() == 0) {
|
if (userName.length() == 0) {
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin");
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos");
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos");
|
||||||
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", "");
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit::EquipIpInit(std::string eth)
|
void PlatformInit::EquipIpInit(std::string eth) {
|
||||||
{
|
// eth0 初始化
|
||||||
//eth0 初始化
|
int flag = 0;
|
||||||
int flag = 0;
|
std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus");
|
||||||
std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus");
|
std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, eth, "subnetMask");
|
||||||
std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, eth, "subnetMask");
|
std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway");
|
||||||
std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway");
|
std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "ipAddress");
|
||||||
std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "ipAddress");
|
std::string strStatus = GetFileContent(NETWORK, 18);
|
||||||
std::string strStatus = GetFileContent(NETWORK, 18);
|
print_red("strStatus:%s\n networkPortStatus:%s dataWatchIpAddress:%s subnetMask:%s gateway:%s\n", strStatus.c_str(), networkPortStatus.c_str(), dataWatchIpAddress.c_str(), subnetMask.c_str(), gateway.c_str());
|
||||||
print_red("strStatus:%s\n networkPortStatus:%s dataWatchIpAddress:%s subnetMask:%s gateway:%s\n",strStatus.c_str(),networkPortStatus.c_str(),dataWatchIpAddress.c_str(),subnetMask.c_str(),gateway.c_str());
|
|
||||||
|
|
||||||
if(0 == networkPortStatus.compare("DHCP"))
|
if (0 == networkPortStatus.compare("DHCP")) {
|
||||||
{
|
print_white("dhcp config\n");
|
||||||
print_white("dhcp config\n");
|
std::string cmd = "";
|
||||||
std::string cmd = "";
|
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
system("sed -i '17c auto eth0' /etc/network/interfaces");
|
system("sed -i '17c auto eth0' /etc/network/interfaces");
|
||||||
system("sed -i '18c iface eth0 inet dhcp' /etc/network/interfaces");
|
system("sed -i '18c iface eth0 inet dhcp' /etc/network/interfaces");
|
||||||
system("sed -i '20c ' /etc/network/interfaces");
|
system("sed -i '20c ' /etc/network/interfaces");
|
||||||
system("sed -i '21c ' /etc/network/interfaces");
|
system("sed -i '21c ' /etc/network/interfaces");
|
||||||
system("sed -i '22c ' /etc/network/interfaces");
|
system("sed -i '22c ' /etc/network/interfaces");
|
||||||
#endif
|
#endif
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
if(eth == "eth0"){
|
if (eth == "eth0") {
|
||||||
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/static/10-eth0-static.network");
|
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/static/10-eth0-static.network");
|
||||||
system("sed -i '6c ' /etc/systemd/network/static/10-eth0-static.network");
|
system("sed -i '6c ' /etc/systemd/network/static/10-eth0-static.network");
|
||||||
system("sed -i '7c ' /etc/systemd/network/static/10-eth0-static.network");
|
system("sed -i '7c ' /etc/systemd/network/static/10-eth0-static.network");
|
||||||
}else if(eth == "eth1"){
|
} else if (eth == "eth1") {
|
||||||
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||||
system("sed -i '6c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
system("sed -i '6c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||||
system("sed -i '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
system("sed -i '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
flag = 0;
|
flag = 0;
|
||||||
}
|
}
|
||||||
if(0 == networkPortStatus.compare("STATIC"))
|
if (0 == networkPortStatus.compare("STATIC")) {
|
||||||
{
|
std::string cmd = "";
|
||||||
std::string cmd = "";
|
print_red("static config\n");
|
||||||
print_red("static config\n");
|
#ifdef IMX6UL_GATEWAY
|
||||||
#ifdef IMX6UL_GATEWAY
|
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
||||||
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
if (dataWatchIpAddress.length() > 0) {
|
||||||
if(dataWatchIpAddress.length() > 0)
|
cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces";
|
||||||
{
|
} else {
|
||||||
cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces";
|
cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces";
|
||||||
}else{
|
}
|
||||||
cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces";
|
system(cmd.c_str());
|
||||||
}
|
cmd.clear();
|
||||||
system(cmd.c_str());
|
|
||||||
cmd.clear();
|
|
||||||
|
|
||||||
if(subnetMask.length() > 0)
|
if (subnetMask.length() > 0) {
|
||||||
{
|
cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces";
|
||||||
cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces";
|
} else {
|
||||||
}else{
|
cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces";
|
||||||
cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces";
|
}
|
||||||
}
|
system(cmd.c_str());
|
||||||
system(cmd.c_str());
|
cmd.clear();
|
||||||
cmd.clear();
|
|
||||||
|
|
||||||
if(gateway.length() > 0)
|
if (gateway.length() > 0) {
|
||||||
{
|
cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces";
|
||||||
cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces";
|
} else {
|
||||||
}else{
|
cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces";
|
||||||
cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces";
|
}
|
||||||
}
|
system(cmd.c_str());
|
||||||
system(cmd.c_str());
|
cmd.clear();
|
||||||
cmd.clear();
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
if(eth == "eth0"){
|
if (eth == "eth0") {
|
||||||
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network";
|
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/static/10-eth0-static.network";
|
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/static/10-eth0-static.network";
|
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
}else if(eth == "eth1"){
|
} else if (eth == "eth1") {
|
||||||
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
|
|
||||||
|
system("reboot");
|
||||||
system("reboot");
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
system("systemctl restart systemd-networkd.service");
|
system("systemctl restart systemd-networkd.service");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public :
|
|||||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static void PlatFormInit();
|
static void Init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user