add zlog.

This commit is contained in:
pandx 2024-10-23 09:58:35 +08:00
parent 9b7ce05eb4
commit ea5dbf1313
5 changed files with 249 additions and 279 deletions

View File

@ -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>

View File

@ -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) {

View File

@ -8,44 +8,48 @@
#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();
@ -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);
@ -116,7 +118,6 @@ int main(int argc, char *argv[])
boost::thread startTcpCgi(attrs, StartCgiServer); boost::thread startTcpCgi(attrs, StartCgiServer);
startTcpCgi.detach(); startTcpCgi.detach();
sleep(5); sleep(5);
uart_inst::instance().ZigbeeInit(); uart_inst::instance().ZigbeeInit();
sleep(1); sleep(1);
@ -130,10 +131,9 @@ 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();
@ -153,12 +153,9 @@ int main(int argc, char *argv[])
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;
} }

View File

@ -4,7 +4,6 @@
#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;
@ -12,7 +11,6 @@ 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 = "";
@ -41,17 +39,11 @@ std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
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() {
{
}
void PlatformInit::PlatFormInit()
{
try { try {
GlobalConfig::MacAddr_G = GetLocalMac("eth0"); GlobalConfig::MacAddr_G = GetLocalMac("eth0");
GlobalConfig::MacAddr_G2 = GetLocalMac("eth1"); GlobalConfig::MacAddr_G2 = GetLocalMac("eth1");
@ -74,8 +66,7 @@ try{
char szUpdateSql[100] = {0x00}; char szUpdateSql[100] = {0x00};
sprintf(szUpdateSql, "gatewayMAC = '%s'", GlobalConfig::MacAddr_G.c_str()); sprintf(szUpdateSql, "gatewayMAC = '%s'", GlobalConfig::MacAddr_G.c_str());
sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL); sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL);
} } else if (strMac != GlobalConfig::MacAddr_G) {
else if(strMac != GlobalConfig::MacAddr_G ){
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n", strMac.c_str(), GlobalConfig::MacAddr_G.c_str()); LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n", strMac.c_str(), GlobalConfig::MacAddr_G.c_str());
strMac.insert(2, ":"); strMac.insert(2, ":");
strMac.insert(5, ":"); strMac.insert(5, ":");
@ -91,8 +82,7 @@ try{
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, ":");
@ -110,16 +100,13 @@ try{
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;
@ -140,7 +127,6 @@ void PlatformInit::TopicInit()
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";
@ -154,9 +140,7 @@ void PlatformInit::TopicInit()
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", "");
@ -168,7 +152,6 @@ void PlatformInit::ConfigFileCheck()
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) {
@ -186,17 +169,14 @@ void PlatformInit::ConfigFileCheck()
} }
} }
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());
@ -209,8 +189,7 @@ void PlatformInit::Sqlite3Init()
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;
@ -235,8 +214,7 @@ void PlatformInit::GPIOInit()
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;
@ -266,9 +244,7 @@ void PlatformInit::SystemInfoInit()
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");
@ -277,8 +253,7 @@ void PlatformInit::UserInit()
} }
} }
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");
@ -288,8 +263,7 @@ void PlatformInit::EquipIpInit(std::string eth)
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
@ -312,14 +286,12 @@ void PlatformInit::EquipIpInit(std::string eth)
#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"; cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces";
} else { } else {
cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces"; cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces";
@ -327,8 +299,7 @@ void PlatformInit::EquipIpInit(std::string eth)
system(cmd.c_str()); system(cmd.c_str());
cmd.clear(); 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";
@ -336,8 +307,7 @@ void PlatformInit::EquipIpInit(std::string eth)
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";
@ -366,7 +336,6 @@ void PlatformInit::EquipIpInit(std::string eth)
} }
#ifdef IMX6UL_GATEWAY #ifdef IMX6UL_GATEWAY
system("reboot"); system("reboot");
#endif #endif
@ -374,4 +343,3 @@ void PlatformInit::EquipIpInit(std::string eth)
system("systemctl restart systemd-networkd.service"); system("systemctl restart systemd-networkd.service");
#endif #endif
} }

View File

@ -16,7 +16,7 @@ public :
* @brief , * @brief ,
* @return void * @return void
*/ */
static void PlatFormInit(); static void Init();
/** /**
* @brief , * @brief ,