diff --git a/.cproject b/.cproject index b9a3ee0..b25dc1a 100644 --- a/.cproject +++ b/.cproject @@ -77,8 +77,6 @@ - - @@ -117,6 +115,7 @@ + @@ -129,6 +128,7 @@ + @@ -137,6 +137,7 @@ + @@ -161,8 +162,6 @@ - - diff --git a/common/common_func.cpp b/common/common_func.cpp index 72fcec2..e5a7f04 100644 --- a/common/common_func.cpp +++ b/common/common_func.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "global.hpp" #include "dbaccess/sql_db.hpp" @@ -33,7 +34,10 @@ char sendpacket[PACKET_SIZE]; char recvpacket[PACKET_SIZE]; static boost::mutex s_config_mu; -Mutex g_tDbMutex; + +zlog_category_t *zct; +zlog_category_t *zbt; + string GetLocalTimeWithMs(void) { string defaultTime = "19700101000000000"; try { @@ -56,6 +60,7 @@ string GetLocalTimeWithMs(void) { return defaultTime; } } + int code_convert(const char *from_charset, const char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen) { iconv_t cd; char **pin = &inbuf; @@ -112,6 +117,7 @@ std::string UTFtoGBK(const char *utf8) { return ""; } } + std::string convertEncoding(const std::string &input, const char *fromEncoding, const char *toEncoding) { iconv_t conv = iconv_open(toEncoding, fromEncoding); if (conv == (iconv_t)-1) { diff --git a/main.cpp b/main.cpp index 7ded1ae..6fcae02 100644 --- a/main.cpp +++ b/main.cpp @@ -8,45 +8,49 @@ #include #include #include -#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" +#include +#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" -namespace{ - PlatformInit *platform = PlatformInit::instance(); - Uart *pUart = Uart::instance(); -} extern std::vector g_VecWaveDataX; extern std::vector g_VecWaveDataY; extern std::vector 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; + +zlog_category_t *zct = NULL; +zlog_category_t *zbt = NULL; + +int main(int argc, char *argv[]) { + int rc = zlog_init("/opt/wlg.conf"); + if (rc) { + printf("init failed\n"); + return -1; } + 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_VecWaveDataY.reserve(1000); - g_VecWaveDataZ.reserve (1500); - // 设置线程属性之栈空间大小 + g_VecWaveDataZ.reserve(1500); 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(); uart_inst::instance().InitZigbee(); @@ -54,7 +58,7 @@ int main(int argc, char *argv[]) boost::thread searchT(SearchThread); searchT.detach(); - // 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信 + // 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信 boost::thread uartReadTh(UartStart); uartReadTh.detach(); @@ -64,7 +68,6 @@ int main(int argc, char *argv[]) boost::thread InitModuleReadTh(InitModule); InitModuleReadTh.detach(); - // 休眠2秒,等待串口线程初始化完毕 sleep(2); @@ -72,7 +75,6 @@ int main(int argc, char *argv[]) boost::thread uartWaveReadTh(UartStartWave); uartWaveReadTh.detach(); - #ifdef G2UL_GATEWAY //启动 RUN LED boost::thread startRunLED(RunLED); @@ -81,7 +83,7 @@ int main(int argc, char *argv[]) #ifdef NR5G_MODULE print_info("NR5G_MODULE \n"); - //5G + // 5G boost::thread startCSQ(GetCSQ); startCSQ.detach(); #ifndef NR5G_MEIGE @@ -90,7 +92,7 @@ int main(int argc, char *argv[]) #endif #endif -#ifdef Q4G_MODULE +#ifdef Q4G_MODULE boost::thread startCSQ(GetCSQ); startCSQ.detach(); print_info("4G_MODULE \n"); @@ -103,19 +105,18 @@ int main(int argc, char *argv[]) // 通过UDP接收数据 boost::thread StartConnectSys(attrs, StartUdpSys); StartConnectSys.detach(); - + //循环检测线程 - boost::thread normalCheckThread(attrs,CheckThread); + boost::thread normalCheckThread(attrs, CheckThread); normalCheckThread.detach(); //启动软件升级线程 boost::thread StartDownloadThread(attrs, RecvUpdateFile); StartDownloadThread.detach(); - - //启动cgi server - boost::thread startTcpCgi(attrs,StartCgiServer); - startTcpCgi.detach(); + //启动cgi server + boost::thread startTcpCgi(attrs, StartCgiServer); + startTcpCgi.detach(); sleep(5); uart_inst::instance().ZigbeeInit(); @@ -130,35 +131,31 @@ int main(int argc, char *argv[]) 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"); + 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)"); } 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); + gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 1); + usleep(20000); + gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0); #endif - WriteWatchDog(fd); + WriteWatchDog(fd); sleep(20); - if(GlobalConfig::threadStatus == 0){ - count ++; - }else if(GlobalConfig::threadStatus == 1){ + if (GlobalConfig::threadStatus == 0) { + count++; + } else if (GlobalConfig::threadStatus == 1) { GlobalConfig::threadStatus = 0; count = 0; } - if(count >= 30){ - LOG_ERROR("===========threadStatus ========failed \n"); + if (count >= 30) { + zlog_error(zbt, "===========threadStatus ========failed"); break; } - } return 0; } - - diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index 9d3b453..4394492 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -4,15 +4,13 @@ #include "common/global.hpp" #include "dbaccess/sql_db.hpp" - /*********************全局变量声明***********************/ -int GlobalConfig::RUN_MODE = 0; +int GlobalConfig::RUN_MODE = 0; int GlobalConfig::QuitFlag_G = 1; int GlobalConfig::LinkStatus_G = 0; int GlobalConfig::LinkCount = 0; int GlobalConfig::net0Status = 1; - std::string GlobalConfig::Version = "3.2.5"; std::string GlobalConfig::MacAddr_G = ""; std::string GlobalConfig::MacAddr_G2 = ""; @@ -27,104 +25,93 @@ int GlobalConfig::ServerPort = 0; int GlobalConfig::threadStatus = 1; int GlobalConfig::day = 0; -extern map g_mapCompress; +extern map g_mapCompress; TopicList GlobalConfig::Topic_G; ZigbeeInfo GlobalConfig::ZigbeeInfo_G; ZIGBEE GlobalConfig::Zigbee_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::UartName_G = "/dev/ttymxc4"; // 处理ZigBee网络接收过程的PanID切换 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() -{ -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(); - - 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"); - } + 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 - std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info","MAC2",NULL); - if(strMac2 == "60294D208518"){ - char szUpdateSql[100]={0x00}; - sprintf(szUpdateSql,"MAC2 = '%s'",GlobalConfig::MacAddr_G2.c_str()); - sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info",szUpdateSql,NULL); - } - else if(strMac2 != GlobalConfig::MacAddr_G2 ){ - LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n",strMac2.c_str(),GlobalConfig::MacAddr_G2.c_str()); - strMac2.insert(2,":"); - strMac2.insert(5,":"); - strMac2.insert(8,":"); - strMac2.insert(11,":"); - strMac2.insert(14,":"); - ModifyMac((char*)strMac2.c_str()); - //system("reboot"); - } + std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info", "MAC2", NULL); + if (strMac2 == "60294D208518") { + char szUpdateSql[100] = {0x00}; + sprintf(szUpdateSql, "MAC2 = '%s'", GlobalConfig::MacAddr_G2.c_str()); + sqlite_db_ctrl::instance().UpdateTableData("t_gateway_info", szUpdateSql, NULL); + } else if (strMac2 != GlobalConfig::MacAddr_G2) { + LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n", strMac2.c_str(), GlobalConfig::MacAddr_G2.c_str()); + strMac2.insert(2, ":"); + strMac2.insert(5, ":"); + strMac2.insert(8, ":"); + strMac2.insert(11, ":"); + strMac2.insert(14, ":"); + ModifyMac((char*)strMac2.c_str()); + // system("reboot"); + } #endif - // sleep(10); - } catch(...){ + // sleep(10); + } catch (...) { print_error("PlatFormInit exception happend.\n"); std::string errorinfo = "系统初始化异常"; } - vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME)," zigbeeShortAddr ",NULL); - for (size_t i = 0; i < vecResult.size(); i++) - { + vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL); + for (size_t i = 0; i < vecResult.size(); i++) { 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.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; @@ -132,15 +119,14 @@ void PlatformInit::TopicInit() 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.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G; - GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi"; 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.mPubLocalCmd= "up/" + GlobalConfig::MacAddr_G + "/recive/cmd"; + GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd"; } - -void PlatformInit::ConfigFileCheck() -{ - if (access(SYSTEMINFOFILE, 0) < 0) { +void PlatformInit::ConfigFileCheck() { + if (access(SYSTEMINFOFILE, 0) < 0) { WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", ""); WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", ""); WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", ""); 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, "Area", "countryId", ""); WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", ""); WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", ""); WriteStr2Config(SYSTEMINFOFILE, "Uint", "uint", "ST"); - } if (access(NETWORKCONFIG, 0) < 0) { WriteStr2Config(NETWORKCONFIG, "Net", "dnsName", " "); WriteStr2Config(NETWORKCONFIG, "Net", "networkPortStatus", "DHCP"); - WriteStr2Config(NETWORKCONFIG, "Net", "gateway", "0.0.0.0"); - WriteStr2Config(NETWORKCONFIG, "Net", "subnetMask", "0.0.0.0"); - WriteStr2Config(NETWORKCONFIG, "Net", "ipAddress", "0.0.0.0"); - WriteStr2Config(NETWORKCONFIG, "Net", "hostName", "0.0.0.0"); + WriteStr2Config(NETWORKCONFIG, "Net", "gateway", "0.0.0.0"); + WriteStr2Config(NETWORKCONFIG, "Net", "subnetMask", "0.0.0.0"); + WriteStr2Config(NETWORKCONFIG, "Net", "ipAddress", "0.0.0.0"); + WriteStr2Config(NETWORKCONFIG, "Net", "hostName", "0.0.0.0"); } if (access(SERVERCONFIG, 0) < 0) { - WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0"); - WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", "51613"); + WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0"); + WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", "51613"); } } -int PlatformInit::ServerIpInit() -{ +int PlatformInit::ServerIpInit() { 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()); - } - + } } -void PlatformInit::Sqlite3Init() -{ +void PlatformInit::Sqlite3Init() { sqlite_db_ctrl::instance().OpenDB(GlobalConfig::DbName_G.c_str()); char szValue[10] = {0x00}; - int nType = readIntValue( "Update", "type",(char*)GlobalConfig::Config_G.c_str()); - if(nType== 1){ - sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str()); - writeIntValue("Update", "type",0,(char*)GlobalConfig::Config_G.c_str()); + int nType = readIntValue("Update", "type", (char*)GlobalConfig::Config_G.c_str()); + if (nType == 1) { + sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_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()); print_info("Sqlite3Init \n"); } -void PlatformInit::GPIOInit() -{ +void PlatformInit::GPIOInit() { #ifdef G2UL_GATEWAY - GlobalConfig::GPIO_G.zigAckrep = 507; - GlobalConfig::GPIO_G.zigAckreset = 499; - GlobalConfig::GPIO_G.zigReset = 496; - GlobalConfig::GPIO_G.commPower = 363; - GlobalConfig::GPIO_G.vol3_8 = 498; - GlobalConfig::GPIO_G.commRest = 466; - GlobalConfig::GPIO_G.wifiPower = 488; - GlobalConfig::GPIO_G.wifiReset = 474; - GlobalConfig::GPIO_G.hardWatchDog = 497; - GlobalConfig::GPIO_G.zigDef = 408; - GlobalConfig::GPIO_G.runLed = 409; - GlobalConfig::GPIO_G.errorLed = 410; - GlobalConfig::GPIO_G.netResetNet0 = 489; + GlobalConfig::GPIO_G.zigAckrep = 507; + GlobalConfig::GPIO_G.zigAckreset = 499; + GlobalConfig::GPIO_G.zigReset = 496; + GlobalConfig::GPIO_G.commPower = 363; + GlobalConfig::GPIO_G.vol3_8 = 498; + GlobalConfig::GPIO_G.commRest = 466; + GlobalConfig::GPIO_G.wifiPower = 488; + GlobalConfig::GPIO_G.wifiReset = 474; + GlobalConfig::GPIO_G.hardWatchDog = 497; + GlobalConfig::GPIO_G.zigDef = 408; + GlobalConfig::GPIO_G.runLed = 409; + GlobalConfig::GPIO_G.errorLed = 410; + GlobalConfig::GPIO_G.netResetNet0 = 489; #else if IMX6UL_GATEWAY - GlobalConfig::GPIO_G.zigAckrep = 119; - GlobalConfig::GPIO_G.zigAckreset = 120; - GlobalConfig::GPIO_G.zigReset = 116; - GlobalConfig::GPIO_G.wifiReset = 8; - GlobalConfig::GPIO_G.commRest = 8; - GlobalConfig::GPIO_G.power = 9; - GlobalConfig::GPIO_G.errorLed = 130; + GlobalConfig::GPIO_G.zigAckrep = 119; + GlobalConfig::GPIO_G.zigAckreset = 120; + GlobalConfig::GPIO_G.zigReset = 116; + GlobalConfig::GPIO_G.wifiReset = 8; + GlobalConfig::GPIO_G.commRest = 8; + GlobalConfig::GPIO_G.power = 9; + GlobalConfig::GPIO_G.errorLed = 130; #endif } -void PlatformInit::SystemInfoInit() -{ - std::ifstream ifileOut(SYSTEMINFOFILE); +void PlatformInit::SystemInfoInit() { + std::ifstream ifileOut(SYSTEMINFOFILE); Json::Reader recvReader; Json::Value Systeminfo; //从配置文件中读取json数据 @@ -248,11 +226,11 @@ void PlatformInit::SystemInfoInit() if (ifileOut.is_open()) { ifileOut.close(); } else { - return; - } - } - ifileOut.close(); - + return; + } + } + ifileOut.close(); + Systeminfo["dataWatchIpAddress"] = GlobalConfig::IpAddr_G; Systeminfo["softVersion"] = GlobalConfig::Version; @@ -263,115 +241,105 @@ void PlatformInit::SystemInfoInit() std::ofstream os; os.open(SYSTEMINFOFILE); os << sw.write(Systeminfo); - os.close(); + os.close(); } - -void PlatformInit::UserInit() -{ +void PlatformInit::UserInit() { std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName"); if (userName.length() == 0) { WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin"); WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos"); - WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", ""); + WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", ""); } } -void PlatformInit::EquipIpInit(std::string eth) -{ - //eth0 初始化 - int flag = 0; - std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus"); - std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, eth, "subnetMask"); - std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway"); - std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "ipAddress"); - 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()); +void PlatformInit::EquipIpInit(std::string eth) { + // eth0 初始化 + int flag = 0; + std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus"); + std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, eth, "subnetMask"); + std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway"); + std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "ipAddress"); + 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()); - if(0 == networkPortStatus.compare("DHCP")) - { - print_white("dhcp config\n"); - std::string cmd = ""; + if (0 == networkPortStatus.compare("DHCP")) { + print_white("dhcp config\n"); + std::string cmd = ""; #ifdef IMX6UL_GATEWAY - system("sed -i '17c auto eth0' /etc/network/interfaces"); - system("sed -i '18c iface eth0 inet dhcp' /etc/network/interfaces"); - system("sed -i '20c ' /etc/network/interfaces"); - system("sed -i '21c ' /etc/network/interfaces"); - system("sed -i '22c ' /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 '20c ' /etc/network/interfaces"); + system("sed -i '21c ' /etc/network/interfaces"); + system("sed -i '22c ' /etc/network/interfaces"); #endif #ifdef G2UL_GATEWAY - if(eth == "eth0"){ - 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 '7c ' /etc/systemd/network/static/10-eth0-static.network"); - }else if(eth == "eth1"){ - 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 '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network"); - } + if (eth == "eth0") { + 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 '7c ' /etc/systemd/network/static/10-eth0-static.network"); + } else if (eth == "eth1") { + 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 '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network"); + } #endif - flag = 0; - } - if(0 == networkPortStatus.compare("STATIC")) - { - std::string cmd = ""; - print_red("static config\n"); -#ifdef IMX6UL_GATEWAY - system("sed -i '18c iface eth0 inet static' /etc/network/interfaces"); - if(dataWatchIpAddress.length() > 0) - { - cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces"; - }else{ - cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); + flag = 0; + } + if (0 == networkPortStatus.compare("STATIC")) { + std::string cmd = ""; + print_red("static config\n"); +#ifdef IMX6UL_GATEWAY + system("sed -i '18c iface eth0 inet static' /etc/network/interfaces"); + if (dataWatchIpAddress.length() > 0) { + cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces"; + } else { + cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces"; + } + system(cmd.c_str()); + cmd.clear(); - if(subnetMask.length() > 0) - { - cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces"; - }else{ - cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); + if (subnetMask.length() > 0) { + cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces"; + } else { + cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces"; + } + system(cmd.c_str()); + cmd.clear(); - if(gateway.length() > 0) - { - cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces"; - }else{ - cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces"; - } - system(cmd.c_str()); - cmd.clear(); + if (gateway.length() > 0) { + cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces"; + } else { + cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces"; + } + system(cmd.c_str()); + cmd.clear(); #endif #ifdef G2UL_GATEWAY - if(eth == "eth0"){ - cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network"; - system(cmd.c_str()); - cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/static/10-eth0-static.network"; - system(cmd.c_str()); - cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/static/10-eth0-static.network"; - system(cmd.c_str()); - }else if(eth == "eth1"){ - cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; - system(cmd.c_str()); - cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; - system(cmd.c_str()); - cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; - system(cmd.c_str()); - } + if (eth == "eth0") { + cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network"; + system(cmd.c_str()); + cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/static/10-eth0-static.network"; + system(cmd.c_str()); + cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/static/10-eth0-static.network"; + system(cmd.c_str()); + } else if (eth == "eth1") { + cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; + system(cmd.c_str()); + cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; + system(cmd.c_str()); + cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network"; + system(cmd.c_str()); + } #endif - flag = 1; - } + flag = 1; + } #ifdef IMX6UL_GATEWAY - - system("reboot"); + system("reboot"); #endif #ifdef G2UL_GATEWAY - system("systemctl restart systemd-networkd.service"); + system("systemctl restart systemd-networkd.service"); #endif } - diff --git a/platform/platform_init.hpp b/platform/platform_init.hpp index 3add775..9b86d80 100644 --- a/platform/platform_init.hpp +++ b/platform/platform_init.hpp @@ -16,7 +16,7 @@ public : * @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区 * @return void */ - static void PlatFormInit(); + static void Init(); /** * @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区