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