From 4ddc9e82855f38fd739eb0098ebc717ffb784f9a Mon Sep 17 00:00:00 2001 From: pandx Date: Wed, 23 Oct 2024 20:33:05 +0800 Subject: [PATCH] modify a little. --- jsonparse/communication_cmd.hpp | 1 - jsonparse/mqtt_cmd_parse.cpp | 52 ++----- jsonparse/web_cmd_parse.cpp | 24 ++-- jsonparse/web_cmd_parse2.cpp | 71 +++++----- jsonparse/web_cmd_parse3.cpp | 6 +- localserver/mqtt_cmd.cpp | 18 +-- platform/platform_init.cpp | 54 +++---- threadfunc/check_thread.cpp | 54 +++---- uart/uart.cpp | 157 +++++++++++---------- uart/uart_cmd.cpp | 19 +-- uart/uart_feature_parse.cpp | 139 ++++++++---------- uart/uart_parameter_config.cpp | 77 +++++----- utility/calculation.cpp | 2 + utility/search_dev.cpp | 16 +-- utility/secure.cpp | 3 +- utility/tcp_cgi.cpp | 18 +-- utility/udp_scan.cpp | 241 ++++++++++++++------------------ wifi_5g/dial.cpp | 35 ++--- wifi_5g/wpa_client.cpp | 42 +++--- 19 files changed, 485 insertions(+), 544 deletions(-) diff --git a/jsonparse/communication_cmd.hpp b/jsonparse/communication_cmd.hpp index cc710b1..f08145d 100644 --- a/jsonparse/communication_cmd.hpp +++ b/jsonparse/communication_cmd.hpp @@ -40,7 +40,6 @@ public: std::string JsonCmd_51(Json::Value &recvBody); std::string JsonCmd_52(); // upload static data std::string JsonCmd_53(Json::Value &recvBody); - void JsonCmd_38(Json::Value &recvBody); //获取原始数据 // web command parse std::string JsonCmd_Cgi_01(Param_01 ¶m); //用户操作处理 diff --git a/jsonparse/mqtt_cmd_parse.cpp b/jsonparse/mqtt_cmd_parse.cpp index 689e622..2dadf50 100644 --- a/jsonparse/mqtt_cmd_parse.cpp +++ b/jsonparse/mqtt_cmd_parse.cpp @@ -1,8 +1,11 @@ #include "communication_cmd.hpp" +#include + #include "dbaccess/sql_db.hpp" #include "platform/platform_init.hpp" #include "utility/md5.h" -#include + +extern zlog_category_t *zct; std::string JsonData::JsonCmd_20(Param_20 ¶m) { Json::Value jsonVal; @@ -29,9 +32,9 @@ std::string JsonData::JsonCmd_20(Param_20 ¶m) { Json::Value jsSystemInfo; Json::Value jsBody; - string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion"); - string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); - string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); + std::string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion"); + std::string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); + std::string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); jsSystemInfo["WebVersion"] = strwebVersion; jsSystemInfo["SystemVersion"] = strsystemVersion; @@ -172,7 +175,7 @@ std::string JsonData::JsonCmd_25(Param_25 ¶m) { print_info("GateWay = %s\n", GateWay); system(GateWay); #endif - platform->EquipIpInit(param.mNet); + PlatformInit::EquipIpInit(param.mNet); } else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") { WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", ""); @@ -328,16 +331,16 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) { jsonVal["message"] = "download failed"; return show_value_.write(jsonVal); } - string md5Val = md5file(updateName.c_str()); - zlog_info(zct,"md5Val = %s", md5Val.c_str()); - zlog_info(zct,"md5 = %s", md5.c_str()); + std::string md5Val = md5file(updateName.c_str()); + zlog_info(zct, "md5Val = %s", md5Val.c_str()); + zlog_info(zct, "md5 = %s", md5.c_str()); if (md5 != md5Val) { jsonVal["success"] = false; jsonVal["message"] = "download file check failed"; return show_value_.write(jsonVal); } if (updateDevice == "1") { // update sensor - string strcmd = "tar xvf "; + std::string strcmd = "tar xvf "; strcmd = strcmd + updateName; strcmd = strcmd + " -C /opt/"; system(strcmd.c_str()); @@ -488,31 +491,6 @@ std::string JsonData::JsonCmd_29(Param_29 ¶m) { return show_value_.write(jsonVal); } -void JsonData::JsonCmd_38(Json::Value &recvBody) { - Json::Value jsChannel = recvBody["channelArray"]; - print_info("jsChannel size : %d\n", jsChannel.size()); - if (jsChannel.isArray()) { - for (int i = 0; i < jsChannel.size(); i++) { - std::string strChannelid = jsChannel[i].asString(); - WAVE_GENERAL wavedata; - - WAVE_CONTAIN wave; - memset(wave.channelId, 0, 16); - sprintf(wave.channelId, "%s", strChannelid.c_str()); - - memset(wave.SensorEngineeringUnit, 0, 32); - sprintf(wave.SensorEngineeringUnit, "%s", wavedata.SensorEngineeringUnit.c_str()); - - wave.total = 1; - wave.count = 1; - wave.type = 0; - wave.flag = 0; - wave.number = wavedata.number; - memcpy(wave.waveData, wavedata.waveData, wavedata.number * sizeof(float)); - } - } -} - void JsonData::DataNodeStatusCheck() { array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL); int nSize = vetRes.size(); @@ -539,7 +517,7 @@ void JsonData::DataNodeStatusCheck() { int lTimeTemp = lNowTime - llastTime; lTimeTemp = abs(lTimeTemp); if (lTimeTemp > onlineCheck) { - zlog_info(zct,"offline DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s", lNowTime, llastTime, vetRes[i][21].c_str()); + zlog_info(zct, "offline DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s", lNowTime, llastTime, vetRes[i][21].c_str()); char whereCon[32] = {0}; sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str()); sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon); @@ -550,13 +528,13 @@ void JsonData::DataNodeStatusCheck() { } if (lTimeTemp > atoi(vetRes[i][21].c_str()) * 5 * 60) //判定传感器是否超过五次未传特征值 { - zlog_info(zct,"lTimeTemp = %d,featureInterVal = %d", lTimeTemp, atoi(vetRes[i][21].c_str())); + zlog_info(zct, "lTimeTemp = %d,featureInterVal = %d", lTimeTemp, atoi(vetRes[i][21].c_str())); count++; } } } if (count == nSize && nodeOnline) { - zlog_error(zct,"ALL Node offline,count = %d", count); + zlog_error(zct, "ALL Node offline,count = %d", count); exit(0); } } diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index a8fc116..9dfe5b1 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -1,8 +1,10 @@ #include "communication_cmd.hpp" +#include #include "dbaccess/sql_db.hpp" #include "platform/platform_init.hpp" #include "utility/md5.h" -#include + +extern zlog_category_t *zct; std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m) { Json::Value jsonVal; @@ -86,7 +88,7 @@ std::string JsonData::JsonCmd_Cgi_07() { jsonVal.clear(); std::string sysStatus = GetSysStatus(); - zlog_info(zct,"sysStatus : %s", sysStatus.c_str()); + zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); Json::Features f = Json::Features::strictMode(); Json::Reader recvReader(f); Json::Value recvSys; @@ -106,7 +108,7 @@ std::string JsonData::JsonCmd_07() { jsonVal.clear(); std::string sysStatus = GetSysStatus(); - zlog_info(zct,"sysStatus : %s", sysStatus.c_str()); + zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); Json::Features f = Json::Features::strictMode(); Json::Reader recvReader(f); Json::Value recvSys; @@ -137,7 +139,6 @@ std::string JsonData::JsonCmd_Cgi_08() { } std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) { - Json::Value jsonVal; jsonVal.clear(); @@ -179,7 +180,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) { jsonVal["packageMax"] = index + 1; } - zlog_info(zct,"09 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d", packgeNo, packgeNum, lastSize, index); + zlog_info(zct, "09 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d", packgeNo, packgeNum, lastSize, index); for (int i = packgeNo * 10; i < packgeNum; i++) { Json::Value jsSensor; std::string strMeasurementID = arrResAll[i][1]; @@ -262,6 +263,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) { } return show_value_.write(jsonVal); } + std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) { Json::Value jsonVal; jsonVal.clear(); @@ -324,7 +326,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) { array_t vecRes; vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon); - zlog_info(zct,"vecRes = %d", vecRes.size()); + zlog_info(zct, "vecRes = %d", vecRes.size()); if (vecRes.size() > 0) { Json::Value jsStaticData; for (int i = 0; i < vecRes.size(); i++) { @@ -357,7 +359,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) { jsonVal["content"] = (jsStaticData); } jsonVal["Static"] = param.strStatic; - zlog_info(zct,"vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str()); + zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str()); } else { jsonVal["success"] = false; jsonVal["content"].resize(0); @@ -383,7 +385,7 @@ std::string JsonData::JsonCmd_Cgi_11(Param_11 ¶m) { array_t arrRes; arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon); int iResult = arrRes.size(); - zlog_info(zct,"iResult = %d", iResult); + zlog_info(zct, "iResult = %d", iResult); if (iResult > 0) { for (int j = 0; j < iResult; j++) { Json::Value jsChannelData; @@ -575,7 +577,7 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { } else { bFlag4 = true; } - zlog_info(zct,"bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d", bFlag1, bFlag2, bFlag3, bFlag4); + zlog_info(zct, "bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d", bFlag1, bFlag2, bFlag3, bFlag4); #ifdef IMX6UL_GATEWAY strNet = param.mNet; param.mNet = "Net"; @@ -591,10 +593,10 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) { #ifdef IMX6UL_GATEWAY char GateWay[100] = {0x00}; sprintf(GateWay, "sed -i '7c route add default gw %s' /etc/init.d/S90start_userapp.sh", param.mGateway.c_str()); - zlog_info(zct,"GateWay = %s", GateWay); + zlog_info(zct, "GateWay = %s", GateWay); system(GateWay); #endif - platform->EquipIpInit(param.mNet); + Platform::EquipIpInit(param.mNet); } else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") { WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", ""); diff --git a/jsonparse/web_cmd_parse2.cpp b/jsonparse/web_cmd_parse2.cpp index db8bf5c..2a7d1a1 100644 --- a/jsonparse/web_cmd_parse2.cpp +++ b/jsonparse/web_cmd_parse2.cpp @@ -1,8 +1,10 @@ #include "communication_cmd.hpp" +#include #include "dbaccess/sql_db.hpp" #include "platform/platform_init.hpp" #include "utility/md5.h" -#include + +extern zlog_category_t *zct; std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) { Json::Value jsonVal; @@ -84,7 +86,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) { jsSensorData["status"] = atoi(arrRes[j][37].c_str()); jsSensorData["timeStamp"] = arrRes[j][38]; jsSensorData["viff"] = atoi(arrRes[j][39].c_str()); - vector vParam; + std::vector vParam; boost::split(vParam, arrRes[j][42], boost::is_any_of(","), boost::token_compress_on); if (vParam.size() > 1) @@ -92,7 +94,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) { else jsSensorData["loose"] = "0"; - vector vParamRSSI; + std::vector vParamRSSI; boost::split(vParamRSSI, arrRes[j][40], boost::is_any_of(","), boost::token_compress_on); if (vParamRSSI.size() > 1) { jsSensorData["RSSI"] = arrRes[j][40]; @@ -279,7 +281,7 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) { sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str()); GetTimeNet(localtimestamp, 1); sprintf(updateSql, "LooseValue = '0,2,"); - string strUpdateSql = string(updateSql) + string(localtimestamp) + "' "; + std::string strUpdateSql = std::string(updateSql) + std::string(localtimestamp) + "' "; sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon); } else { jsonVal["success"] = false; @@ -375,7 +377,7 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) { } jsBody["channelId"] = param.mChannelId; jsBody["package"] = param.mPackageFlag; - zlog_info(zct,"vecWave.size() = %d,sample = %d,second = %f", vecWave.size(), atoi(res[23].c_str()), float(vecWave.size() / atoi(res[23].c_str()))); + zlog_info(zct, "vecWave.size() = %d,sample = %d,second = %f", vecWave.size(), atoi(res[23].c_str()), float(vecWave.size() / atoi(res[23].c_str()))); string::size_type comper = param.mChannelId.find("Z"); if (comper != string::npos && res[17] == "02") { jsBody["second"] = float((float)vecWave.size() / (float)atoi(res[23].c_str())); @@ -435,8 +437,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) { } else { while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算 - vecWave.push_back(fTemp); - + vecWave.push_back(fTemp); } //进行傅立叶变换 @@ -485,10 +486,10 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) { double resolution = 0.0; int SampleRate = 0; - zlog_info(zct,"sensor type %s", res[17].c_str()); + zlog_info(zct, "sensor type %s", res[17].c_str()); if (res[17] == "01") { SampleRate = atoi(res[23].c_str()); - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size(); } else if (res[17] == "02") { @@ -496,10 +497,10 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) { if (comper != string::npos) { SampleRate = atoi(res[23].c_str()); resolution = (double)SampleRate / vecWave.size(); - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution); } else { SampleRate = 8192; - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); if (vecWave.size() < 8192) { resolution = (double)SampleRate / vecWave.size(); } else { @@ -508,7 +509,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) { } } - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f", SampleRate, resolution); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f", SampleRate, resolution); char buf[32]; memset(buf, 0, 32); sprintf(buf, "%f", resolution); @@ -517,6 +518,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) { jsonVal["content"] = jsBody; return show_value_.write(jsonVal); } + std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) { Json::Value jsonVal; Json::Value jsBody; @@ -604,18 +606,18 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) { envWave[i] = envWave[i]*2; }*/ - zlog_info(zct,"2---------------------------------------------->%d", envWave.size()); - zlog_info(zct,"2---------------------------------------------->%f", envWave[10]); + zlog_info(zct, "2---------------------------------------------->%d", envWave.size()); + zlog_info(zct, "2---------------------------------------------->%f", envWave[10]); - zlog_info(zct,"after fft--------------------------------------------------->fftWave.size()=%d", envWave.size()); + zlog_info(zct, "after fft--------------------------------------------------->fftWave.size()=%d", envWave.size()); int flag = param.mPackageFlag; flag = (flag + 1) * sampleRateReference; int number = envWave.size(); int start = param.mPackageFlag * sampleRateReference; - zlog_info(zct,"param.mPackageFlag = %d", param.mPackageFlag); - zlog_info(zct,"param.start = %d", start); - zlog_info(zct,"param.flag = %d", flag); + zlog_info(zct, "param.mPackageFlag = %d", param.mPackageFlag); + zlog_info(zct, "param.start = %d", start); + zlog_info(zct, "param.flag = %d", flag); if (number < sampleRateReference) { flag = number; start = 0; @@ -654,10 +656,10 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) { double resolution = 0.0; int SampleRate = 0; - zlog_info(zct,"sensor type %s", res[17].c_str()); + zlog_info(zct, "sensor type %s", res[17].c_str()); if (res[17] == "01") { SampleRate = atoi(res[23].c_str()); - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); resolution = (((double)SampleRate / 1000) * 1016) / 8192; } else if (res[17] == "02") { string::size_type comper = param.mChannelId.find("Z"); @@ -665,15 +667,15 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) { SampleRate = atoi(res[23].c_str()); resolution = (double)SampleRate / vecWave.size(); - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution); } else { SampleRate = 8000; - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate); resolution = (((double)SampleRate / 1000) * 1024) / 8192; } } - zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f", SampleRate, resolution); + zlog_info(zct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f", SampleRate, resolution); char buf[32]; memset(buf, 0, 32); sprintf(buf, "%f", resolution); @@ -698,8 +700,8 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector ¶m, int isServer) for (int i = 0; i < param.size(); i++) { char dataNodeName[100] = {0x00}; hexToAscii(param[i].mdataNodeName.c_str(), dataNodeName); - zlog_info(zct,"str = %s", dataNodeName); - zlog_info(zct,"dataNodeName = %s", param[i].mdataNodeName.c_str()); + zlog_info(zct, "str = %s", dataNodeName); + zlog_info(zct, "dataNodeName = %s", param[i].mdataNodeName.c_str()); int dataNodeNameLength = param[i].mdataNodeName.length(); if (dataNodeNameLength != 0) { sprintf(updateSql, "dataNodeName = '%s',ZigbeePower = '%d',ZigbeeRetry = '%d',featureInterVal='%d',waveInterVal='%d',range='%d',samplingRate='%d',AccSampleTime = '%d',\ @@ -724,6 +726,7 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector ¶m, int isServer) } return show_value_.write(jsonVal); } + std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) { Json::Value jsonVal; jsonVal.clear(); @@ -735,31 +738,31 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) { strcpy(cmd, "rm -rf /tmp/cgic*"); system(cmd); if (param.fileName == "DataNode.tar") { - string strcmd = "tar xvf /opt/"; + std::string strcmd = "tar xvf /opt/"; strcmd = strcmd + param.fileName; strcmd = strcmd + " -C /opt/"; - zlog_info(zct,"strcmd = %s", strcmd.c_str()); + zlog_info(zct, "strcmd = %s", strcmd.c_str()); system(strcmd.c_str()); } else if (param.fileName == "rfsbu.tar") { - zlog_info(zct,"update rfsbu.tar"); + zlog_info(zct, "update rfsbu.tar"); sleep(3); - zlog_info(zct,"strcmd = %s", param.fileName.c_str()); + zlog_info(zct, "strcmd = %s", param.fileName.c_str()); int iRet = system("/opt/opt.sh"); - zlog_info(zct,"iRet = %d", iRet); + zlog_info(zct, "iRet = %d", iRet); if (iRet == -1) { - zlog_error(zct,"system() error"); + zlog_error(zct, "system() error"); } } else if (param.fileName == "update.json") { - zlog_info(zct,"strcmd = %s", param.fileName.c_str()); + zlog_info(zct, "strcmd = %s", param.fileName.c_str()); ReadStrConfig("/opt/update.json"); } else if (param.fileName == "backup.json") { ImportConfig("/opt/backup.json"); } else if (param.fileName == "DataNode.csv") { - zlog_info(zct,"strcmd = %s", param.fileName.c_str()); + zlog_info(zct, "strcmd = %s", param.fileName.c_str()); int iRet = UpdataDataNodeConfig("/opt/DataNode.csv"); - string str = to_string(iRet) + "个传感器更新成功"; + std::string str = std::to_string(iRet) + "个传感器更新成功"; if (iRet < 0) { jsonVal["success"] = false; jsonVal["message"] = "更新失败!"; diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index 2d75dc5..97f9269 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -1,8 +1,10 @@ #include "communication_cmd.hpp" +#include #include "dbaccess/sql_db.hpp" #include "platform/platform_init.hpp" #include "utility/md5.h" -#include + +extern zlog_category_t *zct; std::string JsonData::JsonCmd_Cgi_default() { Json::Value jsonVal; @@ -118,7 +120,7 @@ std::string JsonData::JsonCmd_Cgi_51(Param_51 ¶m) { char whereCon[1024] = {0}; char updateSql[1024] = {0}; - string gatewayLocation = ""; + std::string gatewayLocation = ""; sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str()); sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str()); diff --git a/localserver/mqtt_cmd.cpp b/localserver/mqtt_cmd.cpp index 527ac41..9e86527 100644 --- a/localserver/mqtt_cmd.cpp +++ b/localserver/mqtt_cmd.cpp @@ -1,12 +1,14 @@ #include "local_server.hpp" +#include #include #include "utility/secure.hpp" #include "jsonparse/communication_cmd.hpp" -#include + +extern zlog_category_t *zct; LocalServer::LocalServer() {} -LocalServer::~LocalServer() { zlog_info(zct,"~LocalServer is called!"); } +LocalServer::~LocalServer() { zlog_info(zct, "~LocalServer is called!"); } void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *topic) { if (pLen == 0) { @@ -14,13 +16,13 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to } std::string data_r = (std::string)(pData_r); - zlog_info(zct,"MQTT recv base64 %s", data_r.c_str()); + zlog_info(zct, "MQTT recv base64 %s", data_r.c_str()); char *base64_data = new char[data_r.length()]; memset(base64_data, 0, data_r.length()); secure::instance().Base64Decode(data_r.c_str(), (unsigned char *)base64_data); std::string pData = std::string(base64_data); delete[] base64_data; - zlog_info(zct,"MQTT recv %s", pData.c_str()); + zlog_info(zct, "MQTT recv %s", pData.c_str()); Json::Reader recvReader; Json::Value recvValue; Json::Value recvBody; @@ -31,7 +33,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to } else { std::string cmdBody = recvValue["cmdBody"].asString(); if (!recvReader.parse(cmdBody, recvBody)) { - zlog_error(zct,"recv body error"); + zlog_error(zct, "recv body error, content:[%s]", cmdBody.c_str()); return; } } @@ -85,7 +87,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to } JsonData jd; std::string data = jd.JsonCmd_20(param); - zlog_info(zct,"20 data: %s", data.c_str()); + zlog_info(zct, "20 data: %s", data.c_str()); data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str()); } break; case kTimeZone: { @@ -199,9 +201,9 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to } break; default: break; } - zlog_info(zct,"cmdType : %d ", cmdType); + zlog_info(zct, "cmdType : %d ", cmdType); } else { - zlog_error(zct,"parase fail"); + zlog_error(zct, "parse fail, content:[%s]", pData.c_str()); } } diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index a52bbb4..f457a67 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -1,10 +1,12 @@ #include "platform_init.hpp" -#include #include +#include #include "common/global.hpp" #include "dbaccess/sql_db.hpp" -/*********************全局变量声明***********************/ +extern zlog_category_t *zct; +extern zlog_category_t *zbt; + int GlobalConfig::RUN_MODE = 0; int GlobalConfig::QuitFlag_G = 1; int GlobalConfig::LinkStatus_G = 0; @@ -25,7 +27,7 @@ int GlobalConfig::ServerPort = 0; int GlobalConfig::threadStatus = 1; int GlobalConfig::day = 0; -extern map g_mapCompress; +extern std::map g_mapCompress; TopicList GlobalConfig::Topic_G; ZigbeeInfo GlobalConfig::ZigbeeInfo_G; @@ -50,24 +52,24 @@ void PlatformInit::Init() { 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(); - zlog_info(zbt,"GlobalConfig::IpAddr_G : %s", GlobalConfig::IpAddr_G.c_str()); + zlog_info(zbt, "GlobalConfig::IpAddr_G : %s", GlobalConfig::IpAddr_G.c_str()); this->ConfigFileCheck(); - zlog_info(zbt,"ConfigFileCheck"); + zlog_info(zbt, "ConfigFileCheck"); this->TopicInit(); - zlog_info(zbt,"TopicInit"); + zlog_info(zbt, "TopicInit"); this->ServerIpInit(); - zlog_info(zbt,"TopicInit"); + zlog_info(zbt, "TopicInit"); this->Sqlite3Init(); this->GPIOInit(); - zlog_info(zbt,"ServerIP : %s ", GlobalConfig::ServerIP.c_str()); + zlog_info(zbt, "ServerIP : %s ", 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) { - zlog_error(zbt,"MAC error strMac1 = %s,MacAddr_G1 = %s", strMac.c_str(), GlobalConfig::MacAddr_G.c_str()); + zlog_error(zbt, "MAC error strMac1 = %s,MacAddr_G1 = %s", strMac.c_str(), GlobalConfig::MacAddr_G.c_str()); strMac.insert(2, ":"); strMac.insert(5, ":"); strMac.insert(8, ":"); @@ -82,7 +84,7 @@ void PlatformInit::Init() { 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) { - zlog_error(zbt,"MAC error strMac2 = %s,MacAddr_G2 = %s", strMac2.c_str(), GlobalConfig::MacAddr_G2.c_str()); + zlog_error(zbt, "MAC error strMac2 = %s,MacAddr_G2 = %s", strMac2.c_str(), GlobalConfig::MacAddr_G2.c_str()); strMac2.insert(2, ":"); strMac2.insert(5, ":"); strMac2.insert(8, ":"); @@ -92,7 +94,7 @@ void PlatformInit::Init() { } #endif } catch (...) { - print_error("PlatFormInit exception happend.\n"); + zlog_error(zbt, "PlatFormInit exception happend."); std::string errorinfo = "系统初始化异常"; } vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL); @@ -104,35 +106,20 @@ void PlatformInit::Init() { 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; - GlobalConfig::Topic_G.mPubWaveData = "wireless/realTimeData/" + GlobalConfig::MacAddr_G; - GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G; - - GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G; // - - GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G; // - + GlobalConfig::Topic_G.mPubCmd = "wireless/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"; - GlobalConfig::Topic_G.mPubLocalWaveQt = "up/" + GlobalConfig::MacAddr_G + "/recive/waveqt"; - GlobalConfig::Topic_G.mPubLocalConfig = "up/" + GlobalConfig::MacAddr_G + "/recive/config"; - GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger"; - GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd"; } @@ -181,7 +168,7 @@ void PlatformInit::Sqlite3Init() { writeIntValue("Update", "type", 0, (char*)GlobalConfig::Config_G.c_str()); } sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str()); - zlog_info(zbt,"Sqlite3Init "); + zlog_info(zbt, "Sqlite3Init "); } void PlatformInit::GPIOInit() { @@ -209,13 +196,14 @@ void PlatformInit::GPIOInit() { GlobalConfig::GPIO_G.errorLed = 130; #endif } + void PlatformInit::SystemInfoInit() { std::ifstream ifileOut(SYSTEMINFOFILE); Json::Reader recvReader; Json::Value Systeminfo; //从配置文件中读取json数据 if (ifileOut.is_open()) { - zlog_info(zbt,"open %s\n", SYSTEMINFOFILE); + zlog_info(zbt, "open %s", SYSTEMINFOFILE); } if (!recvReader.parse(ifileOut, Systeminfo, false)) { if (ifileOut.is_open()) { @@ -256,10 +244,10 @@ void PlatformInit::EquipIpInit(std::string eth) { std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway"); std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "ipAddress"); std::string strStatus = GetFileContent(NETWORK, 18); - zlog_info(zbt,"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()); + zlog_info(zbt, "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")) { - zlog_info(zbt,"dhcp config\n"); + zlog_info(zbt, "dhcp config\n"); std::string cmd = ""; #ifdef IMX6UL_GATEWAY system("sed -i '17c auto eth0' /etc/network/interfaces"); diff --git a/threadfunc/check_thread.cpp b/threadfunc/check_thread.cpp index a79809a..dbe3477 100644 --- a/threadfunc/check_thread.cpp +++ b/threadfunc/check_thread.cpp @@ -13,9 +13,11 @@ #include "common/common_func.hpp" #include "wifi_5g/wpa_client.h" +extern zlog_category_t *zct; +extern zlog_category_t *zbt; void CheckThread() { - zlog_info(zbt,"ENTER CHECK THREAD "); + zlog_info(zbt, "ENTER CHECK THREAD "); int heart_count = 0; @@ -43,7 +45,7 @@ void CheckThread() { if (GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) { GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; - zlog_error(zct,"[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !"); + zlog_error(zct, "[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !"); // 重新写入 0x8888 unsigned short shortAddr = 0x8888; uart_inst::instance().modify_LocalAddr(0x8888); @@ -59,21 +61,21 @@ void CheckThread() { sleep(1); std::string str("8888"); if (GlobalConfig::ZigbeeInfo_G.MyAddr.compare(str) == 0) { - zlog_warn(zct,"[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !"); + zlog_warn(zct, "[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !"); } else { - zlog_error(zct,"[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !"); + zlog_error(zct, "[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !"); } } continue; } if (10 == heart_count) { if (GlobalConfig::LinkCount > 30) { - zlog_error(zct,"MQTT connect failed "); + zlog_error(zct, "MQTT connect failed "); #ifdef IMX6UL_GATEWAY char connect[10] = {0x00}; - readStringValue(zct,"config", "connect", connect, (char *)GlobalConfig::Config_G.c_str()); + readStringValue(zct, "config", "connect", connect, (char *)GlobalConfig::Config_G.c_str()); if (atoi(connect)) { - zlog_error(zct,"MQTT connect failed,reboot"); + zlog_error(zct, "MQTT connect failed,reboot"); exit(0); } #endif @@ -107,12 +109,12 @@ void CheckThread() { iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str()); iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str()); if (iRet != 0) { - zlog_error(zct,"MQTT connect failed ,time check"); + zlog_error(zct, "MQTT connect failed ,time check"); #ifdef IMX6UL_GATEWAY char connect[10] = {0x00}; readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str()); if (atoi(connect)) { - zlog_error(zct,"MQTT connect failed,time check ,reboot"); + zlog_error(zct, "MQTT connect failed,time check ,reboot"); exit(0); } #endif @@ -120,10 +122,10 @@ void CheckThread() { #ifdef IMX6UL_GATEWAY dial.closePort(); gpio_set(GlobalConfig::GPIO_G.commRest, 0); - zlog_warn(zct,"GPIO 8 start"); + zlog_warn(zct, "GPIO 8 start"); sleep(2); gpio_set(GlobalConfig::GPIO_G.commRest, 1); - zlog_warn(zct,"GPIO 8 End"); + zlog_warn(zct, "GPIO 8 End"); sleep(20); dial.openPort("/dev/ttyUSB2"); dial.setState(); @@ -131,14 +133,14 @@ void CheckThread() { #ifdef G2UL_GATEWAY dial.closePort(); gpio_set(GlobalConfig::GPIO_G.commPower, 0); - zlog_warn(zct,"commPower start"); + zlog_warn(zct, "commPower start"); sleep(2); gpio_set(GlobalConfig::GPIO_G.commPower, 1); - zlog_warn(zct,"commPower End"); + zlog_warn(zct, "commPower End"); sleep(20); connectCount++; if (connectCount > 10) { - zlog_error(zct,"5G reset error ,reboot!"); + zlog_error(zct, "5G reset error ,reboot!"); system("reboot"); } #ifndef NR5G_MEIGE @@ -153,7 +155,7 @@ void CheckThread() { #endif #endif #ifdef WIFI_MODULE - zlog_warn(zct,"WiFi reset!"); + zlog_warn(zct, "WiFi reset!"); #ifdef IMX6UL_GATEWAY gpio_set(GlobalConfig::GPIO_G.wifiReset, 0); sleep(5); @@ -205,7 +207,7 @@ void CheckThread() { } if (mqttresend == 7200) { mqttresend = 0; - zlog_info(zct,"mqttresend check"); + zlog_info(zct, "mqttresend check"); Json::Value jsHeart; Json::FastWriter fw; jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; @@ -235,28 +237,28 @@ void CheckThread() { sleep(1); std::string strTime = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon); long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str()); - zlog_info(zct,"online check = %d", lTime); + zlog_info(zct, "online check = %d", lTime); if (lTime > 1800) { - zlog_error(zct,"nowTimetamp = %s,lastTime = %s,lTime = %d", nowTimetamp.c_str(), strTime.c_str(), lTime); + zlog_error(zct, "nowTimetamp = %s,lastTime = %s,lTime = %d", nowTimetamp.c_str(), strTime.c_str(), lTime); } } } if (7200 == Battery) { Battery = 0; - zlog_info(zct,"Battery"); + zlog_info(zct, "Battery"); sqlite_db_ctrl::instance().CalculateBattery(); } if (3500 == loose_check) { - zlog_info(zct,"loosecheck\n"); + zlog_info(zct, "loosecheck\n"); loose_check = 0; sqlite_db_ctrl::instance().CalculateDip(); } if (ModifyAddr == 3600) { - zlog_info(zct,"ModifyAddr check"); + zlog_info(zct, "ModifyAddr check"); ModifyAddr = 0; if (uart_inst::instance().bModifyAddr) { - zlog_error(zct,"ModifyAddr failed "); + zlog_error(zct, "ModifyAddr failed "); exit(0); } } @@ -316,7 +318,7 @@ void CheckThread() { memcpy(todayMonth, buffer + 5, 2); string filename = root + string(dirp->d_name); if (atoi(fileMonth) == atoi(todayMonth) ? abs(atoi(todayDay) - atoi(fileDay)) > 15 : abs(abs(30 - (atoi(fileDay)) + atoi(todayDay))) > 15) { - zlog_info(zct,"filename = %s", filename.c_str()); + zlog_info(zct, "filename = %s", filename.c_str()); remove(filename.c_str()); } } @@ -358,15 +360,15 @@ void CheckThread() { memset(buf, 0, 64); sprintf(buf, "wifi:true Rssi:%s", Rssi.c_str()); - zlog_info(zct,"%s\n", buf); + zlog_info(zct, "%s\n", buf); } else { std::string runinfo = "wifi:false\n"; - zlog_info(zct,"%s\n", runinfo.c_str()); + zlog_info(zct, "%s\n", runinfo.c_str()); } } if (wpa.ReconnectWiFi()) { - zlog_info(zct,"wifi reconnect ok\n"); + zlog_info(zct, "wifi reconnect ok\n"); } } #endif diff --git a/uart/uart.cpp b/uart/uart.cpp index 4f08b9e..33ff333 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -15,7 +15,9 @@ #include #include "utility/serial.h" -char g_UartRecvBuf[GENERAL_BUF_SIZE]; +extern zlog_category_t *zct; +extern zlog_category_t *zbt; + int offSize = 0; pTestRecvCallBack pTestRecv; @@ -35,8 +37,8 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { if (!bUpdate && !bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15) { timeoutflag++; if (timeoutflag > 300) { - zlog_info(zct,"===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize); - zlog_info(zct,"0x9999 timeout %d===============Size = %d", timeoutflag, offSize); + zlog_info(zct, "===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize); + zlog_info(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize); FindRecvPackage(offSize, mUartRecvTmpBuf, head); GlobalConfig::Zigbee_G.MyAddr = 0x8888; timeoutflag = 0; @@ -58,7 +60,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { } else if (bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)) { timeoutflag++; if (timeoutflag > 300) { - zlog_info(zct,"bUpdateconfig %d===============", timeoutflag); + zlog_info(zct, "bUpdateconfig %d===============", timeoutflag); GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; timeoutflag = 0; @@ -92,7 +94,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { memcpy(mUartRecvTmpBuf + offSize, buff, ret); offSize = offSize + ret; if (offSize > BUF_LENGTH * 15) { - zlog_info(zct,"maxSize = %d", offSize); + zlog_info(zct, "maxSize = %d", offSize); memset(mUartRecvTmpBuf, 0, BUF_LENGTH); timeoutflag = 0; offSize = 0; @@ -115,9 +117,9 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { continue; } if (srcshow) { - zlog_info(zct,"0x8888 ===str_recv===,ret = %d", ret); + zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret); for (int i = 0; i < ret; i++) { - zlog_info(zct,"[%02x]", buff[i] & 0xff); + zlog_info(zct, "[%02x]", buff[i] & 0xff); } printf("\n"); FindRecvPackage(ret, buff, head); @@ -137,11 +139,11 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { } } else if (ret > 0) { maxSize += ret; - zlog_info(zct,"0x8888==str_recv===,ret = %d offSize = %d\n", ret, maxSize); + zlog_info(zct, "0x8888==str_recv===,ret = %d offSize = %d\n", ret, maxSize); for (int i = 0; i < ret; i++) { - zlog_info(zct,"%02x ", buff[i] & 0xff); + zlog_info(zct, "%02x ", buff[i] & 0xff); } - zlog_info(zct,"\n"); + zlog_info(zct, "\n"); timeoutflag = 0; m_TimeStamp = 0; memcpy(szbuffer + offSize, buff, ret); @@ -192,9 +194,9 @@ void Uart::InitUart(speed_t speed) { #ifdef IMX6UL_GATEWAY fd = config_uart("/dev/ttymxc4", speed); #endif - zlog_info(zct,"InitUart fd = %d", fd); + zlog_info(zct, "InitUart fd = %d", fd); if (fd < 0) { - zlog_error(zct,"config_uart error"); + zlog_error(zct, "config_uart error"); } } @@ -211,12 +213,12 @@ void Uart::InitZigbeeHW() { if (iRet <= 0) { Close(); sleep(2); - zlog_info(zct,"Speed error"); + zlog_info(zct, "Speed error"); InitUart(B57600); UpdateZigbeeInfoCtrl(); sleep(2); ReadFromUart(); - zlog_info(zct,"modify speed"); + zlog_info(zct, "modify speed"); WriteSpeed2Zigbee(); ReadFromUart(); } @@ -233,21 +235,21 @@ void TestRecv(int status) { void Regist(pTestRecvCallBack pTestRecv1) { pTestRecv = pTestRecv1; } void Uart::InitTestUart(speed_t speed) { - zlog_info(zct,"InitTestUart"); + zlog_info(zct, "InitTestUart"); TestFd = config_uart("/dev/ttymxc2", speed); // Test if (TestFd < 0) { - zlog_error(zct,"Test config_uart error"); + zlog_error(zct, "Test config_uart error"); } Regist(TestRecv); } void Uart::ReadTestUart() { char buff[BUF_LENGTH] = {0x00}; - zlog_info(zct,"ReadTestUart"); + zlog_info(zct, "ReadTestUart"); while (1) { int ret = read_data(TestFd, buff, BUF_LENGTH, 10); if (ret > 0) { - zlog_info(zct,"buff = %s", buff); + zlog_info(zct, "buff = %s", buff); if (!strcmp(buff, "0")) { char buf[256] = {0}; sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str()); @@ -291,11 +293,11 @@ int Uart::ZigbeeTest() { void Uart::WriteToUart(const char *strSend, int pLen) { if (!bUpdate) { - zlog_info(zct,"Write To Uart Start:"); + zlog_info(zct, "Write To Uart Start:"); for (int i = 0; i < pLen; i++) { - zlog_info(zct,"%02X ", *(strSend + i) & 0xFF); + zlog_info(zct, "%02X ", *(strSend + i) & 0xFF); } - zlog_info(zct,"\nWrite To Uart End."); + zlog_info(zct, "\nWrite To Uart End."); } int len = write_data(fd, (char *)strSend, pLen); @@ -304,8 +306,8 @@ void Uart::WriteToUart(const char *strSend, int pLen) { int Uart::ReadFromUart() { char buffer[100] = {0x00}; int len = read_data(fd, (char *)buffer, 100, 10); - for (int i = 0; i < len; i++) zlog_info(zct,"%02X ", buffer[i] & 0xFF); - zlog_info(zct,"==========ReadFromUart========len = %d", len); + for (int i = 0; i < len; i++) zlog_info(zct, "%02X ", buffer[i] & 0xFF); + zlog_info(zct, "==========ReadFromUart========len = %d", len); if (len) { char head[] = {0xAA, 0x55, 0xAA}; @@ -324,7 +326,7 @@ void Uart::Stop() { void Uart::setCallBack(onReceiveUart _callback) { m_callback = _callback; } void Uart::UpdateZigbeeInfo(const char *pData) { - zlog_info(zct,"update gateway zigbee info"); + zlog_info(zct, "update gateway zigbee info"); GlobalConfig::Zigbee_G = *((ZIGBEE *)pData); char buff[8]; sprintf(buff, "%02d", pData[36] & 0xFF); @@ -354,16 +356,16 @@ void Uart::UpdateZigbeeInfo(const char *pData) { sprintf(buff, "%d", pData[63]); GlobalConfig::ZigbeeInfo_G.TranTimeout = std::string(buff); - zlog_info(zct,"local zigbee module info Mode : %d Chan : %d PanID : %s MyAddr : %s DstAddr : %s,RetryNum:%s,TranTimeout:%s", GlobalConfig::ZigbeeInfo_G.DevMode, GlobalConfig::ZigbeeInfo_G.Channel, GlobalConfig::ZigbeeInfo_G.PanID.c_str(), - GlobalConfig::ZigbeeInfo_G.MyAddr.c_str(), GlobalConfig::ZigbeeInfo_G.DstAddr.c_str(), GlobalConfig::ZigbeeInfo_G.RetryNum.c_str(), GlobalConfig::ZigbeeInfo_G.TranTimeout.c_str()); + zlog_info(zct, "local zigbee module info Mode : %d Chan : %d PanID : %s MyAddr : %s DstAddr : %s,RetryNum:%s,TranTimeout:%s", GlobalConfig::ZigbeeInfo_G.DevMode, GlobalConfig::ZigbeeInfo_G.Channel, GlobalConfig::ZigbeeInfo_G.PanID.c_str(), + GlobalConfig::ZigbeeInfo_G.MyAddr.c_str(), GlobalConfig::ZigbeeInfo_G.DstAddr.c_str(), GlobalConfig::ZigbeeInfo_G.RetryNum.c_str(), GlobalConfig::ZigbeeInfo_G.TranTimeout.c_str()); - zlog_info(zct,"PanID = %s,MacAddr_G= %s", GlobalConfig::ZigbeeInfo_G.PanID.c_str(), GlobalConfig::MacAddr_G.c_str()); + zlog_info(zct, "PanID = %s,MacAddr_G= %s", GlobalConfig::ZigbeeInfo_G.PanID.c_str(), GlobalConfig::MacAddr_G.c_str()); std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel"); - zlog_info(zct,"Channel = %d,strchan = %s", GlobalConfig::ZigbeeInfo_G.Channel, strchan.c_str()); + zlog_info(zct, "Channel = %d,strchan = %s", GlobalConfig::ZigbeeInfo_G.Channel, strchan.c_str()); std::string strType = ReadStrByOpt(SYSTEMINFOFILE, "ZigbeeType", "type"); - zlog_info(zct,"TranTimeout = %02x,strType = %s ", GlobalConfig::Zigbee_G.TranTimeout, strType.c_str()); + zlog_info(zct, "TranTimeout = %02x,strType = %s ", GlobalConfig::Zigbee_G.TranTimeout, strType.c_str()); if (strType == "aw21") { unsigned short TranTimeout = 0x0A; WriteTranTimeout2Zigbee(TranTimeout); @@ -373,6 +375,7 @@ void Uart::UpdateZigbeeInfo(const char *pData) { WriteTranTimeout2Zigbee(TranTimeout); } } + void int2bytes(int i, unsigned char *bytes, int size) { memset(bytes, 0, sizeof(unsigned char) * size); bytes[0] = (unsigned char)(0xff & i); @@ -388,7 +391,7 @@ void Uart::DealRecvData(const char *pData) { sprintf(shortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF); unsigned short ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF); int flag = atoi(buf); - zlog_info(zct,"the data package type(1,2,3,4,5,6) is %s,%x", buf); + zlog_info(zct, "the data package type(1,2,3,4,5,6) is %s,%x", buf); switch (flag) { case 1: { // 0x01:设备信息 @@ -412,8 +415,8 @@ void Uart::DealRecvData(const char *pData) { void Uart::DealDataNodeName(const char *pData) { bSendTimeStamp = false; - zlog_info(zct,"DealDataNodeName "); - string strTime = GetLocalTimeWithMs(); + zlog_info(zct, "DealDataNodeName "); + std::string strTime = GetLocalTimeWithMs(); char szShortAdd[8] = {0x00}; char shortAdd[8] = {0x00}; char NodeName[64] = {0x00}; @@ -435,7 +438,7 @@ void Uart::DealDataNodeName(const char *pData) { sprintf(nodeWaveSend, "%d,%d,%d", GET_BIT(pData[79], 0), GET_BIT(pData[79], 1), GET_BIT(pData[79], 2)); char gbkNodeName[128] = {0x00}; sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); - zlog_info(zct,"whereCon = %s", whereCon); + zlog_info(zct, "whereCon = %s", whereCon); array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon); if (vecRes.size() > 1) { for (int i = 0; i < vecRes.size(); i++) { @@ -455,26 +458,26 @@ void Uart::DealDataNodeName(const char *pData) { } } } - string hardVersion = vecRes[0][2]; - string softVersion = vecRes[0][3]; + std::string hardVersion = vecRes[0][2]; + std::string softVersion = vecRes[0][3]; if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)) { memcpy(MeasurementID, vecRes[0][0].c_str(), sizeof(MeasurementID)); } std::string strNodeName(NodeName); - zlog_info(zct,"strNodeName = %s", strNodeName.c_str()); + zlog_info(zct, "strNodeName = %s", strNodeName.c_str()); solve(gbkNodeName, NodeName); - zlog_info(zct,"gbkNodeName = %s", gbkNodeName); - string utfNodeName = GBKToUTF8(gbkNodeName); - zlog_info(zct,"NodeName = %s", NodeName); - zlog_info(zct,"whereCon = %s", whereCon); + zlog_info(zct, "gbkNodeName = %s", gbkNodeName); + std::string utfNodeName = GBKToUTF8(gbkNodeName); + zlog_info(zct, "NodeName = %s", NodeName); + zlog_info(zct, "whereCon = %s", whereCon); sprintf(uplCon, "dataNodeName = '%s' , MeasurementID = '%s',NodeWaveSend = '%s'", gbkNodeName, MeasurementID, nodeWaveSend); iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0); - string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon); + std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon); iRet = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); } void Uart::DealDataNodeInfo(const char *pData) { - zlog_info(zct,"recv remote zigbee module info"); + zlog_info(zct, "recv remote zigbee module info"); RecvData *pRecvData = (RecvData *)pData; char buf[32] = {0}; char chTemp = pRecvData->Data[0]; //设备状态标志 1 byte @@ -565,7 +568,7 @@ void Uart::DealDataNodeInfo(const char *pData) { unsigned char shortAddr[2] = {0x00}; memcpy(shortAddr, (unsigned char *)&pRecvData->Data[46], 2); modify_DistAddr(shortAddr); //修改目标地址 - string strTime = GetLocalTimeWithMs(); + std::string strTime = GetLocalTimeWithMs(); memset(buf, 0, 32); sprintf(buf, "%02x%02x", pRecvData->Data[48], pRecvData->Data[49]); // Zigbee 目标地址 2 byte @@ -768,19 +771,19 @@ void Uart::DealDataNodeInfo(const char *pData) { // 传感器发来的数据包中的表示设备信息的数据转化为json格式后,通过调用data_publish将数据传给mqttclient : Topic:wireless/cmd/60294D203717 data_publish(strCmd26.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str()); - zlog_info(zct,"remote wireless sensor device info AccFlag : %d EquipSta : %d BpNo : %s ConfigFlag : %d EnvelopeBandPass : %s FaultFrequency : %s FeatureInterVal : %u FirstPowerTime : %s HardVersion : %s InitFlag : %d SamplingRate : %d range : %d SerialNo : %s\ + zlog_info(zct, "remote wireless sensor device info AccFlag : %d EquipSta : %d BpNo : %s ConfigFlag : %d EnvelopeBandPass : %s FaultFrequency : %s FeatureInterVal : %u FirstPowerTime : %s HardVersion : %s InitFlag : %d SamplingRate : %d range : %d SerialNo : %s\ SoftVersion : %s StartBrands : %s StopBrands : %s TemBotFlag : %d TemTopFlag : %d WaveInterVal : %d ZigbeeChannel : %d ZigbeeDesAddr : %s ZigbeeFlag : %d ZigbeeLongAddr : %s panid : %s ZigbeeShortAddr : %s Configdate : %s vintegralfilterfrequency : %d RSSI : %d ", - dataNodeInfo.AccFlag, dataNodeInfo.EquipSta, dataNodeInfo.BpNo.c_str(), dataNodeInfo.ConfigFlag, dataNodeInfo.EnvelopeBandPass.c_str(), dataNodeInfo.FaultFrequency.c_str(), dataNodeInfo.FeatureInterVal, dataNodeInfo.FirstPowerTime.c_str(), - dataNodeInfo.HardVersion.c_str(), dataNodeInfo.InitFlag, dataNodeInfo.SamplingRate, dataNodeInfo.Range, dataNodeInfo.SerialNo.c_str(), dataNodeInfo.SoftVersion.c_str(), dataNodeInfo.StartBrands.c_str(), dataNodeInfo.StopBrands.c_str(), dataNodeInfo.TemBotFlag, - dataNodeInfo.TemTopFlag, dataNodeInfo.WaveInterVal, dataNodeInfo.ZigbeeChannel, dataNodeInfo.ZigbeeDesAddr.c_str(), dataNodeInfo.ZigbeeFlag, dataNodeInfo.ZigbeeLongAddr.c_str(), dataNodeInfo.ZigbeePanId.c_str(), dataNodeInfo.ZigbeeShortAddr.c_str(), - dataNodeInfo.ConfigDate.c_str(), dataNodeInfo.VIntegralFilterFrequency, dataNodeInfo.RSSI); + dataNodeInfo.AccFlag, dataNodeInfo.EquipSta, dataNodeInfo.BpNo.c_str(), dataNodeInfo.ConfigFlag, dataNodeInfo.EnvelopeBandPass.c_str(), dataNodeInfo.FaultFrequency.c_str(), dataNodeInfo.FeatureInterVal, dataNodeInfo.FirstPowerTime.c_str(), + dataNodeInfo.HardVersion.c_str(), dataNodeInfo.InitFlag, dataNodeInfo.SamplingRate, dataNodeInfo.Range, dataNodeInfo.SerialNo.c_str(), dataNodeInfo.SoftVersion.c_str(), dataNodeInfo.StartBrands.c_str(), dataNodeInfo.StopBrands.c_str(), dataNodeInfo.TemBotFlag, + dataNodeInfo.TemTopFlag, dataNodeInfo.WaveInterVal, dataNodeInfo.ZigbeeChannel, dataNodeInfo.ZigbeeDesAddr.c_str(), dataNodeInfo.ZigbeeFlag, dataNodeInfo.ZigbeeLongAddr.c_str(), dataNodeInfo.ZigbeePanId.c_str(), dataNodeInfo.ZigbeeShortAddr.c_str(), + dataNodeInfo.ConfigDate.c_str(), dataNodeInfo.VIntegralFilterFrequency, dataNodeInfo.RSSI); if (g_mapCompress.find(dataNodeInfo.ZigbeeShortAddr) == g_mapCompress.end()) { compressWaveChannel tempchannel; g_mapCompress.insert(std::make_pair(dataNodeInfo.ZigbeeShortAddr, tempchannel)); - zlog_info(zct,"new Node,size = %d", g_mapCompress.size()); + zlog_info(zct, "new Node,size = %d", g_mapCompress.size()); } - zlog_info(zct,"DealDataNodeInfo %s ", dataNodeInfo.ZigbeeShortAddr.c_str()); + zlog_info(zct, "DealDataNodeInfo %s ", dataNodeInfo.ZigbeeShortAddr.c_str()); } void Uart::ZigbeeParameterConfig() { @@ -791,18 +794,18 @@ void Uart::ZigbeeParameterConfig() { mssleep(100000); } - zlog_info(zct,"strPanId : %s", strPanId.c_str()); - zlog_info(zct,"MacAddr_G : %s", GlobalConfig::MacAddr_G.c_str()); + zlog_info(zct, "strPanId : %s", strPanId.c_str()); + zlog_info(zct, "MacAddr_G : %s", GlobalConfig::MacAddr_G.c_str()); std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel"); unsigned short Chan = (unsigned short)strtol(strchan.c_str(), NULL, 10); - zlog_info(zct,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u", Chan); - zlog_info(zct,"ZigbeeInfo_G.Channel=%d", GlobalConfig::ZigbeeInfo_G.Channel); + zlog_info(zct, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u", Chan); + zlog_info(zct, "ZigbeeInfo_G.Channel=%d", GlobalConfig::ZigbeeInfo_G.Channel); if (Chan > 10 && Chan < 27) { WriteChanl2Zigbee(Chan); mssleep(100000); } - zlog_info(zct,"PanID1 = %s,strPanId = %s", GlobalConfig::ZigbeeInfo_G.PanID.c_str(), strPanId.c_str()); + zlog_info(zct, "PanID1 = %s,strPanId = %s", GlobalConfig::ZigbeeInfo_G.PanID.c_str(), strPanId.c_str()); long lShortAddr = strtol(strPanId.c_str(), NULL, 16); unsigned short panid = lShortAddr & 0xffff; @@ -810,21 +813,21 @@ void Uart::ZigbeeParameterConfig() { WritePanId2Zigbee(panid); mssleep(100000); - zlog_info(zct,"ZigbeeInfo_G.MyAddr=%s", GlobalConfig::ZigbeeInfo_G.MyAddr.c_str()); + zlog_info(zct, "ZigbeeInfo_G.MyAddr=%s", GlobalConfig::ZigbeeInfo_G.MyAddr.c_str()); } int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { - string strTime = GetLocalTimeWithMs(); + std::string strTime = GetLocalTimeWithMs(); char head1[] = {0xAB, 0xBC, 0xCD}; char head2[] = {0xDE, 0xDF, 0xEF}; int lastSize = 0; char UartRecvBuf[BUF_LENGTH * 15] = {0x00}; char RecvBuf[200] = {0x00}; if (mlastSize > 0) { - zlog_info(zct,"mlastSize = %d", mlastSize); + zlog_info(zct, "mlastSize = %d", mlastSize); memcpy(UartRecvBuf, mUartRecvTmpBuf, mlastSize); for (int i = 0; i < mlastSize; i++) { - zlog_info(zct,"%02x ", UartRecvBuf[i]); + zlog_info(zct, "%02x ", UartRecvBuf[i]); } memset(mUartRecvTmpBuf, 0x00, sizeof(mUartRecvTmpBuf)); } @@ -849,13 +852,13 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && (!bUpdatePre && !bUpdateconfig)) { mPackgeIndex = UartRecvBuf[i + 6] & 0xFF; } else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && (!bUpdatePre && !bUpdateconfig) && command != 2) { - zlog_error(zct,"mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); + zlog_error(zct, "mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); continue; } else if ((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && (!bUpdatePre && !bUpdateconfig) && command != 2) { m_TimeStamp = 0; - zlog_error(zct,"mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); + zlog_error(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); mPackgeIndex = -1; print_error("mPackgeIndex error ShortAddr :%s \n", strShortAddr.c_str()); @@ -865,7 +868,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff); strcat(tmp2, tmp); } - zlog_error(zct,"error str = %s", tmp2); + zlog_error(zct, "error str = %s", tmp2); GlobalConfig::Zigbee_G.MyAddr = 0x8888; tcflush(fd, TCIOFLUSH); sleep(1); @@ -880,11 +883,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { } if (command == 32) { - zlog_info(zct,"bUpdatepackge command = %d ShortAddr :%s", command, strShortAddr.c_str()); + zlog_info(zct, "bUpdatepackge command = %d ShortAddr :%s", command, strShortAddr.c_str()); memcpy(RecvBuf, (char *)&UartRecvBuf[i], 12); if (!CheckCrc(RecvBuf, 11)) { - zlog_info(zct,"CheckCrc error command 20 "); + zlog_info(zct, "CheckCrc error command 20 "); mPackgeIndex = -1; GlobalConfig::Zigbee_G.MyAddr = 0x8888; tcflush(fd, TCIOFLUSH); @@ -905,7 +908,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { if (!CheckCrc(&UartRecvBuf[i], 99)) { m_TimeStamp = 0; mPackgeIndex = -1; - zlog_info(zct,"CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command); + zlog_info(zct, "CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command); print_error("CheckCrc error ShortAddr :%s \n", strShortAddr.c_str()); char tmp[10] = {0x00}; char tmp2[10] = {0x00}; @@ -913,7 +916,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff); strcat(tmp2, tmp); } - zlog_error(zct,"error str = %s", tmp2); + zlog_error(zct, "error str = %s", tmp2); GlobalConfig::Zigbee_G.MyAddr = 0x8888; tcflush(fd, TCIOFLUSH); sleep(1); @@ -946,19 +949,19 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { char RecvBuf[100] = {0x00}; memcpy(RecvBuf, &UartRecvBuf[i], 100); if (!CheckCrc(RecvBuf, 99)) { - zlog_info(zct,"CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command); + zlog_info(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command); break; } DealRecvData(RecvBuf); } else if (bUpdate && !bUpdateconfig && (command == 1 || command == 2 || command == 6 || command == 7)) { - zlog_info(zct,"m_strDestShortAddr = %s,strShortAddr = %s,waittime = %d", m_strDestShortAddr.c_str(), strShortAddr.c_str(), waittime); + zlog_info(zct, "m_strDestShortAddr = %s,strShortAddr = %s,waittime = %d", m_strDestShortAddr.c_str(), strShortAddr.c_str(), waittime); { char RecvBuf[100] = {0x00}; memcpy(RecvBuf, &UartRecvBuf[i], 100); DealRecvData(RecvBuf); - zlog_info(zct,"Online = %s,command = %d", strShortAddr.c_str(), command); + zlog_info(zct, "Online = %s,command = %d", strShortAddr.c_str(), command); waittime = 0; bUpdate = false; bUpdatePre = false; @@ -969,9 +972,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { } } else if (command == 34 && bUpdateconfig) { - zlog_info(zct,"bUpdateconfig command = %d ShortAddr :%s", command, strShortAddr.c_str()); + zlog_info(zct, "bUpdateconfig command = %d ShortAddr :%s", command, strShortAddr.c_str()); memset(RecvBuf, 0x00, sizeof(RecvBuf)); - zlog_info(zct,"bUpdateconfig ShortAddr :%s", strShortAddr.c_str()); + zlog_info(zct, "bUpdateconfig ShortAddr :%s", strShortAddr.c_str()); m_TimeStamp = 0; { @@ -1004,7 +1007,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { if (!strcmp(signalNode, "00") || !strcmp(signalNode, "0")) { char errorInfo[100] = {0x00}; sprintf(errorInfo, "未检测到信号!%s", signalNode); - zlog_error(zct,errorInfo); + zlog_error(zct, errorInfo); } else { char whereCon[1024] = {0}; char updateSql[1024] = {0}; @@ -1041,12 +1044,12 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { char buf[8] = {0x00}; sprintf(buf, "%02d", UartRecvBuf[i + 3] & 0xFF); int command = atoi(buf); - zlog_info(zct,"command = %d", command); + zlog_info(zct, "command = %d", command); if (command == 209) { UpdateZigbeeInfo(&UartRecvBuf[i]); } else if (command == 220) { // DC bModifyAddr = false; - zlog_info(zct,"zigbeeShortAddr = %s , ret = %02d", m_strDestShortAddr.c_str(), UartRecvBuf[i + 6] & 0xFF); + zlog_info(zct, "zigbeeShortAddr = %s , ret = %02d", m_strDestShortAddr.c_str(), UartRecvBuf[i + 6] & 0xFF); if (UartRecvBuf[i + 6] & 0xFF != 00) { modify_LocalAddr(0x8888); } @@ -1062,7 +1065,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { char buf[8] = {0x00}; sprintf(buf, "%02d", UartRecvBuf[i + 3] & 0xFF); int command = atoi(buf); - zlog_info(zct,"command = %d", command); + zlog_info(zct, "command = %d", command); char tmp[16] = {0x00}; if (command == 209) { // D1 pTestRecv(command); @@ -1070,8 +1073,8 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { pTestRecv(command); } else if (command == 220) { // DC bModifyAddr = false; - zlog_info(zct,"%02x,%02x,%02x,%02x,%02x ", UartRecvBuf[i], UartRecvBuf[i + 1], UartRecvBuf[i + 2], UartRecvBuf[i + 3], UartRecvBuf[i + 4]); - zlog_info(zct,"zigbeeShortAddr = %s , ret = %02d", m_strDestShortAddr.c_str(), UartRecvBuf[i + 4] & 0xFF); + zlog_info(zct, "%02x,%02x,%02x,%02x,%02x ", UartRecvBuf[i], UartRecvBuf[i + 1], UartRecvBuf[i + 2], UartRecvBuf[i + 3], UartRecvBuf[i + 4]); + zlog_info(zct, "zigbeeShortAddr = %s , ret = %02d", m_strDestShortAddr.c_str(), UartRecvBuf[i + 4] & 0xFF); } else if (command == 218) { // DA char whereCon[1024] = {0}; diff --git a/uart/uart_cmd.cpp b/uart/uart_cmd.cpp index ac6b0f9..065fc9c 100644 --- a/uart/uart_cmd.cpp +++ b/uart/uart_cmd.cpp @@ -1,10 +1,13 @@ #include "uart.hpp" #include +extern zlog_category_t *zct; +extern zlog_category_t *zbt; + void Uart::UpdateZigbeeInfoCtrl() { char command[5] = {0xab, 0xbc, 0xcd, 0xd1, 0xaa}; WriteToUart(command, 5); - zlog_info(zct,"UpdateZigbeeInfoCtrl "); + zlog_info(zct, "UpdateZigbeeInfoCtrl "); } void Uart::modify_distaddr_info(unsigned short id, char *zigbee, unsigned char *distAddr) { @@ -114,7 +117,7 @@ void Uart::zigbee_reset(unsigned short pad, unsigned short type) { } void Uart::WriteChanl2Zigbee(unsigned char pad) { - zlog_info(zct,"WriteChanl2Zigbee : %d\n", pad); + zlog_info(zct, "WriteChanl2Zigbee : %d\n", pad); unsigned char pad1 = pad; unsigned short tmp; tmp = GlobalConfig::Zigbee_G.MyAddr; @@ -127,10 +130,10 @@ void Uart::WriteChanl2Zigbee(unsigned char pad) { } void Uart::WritePanId2Zigbee(unsigned short pad) { - zlog_info(zct,"WritePanId2Zigbee : %d", pad); + zlog_info(zct, "WritePanId2Zigbee : %d", pad); unsigned short pad1 = pad, tmp; tmp = GlobalConfig::Zigbee_G.MyAddr; - zlog_info(zct,"MyAddr : %d", GlobalConfig::Zigbee_G.MyAddr); + zlog_info(zct, "MyAddr : %d", GlobalConfig::Zigbee_G.MyAddr); swap((char *)&pad1); GlobalConfig::Zigbee_G.PanID = pad1; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); @@ -152,7 +155,7 @@ void Uart::WriteSpeed2Zigbee() { } void Uart::WriteTranTimeout2Zigbee(unsigned char Time) { - zlog_info(zct,"WriteTranTimeout2Zigbee : %d", Time); + zlog_info(zct, "WriteTranTimeout2Zigbee : %d", Time); unsigned short tmp = GlobalConfig::Zigbee_G.MyAddr; GlobalConfig::Zigbee_G.PowerLevel = 0x03; @@ -166,7 +169,7 @@ void Uart::WriteTranTimeout2Zigbee(unsigned char Time) { } void Uart::WriteShortAddr2Zigbee(unsigned short pad) { - zlog_info(zct,"WriteShortAddr2Zigbee : %4x", (unsigned short)pad); + zlog_info(zct, "WriteShortAddr2Zigbee : %4x", (unsigned short)pad); unsigned short pad1 = pad, tmp; tmp = GlobalConfig::Zigbee_G.MyAddr; @@ -180,7 +183,7 @@ void Uart::WriteShortAddr2Zigbee(unsigned short pad) { } void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad, unsigned char *pDestShortAddr) { - zlog_info(zct,"WriteShortAddr2Zigbee : %4x\n", (unsigned short)pad); + zlog_info(zct, "WriteShortAddr2Zigbee : %4x\n", (unsigned short)pad); unsigned short pad1 = pad, tmp; tmp = GlobalConfig::Zigbee_G.MyAddr; swap((char *)&pad1); @@ -190,7 +193,7 @@ void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad, unsigned char *pDe memcpy(&GlobalConfig::Zigbee_G.DstAddr, pDestShortAddr, 2); GlobalConfig::Zigbee_G.MyAddr = pad1; - zlog_info(zct,"DstAddr = %x\n", GlobalConfig::Zigbee_G.DstAddr); + zlog_info(zct, "DstAddr = %x\n", GlobalConfig::Zigbee_G.DstAddr); GlobalConfig::ZigbeeInfo_G.MyAddr = "9999"; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index fdbc52f..e7629de 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -7,10 +7,13 @@ #include #include +extern zlog_category_t *zct; +extern zlog_category_t *zbt; + std::vector g_VecWaveDataX; std::vector g_VecWaveDataY; std::vector g_VecWaveDataZ; -map g_mapCompress; +std::map g_mapCompress; void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) { char insertSql[1024] = {0}; @@ -26,24 +29,23 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { int nodeResend = 0, timing = 0; sprintf(buf, "%02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); if (flag == 1) { - zlog_info(zct,"DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag); + zlog_info(zct, "DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag); } if (bSendTimeStamp) //波形处理中 return; std::string strShortAddr = std::string(buf); - zlog_info(zct,"zigbeeShortAddr='%s'", strShortAddr.c_str()); + zlog_info(zct, "zigbeeShortAddr='%s'", strShortAddr.c_str()); char getLongAddr_sql[32] = {0}; //根据数据包中的传感器的短地址获取数据库中长地址(MAC),在下面判断该传感器是否存在,如果不存在则把数据包丢弃 sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", strShortAddr.c_str()); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " softVersion,dataNodeNo,MeasurementID,ProductNo ", getLongAddr_sql); if (vecResult.size() < 1) { - zlog_error(zct,"device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); - print_error("device info not found\n"); + zlog_error(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); return; } - zlog_info(zct,"--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str()); + zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str()); std::string strLongAddr = vecResult[1]; std::string strMeasurementID = vecResult[2]; @@ -56,7 +58,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { modify_distaddr_info(0x9999, "", pRecvData->ShortAddr); //临时参数配置 mssleep(10000); - zlog_info(zct,"Zigbee Signal !\n"); + zlog_info(zct, "Zigbee Signal !\n"); int Times = 0; mssleep(20000); while (Times < 3) { @@ -83,7 +85,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { } if (isUpdate || bUpdateconfig) { } else { - zlog_info(zct,"DealDataNodeFeature %02x%02x,localaddr %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], UINT16_HIGH(GlobalConfig::Zigbee_G.MyAddr), UINT16_LOW(GlobalConfig::Zigbee_G.MyAddr)); + zlog_info(zct, "DealDataNodeFeature %02x%02x,localaddr %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], UINT16_HIGH(GlobalConfig::Zigbee_G.MyAddr), UINT16_LOW(GlobalConfig::Zigbee_G.MyAddr)); // 进入传输原始数据状态,启动计数 60秒 GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; @@ -115,7 +117,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { packed_data |= (uint64_t)buffer[i] << (8 * (5 - i)); // 从高位开始组合 } // 输出结果 - printf("Resulting 48-bit integer: 0x%012llX\n", packed_data); + zlog_info(zct, "Resulting 48-bit integer: 0x%012llX\n", packed_data); // 提取 15 位的第一个数据 tempchannel.CountX = (packed_data >> 33) & 0x7FFF; // 提取最高的 15 位 @@ -127,8 +129,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { g_mapCompress[strShortAddr] = tempchannel; - zlog_info(zct,"count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ); - zlog_info(zct,"compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ); + zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ); + zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ); } else { memset(whereCon, 0x00, sizeof(whereCon)); memset(updateSql, 0x00, sizeof(updateSql)); @@ -218,7 +220,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (count > 0 || count2 > 0) { char logInfo[20] = {0x00}; sprintf(logInfo, "ShortAddr = %s,staticIndex = %d,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2); - zlog_info(zct,logInfo); + zlog_info(zct, logInfo); return; } memset(whereCon, 0x00, sizeof(whereCon)); @@ -228,7 +230,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { strTmp = "name = '" + std::string(szTableNameStatic) + "' and sql LIKE '%nodeResend%' "; int row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); - zlog_info(zct,"row1 = %d", row); + zlog_info(zct, "row1 = %d", row); if (row == 0) { memset(sztmp, 0x00, sizeof(sztmp)); sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameStatic); @@ -237,7 +239,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { strTmp = "name = '" + std::string(szTableNameData) + "' and sql LIKE '%nodeResend%' "; row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); - zlog_info(zct,"row2 = %d", row); + zlog_info(zct, "row2 = %d", row); if (row == 0) { memset(sztmp, 0x00, sizeof(sztmp)); sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameData); @@ -250,16 +252,16 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (atol(strStaticIndex.c_str()) - staticIndex > 100) { sqlite_db_ctrl::instance().Deletetable(szTableNameStatic); sqlite_db_ctrl::instance().Deletetable(szTableNameData); - zlog_info(zct,"staticIndexNOW = %d,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str()); + zlog_info(zct, "staticIndexNOW = %d,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str()); } - zlog_info(zct,"NowstaticIndex = %d,RecordStaticIndex = %d", staticIndex, atol(strStaticIndex.c_str())); + zlog_info(zct, "NowstaticIndex = %d,RecordStaticIndex = %d", staticIndex, atol(strStaticIndex.c_str())); if (staticIndex != atol(strStaticIndex.c_str() + 1) && strStaticIndex != "" && staticIndex < atol(strStaticIndex.c_str())) { sprintf(whereCon, "StaticIndex = %d order by StaticIndex desc LIMIT 0 , 1", atol(strStaticIndex.c_str())); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon); if (vecResult.size() > 0) { memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str()); - string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon); + std::string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon); long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60; char tmp[10] = {0x00}; sprintf(tmp, "%ld", nNowTimetamp); @@ -267,7 +269,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { nodeResend = 1; } } - zlog_info(zct,"nowTimetamp = %s", nowTimetamp.c_str()); + zlog_info(zct, "nowTimetamp = %s", nowTimetamp.c_str()); // save dataStatic of 7 days char selectCon[128] = {0}; sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", (strMeasurementID + "-S").c_str()); @@ -277,17 +279,17 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (Count == -1) { sqlite_db_ctrl::instance().CreatedataStatictable(szTableName); } - zlog_info(zct,"strLongAddr = %s,strTime = %s", strLongAddr.c_str(), strTime.c_str()); + zlog_info(zct, "strLongAddr = %s,strTime = %s", strLongAddr.c_str(), strTime.c_str()); long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str()); - zlog_info(zct,"lTime = %d,OneWeek = %d", lTime, OneWeek); + zlog_info(zct, "lTime = %d,OneWeek = %d", lTime, OneWeek); - zlog_info(zct,"dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage); + zlog_info(zct, "dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage); sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %d, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '%d',timing = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex, nodeResend, flag, timing); sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str()); if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { - zlog_info(zct,"insert static data to sql"); + zlog_info(zct, "insert static data to sql"); char insertSql[1024] = {0}; sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%d,'%s','1',%d,'','%d','%d'", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend, flag, timing); @@ -306,7 +308,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { } else { memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-S").c_str(), strTime.c_str()); - zlog_info(zct,"update static data to sql"); + zlog_info(zct, "update static data to sql"); sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon); memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str()); @@ -393,23 +395,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { dataDymX.Amp5 = lowbit * n; memset(buf, 0, sizeof(buf)); - dataDymX.EnvelopEnergy = 0; - memset(buf, 0, sizeof(buf)); - dataDymX.Phase1 = 0; - memset(buf, 0, sizeof(buf)); - dataDymX.Phase2 = 0; - memset(buf, 0, sizeof(buf)); - memset(buf, 0, 8); - dataDymX.Phase3 = 0; - memset(buf, 0, sizeof(buf)); sprintf(buf, "%02x%02x", pRecvData->Data[35], pRecvData->Data[34]); @@ -442,8 +435,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str()); sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon); } - zlog_info(zct,"x:%s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, - dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str()); + zlog_info(zct, "x:%s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, + dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str()); Json::Value valNodeData; Json::Value valNodeFeature; @@ -539,23 +532,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { dataDymY.Amp5 = lowbit * n; memset(buf, 0, sizeof(buf)); - dataDymY.EnvelopEnergy = 0; - memset(buf, 0, sizeof(buf)); - dataDymY.Phase1 = 0; - memset(buf, 0, sizeof(buf)); - dataDymY.Phase2 = 0; - memset(buf, 0, sizeof(buf)); - dataDymY.Phase3 = 0; - memset(buf, 0, sizeof(buf)); - dataDymY.Phase4 = 0; memset(whereCon, 0, 1024); @@ -584,8 +568,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str()); sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon); } - zlog_info(zct,"y: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk, - dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, nowTimetamp.c_str()); + zlog_info(zct, "y: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk, + dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, nowTimetamp.c_str()); valNodeFeature["dataNodeNo"] = strMeasurementID; valNodeFeature["ChannelId"] = strMeasurementID + "-Y"; @@ -745,8 +729,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str()); sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon); } - zlog_info(zct,"Z: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk, - dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, nowTimetamp.c_str()); + zlog_info(zct, "Z: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strLongAddr.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk, + dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, nowTimetamp.c_str()); memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str()); @@ -776,7 +760,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str()); std::string strBattery = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "batteryPower", whereCon); - vector vBattery; + std::vector vBattery; vBattery.push_back("0"); vBattery.push_back("0"); if (strBattery.length() > 0) { @@ -808,7 +792,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { std::string strstatisticData = featureValue.write(root); int iRet = data_publish(strstatisticData.c_str(), GlobalConfig::Topic_G.mPubData.c_str()); - zlog_info(zct,"dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d", strLongAddr.c_str(), nowTimetamp.c_str(), iRet); + zlog_info(zct, "dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d", strLongAddr.c_str(), nowTimetamp.c_str(), iRet); if (iRet != 0) { char updateSql[1024] = {0}; memset(whereCon, 0, 64); @@ -819,14 +803,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { } //综上代码,把静态数据,x y z轴的特征值存放到sql数据库中(如果数据原来不存在,则插入新数据;如果存在,则更新数据) - zlog_info(zct,"Dip : %d TemBot : %f TemBot : %f Voltage : %d", dataStatic.Dip, dataStatic.TemBot, dataStatic.TemTop, dataStatic.Voltage); + zlog_info(zct, "Dip : %d TemBot : %f TemBot : %f Voltage : %d", dataStatic.Dip, dataStatic.TemBot, dataStatic.TemTop, dataStatic.Voltage); memset(selectCon, 0x00, sizeof(selectCon)); sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1"); strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon); if (flag == 1) { - zlog_info(zct,"DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); + zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); } } @@ -927,18 +911,17 @@ std::vector Uart::DealData(int iChannel, float coe, int sampleRate, int A compress = g_mapCompress[strShortAddr].compressChannelZ; count = g_mapCompress[strShortAddr].CountZ; } - zlog_info(zct,"len = %d,data = %02x,iChannel = %d,compress = %d,count = %d", j, data[0], iChannel, compress, count); + zlog_info(zct, "len = %d,data = %02x,iChannel = %d,compress = %d,count = %d", j, data[0], iChannel, compress, count); if (j * 92 < count) return vecData; if (compress) { - zlog_info(zct,"iChannel = %d,compress = %d", iChannel, compress); + zlog_info(zct, "iChannel = %d,compress = %d", iChannel, compress); int r = lzo1x_decompress(data, count, outdata, &new_len, NULL); - zlog_info(zct,"lzo1x_decompress end"); + zlog_info(zct, "lzo1x_decompress end"); if (r == LZO_E_OK) { - zlog_info(zct,"iChannel = %d ,ShortAddr = %s decompressed %lu bytes back into %lu bytes", iChannel, strShortAddr.c_str(), (unsigned long)j * 92, (unsigned long)new_len); + zlog_info(zct, "iChannel = %d ,ShortAddr = %s decompressed %lu bytes back into %lu bytes", iChannel, strShortAddr.c_str(), (unsigned long)j * 92, (unsigned long)new_len); } else { - - zlog_error(zct,"internal error - decompression failed: %d,channel = %d,ShortAddr = %s", r, iChannel, strShortAddr.c_str()); + zlog_error(zct, "internal error - decompression failed: %d,channel = %d,ShortAddr = %s", r, iChannel, strShortAddr.c_str()); return vecData; } memcpy(dealdata, outdata, new_len); @@ -960,15 +943,15 @@ std::vector Uart::DealData(int iChannel, float coe, int sampleRate, int A vecData.push_back(fTemp); if (strProduct == "01") { if (vecData.size() == sampleRate * ACCSampleTime && iChannel == 3) { //过滤数据包结尾空数据 - zlog_info(zct,"%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); + zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); break; } if (vecData.size() == sampleRate * ACCSampleTime && iChannel == 4) { //过滤数据包结尾空数据 - zlog_info(zct,"%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); + zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); break; } if (vecData.size() == sampleRate * ACCSampleTime && iChannel == 5) { //过滤数据包结尾空数据 - zlog_info(zct,"%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); + zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime); break; } @@ -986,6 +969,7 @@ std::vector Uart::DealData(int iChannel, float coe, int sampleRate, int A } return vecData; } + void Uart::DealWave() { std::string strShortAddr = ""; std::string strShortAddrTemp; @@ -1025,7 +1009,7 @@ void Uart::DealWave() { sprintf(getrange, "%s", ran.c_str()); n = (int)strtol(getrange, NULL, 32); if (m_waveCountX > 0 || VecWaveDataX.size() > 0) { - zlog_info(zct,"m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size()); + zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size()); coe = Calcoe(n, 3, strProduct, range); vecData = DealData(3, coe, sampleRate, ACCSampleTime, strProduct); WriteDatFile(sampleRate, strMeasurementID, 3, vecData); @@ -1034,7 +1018,7 @@ void Uart::DealWave() { VecWaveDataX.clear(); } if (m_waveCountY > 0 || VecWaveDataY.size() > 0) { - zlog_info(zct,"m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size()); + zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size()); coe = Calcoe(n, 4, strProduct, range); vecData = DealData(4, coe, sampleRate, ACCSampleTime, strProduct); WriteDatFile(sampleRate, strMeasurementID, 4, vecData); @@ -1043,7 +1027,7 @@ void Uart::DealWave() { VecWaveDataY.clear(); } if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) { - zlog_info(zct,"m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size()); + zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size()); coe = Calcoe(n, 5, strProduct, range); vecData = DealData(5, coe, sampleRate, ACCSampleTime, strProduct); WriteDatFile(sampleRate, strMeasurementID, 5, vecData); @@ -1059,6 +1043,7 @@ void Uart::DealWave() { wave_trans_ = false; } } + float Uart::Calcoe(int ran, int iChannel, string &product, int range) { float coe = 0.0; if (product == "01") { @@ -1085,12 +1070,12 @@ float Uart::Calcoe(int ran, int iChannel, string &product, int range) { coe = 0.00048828125; } if (iChannel == 5) { - - coe = 0.00172607421875; + coe = 0.00172607421875; } } return coe; } + void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, std::vector &vecData) { if (vecData.size() <= 0) return; std::string strFileName = ""; @@ -1120,7 +1105,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, FILE *fp = fopen(strFileName.c_str(), "w"); fwrite(localtimestamp, sizeof(localtimestamp), 1, fp); - zlog_info(zct,"fopen FIle vecData.size : %d", vecData.size()); + zlog_info(zct, "fopen FIle vecData.size : %d", vecData.size()); float mean = Calculation::mean(vecData); float frTemp; char buf[33] = {0x00}; @@ -1171,7 +1156,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, sprintf(updateSql, "waveName='%s',timeStamp='%s'", strFileName_Record.c_str(), nowTimetamp.c_str()); memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", strChannelID.c_str(), strTime.c_str()); - zlog_info(zct,"update static data to sql"); + zlog_info(zct, "update static data to sql"); sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon); } //传感器发来的数据包中的表示设备信息的数据转化为json格式后,通过调用data_publish将数据传给mqttclient : Topic:wireless/cmd/60294D203717 @@ -1183,13 +1168,13 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, char tmpWhere[128] = {0x00}; sprintf(tmpWhere, "channelID = '%s' and sendMsg = 0 ", strChannelID.c_str()); int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere); - zlog_error(zct,"save channlID %s dat count = %d", strChannelID.c_str(), count); + zlog_error(zct, "save channlID %s dat count = %d", strChannelID.c_str(), count); if (count <= 12) { sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str()); sprintf(updateSql, "SendMsg = 0 "); sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon); - zlog_error(zct,"send failed,filename %s,iRet = %d", strFileName.c_str(), iRet); - string strFileName_failed = strFileName + "_" + nowTimetamp; + zlog_error(zct, "send failed,filename %s,iRet = %d", strFileName.c_str(), iRet); + std::string strFileName_failed = strFileName + "_" + nowTimetamp; char tmpCmd[128] = {0x00}; sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str()); system(tmpCmd); @@ -1208,11 +1193,11 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, sprintf(updateSql, "sendMsg = 0"); int iRet2 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon); - string strFileName_failed = strFileName + "_" + nowTimetamp; + std::string strFileName_failed = strFileName + "_" + nowTimetamp; char tmpCmd[128] = {0x00}; sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str()); system(tmpCmd); - zlog_info(zct,"cp dat file %s \n", tmpCmd); + zlog_info(zct, "cp dat file %s \n", tmpCmd); memset(tmpWhere, 0x00, sizeof(tmpWhere)); sprintf(tmpWhere, " channelID = '%s' and sendMsg = 0 ", strChannelID.c_str()); @@ -1221,11 +1206,11 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, memset(tmpCmd, 0x00, sizeof(tmpCmd)); sprintf(tmpCmd, "rm %s ", vecRet[1].c_str()); system(tmpCmd); - zlog_info(zct,"rm dat file %s \n", tmpCmd); + zlog_info(zct, "rm dat file %s \n", tmpCmd); } } else { - zlog_info(zct,"send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size()); + zlog_info(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size()); } #ifdef G2UL_GATEWAY //存储6条波形数据 char whereCon[1024] = {0x00}; @@ -1233,7 +1218,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, char tmpWhere[128] = {0x00}; sprintf(tmpWhere, "channelID = '%s' and save = 1 ", strChannelID.c_str()); int count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", tmpWhere); - zlog_info(zct,"save channlID %s dat count = %d\n", strChannelID.c_str(), count); + zlog_info(zct, "save channlID %s dat count = %d\n", strChannelID.c_str(), count); if (count <= 5) { sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", strChannelID.c_str(), nowTimetamp.c_str()); sprintf(updateSql, "save = 1 "); @@ -1269,11 +1254,11 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, memset(tmpCmd, 0x00, sizeof(tmpCmd)); sprintf(tmpCmd, "rm %s ", (vecRet[1] + "_save").c_str()); system(tmpCmd); - zlog_info(zct,"rm dat file %s ", tmpCmd); + zlog_info(zct, "rm dat file %s ", tmpCmd); } #endif - zlog_info(zct,"write data to filename %s", strFileName.c_str()); + zlog_info(zct, "write data to filename %s", strFileName.c_str()); std::vector().swap(vecData); sleep(1); } \ No newline at end of file diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index eb164d9..75edfc9 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -7,6 +7,9 @@ #include #include +extern zlog_category_t* zct; +extern zlog_category_t* zbt; + void Uart::openSwitch() { char buffer[100] = {0x00}; int len; @@ -46,7 +49,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) { if (vecResult.size() < 1) { return false; } - zlog_info(zct,"hardversion %s,softversion %s", vecResult[0].c_str(), vecResult[1].c_str()); + zlog_info(zct, "hardversion %s,softversion %s", vecResult[0].c_str(), vecResult[1].c_str()); int thisindex = -1; int flag = -1; for (int j = 0; j < vecDataNodeUpdate.size(); j++) { @@ -67,12 +70,12 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) { if (thisindex < 0) return false; - zlog_info(zct,"thisindex = %d", thisindex); + zlog_info(zct, "thisindex = %d", thisindex); FILE* pFile = NULL; int thisSize = 0; DataNodeUpdateFile = "/opt/DataNode/" + strFileName; - zlog_info(zct,"strFileName = %s", DataNodeUpdateFile.c_str()); + zlog_info(zct, "strFileName = %s", DataNodeUpdateFile.c_str()); pFile = fopen(DataNodeUpdateFile.c_str(), "rb"); if (pFile == NULL) { return false; @@ -85,7 +88,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) { unsigned char Data[12] = {0x00}; unsigned char size[4] = {0x00}; - zlog_info(zct,"thisSize = %d", thisSize); + zlog_info(zct, "thisSize = %d", thisSize); //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 升级包大小[4byte] CRC校验[1byte] Data[0] = 0xAA; Data[1] = 0x55; @@ -108,25 +111,25 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) { WriteToUart((const char*)Data, 12); int iRet = CheckZigbeeACK(); if (iRet == 0) { - zlog_info(zct,"Packge ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } else { - zzlog_error(zct,zct,"Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zzlog_error(zct, zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } - string strTime = GetLocalTimeWithMs(); - zlog_info(zct,"ReadUpdatePackge strTime = %s", strTime.c_str()); + std::string strTime = GetLocalTimeWithMs(); + zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str()); return true; } + void Uart::UpdateWirelessNode(unsigned short shortAdd) { - string strTime = GetLocalTimeWithMs(); - zlog_info(zct,"UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x", strTime.c_str(), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + std::string strTime = GetLocalTimeWithMs(); + zlog_info(zct, "UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x", strTime.c_str(), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); FILE* pFile = NULL; int thisSize = 0; char* buffer = NULL; int resendCount = 0; pFile = fopen(DataNodeUpdateFile.c_str(), "rb"); - if (pFile != NULL) - { + if (pFile != NULL) { while (fgetc(pFile) != EOF) { ++thisSize; } @@ -139,7 +142,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) { int lastSize = thisSize % 92; unsigned char UpdateData[100] = {0x00}; //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte] - zlog_info(zct,"Start Update!!! file Size = %d", thisSize); + zlog_info(zct, "Start Update!!! file Size = %d", thisSize); unsigned char tmp = 0x00; gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0); mssleep(1000); @@ -172,10 +175,10 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) { if (time >= 150) { resendCount++; if (resendCount < 5) { - zlog_error(zct," RESEND gpio_read failed shortAdd %x %x,error index %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd), j); + zlog_error(zct, " RESEND gpio_read failed shortAdd %x %x,error index %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd), j); } else { - zlog_error(zct,"gpio_read failed shortAdd %x %x,error index %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd), j); - zlog_error(zct,"gpio_read failed \n"); + zlog_error(zct, "gpio_read failed shortAdd %x %x,error index %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd), j); + zlog_error(zct, "gpio_read failed \n"); GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; bUpdate = false; @@ -184,9 +187,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) { } gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0); mssleep(2000); - memset(UpdateData, 0x00, sizeof(UpdateData)); - mssleep(5000); } if (gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1); @@ -221,8 +222,8 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) { time += 1; } while (time < 150); if (time >= 150) { - zlog_error(zct,"gpio_read failed shortAdd %x %x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); - zlog_error(zct,"gpio_read failed "); + zlog_error(zct, "gpio_read failed shortAdd %x %x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + zlog_error(zct, "gpio_read failed "); GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; bUpdate = false; @@ -230,9 +231,9 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) { } memset(UpdateData, 0x00, sizeof(UpdateData)); } - zlog_info(zct,"Update END!!! file Size = %d", thisSize); - }else{ - zlog_error(zct,"open file failed "); + zlog_info(zct, "Update END!!! file Size = %d", thisSize); + } else { + zlog_error(zct, "open file failed "); } endUpdate: resendCount = 0; @@ -249,7 +250,7 @@ endUpdate: GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; - zlog_info(zct,"UpdateWirelessNode end"); + zlog_info(zct, "UpdateWirelessNode end"); } int Uart::UpdateConfig(unsigned char* pDestShortAddr) { @@ -260,7 +261,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { vec_t vecResultNode = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon); if (vecResultNode.size() <= 0) return -1; if (vecResultNode[41] == "0") { - zlog_info(zct,"UpdateConfig"); + zlog_info(zct, "UpdateConfig"); bUpdateconfig = true; unsigned short localAddr = 0x9999; GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS; @@ -276,7 +277,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { sprintf(selCon, "featureInterVal,waveInterVal,range,samplingRate,ACCSampleTime,startBrands,stopBrands,\ envelopeBandPass,faultFrequency,timeStamp,viff,ZigbeePower,ZigbeeRetry,MeasurementID,NodeWaveSend"); vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selCon, whereCon); - zlog_info(zct,"vecResult size = %d", vecResult.size()); + zlog_info(zct, "vecResult size = %d", vecResult.size()); if (vecResult.size() < 1) { return -1; } @@ -326,7 +327,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { int x = atoi(vecResult[2].c_str()); UpdateData[21] = BUILD_UINT2(x, y); UpdateData[22] = atoi(vecResult[4].c_str()) & 0xFF; - zlog_info(zct,"vecResult size = %s==%s==%s==%s=%s\n", vecResult[5].c_str(), vecResult[6].c_str(), vecResult[7].c_str(), vecResult[8].c_str(), vecResult[14].c_str()); + zlog_info(zct, "vecResult size = %s==%s==%s==%s=%s\n", vecResult[5].c_str(), vecResult[6].c_str(), vecResult[7].c_str(), vecResult[8].c_str(), vecResult[14].c_str()); vector vStart, vStop, vEnvelopeBandPass, vfaultFrequency, vNodeWaveSend; boost::split(vStart, vecResult[5], boost::is_any_of(","), boost::token_compress_on); boost::split(vStop, vecResult[6], boost::is_any_of(","), boost::token_compress_on); @@ -428,9 +429,9 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { WriteToUart((const char*)UpdateData, 100); int iRet = CheckZigbeeACK(); if (iRet == 0) { - zlog_info(zct,"updataconfig ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_info(zct, "updataconfig ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } else { - zlog_error(zct,"updataconfig ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_error(zct, "updataconfig ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } return 0; } else if (vecResultNode[41] == "-1") { @@ -438,7 +439,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { unsigned short localAddr = 0x9999; GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; - string strName = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon); + std::string strName = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon); unsigned char UpdateData[100] = {0x00}; //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte] @@ -471,17 +472,19 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) { WriteToUart((const char*)UpdateData, 100); int iRet = CheckZigbeeACK(); if (iRet == 0) { - zlog_info(zct,"updataname ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_info(zct, "updataname ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } else { - zlog_error(zct,"updataname ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_error(zct, "updataname ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } return 0; } - + return 0; } else { + zlog_error(zct, "invalid vecResultNode[41]:%c", vecResultNode[41]); return -1; } } + int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /*,int nodewaveindex,int nodetime,int nodeindex*/) { if (modifyaddr) modify_DistAddr(pDestShortAddr); mssleep(10000); @@ -489,8 +492,8 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr / char localtimestamp[32] = {0x00}; int millisecond = 0; - string rtcTime = GetRTC(localtimestamp, millisecond); - zlog_info(zct,"ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d ", pDestShortAddr[0], pDestShortAddr[1], rtcTime.c_str(), localtimestamp, millisecond, bSendTimeStamp); + std::string rtcTime = GetRTC(localtimestamp, millisecond); + zlog_info(zct, "ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d ", pDestShortAddr[0], pDestShortAddr[1], rtcTime.c_str(), localtimestamp, millisecond, bSendTimeStamp); unsigned char UpdateData[100] = {0x00}; UpdateData[0] = 0xAA; @@ -516,9 +519,9 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr / WriteToUart((const char*)UpdateData, 100); int iRet = CheckZigbeeACK(); if (iRet == 0) { - zlog_info(zct,"NodeTime ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_info(zct, "NodeTime ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } else { - zlog_error(zct,"NodeTime ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); + zlog_error(zct, "NodeTime ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); } return iRet; } diff --git a/utility/calculation.cpp b/utility/calculation.cpp index 87bd7e5..cbd5a6a 100644 --- a/utility/calculation.cpp +++ b/utility/calculation.cpp @@ -48,6 +48,7 @@ void Calculation::iFFT(int n, fftw_complex *in, fftw_complex *out) { fftw_destroy_plan(p); fftw_cleanup(); } + void Calculation::_iFFT(std::vector &vecrealData, std::vector &vecimageData, std::vector &veciFFTData) { fftw_complex *inFFt, *outFFt; int N = vecrealData.size(); @@ -67,6 +68,7 @@ void Calculation::_iFFT(std::vector &vecrealData, std::vector &vec fftw_free(inFFt); fftw_free(outFFt); } + void Calculation::_FFT(std::vector &vecData, std::vector &vecFFTrealData, std::vector &vecFFTimageData) { fftw_complex *inHilFFt, *outHilFFt; inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size()); diff --git a/utility/search_dev.cpp b/utility/search_dev.cpp index 6e87608..78af5ba 100644 --- a/utility/search_dev.cpp +++ b/utility/search_dev.cpp @@ -2,9 +2,11 @@ #include #include #include +#include #include #include +extern zlog_category_t *zct; static const char* MULTICAST_HOST_NAME1 = "224.0.0.1"; //组播接收平台搜索信号地址 static const int MULTICAST_PORT_RECV1 = 7301; //组播接收端口 @@ -26,15 +28,13 @@ void SearchDev::Init() { } } -void SearchDev::GwRouteInit() { - -} +void SearchDev::GwRouteInit() {} void SearchDev::HandleSend_1(const char* pMsg, const boost::system::error_code& pEc) { if (pEc) { - zlog_info(zct,"send udp error 7302"); + zlog_info(zct, "send udp error 7302"); } else { - zlog_info(zct,"send udp ok 7302"); + zlog_info(zct, "send udp ok 7302"); } } @@ -48,7 +48,7 @@ void SearchDev::MultiCastRecv_1() { void SearchDev::HandleRecv_1(const boost::system::error_code& pEc, size_t pBytesRecv) { if (!pEc) { - zlog_info(zct,"mRecvBuf1 : %s", mRecvBuf1); + zlog_info(zct, "mRecvBuf1 : %s", mRecvBuf1); std::string data = std::string(mRecvBuf1); Json::Value jsData; Json::Reader recvReader; @@ -65,7 +65,7 @@ void SearchDev::HandleRecv_1(const boost::system::error_code& pEc, size_t pBytes jsData["status"] = "ACK"; jsData["DeviceType"] = "WirelessGateWay"; std::string strData = fw.write(jsData); - zlog_info(zct,"send info %s ip: %s\n", strData.c_str(), mRecvEP1.address().to_string().c_str()); + zlog_info(zct, "send info %s ip: %s\n", strData.c_str(), mRecvEP1.address().to_string().c_str()); ip::udp::endpoint remoteEP(ip::address::from_string(mRecvEP1.address().to_string()), MULTICAST_PORT_SEND); mSockRecv_1.async_send_to(boost::asio::buffer(strData), remoteEP, boost::bind(&SearchDev::HandleSend_1, this, "SockRecv_1_1", boost::asio::placeholders::error)); } @@ -73,7 +73,7 @@ void SearchDev::HandleRecv_1(const boost::system::error_code& pEc, size_t pBytes default: break; } } else { - zlog_error(zct,"parse error\n"); + zlog_error(zct, "parse error\n"); } MultiCastRecv_1(); } else { diff --git a/utility/secure.cpp b/utility/secure.cpp index 9389e32..24f519c 100644 --- a/utility/secure.cpp +++ b/utility/secure.cpp @@ -1,3 +1,4 @@ +#include "secure.hpp" #include #include #include @@ -5,7 +6,7 @@ #include #include #include -#include "SH_Secure.hpp" + #define AES_ENCRYPT 2 #define AES_DECRYPT 0 diff --git a/utility/tcp_cgi.cpp b/utility/tcp_cgi.cpp index 1da39ac..4cef81a 100644 --- a/utility/tcp_cgi.cpp +++ b/utility/tcp_cgi.cpp @@ -1,8 +1,10 @@ #include "tcp_cgi.hpp" +#include +extern zlog_category_t *zct; +extern zlog_category_t *zbt; - -TcpCgi::TcpCgi() { zlog_info(zbt,"TcpCgi Init"); } +TcpCgi::TcpCgi() { zlog_info(zbt, "TcpCgi Init"); } void TcpCgi::startCgiServer() { int listenfd, connfd; @@ -12,7 +14,7 @@ void TcpCgi::startCgiServer() { char buff[40960]; int n; if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - zlog_info(zct,"create socket error: %s(errno: %d)", strerror(errno), errno); + zlog_error(zbt, "create socket error: %s(errno: %d)", strerror(errno), errno); return; } setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&mw_optval, sizeof(mw_optval)); @@ -23,23 +25,23 @@ void TcpCgi::startCgiServer() { servaddr.sin_port = htons(7305); if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { - zlog_info(zct,"bind socket error: %s(errno: %d)", strerror(errno), errno); + zlog_error(zbt, "bind socket error: %s(errno: %d)", strerror(errno), errno); return; } if (listen(listenfd, 10) == -1) { - zlog_info(zct,"listen socket error: %s(errno: %d)", strerror(errno), errno); + zlog_error(zbt, "listen socket error: %s(errno: %d)", strerror(errno), errno); return; } while (1) { if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) == -1) { - zlog_info(zct,"accept socket error: %s(errno: %d)", strerror(errno), errno); + zlog_error(zct, "accept socket error: %s(errno: %d)", strerror(errno), errno); continue; } n = recv(connfd, buff, 40960, 0); if (n <= 0) { - zlog_info(zct,("recv fail"); + zlog_info(zct, "recv 0 and will close"); close(connfd); } else { buff[n] = '\0'; @@ -47,7 +49,7 @@ void TcpCgi::startCgiServer() { std::string recvData = std::string(buff); std::string reqData = cidwServer->HandleCgi_cmd(recvData); if (send(connfd, reqData.c_str(), reqData.length(), 0) < 0) { - zlog_error(zct,"send msg error: %s(errno: %d)", strerror(errno), errno); + zlog_error(zct, "send msg error: %s(errno: %d)", strerror(errno), errno); } close(connfd); } diff --git a/utility/udp_scan.cpp b/utility/udp_scan.cpp index ddccaf8..fc20b51 100644 --- a/utility/udp_scan.cpp +++ b/utility/udp_scan.cpp @@ -1,171 +1,134 @@ #include "udp_scan.hpp" #include #include +#include #include "common/common_func.hpp" #include "common/global.hpp" +extern zlog_category_t *zct; +extern zlog_category_t *zbt; -UdpSys::UdpSys(): - mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303)) -{ - zlog_info(zct,"UdpQt Init"); -} +UdpSys::UdpSys() : mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303)) { zlog_info(zct, "UdpQt Init"); } +void UdpSys::ClearConnect() { remoteIp.clear(); } -void UdpSys::ClearConnect() -{ - remoteIp.clear(); -} - -void UdpSys::StartConnectSysUdp() -{ - zlog_info(zct,"start connect QT"); - if (udpSock.is_open()) { - boost::asio::socket_base::linger option1(true, 0); - udpSock.set_option(option1); - boost::asio::socket_base::send_buffer_size option4(125000); - udpSock.set_option(option4); - remoteEndPoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 9998); - remoteEndPoint.address(boost::asio::ip::address::from_string("127.0.0.1")); - recvUdpData(); - mIoSev.run(); - } -} - -void UdpSys::handle_send_to(const boost::system::error_code& ec, - size_t trans) -{ - if (ec) { - zlog_error(zct,"send the udp to sys error! "); - } else { - zlog_info(zct,"send the udp to sys ok! "); +void UdpSys::StartConnectSysUdp() { + zlog_info(zbt, "start connect QT"); + if (udpSock.is_open()) { + boost::asio::socket_base::linger option1(true, 0); + udpSock.set_option(option1); + boost::asio::socket_base::send_buffer_size option4(125000); + udpSock.set_option(option4); + remoteEndPoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 9998); + remoteEndPoint.address(boost::asio::ip::address::from_string("127.0.0.1")); + recvUdpData(); + mIoSev.run(); } } -void UdpSys::SendUdpToSingle(std::string pData) -{ - boost::mutex::scoped_lock lock(udpMutex); - int len = pData.length(); - if (len <= 0) - return ; - char *mi = new char[len + 3]; - memset(mi, 0, len + 3); - strcpy(mi, pData.c_str()); - strcat(mi, "\r\n"); - zlog_info(zct,"sys send single : %s ", pData.c_str()); - udpSock.async_send_to(boost::asio::buffer(mi,len + 3), remoteEndPoint, - boost::bind(&UdpSys::handle_send_to, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - delete [] mi; +void UdpSys::handle_send_to(const boost::system::error_code& ec, size_t trans) { + if (ec) { + zlog_error(zct, "send the udp to sys error! "); + } else { + zlog_info(zct, "send the udp to sys ok! "); + } } -void UdpSys::recvUdpData() -{ - udpSock.async_receive_from(boost::asio::buffer(m_buffer), senderEndPoint, - boost::bind(&UdpSys::HandleRead, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); +void UdpSys::SendUdpToSingle(std::string pData) { + boost::mutex::scoped_lock lock(udpMutex); + int len = pData.length(); + if (len <= 0) return; + char* mi = new char[len + 3]; + memset(mi, 0, len + 3); + strcpy(mi, pData.c_str()); + strcat(mi, "\r\n"); + zlog_info(zct, "sys send single : %s ", pData.c_str()); + udpSock.async_send_to(boost::asio::buffer(mi, len + 3), remoteEndPoint, boost::bind(&UdpSys::handle_send_to, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + delete[] mi; } +void UdpSys::recvUdpData() { udpSock.async_receive_from(boost::asio::buffer(m_buffer), senderEndPoint, boost::bind(&UdpSys::HandleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } -void UdpSys::HandleRead(const boost::system::error_code& pEc, - std::size_t pBytesTransferred) -{ - std::string ip = senderEndPoint.address().to_string(); - if (pEc) { - std::cerr << pEc.value() <0){ - AnalysisDataSys(read_cmd); - } - } - recvUdpData(); +void UdpSys::HandleRead(const boost::system::error_code& pEc, std::size_t pBytesTransferred) { + std::string ip = senderEndPoint.address().to_string(); + if (pEc) { + std::cerr << pEc.value() << std::endl; + std::cerr << pEc.category().name() << std::endl; + std::cerr << pEc.message() << std::endl; + } else if (pBytesTransferred == 0) { + std::cout << "rev has rec!" << std::endl; + if (pBytesTransferred == 0) { + std::cerr << "[ Read 0 Bytes ][ " << ip << " Quit ! ]" << std::endl; + } + } else { + std::string read_cmd(m_buffer.data(), pBytesTransferred); + print_light_purple("%s", read_cmd.c_str()); + if (read_cmd.length() > 0) { + AnalysisDataSys(read_cmd); + } + } + recvUdpData(); } -void UdpSys::AnalysisDataSys(std::string cmd) -{ - zlog_info(zct,"%s", cmd.c_str()); - Json::Reader recvReader; - Json::Value JsonVal; - if(recvReader.parse(cmd,JsonVal)) { - int cmdType = atoi(JsonVal["cmd"].asString().c_str()); - switch (cmdType) { - case 3:{ //配置服务器 - std::string strServerIp = JsonVal["localServerIpAddress"].asString(); - int localServerPort = JsonVal["localServerPort"].asInt(); - - std::string strDataWatchAddedBy = "system"; - if (!JsonVal["dataNodeGatewayAddedBy"].isNull()) { +void UdpSys::AnalysisDataSys(std::string cmd) { + zlog_info(zct, "%s", cmd.c_str()); + Json::Reader recvReader; + Json::Value JsonVal; + if (recvReader.parse(cmd, JsonVal)) { + int cmdType = atoi(JsonVal["cmd"].asString().c_str()); + switch (cmdType) { + case 3: { //配置服务器 + std::string strServerIp = JsonVal["localServerIpAddress"].asString(); + int localServerPort = JsonVal["localServerPort"].asInt(); + + std::string strDataWatchAddedBy = "system"; + if (!JsonVal["dataNodeGatewayAddedBy"].isNull()) { strDataWatchAddedBy = JsonVal["dataNodeGatewayAddedBy"].asString(); - WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", strDataWatchAddedBy); - } + WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", strDataWatchAddedBy); + } - zlog_info(zct,"strServerIp : %s ", strServerIp.c_str()); - if (strServerIp.compare(GlobalConfig::ServerIP) != 0 || localServerPort != GlobalConfig::ServerPort) - { + zlog_info(zct, "strServerIp : %s ", strServerIp.c_str()); + if (strServerIp.compare(GlobalConfig::ServerIP) != 0 || localServerPort != GlobalConfig::ServerPort) { GlobalConfig::ServerIP = strServerIp; - GlobalConfig::ServerPort = localServerPort; + GlobalConfig::ServerPort = localServerPort; - WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", GlobalConfig::ServerIP); - WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", to_string(GlobalConfig::ServerPort)); + WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", GlobalConfig::ServerIP); + WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", to_string(GlobalConfig::ServerPort)); - std::string fileserver = ReadStrByOpt(SERVERCONFIG, "FileServer", "FileServerIpAddress"); - if (0 == fileserver.compare("0.0.0.0") || 0 == fileserver.length()) { - WriteStr2Config(SERVERCONFIG, "FileServer", "FileServerIpAddress", GlobalConfig::ServerIP); - } - - JsonVal["status"] = "ACK"; - Json::FastWriter fw; - std::string str = fw.write(JsonVal); - zlog_info(zct,"send info : %s ", str.c_str()); - boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), - MULTICAST_PORT_SEND); - udpSock.async_send_to(boost::asio::buffer(str),remoteEP, - boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } else { - //TODO: add log here - } - } - break; - case 4:{ - Json::FastWriter fw; - std::string status = JsonVal["status"].asString(); - if(status.compare("REQ") == 0) - { + std::string fileserver = ReadStrByOpt(SERVERCONFIG, "FileServer", "FileServerIpAddress"); + if (0 == fileserver.compare("0.0.0.0") || 0 == fileserver.length()) { + WriteStr2Config(SERVERCONFIG, "FileServer", "FileServerIpAddress", GlobalConfig::ServerIP); + } + + JsonVal["status"] = "ACK"; + Json::FastWriter fw; + std::string str = fw.write(JsonVal); + zlog_info(zct, "send info : %s ", str.c_str()); + boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), MULTICAST_PORT_SEND); + udpSock.async_send_to(boost::asio::buffer(str), remoteEP, boost::bind(&UdpSys::handle_send_to, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + } else { + zlog_info(zbt, "server ip and port not change"); + } + } break; + case 4: { + Json::FastWriter fw; + std::string status = JsonVal["status"].asString(); + if (status.compare("REQ") == 0) { JsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G.c_str(); JsonVal["localServerIpAddress"] = GlobalConfig::ServerIP; JsonVal["status"] = "ACK"; std::string data = fw.write(JsonVal); - boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), - MULTICAST_PORT_SEND); - udpSock.async_send_to(boost::asio::buffer(data),remoteEP, - boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); + boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), MULTICAST_PORT_SEND); + udpSock.async_send_to(boost::asio::buffer(data), remoteEP, boost::bind(&UdpSys::handle_send_to, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } - } - break; - default: - break; - } - }else - { - zlog_error(zct,"json parse failed"); - } + } break; + default: break; + } + } else { + zlog_error(zct, "json parse failed"); + } } -UdpSys::~UdpSys() -{ - if (udpSock.is_open()) - udpSock.close(); +UdpSys::~UdpSys() { + if (udpSock.is_open()) udpSock.close(); } diff --git a/wifi_5g/dial.cpp b/wifi_5g/dial.cpp index 4fe7984..46d8210 100644 --- a/wifi_5g/dial.cpp +++ b/wifi_5g/dial.cpp @@ -4,6 +4,7 @@ #include #include "common/common_func.hpp" +extern zlog_category_t *zct; Dial::Dial() { m_fd = 0; @@ -16,12 +17,12 @@ Dial::~Dial() {} int Dial::openPort(const char *pPort) { m_fd = config_uart(pPort, 115200); - zlog_info(zct,"m_fd = %d\n", m_fd); + zlog_info(zct, "m_fd = %d\n", m_fd); return m_fd; } int Dial::parseData(Event event, const char *pData) { - zlog_info(zct,"m_curState = %d,event = %d\n", m_curState, event); + zlog_info(zct, "m_curState = %d,event = %d\n", m_curState, event); std::string signal; std::string ret; std::string str; @@ -45,10 +46,10 @@ int Dial::parseData(Event event, const char *pData) { GlobalConfig::NetType = GetOneContent(pData, 2, ","); signal = GetOneContent(pData, 12, ","); GlobalConfig::NetSignal = atoi(signal.c_str()); - zlog_info(zct,"NetStatus = %s,NetSignal = %d", GlobalConfig::NetStatus.c_str(), GlobalConfig::NetSignal); + zlog_info(zct, "NetStatus = %s,NetSignal = %d", GlobalConfig::NetStatus.c_str(), GlobalConfig::NetSignal); break; case Event_QNETDEVCTL: - zlog_info(zct,"m_curState Event_QNETDEVCTL = %d", m_curState); + zlog_info(zct, "m_curState Event_QNETDEVCTL = %d", m_curState); if (m_dial == 1) { m_curState = QNETDEVSTATUS; } @@ -89,7 +90,7 @@ int Dial::parseData(Event event, const char *pData) { if (pos > 0) { std::string socTmp = str.substr(pos + 14, 2); GlobalConfig::NR5GTemp = socTmp; - zlog_info(zct,"NR5GTemp = %s", GlobalConfig::NR5GTemp.c_str()); + zlog_info(zct, "NR5GTemp = %s", GlobalConfig::NR5GTemp.c_str()); } break; @@ -122,49 +123,49 @@ int Dial::recvData() { char *pdata = strstr((char *)szbuffer, strQENG); if (pdata) { strncpy(data, pdata + 7, sizeof(data)); - zlog_info(zct,"strQENG = %s", data); + zlog_info(zct, "strQENG = %s", data); parseData(Event_QENG, data); } pdata = strstr((char *)szbuffer, strQNETDEVCTL); if (pdata) { strncpy(data, pdata + 13, sizeof(data)); - zlog_info(zct,"strQNETDEVCTL = %s", data); + zlog_info(zct, "strQNETDEVCTL = %s", data); parseData(Event_QNETDEVCTL, data); } pdata = strstr((char *)szbuffer, strQICSGP); if (pdata) { strncpy(data, pdata + 9, sizeof(data)); - zlog_info(zct,"strQICSGP = %s", data); + zlog_info(zct, "strQICSGP = %s", data); parseData(Event_QICSGPAPN, data); } pdata = strstr((char *)szbuffer, strQNETDEVSTATUS); if (pdata) { strncpy(data, pdata + 16, sizeof(data)); - zlog_info(zct,"strQNETDEVSTATUS = %s", data); + zlog_info(zct, "strQNETDEVSTATUS = %s", data); parseData(Event_QNETDEVSTATUS, data); } pdata = strstr((char *)szbuffer, strQCFG); if (pdata) { strncpy(data, pdata + 7, sizeof(data)); - zlog_info(zct,"strQCFG = %s", data); + zlog_info(zct, "strQCFG = %s", data); parseData(Event_QCFGNET, data); } pdata = strstr((char *)szbuffer, strCPIN); if (pdata) { strncpy(data, pdata + 7, sizeof(data)); - zlog_info(zct,"strCPIN = %s", data); + zlog_info(zct, "strCPIN = %s", data); parseData(Event_CPIN, data); } pdata = strstr((char *)szbuffer, strQTEMP); if (pdata) { strncpy(data, pdata + 8, sizeof(data)); - zlog_info(zct,"strQTEMP = %s", data); + zlog_info(zct, "strQTEMP = %s", data); parseData(Event_TEMP, data); } pdata = strstr((char *)szbuffer, strERROR); if (pdata) { strncpy(data, pdata + 12, sizeof(data)); - zlog_info(zct,"strERROR = %s", data); + zlog_info(zct, "strERROR = %s", data); parseData(Event_ERROR, data); } pdata = strstr((char *)szbuffer, strOK); @@ -176,10 +177,10 @@ int Dial::recvData() { } mssleep(100); } else if (ret > 0) { - zlog_info(zct,"ret = %d,buff = %s", ret, buff); + zlog_info(zct, "ret = %d,buff = %s", ret, buff); memcpy(szbuffer + offSize, buff, ret); offSize = offSize + ret; - zlog_info(zct,"szbuffer = %s", szbuffer); + zlog_info(zct, "szbuffer = %s", szbuffer); continue; } mssleep(500000); @@ -196,7 +197,7 @@ int Dial::configApn() { char szCmd[100] = {0x00}; sprintf(szCmd, "AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n", strAPN.c_str()); int iRet = write_data(m_fd, szCmd, strlen(strAPN.c_str()) + 34); - zlog_info(zct,"configApn = %d,data = %s\n", iRet, szCmd); + zlog_info(zct, "configApn = %d,data = %s\n", iRet, szCmd); } int Dial::getCsq() { write_data(m_fd, "AT+QENG=\"servingcell\"\r\n", 27); } @@ -205,7 +206,7 @@ int Dial::getTemp() { write_data(m_fd, "AT+QTEMP\r\n", 12); } int Dial::conncectUSB() { int iRet = write_data(m_fd, "AT+QNETDEVCTL=1,1,1\r\n", 23); - zlog_info(zct,"conncectUSB = %d\n", iRet); + zlog_info(zct, "conncectUSB = %d\n", iRet); } int Dial::dial5G() { diff --git a/wifi_5g/wpa_client.cpp b/wifi_5g/wpa_client.cpp index 08eef42..e96472a 100644 --- a/wifi_5g/wpa_client.cpp +++ b/wifi_5g/wpa_client.cpp @@ -16,6 +16,8 @@ #include #include +extern zlog_category_t *zct; + namespace wifi { size_t strlcpy(char *dst, const char *src, size_t dst_sz) { @@ -126,7 +128,7 @@ WPAClient::~WPAClient() { Close(wpa_context_); } bool WPAClient::Init() { wpa_context_ = Open(wpa_control_path_); if (wpa_context_ == NULL) { - zlog_error(zct,"open wpa failed"); + zlog_error(zct, "open wpa failed"); return false; } SetConnStatus(STEP_SCAN); @@ -181,7 +183,7 @@ int WPAClient::GetWiFiRssi() { } char temp[1024] = {0}; strcpy(temp, recv.data()); - zlog_info(zct,"recv = %s\n", recv.c_str()); + zlog_info(zct, "recv = %s\n", recv.c_str()); char *key = NULL; key = strstr(temp, rssi_key.data()); if (key == NULL) { @@ -201,27 +203,27 @@ bool WPAClient::ConnectWiFi(const std::string &ssid, const std::string &password if (!CleanAllWiFi()) { return false; } - zlog_info(zct,"CleanAllWiFi "); + zlog_info(zct, "CleanAllWiFi "); if (!AddWiFi(net_id)) { return false; } - zlog_info(zct,"AddWiFi "); + zlog_info(zct, "AddWiFi "); if (!SetSSID(ssid, net_id)) { return false; } - zlog_info(zct,"SetSSID "); + zlog_info(zct, "SetSSID "); if (!SetPassword(password, 0)) { return false; } if (!SetProtocol(net_id, 1)) { return false; } - zlog_info(zct,"SetProtocol"); + zlog_info(zct, "SetProtocol"); SetScanSSID(net_id); if (!EnableWiFi(net_id)) { return false; } - zlog_info(zct,"EnableWiFi"); + zlog_info(zct, "EnableWiFi"); return CheckCommandWithOk("SAVE_CONFIG"); // return true; } @@ -232,24 +234,24 @@ bool WPAClient::ConnectWiFiWithNoPassword(const std::string &ssid) { if (!CleanAllWiFi()) { return false; } - zlog_info(zct,"CleanAllWiFi"); + zlog_info(zct, "CleanAllWiFi"); if (!AddWiFi(net_id)) { return false; } - zlog_info(zct,"AddWiFi"); + zlog_info(zct, "AddWiFi"); if (!SetSSID(ssid, net_id)) { return false; } - zlog_info(zct,"SetSSID"); + zlog_info(zct, "SetSSID"); if (!SetProtocol(net_id, 0)) { return false; } - zlog_info(zct,"SetProtocol"); + zlog_info(zct, "SetProtocol"); SetScanSSID(net_id); if (!EnableWiFi(net_id)) { return false; } - zlog_info(zct,"EnableWiFi"); + zlog_info(zct, "EnableWiFi"); return CheckCommandWithOk("SAVE_CONFIG"); } @@ -312,7 +314,7 @@ WPAContext *WPAClient::Open(const std::string &path) { struct WPAContext *ctrl; ctrl = (struct WPAContext *)malloc(sizeof(struct WPAContext)); if (ctrl == NULL) { - zlog_error(zct,"malloc failed"); + zlog_error(zct, "malloc failed"); return NULL; } memset(ctrl, 0, sizeof(struct WPAContext)); @@ -322,7 +324,7 @@ WPAContext *WPAClient::Open(const std::string &path) { size_t res; ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0); if (ctrl->s < 0) { - zlog_error(zct,"socket failed"); + zlog_error(zct, "socket failed"); free(ctrl); return NULL; } @@ -335,7 +337,7 @@ try_again: "%d-%d", (int)getpid(), counter); if (ret < 0 || (size_t)ret >= sizeof(ctrl->local.sun_path)) { - zlog_error(zct,"snprintf failed"); + zlog_error(zct, "snprintf failed"); close(ctrl->s); free(ctrl); return NULL; @@ -352,7 +354,7 @@ try_again: unlink(ctrl->local.sun_path); goto try_again; } - zlog_error(zct,"bind failed"); + zlog_error(zct, "bind failed"); close(ctrl->s); free(ctrl); return NULL; @@ -365,7 +367,7 @@ try_again: return NULL; } if (connect(ctrl->s, (struct sockaddr *)&ctrl->dest, sizeof(ctrl->dest)) < 0) { - zlog_error(zct,"connect failed"); + zlog_error(zct, "connect failed"); close(ctrl->s); unlink(ctrl->local.sun_path); free(ctrl); @@ -391,7 +393,7 @@ bool WPAClient::Request(WPAContext *context, const std::string &cmd, std::string _cmd = cmd.data(); _cmd_len = cmd.length(); if (wpa_context_ == NULL) { - zlog_error(zct,"wpa_context_ is null"); + zlog_error(zct, "wpa_context_ is null"); return false; } if (send(wpa_context_->s, _cmd, _cmd_len, 0) < 0) { @@ -426,10 +428,10 @@ bool WPAClient::Request(WPAContext *context, const std::string &cmd, std::string bool WPAClient::CheckCommandWithOk(const std::string cmd) { std::string recv; if (!Request(wpa_context_, cmd, recv)) { - zlog_error(zct,"send cmd falied"); + zlog_error(zct, "send cmd falied"); return false; } - zlog_error(zct,"recv cmd %s", recv.data()); + zlog_error(zct, "recv cmd %s", recv.data()); if (strstr(recv.data(), "OK") == NULL) { return false; }