add log info
This commit is contained in:
parent
344d6fee05
commit
6a7f2712e4
@ -40,7 +40,7 @@ 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); //用户操作处理
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#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>
|
||||||
|
|
||||||
std::string JsonData::JsonCmd_20(Param_20 ¶m) {
|
std::string JsonData::JsonCmd_20(Param_20 ¶m) {
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
@ -238,7 +239,6 @@ std::string JsonData::JsonCmd_26(Param_26 ¶m) {
|
|||||||
jsSensorData["featureInterVal"] = (arrRes[j][21]);
|
jsSensorData["featureInterVal"] = (arrRes[j][21]);
|
||||||
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
||||||
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
||||||
// jsSensorData["scope"] = atoi(arrRes[j][24]);
|
|
||||||
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
||||||
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
||||||
jsSensorData["faultFrequency"] = arrRes[j][27];
|
jsSensorData["faultFrequency"] = arrRes[j][27];
|
||||||
@ -329,8 +329,8 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
|
|||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
}
|
}
|
||||||
string md5Val = md5file(updateName.c_str());
|
string md5Val = md5file(updateName.c_str());
|
||||||
printf("md5Val = %s\n", md5Val.c_str());
|
zlog_info(zct,"md5Val = %s", md5Val.c_str());
|
||||||
printf("md5 = %s\n", 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";
|
||||||
@ -488,6 +488,31 @@ 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();
|
||||||
@ -514,7 +539,7 @@ void JsonData::DataNodeStatusCheck() {
|
|||||||
int lTimeTemp = lNowTime - llastTime;
|
int lTimeTemp = lNowTime - llastTime;
|
||||||
lTimeTemp = abs(lTimeTemp);
|
lTimeTemp = abs(lTimeTemp);
|
||||||
if (lTimeTemp > onlineCheck) {
|
if (lTimeTemp > onlineCheck) {
|
||||||
LOG_DEBUG("offline DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s\n", 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);
|
||||||
@ -525,13 +550,13 @@ void JsonData::DataNodeStatusCheck() {
|
|||||||
}
|
}
|
||||||
if (lTimeTemp > atoi(vetRes[i][21].c_str()) * 5 * 60) //判定传感器是否超过五次未传特征值
|
if (lTimeTemp > atoi(vetRes[i][21].c_str()) * 5 * 60) //判定传感器是否超过五次未传特征值
|
||||||
{
|
{
|
||||||
LOG_DEBUG("lTimeTemp = %d,featureInterVal = %d\n", 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) {
|
||||||
LOG_ERROR("ALL Node offline,count = %d\n", count);
|
zlog_error(zct,"ALL Node offline,count = %d", count);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#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>
|
||||||
|
|
||||||
std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m) {
|
std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m) {
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
@ -85,7 +86,7 @@ std::string JsonData::JsonCmd_Cgi_07() {
|
|||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
std::string sysStatus = GetSysStatus();
|
std::string sysStatus = GetSysStatus();
|
||||||
|
|
||||||
print_info("sysStatus : %s\n", 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;
|
||||||
@ -105,7 +106,7 @@ std::string JsonData::JsonCmd_07() {
|
|||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
std::string sysStatus = GetSysStatus();
|
std::string sysStatus = GetSysStatus();
|
||||||
|
|
||||||
print_info("sysStatus : %s\n", 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;
|
||||||
@ -136,7 +137,7 @@ std::string JsonData::JsonCmd_Cgi_08() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||||
// LOG_INFO("09 start\n");
|
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
|
|
||||||
@ -178,9 +179,8 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
|||||||
jsonVal["packageMax"] = index + 1;
|
jsonVal["packageMax"] = index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("09 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n", 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++) {
|
||||||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@vetRes=%s\n", arrResAll[i][1].c_str());
|
|
||||||
Json::Value jsSensor;
|
Json::Value jsSensor;
|
||||||
std::string strMeasurementID = arrResAll[i][1];
|
std::string strMeasurementID = arrResAll[i][1];
|
||||||
char whereCon[512] = {};
|
char whereCon[512] = {};
|
||||||
@ -260,7 +260,6 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
|||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
}
|
}
|
||||||
// LOG_INFO("09 end\n");
|
|
||||||
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) {
|
||||||
@ -315,7 +314,6 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
|||||||
jsonVal["packageMax"] = index;
|
jsonVal["packageMax"] = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("10 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n",packgeNo,packgeNum,lastSize,index);
|
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
|
|
||||||
if (param.timeEnd == "") {
|
if (param.timeEnd == "") {
|
||||||
@ -326,7 +324,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);
|
||||||
print_info("vecRes = %d\n", 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++) {
|
||||||
@ -359,7 +357,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
|||||||
jsonVal["content"] = (jsStaticData);
|
jsonVal["content"] = (jsStaticData);
|
||||||
}
|
}
|
||||||
jsonVal["Static"] = param.strStatic;
|
jsonVal["Static"] = param.strStatic;
|
||||||
print_info("vecRes = %d,channelID = %s\n", 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);
|
||||||
@ -385,7 +383,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();
|
||||||
print_info("iResult = %d\n", 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;
|
||||||
@ -491,7 +489,6 @@ std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶m) {
|
|||||||
|
|
||||||
jsBody["SystemInfo"] = jsSystemInfo;
|
jsBody["SystemInfo"] = jsSystemInfo;
|
||||||
|
|
||||||
// std::string dataBody = show_value_.write(jsBody);
|
|
||||||
jsonVal["content"] = jsBody;
|
jsonVal["content"] = jsBody;
|
||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
}
|
}
|
||||||
@ -578,7 +575,7 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m) {
|
|||||||
} else {
|
} else {
|
||||||
bFlag4 = true;
|
bFlag4 = true;
|
||||||
}
|
}
|
||||||
print_info("bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d\n", 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";
|
||||||
@ -594,7 +591,7 @@ 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());
|
||||||
print_info("GateWay = %s\n", GateWay);
|
zlog_info(zct,"GateWay = %s", GateWay);
|
||||||
system(GateWay);
|
system(GateWay);
|
||||||
#endif
|
#endif
|
||||||
platform->EquipIpInit(param.mNet);
|
platform->EquipIpInit(param.mNet);
|
||||||
|
|||||||
@ -2,10 +2,9 @@
|
|||||||
#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>
|
||||||
|
|
||||||
std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||||
// LOG_INFO("26 start\n");
|
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
|
|
||||||
@ -16,7 +15,6 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
|||||||
|
|
||||||
char looseValue[10] = {0x00};
|
char looseValue[10] = {0x00};
|
||||||
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
||||||
// print_debug("loose = %f \n",atof(looseValue));
|
|
||||||
Json::Value jsArray;
|
Json::Value jsArray;
|
||||||
array_t arrRes;
|
array_t arrRes;
|
||||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||||
@ -46,8 +44,6 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
|||||||
packgeMax = index + 1;
|
packgeMax = index + 1;
|
||||||
jsonVal["packageMax"] = index;
|
jsonVal["packageMax"] = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("26 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n", packgeNo, packgeNum, lastSize, index);
|
|
||||||
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
||||||
Json::Value jsSensorData;
|
Json::Value jsSensorData;
|
||||||
jsSensorData["dataNodeNo"] = arrRes[j][0];
|
jsSensorData["dataNodeNo"] = arrRes[j][0];
|
||||||
@ -73,7 +69,6 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
|||||||
jsSensorData["featureInterVal"] = atoi(arrRes[j][21].c_str());
|
jsSensorData["featureInterVal"] = atoi(arrRes[j][21].c_str());
|
||||||
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
||||||
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
||||||
// jsSensorData["scope"] = atoi(arrRes[j][24]);
|
|
||||||
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
||||||
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
||||||
jsSensorData["faultFrequency"] = arrRes[j][27];
|
jsSensorData["faultFrequency"] = arrRes[j][27];
|
||||||
@ -90,8 +85,6 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
|||||||
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;
|
vector<string> vParam;
|
||||||
|
|
||||||
print_info("loose = %s\n", arrRes[j][42].c_str());
|
|
||||||
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)
|
||||||
@ -116,7 +109,6 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
|||||||
jsArray.resize(0);
|
jsArray.resize(0);
|
||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
}
|
}
|
||||||
// LOG_INFO("26 end\n");
|
|
||||||
jsonVal["gatewayMac"] = GlobalConfig::MacAddr_G;
|
jsonVal["gatewayMac"] = GlobalConfig::MacAddr_G;
|
||||||
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G;
|
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G;
|
||||||
jsonVal["content"]["dataNodeArray"] = jsArray;
|
jsonVal["content"]["dataNodeArray"] = jsArray;
|
||||||
@ -167,7 +159,6 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) {
|
|||||||
char hex[100];
|
char hex[100];
|
||||||
nodeArray.append(arrRes[j][0]);
|
nodeArray.append(arrRes[j][0]);
|
||||||
stringToHex(arrRes[j][1].c_str(), hex);
|
stringToHex(arrRes[j][1].c_str(), hex);
|
||||||
print_info("hex = %s\n", hex);
|
|
||||||
nodeArray.append(hex);
|
nodeArray.append(hex);
|
||||||
nodeArray.append(arrRes[j][2]);
|
nodeArray.append(arrRes[j][2]);
|
||||||
nodeArray.append(arrRes[j][3]);
|
nodeArray.append(arrRes[j][3]);
|
||||||
@ -289,7 +280,6 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
|||||||
GetTimeNet(localtimestamp, 1);
|
GetTimeNet(localtimestamp, 1);
|
||||||
sprintf(updateSql, "LooseValue = '0,2,");
|
sprintf(updateSql, "LooseValue = '0,2,");
|
||||||
string strUpdateSql = string(updateSql) + string(localtimestamp) + "' ";
|
string strUpdateSql = string(updateSql) + string(localtimestamp) + "' ";
|
||||||
print_info("updateSql = %s\n", strUpdateSql.c_str());
|
|
||||||
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;
|
||||||
@ -330,7 +320,6 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
|||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["message"] = " ";
|
jsonVal["message"] = " ";
|
||||||
std::vector<float> vecWave;
|
std::vector<float> vecWave;
|
||||||
/* 新增代码 */
|
|
||||||
char whereCon[64] = {};
|
char whereCon[64] = {};
|
||||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||||
@ -345,20 +334,10 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
|||||||
jsonVal["message"] = "error";
|
jsonVal["message"] = "error";
|
||||||
} else {
|
} else {
|
||||||
float fTemp = 0;
|
float fTemp = 0;
|
||||||
|
|
||||||
// std::vector<float> hanningWave;
|
|
||||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
vecWave.push_back(fTemp);
|
vecWave.push_back(fTemp);
|
||||||
}
|
}
|
||||||
//测试正弦波
|
|
||||||
// pCalculation->GenerateSin(vecWave);
|
|
||||||
|
|
||||||
//添加汉宁窗
|
|
||||||
/*pCalculation->Hanning(vecWave, hanningWave);
|
|
||||||
for(int i = 0; i < vecWave.size();i++){
|
|
||||||
vecWave[i] = (vecWave[i]*hanningWave[i]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * 1024;
|
flag = (flag + 1) * 1024;
|
||||||
@ -383,7 +362,6 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
|||||||
strWaveData = strWaveData + "," + waveTemp;
|
strWaveData = strWaveData + "," + waveTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int max = number / 1024;
|
int max = number / 1024;
|
||||||
if (max == 0 && number > 0) {
|
if (max == 0 && number > 0) {
|
||||||
max = 1;
|
max = 1;
|
||||||
@ -395,10 +373,9 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
|||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "没有数据文件";
|
jsonVal["message"] = "没有数据文件";
|
||||||
}
|
}
|
||||||
|
|
||||||
jsBody["channelId"] = param.mChannelId;
|
jsBody["channelId"] = param.mChannelId;
|
||||||
jsBody["package"] = param.mPackageFlag;
|
jsBody["package"] = param.mPackageFlag;
|
||||||
print_info("vecWave.size() = %d,sample = %d,second = %f\n", 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()));
|
||||||
@ -458,44 +435,18 @@ 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进行计算
|
||||||
// if(i < 8192)
|
vecWave.push_back(fTemp);
|
||||||
{ vecWave.push_back(fTemp); }
|
|
||||||
// else{
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
}
|
|
||||||
//测试正弦波
|
|
||||||
// pCalculation->GenerateSin(vecWave);
|
|
||||||
|
|
||||||
// if(vecWave.size() < 8192){
|
}
|
||||||
// for(int i = vecWave.size(); i < 8192;i++){
|
|
||||||
// vecWave.push_back(0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//添加汉宁窗
|
|
||||||
// pCalculation->Hanning(vecWave, hanningWave);
|
|
||||||
// for(int i = 0; i < vecWave.size();i++){
|
|
||||||
// addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//进行傅立叶变换
|
//进行傅立叶变换
|
||||||
pCalculation->FFTSpec(vecWave, fftWave);
|
pCalculation->FFTSpec(vecWave, fftWave);
|
||||||
sampleRateReference = 1024;
|
sampleRateReference = 1024;
|
||||||
}
|
}
|
||||||
/*for(int i = 0; i < fftWave.size();i++){
|
|
||||||
fftWave[i] = fftWave[i]*2;
|
|
||||||
}*/
|
|
||||||
printf("2---------------------------------------------->vecWave = %d,fftWave = %d\n", vecWave.size(), fftWave.size());
|
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * sampleRateReference;
|
flag = (flag + 1) * sampleRateReference;
|
||||||
int number = fftWave.size();
|
int number = fftWave.size();
|
||||||
printf("number---------------------------------------------->%d\n", number);
|
|
||||||
int start = param.mPackageFlag * sampleRateReference;
|
int start = param.mPackageFlag * sampleRateReference;
|
||||||
printf("param.mPackageFlag = %d\n", param.mPackageFlag);
|
|
||||||
printf("param.start = %d\n", start);
|
|
||||||
printf("param.flag = %d\n", flag);
|
|
||||||
if (number < sampleRateReference) {
|
if (number < sampleRateReference) {
|
||||||
flag = number;
|
flag = number;
|
||||||
start = 0;
|
start = 0;
|
||||||
@ -517,7 +468,6 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int max = number / sampleRateReference;
|
int max = number / sampleRateReference;
|
||||||
print_info("max = %d\n", max);
|
|
||||||
if (max == 0 && number > 0) {
|
if (max == 0 && number > 0) {
|
||||||
max = 1;
|
max = 1;
|
||||||
}
|
}
|
||||||
@ -535,23 +485,21 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
|
|
||||||
double resolution = 0.0;
|
double resolution = 0.0;
|
||||||
int SampleRate = 0;
|
int SampleRate = 0;
|
||||||
print_info("sensor type %s\n", 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());
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", SampleRate);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate);
|
||||||
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
||||||
// resolution = (double)SampleRate/vecWave.size();
|
|
||||||
|
|
||||||
} 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");
|
||||||
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();
|
||||||
// resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n", SampleRate, resolution);
|
|
||||||
} else {
|
} else {
|
||||||
SampleRate = 8192;
|
SampleRate = 8192;
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", 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 {
|
||||||
@ -560,7 +508,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n", 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);
|
||||||
@ -656,18 +604,18 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
|||||||
envWave[i] = envWave[i]*2;
|
envWave[i] = envWave[i]*2;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
printf("2---------------------------------------------->%d\n", envWave.size());
|
zlog_info(zct,"2---------------------------------------------->%d", envWave.size());
|
||||||
printf("2---------------------------------------------->%f\n", envWave[10]);
|
zlog_info(zct,"2---------------------------------------------->%f", envWave[10]);
|
||||||
|
|
||||||
print_info("after fft--------------------------------------------------->fftWave.size()=%d\n", 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;
|
||||||
printf("param.mPackageFlag = %d\n", param.mPackageFlag);
|
zlog_info(zct,"param.mPackageFlag = %d", param.mPackageFlag);
|
||||||
printf("param.start = %d\n", start);
|
zlog_info(zct,"param.start = %d", start);
|
||||||
printf("param.flag = %d\n", flag);
|
zlog_info(zct,"param.flag = %d", flag);
|
||||||
if (number < sampleRateReference) {
|
if (number < sampleRateReference) {
|
||||||
flag = number;
|
flag = number;
|
||||||
start = 0;
|
start = 0;
|
||||||
@ -706,10 +654,10 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
|||||||
|
|
||||||
double resolution = 0.0;
|
double resolution = 0.0;
|
||||||
int SampleRate = 0;
|
int SampleRate = 0;
|
||||||
print_info("sensor type %s\n", 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());
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", 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");
|
||||||
@ -717,15 +665,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();
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n", SampleRate, resolution);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||||
} else {
|
} else {
|
||||||
SampleRate = 8000;
|
SampleRate = 8000;
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", SampleRate);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate);
|
||||||
resolution = (((double)SampleRate / 1000) * 1024) / 8192;
|
resolution = (((double)SampleRate / 1000) * 1024) / 8192;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n", 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);
|
||||||
@ -750,8 +698,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);
|
||||||
print_info("str = %s\n", dataNodeName);
|
zlog_info(zct,"str = %s", dataNodeName);
|
||||||
print_info("dataNodeName = %s\n", 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',\
|
||||||
@ -790,25 +738,25 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) {
|
|||||||
string strcmd = "tar xvf /opt/";
|
string strcmd = "tar xvf /opt/";
|
||||||
strcmd = strcmd + param.fileName;
|
strcmd = strcmd + param.fileName;
|
||||||
strcmd = strcmd + " -C /opt/";
|
strcmd = strcmd + " -C /opt/";
|
||||||
print_info("strcmd = %s\n", 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") {
|
||||||
LOG_INFO("update rfsbu.tar\n");
|
zlog_info(zct,"update rfsbu.tar");
|
||||||
sleep(3);
|
sleep(3);
|
||||||
print_info("strcmd = %s\n", 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");
|
||||||
print_info("iRet = %d\n", iRet);
|
zlog_info(zct,"iRet = %d", iRet);
|
||||||
if (iRet == -1) {
|
if (iRet == -1) {
|
||||||
perror("system() error");
|
zlog_error(zct,"system() error");
|
||||||
}
|
}
|
||||||
} else if (param.fileName == "update.json") {
|
} else if (param.fileName == "update.json") {
|
||||||
print_info("strcmd = %s\n", 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") {
|
||||||
print_info("strcmd = %s\n", 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) + "个传感器更新成功";
|
string str = to_string(iRet) + "个传感器更新成功";
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#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>
|
||||||
|
|
||||||
std::string JsonData::JsonCmd_Cgi_default() {
|
std::string JsonData::JsonCmd_Cgi_default() {
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
@ -151,7 +152,7 @@ std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
|||||||
std::vector<std::string> vecSsid;
|
std::vector<std::string> vecSsid;
|
||||||
boost::split(vecSsid, netssid, boost::is_any_of("\n"), boost::token_compress_off);
|
boost::split(vecSsid, netssid, boost::is_any_of("\n"), boost::token_compress_off);
|
||||||
jsBody["type"] = "SCAN";
|
jsBody["type"] = "SCAN";
|
||||||
print_info("netssid : %s %d\n", netssid.c_str(), vecSsid.size());
|
zlog_info(zct,"netssid : %s %d", netssid.c_str(), vecSsid.size());
|
||||||
for (unsigned int i = 1; i < vecSsid.size() - 1; i++) {
|
for (unsigned int i = 1; i < vecSsid.size() - 1; i++) {
|
||||||
std::vector<std::string> data;
|
std::vector<std::string> data;
|
||||||
boost::split(data, vecSsid[i], boost::is_any_of("\t"), boost::token_compress_off);
|
boost::split(data, vecSsid[i], boost::is_any_of("\t"), boost::token_compress_off);
|
||||||
@ -164,7 +165,7 @@ std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
|||||||
jsBody["wifilist"].append(wifiInfo);
|
jsBody["wifilist"].append(wifiInfo);
|
||||||
}
|
}
|
||||||
} else if (1 == param.mMode) { // 设置
|
} else if (1 == param.mMode) { // 设置
|
||||||
print_info("set WiFi\n");
|
zlog_info(zct,"set WiFi");
|
||||||
wifi::WPAClient wpa;
|
wifi::WPAClient wpa;
|
||||||
jsBody["ssid"] = param.mSsid;
|
jsBody["ssid"] = param.mSsid;
|
||||||
if (param.mPassWord.length() > 0) {
|
if (param.mPassWord.length() > 0) {
|
||||||
@ -241,14 +242,13 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
jsonVal["message"] = " ";
|
jsonVal["message"] = " ";
|
||||||
std::vector<float> vecWave;
|
std::vector<float> vecWave;
|
||||||
std::vector<float> IntegrationWave;
|
std::vector<float> IntegrationWave;
|
||||||
/* 新增代码 */
|
|
||||||
char whereCon[64] = {};
|
char whereCon[64] = {};
|
||||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||||
int SampleRate = 0;
|
int SampleRate = 0;
|
||||||
double resolution = 0.0;
|
double resolution = 0.0;
|
||||||
SampleRate = atoi(res[23].c_str());
|
SampleRate = atoi(res[23].c_str());
|
||||||
print_info("sensor type %s\n", res[17].c_str());
|
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||||
|
|
||||||
char localtimestamp[32] = {0};
|
char localtimestamp[32] = {0};
|
||||||
std::string strWaveData = "";
|
std::string strWaveData = "";
|
||||||
@ -268,18 +268,17 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
vecWave.push_back(fTemp);
|
vecWave.push_back(fTemp);
|
||||||
}
|
}
|
||||||
if (res[17] == "01") {
|
if (res[17] == "01") {
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", 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") {
|
||||||
string::size_type comper = param.mChannelId.find("Z");
|
string::size_type comper = param.mChannelId.find("Z");
|
||||||
if (comper != string::npos) {
|
if (comper != string::npos) {
|
||||||
resolution = (double)SampleRate / vecWave.size();
|
resolution = (double)SampleRate / vecWave.size();
|
||||||
// resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n", SampleRate, resolution);
|
|
||||||
} else {
|
} else {
|
||||||
SampleRate = 8000;
|
SampleRate = 8000;
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", SampleRate);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate);
|
||||||
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
|
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,16 +286,6 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
//积分
|
//积分
|
||||||
pCalculation->Integration(vecWave, IntegrationWave, resolution);
|
pCalculation->Integration(vecWave, IntegrationWave, resolution);
|
||||||
|
|
||||||
//测试正弦波
|
|
||||||
// pCalculation->GenerateSin(vecWave);
|
|
||||||
// pCalculation->Integration(vecWave, IntegrationWave);
|
|
||||||
|
|
||||||
//添加汉宁窗
|
|
||||||
/*pCalculation->Hanning(vecWave, hanningWave);
|
|
||||||
for(int i = 0; i < vecWave.size();i++){
|
|
||||||
vecWave[i] = (vecWave[i]*hanningWave[i]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * 1024;
|
flag = (flag + 1) * 1024;
|
||||||
int number = IntegrationWave.size();
|
int number = IntegrationWave.size();
|
||||||
@ -335,7 +324,7 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
|
|
||||||
jsBody["channelId"] = param.mChannelId;
|
jsBody["channelId"] = param.mChannelId;
|
||||||
jsBody["package"] = param.mPackageFlag;
|
jsBody["package"] = param.mPackageFlag;
|
||||||
print_info("vecWave.size() = %d,sample = %d,second = %f\n", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.size() / atoi(res[23].c_str())));
|
zlog_info(zct,"vecWave.size() = %d,sample = %d,second = %f", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.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)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
||||||
@ -371,14 +360,13 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|||||||
std::vector<float> fftWave;
|
std::vector<float> fftWave;
|
||||||
std::vector<float> IntegrationWave;
|
std::vector<float> IntegrationWave;
|
||||||
int sampleRateReference = 0;
|
int sampleRateReference = 0;
|
||||||
/* 新增代码 */
|
char whereCon[64] = {0};
|
||||||
char whereCon[64] = {};
|
|
||||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||||
int SampleRate = 0;
|
int SampleRate = 0;
|
||||||
double resolution = 0.0;
|
double resolution = 0.0;
|
||||||
SampleRate = atoi(res[23].c_str());
|
SampleRate = atoi(res[23].c_str());
|
||||||
print_info("sensor type %s\n", res[17].c_str());
|
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||||
|
|
||||||
if (access(filename.c_str(), 0) >= 0) {
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
std::ifstream inFile(filename.c_str(), ios::in | ios::binary);
|
std::ifstream inFile(filename.c_str(), ios::in | ios::binary);
|
||||||
@ -403,28 +391,24 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
||||||
// if(i < 8192)
|
|
||||||
{ vecWave.push_back(fTemp); }
|
vecWave.push_back(fTemp);
|
||||||
// else{
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
}
|
}
|
||||||
if (res[17] == "01") {
|
if (res[17] == "01") {
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", SampleRate);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d", SampleRate);
|
||||||
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
||||||
// resolution = (double)SampleRate/vecWave.size();
|
|
||||||
|
|
||||||
} 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");
|
||||||
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();
|
||||||
// resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n", SampleRate, resolution);
|
zlog_info(zct,"@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||||
} else {
|
} else {
|
||||||
SampleRate = 8192;
|
SampleRate = 8192;
|
||||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n", 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 {
|
||||||
@ -432,39 +416,23 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//测试正弦波
|
|
||||||
// pCalculation->GenerateSin(vecWave);
|
|
||||||
|
|
||||||
// if(vecWave.size() < 8192){
|
// 积分
|
||||||
// for(int i = vecWave.size(); i < 8192;i++){
|
|
||||||
// vecWave.push_back(0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //添加汉宁窗
|
|
||||||
// pCalculation->Hanning(vecWave, hanningWave);
|
|
||||||
// for(int i = 0; i < vecWave.size();i++){
|
|
||||||
// addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //积分
|
|
||||||
pCalculation->Integration(vecWave, IntegrationWave, resolution);
|
pCalculation->Integration(vecWave, IntegrationWave, resolution);
|
||||||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||||||
|
|
||||||
sampleRateReference = 1024;
|
sampleRateReference = 1024;
|
||||||
}
|
}
|
||||||
/*for(int i = 0; i < fftWave.size();i++){
|
zlog_info(zct,"2---------------------------------------------->vecWave = %d,fftWave = %d", vecWave.size(), fftWave.size());
|
||||||
fftWave[i] = fftWave[i]*2;
|
|
||||||
}*/
|
|
||||||
printf("2---------------------------------------------->vecWave = %d,fftWave = %d\n", vecWave.size(), fftWave.size());
|
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * sampleRateReference;
|
flag = (flag + 1) * sampleRateReference;
|
||||||
int number = fftWave.size();
|
int number = fftWave.size();
|
||||||
printf("number---------------------------------------------->%d\n", number);
|
zlog_info(zct,"number---------------------------------------------->%d", number);
|
||||||
int start = param.mPackageFlag * sampleRateReference;
|
int start = param.mPackageFlag * sampleRateReference;
|
||||||
printf("param.mPackageFlag = %d\n", param.mPackageFlag);
|
zlog_info(zct,"param.mPackageFlag = %d", param.mPackageFlag);
|
||||||
printf("param.start = %d\n", start);
|
zlog_info(zct,"param.start = %d", start);
|
||||||
printf("param.flag = %d\n", flag);
|
zlog_info(zct,"param.flag = %d", flag);
|
||||||
if (number < sampleRateReference) {
|
if (number < sampleRateReference) {
|
||||||
flag = number;
|
flag = number;
|
||||||
start = 0;
|
start = 0;
|
||||||
@ -502,7 +470,7 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|||||||
jsBody["timestamp"] = string(localtimestamp);
|
jsBody["timestamp"] = string(localtimestamp);
|
||||||
jsBody["Data"] = strWaveData;
|
jsBody["Data"] = strWaveData;
|
||||||
|
|
||||||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n", 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);
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
#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>
|
||||||
|
|
||||||
LocalServer::LocalServer() {}
|
LocalServer::LocalServer() {}
|
||||||
|
|
||||||
LocalServer::~LocalServer() { print_info("~LocalServer is called!\n"); }
|
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) {
|
||||||
@ -13,13 +14,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);
|
||||||
LOG_INFO("MQTT recv base64 %s\n", 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;
|
||||||
LOG_INFO("MQTT recv %s\n", 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;
|
||||||
@ -30,7 +31,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)) {
|
||||||
print_error("recv body error");
|
zlog_error(zct,"recv body error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +85,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);
|
||||||
print_info("20 data: %s\n", 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: {
|
||||||
@ -198,9 +199,9 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
|||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
print_brown("cmdType : %d \n", cmdType);
|
zlog_info(zct,"cmdType : %d ", cmdType);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print_error("parase fail \n");
|
zlog_error(zct,"parase fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#include "local_server.hpp"
|
#include "local_server.hpp"
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||||
try {
|
try {
|
||||||
print_purple("HandleCgi Data = %s \n", pData.c_str());
|
zlog_info(zct,"HandleCgi Data = %s ", pData.c_str());
|
||||||
Json::Features f = Json::Features::strictMode();
|
Json::Features f = Json::Features::strictMode();
|
||||||
Json::Reader recvReader(f);
|
Json::Reader recvReader(f);
|
||||||
Json::Value recvValue;
|
Json::Value recvValue;
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
#include "common/global.hpp"
|
#include "common/global.hpp"
|
||||||
#include "utility/secure.hpp"
|
#include "utility/secure.hpp"
|
||||||
@ -41,7 +42,6 @@ void register_collback(connect_callback connect_c, message_callback message_c, s
|
|||||||
int data_publish(const char *str, const char *topic) {
|
int data_publish(const char *str, const char *topic) {
|
||||||
int iRet = -1;
|
int iRet = -1;
|
||||||
if (mosq != NULL) {
|
if (mosq != NULL) {
|
||||||
// print_blue("data_publish: %s %s\n", str, topic);
|
|
||||||
std::string strTopic = std::string(topic);
|
std::string strTopic = std::string(topic);
|
||||||
if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos) {
|
if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos) {
|
||||||
std::string pData = (std::string)str;
|
std::string pData = (std::string)str;
|
||||||
@ -49,12 +49,8 @@ int data_publish(const char *str, const char *topic) {
|
|||||||
memset(base64_aes, 0, pData.length() * 2);
|
memset(base64_aes, 0, pData.length() * 2);
|
||||||
Secure::instance()->Base64Encode((unsigned char *)pData.c_str(), base64_aes, pData.length());
|
Secure::instance()->Base64Encode((unsigned char *)pData.c_str(), base64_aes, pData.length());
|
||||||
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(base64_aes), base64_aes, ud.topic_qos, false);
|
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(base64_aes), base64_aes, ud.topic_qos, false);
|
||||||
// char *base64_data = new char[pData.length() * 2];
|
|
||||||
// memset(base64_data, 0, pData.length() *2);
|
|
||||||
// Secure::instance()->Base64Decode(base64_aes, (unsigned char*)base64_data);
|
|
||||||
// std::string pData = std::string(base64_data);
|
|
||||||
if (base64_aes != NULL) delete[] base64_aes;
|
if (base64_aes != NULL) delete[] base64_aes;
|
||||||
// free(out);
|
|
||||||
} else {
|
} else {
|
||||||
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(str), str, ud.topic_qos, false);
|
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(str), str, ud.topic_qos, false);
|
||||||
}
|
}
|
||||||
@ -117,7 +113,7 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
int reconnect = 0;
|
int reconnect = 0;
|
||||||
if (my_connect_callback == NULL || my_message_callback == NULL || my_subscribe_callback == NULL || my_log_callback == NULL) {
|
if (my_connect_callback == NULL || my_message_callback == NULL || my_subscribe_callback == NULL || my_log_callback == NULL) {
|
||||||
print_info("please call the register_collback function first.\n");
|
zlog_error(zct,"please call the register_collback function first.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +122,6 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
memset(&mqttsdata, 0, sizeof(mqttsdata_t));
|
memset(&mqttsdata, 0, sizeof(mqttsdata_t));
|
||||||
memcpy(mqttsdata.gwid, gwid, strlen(gwid));
|
memcpy(mqttsdata.gwid, gwid, strlen(gwid));
|
||||||
|
|
||||||
// mqttsdata.username = "admin";
|
|
||||||
// mqttsdata.password = "password";
|
|
||||||
salt = std::string(mqttsdata.salt);
|
salt = std::string(mqttsdata.salt);
|
||||||
memset(&ud, 0, sizeof(struct userdata));
|
memset(&ud, 0, sizeof(struct userdata));
|
||||||
ud.eol = true;
|
ud.eol = true;
|
||||||
@ -141,9 +135,7 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
#else
|
#else
|
||||||
mqttsdata.qos = qos;
|
mqttsdata.qos = qos;
|
||||||
#endif
|
#endif
|
||||||
print_info("mqttsdata.qos = %d\n", mqttsdata.qos);
|
zlog_info(zct,"mqttsdata.qos = %d", mqttsdata.qos);
|
||||||
// std::string username = "root";
|
|
||||||
// std::string password = "xom!*283#@XHG";
|
|
||||||
|
|
||||||
std::string username = ReadStrByOpt(SERVERCONFIG, "Server", "UserName");
|
std::string username = ReadStrByOpt(SERVERCONFIG, "Server", "UserName");
|
||||||
std::string password = ReadStrByOpt(SERVERCONFIG, "Server", "Password");
|
std::string password = ReadStrByOpt(SERVERCONFIG, "Server", "Password");
|
||||||
@ -157,7 +149,7 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
|
|
||||||
char passWord[100];
|
char passWord[100];
|
||||||
sprintf(passWord, "%s", password.c_str());
|
sprintf(passWord, "%s", password.c_str());
|
||||||
print_info("userName = %s , passWord = %s\n", userName, passWord);
|
zlog_info(zct,"userName = %s , passWord = %s", userName, passWord);
|
||||||
ud.username = userName;
|
ud.username = userName;
|
||||||
ud.password = passWord;
|
ud.password = passWord;
|
||||||
|
|
||||||
@ -176,43 +168,43 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
sprintf(req_topic, "dev/cidwcc");
|
sprintf(req_topic, "dev/cidwcc");
|
||||||
ud.topics[ud.topic_count - 1] = req_topic;
|
ud.topics[ud.topic_count - 1] = req_topic;
|
||||||
ud.verbose = 1;
|
ud.verbose = 1;
|
||||||
// fprintf(stderr, "topic = %s!!!!!!!!!!!\n", ud.topics[ud.topic_count - 1]);
|
|
||||||
memset(res_topic, 0, 100);
|
memset(res_topic, 0, 100);
|
||||||
sprintf(res_topic, "gw/will");
|
sprintf(res_topic, "gw/will");
|
||||||
print_info("res_topic:%s\n", res_topic);
|
zlog_info(zct,"res_topic:%s", res_topic);
|
||||||
will_topic = res_topic;
|
will_topic = res_topic;
|
||||||
ud.resp_topic = res_topic;
|
ud.resp_topic = res_topic;
|
||||||
sprintf(will_payload, "{\"cmd\":\"15\",\"gwID\":\"%s\"}", mqttsdata.gwid);
|
sprintf(will_payload, "{\"cmd\":\"15\",\"gwID\":\"%s\"}", mqttsdata.gwid);
|
||||||
will_payloadlen = strlen(will_payload);
|
will_payloadlen = strlen(will_payload);
|
||||||
print_info("will_payload:%s,will_payloadlen:%ld\n", will_payload, will_payloadlen);
|
zlog_info(zct,"will_payload:%s,will_payloadlen:%ld", will_payload, will_payloadlen);
|
||||||
if (clean_session == false && (id_prefix || !id)) {
|
if (clean_session == false && (id_prefix || !id)) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: You must provide a client id if you are using the -c option.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ud.topic_count == 0) {
|
if (ud.topic_count == 0) {
|
||||||
fprintf(stderr, "Error: You must specify a topic to subscribe to.\n");
|
zlog_error(zct, "Error: You must specify a topic to subscribe to.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (will_payload && !will_topic) {
|
if (will_payload && !will_topic) {
|
||||||
fprintf(stderr, "Error: Will payload given, but no will topic given.\n");
|
zlog_error(zct, "Error: Will payload given, but no will topic given.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (will_retain && !will_topic) {
|
if (will_retain && !will_topic) {
|
||||||
fprintf(stderr, "Error: Will retain given, but no will topic given.\n");
|
zlog_error(zct, "Error: Will retain given, but no will topic given.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ud.password && !ud.username) {
|
if (ud.password && !ud.username) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Warning: Not using password since username not set.\n");
|
if (!ud.quiet) zlog_error(zct, "Warning: Not using password since username not set.");
|
||||||
}
|
}
|
||||||
if (psk && !psk_identity) {
|
if (psk && !psk_identity) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: --psk-identity required if --psk used.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: --psk-identity required if --psk used.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (id_prefix) {
|
if (id_prefix) {
|
||||||
id = (char *)malloc(strlen(id_prefix) + 10);
|
id = (char *)malloc(strlen(id_prefix) + 10);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Out of memory.");
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -224,7 +216,7 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
len = strlen("mosqsub/-") + 6 + strlen(hostname);
|
len = strlen("mosqsub/-") + 6 + strlen(hostname);
|
||||||
id = (char *)malloc(len);
|
id = (char *)malloc(len);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Out of memory.\n");
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -235,15 +227,15 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
|
id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_info("id:%s\n", id);
|
zlog_info(zct, "id:%s", id);
|
||||||
mosq = mosquitto_new(id, clean_session, &ud);
|
mosq = mosquitto_new(id, clean_session, &ud);
|
||||||
if (!mosq) {
|
if (!mosq) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ENOMEM:
|
case ENOMEM:
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Out of memory.");
|
||||||
break;
|
break;
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Invalid id and/or clean_session .\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Invalid id and/or clean_session .");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
@ -256,21 +248,21 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
if (!psk) {
|
if (!psk) {
|
||||||
psk = (char *)malloc(32 * sizeof(char));
|
psk = (char *)malloc(32 * sizeof(char));
|
||||||
if (!psk) {
|
if (!psk) {
|
||||||
fprintf(stderr, "Error: No free space %d\n", __LINE__);
|
zlog_error(zct, "Error: No free space %d", __LINE__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(psk, 0, 32);
|
memset(psk, 0, 32);
|
||||||
snprintf(psk, 32, "%ld", getpid());
|
snprintf(psk, 32, "%ld", getpid());
|
||||||
psk_identity = (char *)malloc(32 * sizeof(char));
|
psk_identity = (char *)malloc(32 * sizeof(char));
|
||||||
if (!psk_identity) {
|
if (!psk_identity) {
|
||||||
fprintf(stderr, "Error: No free space %d\n", __LINE__);
|
zlog_error(zct, "Error: No free space %d", __LINE__);
|
||||||
free(psk);
|
free(psk);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strncpy(psk_identity, psk, 32);
|
strncpy(psk_identity, psk, 32);
|
||||||
}
|
}
|
||||||
if (will_topic && mosquitto_will_set(mosq, will_topic, will_payloadlen, will_payload, will_qos, will_retain)) {
|
if (will_topic && mosquitto_will_set(mosq, will_topic, will_payloadlen, will_payload, will_qos, will_retain)) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Problem setting will.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Problem setting will.");
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
free(psk);
|
free(psk);
|
||||||
free(psk_identity);
|
free(psk_identity);
|
||||||
@ -278,33 +270,13 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ud.username && mosquitto_username_pw_set(mosq, ud.username, ud.password)) {
|
if (ud.username && mosquitto_username_pw_set(mosq, ud.username, ud.password)) {
|
||||||
if (!ud.quiet) fprintf(stderr, "Error: Problem setting username and password.\n");
|
if (!ud.quiet) zlog_error(zct, "Error: Problem setting username and password.");
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
free(psk);
|
free(psk);
|
||||||
free(psk_identity);
|
free(psk_identity);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (insecure && mosquitto_tls_insecure_set(mosq, false)){
|
|
||||||
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS insecure option.\n");
|
|
||||||
// mosquitto_lib_cleanup();
|
|
||||||
// free(psk);
|
|
||||||
// free(psk_identity);
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (psk && mosquitto_tls_psk_set(mosq, psk, psk_identity, NULL)){
|
|
||||||
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n");
|
|
||||||
// mosquitto_lib_cleanup();
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (tls_version && mosquitto_tls_opts_set(mosq, 0, tls_version, ciphers)){
|
|
||||||
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS options.\n");
|
|
||||||
// mosquitto_lib_cleanup();
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
mosquitto_connect_callback_set(mosq, my_connect_callback);
|
mosquitto_connect_callback_set(mosq, my_connect_callback);
|
||||||
mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
|
mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
|
||||||
mosquitto_message_callback_set(mosq, my_message_callback);
|
mosquitto_message_callback_set(mosq, my_message_callback);
|
||||||
@ -319,24 +291,21 @@ int start_client(const char *boardname, const char *gwid, const char *gwip, cons
|
|||||||
} else {
|
} else {
|
||||||
rc = mosquitto_connect_bind(mosq, host, port, keepalive, bind_address);
|
rc = mosquitto_connect_bind(mosq, host, port, keepalive, bind_address);
|
||||||
}
|
}
|
||||||
print_info("host = %s port = %d rc = %d\n", host, port, rc);
|
zlog_info(zct,"host = %s port = %d rc = %d", host, port, rc);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
if (!ud.quiet) {
|
if (!ud.quiet) {
|
||||||
if (rc == MOSQ_ERR_ERRNO) {
|
if (rc == MOSQ_ERR_ERRNO) {
|
||||||
// strerror_r(errno, err, 1024);
|
|
||||||
// fprintf(stderr, "Error_: %s\n", err);
|
|
||||||
// print_info("%s",stderr);
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to connect (%d).\n", rc);
|
zlog_error(zct, "Unable to connect (%d).", rc);
|
||||||
print_info("%s", stderr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto mosq_free;
|
goto mosq_free;
|
||||||
}
|
}
|
||||||
rc = mosquitto_loop_forever(mosq, -1, 1);
|
rc = mosquitto_loop_forever(mosq, -1, 1);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
fprintf(stderr, "Error: %s\n", mosquitto_strerror(rc));
|
zlog_error(zct, "Error: %s", mosquitto_strerror(rc));
|
||||||
print_info("%s", stderr);
|
|
||||||
}
|
}
|
||||||
mosq_free:
|
mosq_free:
|
||||||
mosquitto_destroy(mosq);
|
mosquitto_destroy(mosq);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "platform_init.hpp"
|
#include "platform_init.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <zlog.h>
|
||||||
#include "common/global.hpp"
|
#include "common/global.hpp"
|
||||||
#include "dbaccess/sql_db.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
|
|
||||||
@ -50,31 +50,30 @@ 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();
|
||||||
print_info("GlobalConfig::IpAddr_G : %s\n", GlobalConfig::IpAddr_G.c_str());
|
zlog_info(zbt,"GlobalConfig::IpAddr_G : %s", GlobalConfig::IpAddr_G.c_str());
|
||||||
this->ConfigFileCheck();
|
this->ConfigFileCheck();
|
||||||
print_info("ConfigFileCheck\n");
|
zlog_info(zbt,"ConfigFileCheck");
|
||||||
this->TopicInit();
|
this->TopicInit();
|
||||||
print_info("TopicInit\n");
|
zlog_info(zbt,"TopicInit");
|
||||||
this->ServerIpInit();
|
this->ServerIpInit();
|
||||||
print_info("TopicInit\n");
|
zlog_info(zbt,"TopicInit");
|
||||||
this->Sqlite3Init();
|
this->Sqlite3Init();
|
||||||
this->GPIOInit();
|
this->GPIOInit();
|
||||||
|
|
||||||
print_info("ServerIP : %s \n", 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) {
|
||||||
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n", 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, ":");
|
||||||
strMac.insert(11, ":");
|
strMac.insert(11, ":");
|
||||||
strMac.insert(14, ":");
|
strMac.insert(14, ":");
|
||||||
ModifyMac((char*)strMac.c_str());
|
ModifyMac((char*)strMac.c_str());
|
||||||
// system("reboot");
|
|
||||||
}
|
}
|
||||||
#ifdef G2UL_GATEWAY
|
#ifdef G2UL_GATEWAY
|
||||||
std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info", "MAC2", NULL);
|
std::string strMac2 = sqlite_db_ctrl::instance().GetData("t_gateway_info", "MAC2", NULL);
|
||||||
@ -83,18 +82,15 @@ 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) {
|
||||||
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n", 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, ":");
|
||||||
strMac2.insert(11, ":");
|
strMac2.insert(11, ":");
|
||||||
strMac2.insert(14, ":");
|
strMac2.insert(14, ":");
|
||||||
ModifyMac((char*)strMac2.c_str());
|
ModifyMac((char*)strMac2.c_str());
|
||||||
// system("reboot");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// sleep(10);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
print_error("PlatFormInit exception happend.\n");
|
print_error("PlatFormInit exception happend.\n");
|
||||||
std::string errorinfo = "系统初始化异常";
|
std::string errorinfo = "系统初始化异常";
|
||||||
@ -184,9 +180,8 @@ void PlatformInit::Sqlite3Init() {
|
|||||||
sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
sqlite_db_ctrl::instance().SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
||||||
writeIntValue("Update", "type", 0, (char*)GlobalConfig::Config_G.c_str());
|
writeIntValue("Update", "type", 0, (char*)GlobalConfig::Config_G.c_str());
|
||||||
}
|
}
|
||||||
print_info("szValue = %d\n", nType);
|
|
||||||
sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str());
|
sqlite_db_ctrl::instance().SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||||
print_info("Sqlite3Init \n");
|
zlog_info(zbt,"Sqlite3Init ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit::GPIOInit() {
|
void PlatformInit::GPIOInit() {
|
||||||
@ -220,7 +215,7 @@ void PlatformInit::SystemInfoInit() {
|
|||||||
Json::Value Systeminfo;
|
Json::Value Systeminfo;
|
||||||
//从配置文件中读取json数据
|
//从配置文件中读取json数据
|
||||||
if (ifileOut.is_open()) {
|
if (ifileOut.is_open()) {
|
||||||
print_blue("open %s\n", SYSTEMINFOFILE);
|
zlog_info(zbt,"open %s\n", SYSTEMINFOFILE);
|
||||||
}
|
}
|
||||||
if (!recvReader.parse(ifileOut, Systeminfo, false)) {
|
if (!recvReader.parse(ifileOut, Systeminfo, false)) {
|
||||||
if (ifileOut.is_open()) {
|
if (ifileOut.is_open()) {
|
||||||
@ -261,10 +256,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);
|
||||||
print_red("strStatus:%s\n networkPortStatus:%s dataWatchIpAddress:%s subnetMask:%s gateway:%s\n", strStatus.c_str(), networkPortStatus.c_str(), dataWatchIpAddress.c_str(), subnetMask.c_str(), gateway.c_str());
|
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")) {
|
||||||
print_white("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");
|
||||||
@ -288,7 +283,6 @@ void PlatformInit::EquipIpInit(std::string eth) {
|
|||||||
}
|
}
|
||||||
if (0 == networkPortStatus.compare("STATIC")) {
|
if (0 == networkPortStatus.compare("STATIC")) {
|
||||||
std::string cmd = "";
|
std::string cmd = "";
|
||||||
print_red("static config\n");
|
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
||||||
if (dataWatchIpAddress.length() > 0) {
|
if (dataWatchIpAddress.length() > 0) {
|
||||||
|
|||||||
@ -8,15 +8,15 @@
|
|||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <zlog.h>
|
||||||
#include "uart/uart.hpp"
|
#include "uart/uart.hpp"
|
||||||
#include "common/common_func.hpp"
|
#include "common/common_func.hpp"
|
||||||
#include "wifi_5g/wpa_client.h"
|
#include "wifi_5g/wpa_client.h"
|
||||||
|
|
||||||
|
|
||||||
void CheckThread() {
|
void CheckThread() {
|
||||||
print_info("ENTER CHECK THREAD \n");
|
zlog_info(zbt,"ENTER CHECK THREAD ");
|
||||||
std::string runinfo = "ENTER CHECK THREAD ";
|
|
||||||
LOG_INFO(runinfo.c_str());
|
|
||||||
int heart_count = 0;
|
int heart_count = 0;
|
||||||
|
|
||||||
int time_check = 0;
|
int time_check = 0;
|
||||||
@ -43,7 +43,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;
|
||||||
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !\n");
|
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 +59,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) {
|
||||||
LOG_INFO("[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !\n");
|
zlog_warn(zct,"[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !");
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !\n");
|
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) {
|
||||||
LOG_ERROR("MQTT connect failed\n");
|
zlog_error(zct,"MQTT connect failed ");
|
||||||
#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(zct,"config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
||||||
if (atoi(connect)) {
|
if (atoi(connect)) {
|
||||||
LOG_ERROR("MQTT connect failed,reboot\n");
|
zlog_error(zct,"MQTT connect failed,reboot");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -107,12 +107,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) {
|
||||||
LOG_ERROR("MQTT connect failed ,time check\n");
|
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)) {
|
||||||
LOG_ERROR("MQTT connect failed,time check ,reboot\n");
|
zlog_error(zct,"MQTT connect failed,time check ,reboot");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -120,10 +120,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);
|
||||||
LOG_DEBUG("GPIO 8 start\n");
|
zlog_warn(zct,"GPIO 8 start");
|
||||||
sleep(2);
|
sleep(2);
|
||||||
gpio_set(GlobalConfig::GPIO_G.commRest, 1);
|
gpio_set(GlobalConfig::GPIO_G.commRest, 1);
|
||||||
LOG_DEBUG("GPIO 8 End\n");
|
zlog_warn(zct,"GPIO 8 End");
|
||||||
sleep(20);
|
sleep(20);
|
||||||
dial.openPort("/dev/ttyUSB2");
|
dial.openPort("/dev/ttyUSB2");
|
||||||
dial.setState();
|
dial.setState();
|
||||||
@ -131,14 +131,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);
|
||||||
LOG_DEBUG("commPower start\n");
|
zlog_warn(zct,"commPower start");
|
||||||
sleep(2);
|
sleep(2);
|
||||||
gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
||||||
LOG_DEBUG("commPower End\n");
|
zlog_warn(zct,"commPower End");
|
||||||
sleep(20);
|
sleep(20);
|
||||||
connectCount++;
|
connectCount++;
|
||||||
if (connectCount > 10) {
|
if (connectCount > 10) {
|
||||||
LOG_ERROR("5G reset error ,reboot!\n");
|
zlog_error(zct,"5G reset error ,reboot!");
|
||||||
system("reboot");
|
system("reboot");
|
||||||
}
|
}
|
||||||
#ifndef NR5G_MEIGE
|
#ifndef NR5G_MEIGE
|
||||||
@ -153,7 +153,7 @@ void CheckThread() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIFI_MODULE
|
#ifdef WIFI_MODULE
|
||||||
LOG_ERROR("WiFi reset!\n");
|
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);
|
||||||
@ -195,7 +195,6 @@ void CheckThread() {
|
|||||||
int hour = 0;
|
int hour = 0;
|
||||||
struct tm *tm_info = get_current_date();
|
struct tm *tm_info = get_current_date();
|
||||||
hour = tm_info->tm_hour;
|
hour = tm_info->tm_hour;
|
||||||
print_info("hour = %d\n", hour);
|
|
||||||
int statistics = readIntValue("config", "statistics", (char *)GlobalConfig::Config_G.c_str());
|
int statistics = readIntValue("config", "statistics", (char *)GlobalConfig::Config_G.c_str());
|
||||||
if (statistics == 0 && hour > 13) {
|
if (statistics == 0 && hour > 13) {
|
||||||
writeIntValue("config", "statistics", 1, (char *)GlobalConfig::Config_G.c_str());
|
writeIntValue("config", "statistics", 1, (char *)GlobalConfig::Config_G.c_str());
|
||||||
@ -206,7 +205,7 @@ void CheckThread() {
|
|||||||
}
|
}
|
||||||
if (mqttresend == 7200) {
|
if (mqttresend == 7200) {
|
||||||
mqttresend = 0;
|
mqttresend = 0;
|
||||||
LOG_INFO("mqttresend check\n");
|
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;
|
||||||
@ -236,28 +235,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());
|
||||||
LOG_INFO("online check = %d\n", lTime);
|
zlog_info(zct,"online check = %d", lTime);
|
||||||
if (lTime > 1800) {
|
if (lTime > 1800) {
|
||||||
LOG_ERROR("nowTimetamp = %s,lastTime = %s,lTime = %d\n", 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;
|
||||||
LOG_INFO("Battery\n");
|
zlog_info(zct,"Battery");
|
||||||
sqlite_db_ctrl::instance().CalculateBattery();
|
sqlite_db_ctrl::instance().CalculateBattery();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (3500 == loose_check) {
|
if (3500 == loose_check) {
|
||||||
LOG_INFO("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) {
|
||||||
LOG_INFO("ModifyAddr check\n");
|
zlog_info(zct,"ModifyAddr check");
|
||||||
ModifyAddr = 0;
|
ModifyAddr = 0;
|
||||||
if (uart_inst::instance().bModifyAddr) {
|
if (uart_inst::instance().bModifyAddr) {
|
||||||
LOG_ERROR("ModifyAddr failed \n");
|
zlog_error(zct,"ModifyAddr failed ");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,7 +316,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) {
|
||||||
LOG_INFO("filename = %s\n", filename.c_str());
|
zlog_info(zct,"filename = %s", filename.c_str());
|
||||||
remove(filename.c_str());
|
remove(filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,23 +358,21 @@ 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());
|
||||||
print_info("%s\n", buf);
|
zlog_info(zct,"%s\n", buf);
|
||||||
LOG_INFO("%s\n", buf);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
std::string runinfo = "wifi:false\n";
|
std::string runinfo = "wifi:false\n";
|
||||||
print_info("%s\n", runinfo.c_str());
|
zlog_info(zct,"%s\n", runinfo.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (wpa.ReconnectWiFi()) {
|
if (wpa.ReconnectWiFi()) {
|
||||||
print_info("wifi reconnect ok\n");
|
zlog_info(zct,"wifi reconnect ok\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (reset_flag > 7200) {
|
if (reset_flag > 7200) {
|
||||||
reset_flag = 0;
|
reset_flag = 0;
|
||||||
// exit(0);
|
|
||||||
}
|
}
|
||||||
Battery++;
|
Battery++;
|
||||||
reset_flag++;
|
reset_flag++;
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <boost/typeof/typeof.hpp>
|
#include <boost/typeof/typeof.hpp>
|
||||||
|
#include <zlog.h>
|
||||||
#include "uart/uart.hpp"
|
#include "uart/uart.hpp"
|
||||||
#include "common/common_func.hpp"
|
#include "common/common_func.hpp"
|
||||||
#include "wifi_5g/dial.h"
|
#include "wifi_5g/dial.h"
|
||||||
@ -23,7 +23,7 @@ static long long connect_time = 0; // ms
|
|||||||
Dial dial;
|
Dial dial;
|
||||||
|
|
||||||
void StartCgiServer() {
|
void StartCgiServer() {
|
||||||
print_info("start deal cgi\n");
|
zlog_info(zbt,"start deal cgi");
|
||||||
TcpCgi *tcpCgi = TcpCgi::instance();
|
TcpCgi *tcpCgi = TcpCgi::instance();
|
||||||
while (1) {
|
while (1) {
|
||||||
tcpCgi->startCgiServer();
|
tcpCgi->startCgiServer();
|
||||||
@ -50,7 +50,7 @@ void HeartRep() {
|
|||||||
jsHeart["IP"] = GlobalConfig::IpAddr_G;
|
jsHeart["IP"] = GlobalConfig::IpAddr_G;
|
||||||
std::string strJson = fw.write(jsHeart);
|
std::string strJson = fw.write(jsHeart);
|
||||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||||
print_info("heart = %s,iRet = %d\n", strJson.c_str(), iRet);
|
zlog_info(zct,"heart = %s,iRet = %d", strJson.c_str(), iRet);
|
||||||
if (iRet != 0) {
|
if (iRet != 0) {
|
||||||
gpio_set(GlobalConfig::GPIO_G.errorLed, 1);
|
gpio_set(GlobalConfig::GPIO_G.errorLed, 1);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
@ -111,7 +111,7 @@ open4G:
|
|||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
timeoutflag++;
|
timeoutflag++;
|
||||||
if (timeoutflag > 5) {
|
if (timeoutflag > 5) {
|
||||||
print_info("timeoutflag = %d\n", timeoutflag);
|
zlog_info("timeoutflag = %d\n", timeoutflag);
|
||||||
timeoutflag = 0;
|
timeoutflag = 0;
|
||||||
const char *str2 = "+QENG: ";
|
const char *str2 = "+QENG: ";
|
||||||
char csq[128] = {0};
|
char csq[128] = {0};
|
||||||
@ -119,12 +119,11 @@ open4G:
|
|||||||
if (pdata) {
|
if (pdata) {
|
||||||
strncpy(csq, pdata + 7, sizeof(csq));
|
strncpy(csq, pdata + 7, sizeof(csq));
|
||||||
|
|
||||||
// printf("SIM-CSQ: %s\n", csq);
|
|
||||||
GlobalConfig::NetStatus = GetOneContent(csq, 1, ",");
|
GlobalConfig::NetStatus = GetOneContent(csq, 1, ",");
|
||||||
string signal = GetOneContent(csq, 13, ",");
|
string signal = GetOneContent(csq, 13, ",");
|
||||||
GlobalConfig::NetSignal = atoi(signal.c_str());
|
GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||||
GlobalConfig::NetType = GetOneContent(csq, 2, ",");
|
GlobalConfig::NetType = GetOneContent(csq, 2, ",");
|
||||||
print_info("NetStatus = %s,NetSignal = %d\n", GlobalConfig::NetStatus.c_str(), GlobalConfig::NetSignal);
|
zlog_info(zct,"NetStatus = %s,NetSignal = %d", GlobalConfig::NetStatus.c_str(), GlobalConfig::NetSignal);
|
||||||
}
|
}
|
||||||
memset(szbuffer, 0x00, sizeof(szbuffer));
|
memset(szbuffer, 0x00, sizeof(szbuffer));
|
||||||
offSize = 0;
|
offSize = 0;
|
||||||
@ -132,10 +131,10 @@ open4G:
|
|||||||
}
|
}
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
} else if (ret > 0) {
|
} else if (ret > 0) {
|
||||||
print_info("ret = %d,buff = %s\n", 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;
|
||||||
print_info("szbuffer = %s\n", szbuffer);
|
zlog_info(zct,"szbuffer = %s", szbuffer);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sleep(10);
|
sleep(10);
|
||||||
@ -154,13 +153,13 @@ dial5G:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UartStart() {
|
void UartStart() {
|
||||||
print_info("zigAckrep = %d,zigAckreset = %d,zigReset = %d,errorLed = %d,power = %d", GlobalConfig::GPIO_G.zigAckrep, GlobalConfig::GPIO_G.zigAckreset, GlobalConfig::GPIO_G.zigReset, GlobalConfig::GPIO_G.errorLed, GlobalConfig::GPIO_G.power);
|
zlog_info(zbt,"zigAckrep = %d,zigAckreset = %d,zigReset = %d,errorLed = %d,power = %d", GlobalConfig::GPIO_G.zigAckrep, GlobalConfig::GPIO_G.zigAckreset, GlobalConfig::GPIO_G.zigReset, GlobalConfig::GPIO_G.errorLed, GlobalConfig::GPIO_G.power);
|
||||||
InitGpio(GlobalConfig::GPIO_G.zigAckrep, 0); // ACK
|
InitGpio(GlobalConfig::GPIO_G.zigAckrep, 0); // ACK
|
||||||
InitGpio(GlobalConfig::GPIO_G.zigAckreset, 1); // ACK reset
|
InitGpio(GlobalConfig::GPIO_G.zigAckreset, 1); // ACK reset
|
||||||
InitGpio(GlobalConfig::GPIO_G.zigReset, 1); // Zigbee reset
|
InitGpio(GlobalConfig::GPIO_G.zigReset, 1); // Zigbee reset
|
||||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1);
|
gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1);
|
||||||
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
|
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
|
||||||
print_info("GPIO Init1\n");
|
zlog_info(zbt,"GPIO Init");
|
||||||
|
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
InitGpio(GlobalConfig::GPIO_G.errorLed, 1); //指示灯
|
InitGpio(GlobalConfig::GPIO_G.errorLed, 1); //指示灯
|
||||||
@ -217,7 +216,7 @@ void InitModule() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIFI_MODULE
|
#ifdef WIFI_MODULE
|
||||||
print_info("Init WiFi!\n");
|
zlog_info(zbt,"Init WiFi!");
|
||||||
|
|
||||||
#ifdef IMX6UL_GATEWAY
|
#ifdef IMX6UL_GATEWAY
|
||||||
InitGpio(GlobalConfig::GPIO_G.wifiReset, 1); // WiFi模组复位,0复位,1取消复位
|
InitGpio(GlobalConfig::GPIO_G.wifiReset, 1); // WiFi模组复位,0复位,1取消复位
|
||||||
@ -266,18 +265,18 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) {
|
|||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
for (int i = 0; i < ud->topic_count; i++) {
|
for (int i = 0; i < ud->topic_count; i++) {
|
||||||
print_purple("mosquitto_subscribe ud->topics[%d]:%s\n", i, ud->topics[i]);
|
zlog_info(zct,"mosquitto_subscribe ud->topics[%d]:%s", i, ud->topics[i]);
|
||||||
int iret = mosquitto_subscribe(mosq, NULL, ud->topics[i], ud->topic_qos);
|
int iret = mosquitto_subscribe(mosq, NULL, ud->topics[i], ud->topic_qos);
|
||||||
print_purple("mosquitto_subscribe ret:%d\n", iret);
|
zlog_info(zct,"mosquitto_subscribe ret:%d", iret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int iret = mosquitto_subscribe(mosq, NULL, GlobalConfig::Topic_G.mSubData.c_str(), 1);
|
int iret = mosquitto_subscribe(mosq, NULL, GlobalConfig::Topic_G.mSubData.c_str(), 1);
|
||||||
print_debug("mosquitto_subscribe's return value: %d\n", iret);
|
zlog_info(zct,"mosquitto_subscribe's return value: %d", iret);
|
||||||
|
|
||||||
char gwTime[32] = {0};
|
char gwTime[32] = {0};
|
||||||
GetTimeNet(gwTime, 0);
|
GetTimeNet(gwTime, 0);
|
||||||
connect_time = strtoll(gwTime, NULL, 10);
|
connect_time = strtoll(gwTime, NULL, 10);
|
||||||
print_debug("connect_time:%lld\n", connect_time);
|
zlog_info(zct,"connect_time:%lld", connect_time);
|
||||||
long long difftime_ms = connect_time - connect_lost_time;
|
long long difftime_ms = connect_time - connect_lost_time;
|
||||||
if (difftime_ms > 20 * 1000) { // 超过20秒,判定为连接断开
|
if (difftime_ms > 20 * 1000) { // 超过20秒,判定为连接断开
|
||||||
char reply_string[256] = {0};
|
char reply_string[256] = {0};
|
||||||
@ -299,17 +298,16 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) {
|
|||||||
std::string topic = "equipment/state/" + GlobalConfig::MacAddr_G;
|
std::string topic = "equipment/state/" + GlobalConfig::MacAddr_G;
|
||||||
int ret = data_publish(instr.c_str(), topic.c_str());
|
int ret = data_publish(instr.c_str(), topic.c_str());
|
||||||
if (ret != MOSQ_ERR_SUCCESS) {
|
if (ret != MOSQ_ERR_SUCCESS) {
|
||||||
print_debug("Publish failed:%d, %s\n", ret, instr.c_str());
|
zlog_info(zct,"Publish failed:%d, %s", ret, instr.c_str());
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalConfig::LinkStatus_G = 1;
|
GlobalConfig::LinkStatus_G = 1;
|
||||||
print_debug("Connect to server success.\n");
|
zlog_info(zct,"Connect to server success.");
|
||||||
|
|
||||||
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());
|
||||||
std::string str = std::string(buf);
|
std::string str = std::string(buf);
|
||||||
// data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
|
||||||
std::string runinfo = "本地服务器连接成功";
|
std::string runinfo = "本地服务器连接成功";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -334,13 +332,12 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) {
|
|||||||
void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) {
|
void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ret = disconnect();
|
ret = disconnect();
|
||||||
// LOG_ERROR("The MQTT connection lost:%d\n", ret);
|
zlog_info(zct,"The MQTT connection lost\n");
|
||||||
print_debug("The MQTT connection lost\n");
|
|
||||||
char gwTime[32] = {0};
|
char gwTime[32] = {0};
|
||||||
GetTimeNet(gwTime, 0);
|
GetTimeNet(gwTime, 0);
|
||||||
uptime = std::string(gwTime);
|
uptime = std::string(gwTime);
|
||||||
connect_lost_time = strtoll(uptime.c_str(), NULL, 10);
|
connect_lost_time = strtoll(uptime.c_str(), NULL, 10);
|
||||||
print_debug("connect_lost_time:%lld\n", connect_lost_time);
|
zlog_info(zct,"connect_lost_time:%lld\n", connect_lost_time);
|
||||||
GlobalConfig::LinkStatus_G = 0;
|
GlobalConfig::LinkStatus_G = 0;
|
||||||
GlobalConfig::LinkCount = GlobalConfig::LinkCount + 1;
|
GlobalConfig::LinkCount = GlobalConfig::LinkCount + 1;
|
||||||
|
|
||||||
@ -369,11 +366,8 @@ void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) {
|
|||||||
int iRet = reconnect();
|
int iRet = reconnect();
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
sprintf(buf, "wifi RSSI:%s,state:%s,MQTT reconnect :%d\n", RSSI.c_str(), state.c_str(), iRet);
|
sprintf(buf, "wifi RSSI:%s,state:%s,MQTT reconnect :%d\n", RSSI.c_str(), state.c_str(), iRet);
|
||||||
// LOG_WARN(" %s\n",buf);
|
|
||||||
int status = Ping(GlobalConfig::ServerIP.c_str(), 10000);
|
zlog_info(zct,"%s\n", buf);
|
||||||
;
|
|
||||||
// LOG_WARN(" netStatus %d\n",status);
|
|
||||||
print_info("%s\n", buf);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -397,14 +391,13 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
|
|||||||
if (ud->verbose) {
|
if (ud->verbose) {
|
||||||
if (message->payloadlen) {
|
if (message->payloadlen) {
|
||||||
std::string strtopic(message->topic);
|
std::string strtopic(message->topic);
|
||||||
print_info("strtopic : %s \n", strtopic.c_str());
|
zlog_info(zct,"strtopic : %s \n", strtopic.c_str());
|
||||||
cidwServer->HandleFromServer((const char *)message->payload, message->payloadlen, message->topic);
|
cidwServer->HandleFromServer((const char *)message->payload, message->payloadlen, message->topic);
|
||||||
if (ud->eol) {
|
if (ud->eol) {
|
||||||
print_brown("\n");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ud->eol) {
|
if (ud->eol) {
|
||||||
print_brown("%s (null)\n", message->topic);
|
zlog_info(zct,"%s (null)\n", message->topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -412,7 +405,6 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
|
|||||||
if (message->payloadlen) {
|
if (message->payloadlen) {
|
||||||
fwrite(message->payload, 1, message->payloadlen, stdout);
|
fwrite(message->payload, 1, message->payloadlen, stdout);
|
||||||
if (ud->eol) {
|
if (ud->eol) {
|
||||||
print_red("\n");
|
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
@ -424,9 +416,9 @@ void my_subscribe_callback(struct mosquitto *mosq, void *obj, int mid, int qos_c
|
|||||||
struct userdata *ud;
|
struct userdata *ud;
|
||||||
assert(obj);
|
assert(obj);
|
||||||
ud = (struct userdata *)obj;
|
ud = (struct userdata *)obj;
|
||||||
if (!ud->quiet) print_brown("Subscribed (mid: %d): %d", mid, granted_qos[0]);
|
if (!ud->quiet) zlog_info(zct,"Subscribed (mid: %d): %d", mid, granted_qos[0]);
|
||||||
for (i = 1; i < qos_count; i++) {
|
for (i = 1; i < qos_count; i++) {
|
||||||
if (!ud->quiet) print_brown(", %d", granted_qos[i]);
|
if (!ud->quiet) zlog_info(zct,", %d", granted_qos[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,7 +433,7 @@ void my_log_callback(struct mosquitto *mosq, void *obj, int level, const char *s
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StartMqttClient() {
|
void StartMqttClient() {
|
||||||
print_info("start mqtt \n");
|
zlog_info(zct,"start mqtt \n");
|
||||||
std::string runinfo = "MQTT通信模块启动";
|
std::string runinfo = "MQTT通信模块启动";
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -461,7 +453,7 @@ void SearchThread() {
|
|||||||
|
|
||||||
while (GlobalConfig::QuitFlag_G) {
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
if (GlobalConfig::IpAddr_G.length() > 0 && 0 != GlobalConfig::IpAddr_G.compare("0.0.0.0")) {
|
if (GlobalConfig::IpAddr_G.length() > 0 && 0 != GlobalConfig::IpAddr_G.compare("0.0.0.0")) {
|
||||||
print_info("%s\n", runinfo.c_str());
|
zlog_info("%s\n", runinfo.c_str());
|
||||||
boost::asio::io_service io_service;
|
boost::asio::io_service io_service;
|
||||||
SearchDev *searchDevObj = new SearchDev(io_service);
|
SearchDev *searchDevObj = new SearchDev(io_service);
|
||||||
searchDevObj->MultiCastRecv();
|
searchDevObj->MultiCastRecv();
|
||||||
@ -469,7 +461,7 @@ void SearchThread() {
|
|||||||
delete searchDevObj;
|
delete searchDevObj;
|
||||||
}
|
}
|
||||||
sleep(5);
|
sleep(5);
|
||||||
print_error("SearchThred restart.\n");
|
zlog_info(zct,"SearchThred restart.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,8 +473,7 @@ void RecvUpdateFile() {
|
|||||||
acceptor.accept(socket);
|
acceptor.accept(socket);
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
if (ec) {
|
if (ec) {
|
||||||
print_error("%s\n", boost::system::system_error(ec).what());
|
zlog_error("%s\n", boost::system::system_error(ec).what());
|
||||||
// return -1;
|
|
||||||
}
|
}
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
@ -491,22 +482,22 @@ void RecvUpdateFile() {
|
|||||||
bzero(buffer, 1024);
|
bzero(buffer, 1024);
|
||||||
fp = fopen("/tmp/upgrade.tar.gz", "w");
|
fp = fopen("/tmp/upgrade.tar.gz", "w");
|
||||||
if (NULL == fp) {
|
if (NULL == fp) {
|
||||||
print_info("File:\t Can Not Open To Write\n");
|
zlog_info(zct,"File:\t Can Not Open To Write\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
while (len = socket.read_some(boost::asio::buffer(buffer), ec)) {
|
while (len = socket.read_some(boost::asio::buffer(buffer), ec)) {
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
print_info("Receive Data From Server Failed! \n");
|
zlog_info(zct,"Receive Data From Server Failed! \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
write_len = fwrite(buffer, sizeof(char), len, fp);
|
write_len = fwrite(buffer, sizeof(char), len, fp);
|
||||||
if (write_len < len) {
|
if (write_len < len) {
|
||||||
print_info("File:test Write Failed!\n");
|
zlog_info("File:test Write Failed!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bzero(buffer, 1024);
|
bzero(buffer, 1024);
|
||||||
}
|
}
|
||||||
print_info("Receive File From Server Finished! \n");
|
zlog_info(zct,"Receive File From Server Finished! \n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
Json::Value jsData;
|
Json::Value jsData;
|
||||||
Json::FastWriter fw;
|
Json::FastWriter fw;
|
||||||
|
|||||||
143
uart/uart.cpp
143
uart/uart.cpp
@ -12,8 +12,10 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/timer.hpp>
|
#include <boost/timer.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <zlog.h>
|
||||||
#include "utility/serial.h"
|
#include "utility/serial.h"
|
||||||
|
|
||||||
|
char g_UartRecvBuf[GENERAL_BUF_SIZE];
|
||||||
int offSize = 0;
|
int offSize = 0;
|
||||||
pTestRecvCallBack pTestRecv;
|
pTestRecvCallBack pTestRecv;
|
||||||
|
|
||||||
@ -33,8 +35,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) {
|
||||||
LOG_DEBUG("===============0x9999 timeout= %d offSize = %d===============\n", timeoutflag, offSize);
|
zlog_info(zct,"===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize);
|
||||||
print_info("0x9999 timeout %d===============Size = %d\n", 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;
|
||||||
@ -50,13 +52,13 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||||
|
|
||||||
LOG_DEBUG("wave end\n");
|
zlog_info(zct,("wave end");
|
||||||
}
|
}
|
||||||
mssleep(10000);
|
mssleep(10000);
|
||||||
} else if (bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)) {
|
} else if (bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)) {
|
||||||
timeoutflag++;
|
timeoutflag++;
|
||||||
if (timeoutflag > 300) {
|
if (timeoutflag > 300) {
|
||||||
print_info("bUpdateconfig %d===============\n", 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;
|
||||||
@ -90,7 +92,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) {
|
||||||
LOG_INFO("maxSize = %d\n", 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;
|
||||||
@ -113,9 +115,9 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (srcshow) {
|
if (srcshow) {
|
||||||
print_info("0x8888 ===str_recv===,ret = %d\n", ret);
|
zlog_info(zct,"0x8888 ===str_recv===,ret = %d", ret);
|
||||||
for (int i = 0; i < ret; i++) {
|
for (int i = 0; i < ret; i++) {
|
||||||
print_debug("[%02x]", buff[i] & 0xff);
|
zlog_info(zct,"[%02x]", buff[i] & 0xff);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
FindRecvPackage(ret, buff, head);
|
FindRecvPackage(ret, buff, head);
|
||||||
@ -135,11 +137,11 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
}
|
}
|
||||||
} else if (ret > 0) {
|
} else if (ret > 0) {
|
||||||
maxSize += ret;
|
maxSize += ret;
|
||||||
print_debug("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++) {
|
||||||
print_debug("%02x ", buff[i] & 0xff);
|
zlog_info(zct,"%02x ", buff[i] & 0xff);
|
||||||
}
|
}
|
||||||
print_debug("\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);
|
||||||
@ -190,9 +192,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
|
||||||
print_info("InitUart fd = %d\n", fd);
|
zlog_info(zct,"InitUart fd = %d", fd);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("config_uart error\n");
|
zlog_error(zct,"config_uart error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,12 +211,12 @@ void Uart::InitZigbeeHW() {
|
|||||||
if (iRet <= 0) {
|
if (iRet <= 0) {
|
||||||
Close();
|
Close();
|
||||||
sleep(2);
|
sleep(2);
|
||||||
print_info("Speed error\n");
|
zlog_info(zct,"Speed error");
|
||||||
InitUart(B57600);
|
InitUart(B57600);
|
||||||
UpdateZigbeeInfoCtrl();
|
UpdateZigbeeInfoCtrl();
|
||||||
sleep(2);
|
sleep(2);
|
||||||
ReadFromUart();
|
ReadFromUart();
|
||||||
print_info("modify speed\n");
|
zlog_info(zct,"modify speed");
|
||||||
WriteSpeed2Zigbee();
|
WriteSpeed2Zigbee();
|
||||||
ReadFromUart();
|
ReadFromUart();
|
||||||
}
|
}
|
||||||
@ -231,21 +233,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) {
|
||||||
print_info("InitTestUart\n");
|
zlog_info(zct,"InitTestUart");
|
||||||
TestFd = config_uart("/dev/ttymxc2", speed); // Test
|
TestFd = config_uart("/dev/ttymxc2", speed); // Test
|
||||||
if (TestFd < 0) {
|
if (TestFd < 0) {
|
||||||
printf("Test config_uart error\n");
|
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};
|
||||||
print_info("ReadTestUart\n");
|
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) {
|
||||||
print_info("buff = %s\n", 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());
|
||||||
@ -289,11 +291,11 @@ int Uart::ZigbeeTest() {
|
|||||||
|
|
||||||
void Uart::WriteToUart(const char *strSend, int pLen) {
|
void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||||
if (!bUpdate) {
|
if (!bUpdate) {
|
||||||
print_debug("Write To Uart Start:\n");
|
zlog_info(zct,"Write To Uart Start:");
|
||||||
for (int i = 0; i < pLen; i++) {
|
for (int i = 0; i < pLen; i++) {
|
||||||
print_debug("%02X ", *(strSend + i) & 0xFF);
|
zlog_info(zct,"%02X ", *(strSend + i) & 0xFF);
|
||||||
}
|
}
|
||||||
print_debug("\nWrite To Uart End.\n");
|
zlog_info(zct,"\nWrite To Uart End.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = write_data(fd, (char *)strSend, pLen);
|
int len = write_data(fd, (char *)strSend, pLen);
|
||||||
@ -302,9 +304,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++) print_debug("%02X ", buffer[i] & 0xFF);
|
for (int i = 0; i < len; i++) zlog_info(zct,"%02X ", buffer[i] & 0xFF);
|
||||||
print_info("\n");
|
zlog_info(zct,"==========ReadFromUart========len = %d", len);
|
||||||
print_info("==========ReadFromUart========len = %d\n", len);
|
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
char head[] = {0xAA, 0x55, 0xAA};
|
char head[] = {0xAA, 0x55, 0xAA};
|
||||||
@ -323,7 +324,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) {
|
||||||
print_info("update gateway zigbee info\n");
|
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);
|
||||||
@ -353,16 +354,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);
|
||||||
|
|
||||||
LOG_INFO("local zigbee module info Mode : %d Chan : %d PanID : %s MyAddr : %s DstAddr : %s,RetryNum:%s,TranTimeout:%s\n", 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());
|
||||||
|
|
||||||
LOG_INFO("PanID = %s,MacAddr_G= %s\n", 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");
|
||||||
LOG_INFO("Channel = %d,strchan = %s\n", 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");
|
||||||
print_info("TranTimeout = %02x,strType = %s \n", 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);
|
||||||
@ -387,7 +388,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);
|
||||||
print_info("the data package type(1,2,3,4,5,6) is %s,%x\n", buf, pData[5] & 0xFF);
|
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:设备信息
|
||||||
@ -411,7 +412,7 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
|
|
||||||
void Uart::DealDataNodeName(const char *pData) {
|
void Uart::DealDataNodeName(const char *pData) {
|
||||||
bSendTimeStamp = false;
|
bSendTimeStamp = false;
|
||||||
print_info("DealDataNodeName \n");
|
zlog_info(zct,"DealDataNodeName ");
|
||||||
string strTime = GetLocalTimeWithMs();
|
string strTime = GetLocalTimeWithMs();
|
||||||
char szShortAdd[8] = {0x00};
|
char szShortAdd[8] = {0x00};
|
||||||
char shortAdd[8] = {0x00};
|
char shortAdd[8] = {0x00};
|
||||||
@ -434,7 +435,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);
|
||||||
print_info("whereCon = %s\n", 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++) {
|
||||||
@ -460,12 +461,12 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
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);
|
||||||
print_info("strNodeName = %s\n", strNodeName.c_str());
|
zlog_info(zct,"strNodeName = %s", strNodeName.c_str());
|
||||||
solve(gbkNodeName, NodeName);
|
solve(gbkNodeName, NodeName);
|
||||||
print_info("gbkNodeName = %s\n", gbkNodeName);
|
zlog_info(zct,"gbkNodeName = %s", gbkNodeName);
|
||||||
string utfNodeName = GBKToUTF8(gbkNodeName);
|
string utfNodeName = GBKToUTF8(gbkNodeName);
|
||||||
print_info("NodeName = %s\n", NodeName);
|
zlog_info(zct,"NodeName = %s", NodeName);
|
||||||
print_info("whereCon = %s\n", 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);
|
string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||||
@ -473,7 +474,7 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::DealDataNodeInfo(const char *pData) {
|
void Uart::DealDataNodeInfo(const char *pData) {
|
||||||
print_info("recv remote zigbee module info\n");
|
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
|
||||||
@ -495,7 +496,6 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
|
|
||||||
chTemp = pRecvData->Data[10]; //软件版本 1 byte
|
chTemp = pRecvData->Data[10]; //软件版本 1 byte
|
||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
// sprintf(buf, "%02x", chTemp);
|
|
||||||
sprintf(buf, "%.1f", 0.1 * chTemp);
|
sprintf(buf, "%.1f", 0.1 * chTemp);
|
||||||
dataNodeInfo.SoftVersion = std::string(buf);
|
dataNodeInfo.SoftVersion = std::string(buf);
|
||||||
|
|
||||||
@ -516,11 +516,9 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
sprintf(buf, "%d", BUILD_UINT32(pRecvData->Data[23], pRecvData->Data[24], pRecvData->Data[25], pRecvData->Data[26]));
|
sprintf(buf, "%d", BUILD_UINT32(pRecvData->Data[23], pRecvData->Data[24], pRecvData->Data[25], pRecvData->Data[26]));
|
||||||
dataNodeInfo.WakeupTime = atoi(buf); //唤醒次数 4 byte
|
dataNodeInfo.WakeupTime = atoi(buf); //唤醒次数 4 byte
|
||||||
printf("WakeupTime = %d\n", dataNodeInfo.WakeupTime);
|
|
||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
sprintf(buf, "%d", BUILD_UINT32(pRecvData->Data[27], pRecvData->Data[28], pRecvData->Data[29], pRecvData->Data[30]));
|
sprintf(buf, "%d", BUILD_UINT32(pRecvData->Data[27], pRecvData->Data[28], pRecvData->Data[29], pRecvData->Data[30]));
|
||||||
dataNodeInfo.StaticTime = atoi(buf); //特征值发送次数 4 byte
|
dataNodeInfo.StaticTime = atoi(buf); //特征值发送次数 4 byte
|
||||||
printf("StaticTime = %d\n", dataNodeInfo.StaticTime);
|
|
||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
|
|
||||||
dataNodeInfo.WaveTime = BUILD_UINT32(pRecvData->Data[31], pRecvData->Data[32], pRecvData->Data[33], pRecvData->Data[34]); //原始波形发送次数 4 byte
|
dataNodeInfo.WaveTime = BUILD_UINT32(pRecvData->Data[31], pRecvData->Data[32], pRecvData->Data[33], pRecvData->Data[34]); //原始波形发送次数 4 byte
|
||||||
@ -591,7 +589,6 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
unsigned char range = (chTemp >> 2) & 0x3;
|
unsigned char range = (chTemp >> 2) & 0x3;
|
||||||
dataNodeInfo.Range = range;
|
dataNodeInfo.Range = range;
|
||||||
int SamplingRate = (chTemp & 0x3);
|
int SamplingRate = (chTemp & 0x3);
|
||||||
print_info("SamplingRate = %d\n", SamplingRate);
|
|
||||||
if (SamplingRate == 0) {
|
if (SamplingRate == 0) {
|
||||||
dataNodeInfo.SamplingRate = 3200;
|
dataNodeInfo.SamplingRate = 3200;
|
||||||
} else if (SamplingRate == 1) {
|
} else if (SamplingRate == 1) {
|
||||||
@ -606,7 +603,6 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
unsigned char range = (chTemp >> 3) & 0x7;
|
unsigned char range = (chTemp >> 3) & 0x7;
|
||||||
dataNodeInfo.Range = range;
|
dataNodeInfo.Range = range;
|
||||||
int SamplingRate = (chTemp & 0x7);
|
int SamplingRate = (chTemp & 0x7);
|
||||||
print_info("SamplingRate = %d\n", SamplingRate);
|
|
||||||
if (SamplingRate == 0) {
|
if (SamplingRate == 0) {
|
||||||
dataNodeInfo.SamplingRate = 8000;
|
dataNodeInfo.SamplingRate = 8000;
|
||||||
} else if (SamplingRate == 1) {
|
} else if (SamplingRate == 1) {
|
||||||
@ -772,8 +768,8 @@ 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());
|
||||||
|
|
||||||
print_info("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 \n",
|
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(),
|
||||||
@ -782,9 +778,9 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
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));
|
||||||
print_info("new Node,size = %d\n", g_mapCompress.size());
|
zlog_info(zct,"new Node,size = %d", g_mapCompress.size());
|
||||||
}
|
}
|
||||||
LOG_INFO("DealDataNodeInfo %s \n", dataNodeInfo.ZigbeeShortAddr.c_str());
|
zlog_info(zct,"DealDataNodeInfo %s ", dataNodeInfo.ZigbeeShortAddr.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uart::ZigbeeParameterConfig() {
|
void Uart::ZigbeeParameterConfig() {
|
||||||
@ -795,18 +791,18 @@ void Uart::ZigbeeParameterConfig() {
|
|||||||
mssleep(100000);
|
mssleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_info("strPanId : %s\n", strPanId.c_str());
|
zlog_info(zct,"strPanId : %s", strPanId.c_str());
|
||||||
print_info("MacAddr_G : %s\n", 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);
|
||||||
print_info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u\n", Chan);
|
zlog_info(zct,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u", Chan);
|
||||||
print_info("ZigbeeInfo_G.Channel=%d\n", 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);
|
||||||
}
|
}
|
||||||
print_info("PanID1 = %s,strPanId = %s\n", 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;
|
||||||
@ -814,7 +810,7 @@ void Uart::ZigbeeParameterConfig() {
|
|||||||
WritePanId2Zigbee(panid);
|
WritePanId2Zigbee(panid);
|
||||||
mssleep(100000);
|
mssleep(100000);
|
||||||
|
|
||||||
print_info("ZigbeeInfo_G.MyAddr=%s\n", 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) {
|
||||||
@ -825,12 +821,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
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) {
|
||||||
print_info("mlastSize = %d\n", 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++) {
|
||||||
print_info("%02x ", UartRecvBuf[i]);
|
zlog_info(zct,"%02x ", UartRecvBuf[i]);
|
||||||
}
|
}
|
||||||
print_info("\n ");
|
|
||||||
memset(mUartRecvTmpBuf, 0x00, sizeof(mUartRecvTmpBuf));
|
memset(mUartRecvTmpBuf, 0x00, sizeof(mUartRecvTmpBuf));
|
||||||
}
|
}
|
||||||
memcpy(UartRecvBuf + mlastSize, mUartRecvBuf, bytesRead);
|
memcpy(UartRecvBuf + mlastSize, mUartRecvBuf, bytesRead);
|
||||||
@ -854,13 +849,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) {
|
||||||
LOG_ERROR("mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s \n", 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;
|
||||||
|
|
||||||
LOG_ERROR("mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s \n", 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());
|
||||||
|
|
||||||
@ -870,7 +865,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);
|
||||||
}
|
}
|
||||||
LOG_ERROR("error str = %s\n", 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);
|
||||||
@ -885,11 +880,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command == 32) {
|
if (command == 32) {
|
||||||
LOG_INFO("bUpdatepackge command = %d ShortAddr :%s\n", 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)) {
|
||||||
LOG_INFO("CheckCrc error command 20 \n");
|
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);
|
||||||
@ -910,7 +905,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;
|
||||||
LOG_INFO("CheckCrc error ShortAddr :%s command = %d\n", 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};
|
||||||
@ -918,8 +913,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);
|
||||||
}
|
}
|
||||||
LOG_ERROR("error str = %s\n", tmp2);
|
zlog_error(zct,"error str = %s", tmp2);
|
||||||
print_info("\n");
|
|
||||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||||
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
@ -952,19 +946,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)) {
|
||||||
LOG_INFO("CheckCrc error ShortAddr :%s command = %d \n", 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)) {
|
||||||
print_info("m_strDestShortAddr = %s,strShortAddr = %s,waittime = %d\n", 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);
|
||||||
LOG_INFO("Online = %s,command = %d\n", 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;
|
||||||
@ -975,9 +969,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (command == 34 && bUpdateconfig) {
|
} else if (command == 34 && bUpdateconfig) {
|
||||||
LOG_INFO("bUpdateconfig command = %d ShortAddr :%s\n", 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));
|
||||||
print_info("bUpdateconfig ShortAddr :%s\n", strShortAddr.c_str());
|
zlog_info(zct,"bUpdateconfig ShortAddr :%s", strShortAddr.c_str());
|
||||||
|
|
||||||
m_TimeStamp = 0;
|
m_TimeStamp = 0;
|
||||||
{
|
{
|
||||||
@ -1010,7 +1004,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);
|
||||||
LOG_ERROR(errorInfo);
|
zlog_error(zct,errorInfo);
|
||||||
} else {
|
} else {
|
||||||
char whereCon[1024] = {0};
|
char whereCon[1024] = {0};
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
@ -1027,7 +1021,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||||
if (vParamRSSI.size() > 0) {
|
if (vParamRSSI.size() > 0) {
|
||||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
|
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
|
||||||
// LOG_INFO(updateSql);
|
|
||||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||||
}
|
}
|
||||||
@ -1048,12 +1041,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);
|
||||||
print_info("command = %d\n", 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;
|
||||||
LOG_INFO("zigbeeShortAddr = %s , ret = %02d\n", 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);
|
||||||
}
|
}
|
||||||
@ -1069,7 +1062,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);
|
||||||
print_info("command = %d\n", 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);
|
||||||
@ -1077,8 +1070,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;
|
||||||
print_info("%02x,%02x,%02x,%02x,%02x \n", 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]);
|
||||||
LOG_INFO("zigbeeShortAddr = %s , ret = %02d\n", 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,9 +1,10 @@
|
|||||||
#include "uart.hpp"
|
#include "uart.hpp"
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
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);
|
||||||
LOG_INFO("UpdateZigbeeInfoCtrl \n");
|
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) {
|
||||||
@ -113,7 +114,7 @@ void Uart::zigbee_reset(unsigned short pad, unsigned short type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WriteChanl2Zigbee(unsigned char pad) {
|
void Uart::WriteChanl2Zigbee(unsigned char pad) {
|
||||||
print_info("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;
|
||||||
@ -126,10 +127,10 @@ void Uart::WriteChanl2Zigbee(unsigned char pad) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WritePanId2Zigbee(unsigned short pad) {
|
void Uart::WritePanId2Zigbee(unsigned short pad) {
|
||||||
print_info("WritePanId2Zigbee : %d\n", 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;
|
||||||
print_info("MyAddr : %d\n", 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);
|
||||||
@ -151,7 +152,7 @@ void Uart::WriteSpeed2Zigbee() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WriteTranTimeout2Zigbee(unsigned char Time) {
|
void Uart::WriteTranTimeout2Zigbee(unsigned char Time) {
|
||||||
print_info("WriteTranTimeout2Zigbee : %d\n", 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;
|
||||||
@ -165,7 +166,7 @@ void Uart::WriteTranTimeout2Zigbee(unsigned char Time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WriteShortAddr2Zigbee(unsigned short pad) {
|
void Uart::WriteShortAddr2Zigbee(unsigned short pad) {
|
||||||
print_info("WriteShortAddr2Zigbee : %4x\n", (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;
|
||||||
|
|
||||||
@ -179,7 +180,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) {
|
||||||
print_info("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);
|
||||||
@ -189,7 +190,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;
|
||||||
|
|
||||||
print_info("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);
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
std::vector<RecvData> g_VecWaveDataX;
|
std::vector<RecvData> g_VecWaveDataX;
|
||||||
std::vector<RecvData> g_VecWaveDataY;
|
std::vector<RecvData> g_VecWaveDataY;
|
||||||
@ -18,7 +19,6 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||||
print_info("recv feature\n");
|
|
||||||
RecvData *pRecvData = (RecvData *)pData;
|
RecvData *pRecvData = (RecvData *)pData;
|
||||||
char whereCon[1024] = {0};
|
char whereCon[1024] = {0};
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
@ -26,24 +26,24 @@ 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) {
|
||||||
LOG_INFO("DealDataNodeFeature %02x%02x, %d\n", 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);
|
||||||
print_info("zigbeeShortAddr='%s'\n", 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) {
|
||||||
LOG_ERROR("device info not found %02x%02x\n", 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");
|
print_error("device info not found\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print_info("--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s\n", 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 +56,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);
|
||||||
|
|
||||||
LOG_DEBUG("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 +83,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
}
|
}
|
||||||
if (isUpdate || bUpdateconfig) {
|
if (isUpdate || bUpdateconfig) {
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("DealDataNodeFeature %02x%02x,localaddr %02x%02x \n", 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;
|
||||||
@ -127,8 +127,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
|
|
||||||
g_mapCompress[strShortAddr] = tempchannel;
|
g_mapCompress[strShortAddr] = tempchannel;
|
||||||
|
|
||||||
print_info("count X = %d,Y = %d,Z = %d\n", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
zlog_info(zct,"count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
||||||
print_info("compress X = %d,Y = %d,Z = %d \n", 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));
|
||||||
@ -142,10 +142,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
}
|
}
|
||||||
long staticIndex = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
long staticIndex = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
||||||
|
|
||||||
print_info("staticIndex = %d\n", staticIndex);
|
|
||||||
|
|
||||||
// LOG_INFO("staticIndex = %d\n",staticIndex);
|
|
||||||
|
|
||||||
char localtimestamp[32] = {0};
|
char localtimestamp[32] = {0};
|
||||||
GetTimeNet(localtimestamp, 1);
|
GetTimeNet(localtimestamp, 1);
|
||||||
std::string nowTimetamp = std::string(localtimestamp);
|
std::string nowTimetamp = std::string(localtimestamp);
|
||||||
@ -159,14 +155,12 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
DataRecvStatic dataStatic;
|
DataRecvStatic dataStatic;
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
sprintf(buf, "%02x%02x", pRecvData->Data[5], pRecvData->Data[4]);
|
sprintf(buf, "%02x%02x", pRecvData->Data[5], pRecvData->Data[4]);
|
||||||
print_blue("!!!!!!!!!!!!!!!!!!!!!!%s\n", buf);
|
|
||||||
iTemp = (int)strtol(buf, NULL, 16);
|
iTemp = (int)strtol(buf, NULL, 16);
|
||||||
dataStatic.Dip = iTemp;
|
dataStatic.Dip = iTemp;
|
||||||
|
|
||||||
int fTemp = 0;
|
int fTemp = 0;
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
sprintf(buf, "%02x%02x", pRecvData->Data[1], pRecvData->Data[0]);
|
sprintf(buf, "%02x%02x", pRecvData->Data[1], pRecvData->Data[0]);
|
||||||
print_blue("@@@@@@@@@@@@@@@@@%s\n", buf);
|
|
||||||
iTemp = (int)strtol(buf, NULL, 16);
|
iTemp = (int)strtol(buf, NULL, 16);
|
||||||
if (iTemp < 0x8000) {
|
if (iTemp < 0x8000) {
|
||||||
fTemp = iTemp;
|
fTemp = iTemp;
|
||||||
@ -200,8 +194,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
n = ScaleConvert(highbit);
|
n = ScaleConvert(highbit);
|
||||||
dataStatic.nodeWorkTime = lowbit * n;
|
dataStatic.nodeWorkTime = lowbit * n;
|
||||||
|
|
||||||
print_info("workTime = %f\n", dataStatic.nodeWorkTime);
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
sprintf(buf, "%02x%02x", pRecvData->Data[33], pRecvData->Data[32]);
|
sprintf(buf, "%02x%02x", pRecvData->Data[33], pRecvData->Data[32]);
|
||||||
iTemp = (unsigned int)strtol(buf, NULL, 16);
|
iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||||
@ -209,7 +201,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
lowbit = iTemp & 0x3fff;
|
lowbit = iTemp & 0x3fff;
|
||||||
n = ScaleConvert(highbit);
|
n = ScaleConvert(highbit);
|
||||||
dataStatic.nodeSendTime = lowbit * n;
|
dataStatic.nodeSendTime = lowbit * n;
|
||||||
print_info("SendTime = %f\n", dataStatic.nodeSendTime);
|
|
||||||
dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime;
|
dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime;
|
||||||
|
|
||||||
RecordBattery(strLongAddr, dataStatic, nowTimetamp);
|
RecordBattery(strLongAddr, dataStatic, nowTimetamp);
|
||||||
@ -227,7 +218,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);
|
||||||
LOG_DEBUG(logInfo);
|
zlog_info(zct,logInfo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
@ -237,7 +228,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());
|
||||||
print_info("row1 = %d\n", 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);
|
||||||
@ -246,7 +237,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());
|
||||||
print_info("row2 = %d\n", 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);
|
||||||
@ -259,9 +250,9 @@ 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);
|
||||||
LOG_INFO("staticIndexNOW = %d,strStaticIndexLast = %s\n", staticIndex, strStaticIndex.c_str());
|
zlog_info(zct,"staticIndexNOW = %d,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str());
|
||||||
}
|
}
|
||||||
print_info("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);
|
||||||
@ -276,7 +267,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
nodeResend = 1;
|
nodeResend = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_info("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());
|
||||||
@ -286,17 +277,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);
|
||||||
}
|
}
|
||||||
print_info("strLongAddr = %s,strTime = %s\n", 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());
|
||||||
print_info("lTime = %d,OneWeek = %d\n", lTime, OneWeek);
|
zlog_info(zct,"lTime = %d,OneWeek = %d", lTime, OneWeek);
|
||||||
|
|
||||||
print_info("dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d\n", 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) {
|
||||||
print_info("insert static data to sql\n");
|
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);
|
||||||
@ -315,7 +306,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());
|
||||||
print_info("update static data to sql\n");
|
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());
|
||||||
@ -451,7 +442,7 @@ 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);
|
||||||
}
|
}
|
||||||
print_info("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\n", 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;
|
||||||
@ -593,7 +584,7 @@ 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);
|
||||||
}
|
}
|
||||||
print_info("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\n", 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;
|
||||||
@ -754,7 +745,7 @@ 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);
|
||||||
}
|
}
|
||||||
print_info("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\n", 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));
|
||||||
@ -815,9 +806,9 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
root["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
root["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
Json::FastWriter featureValue;
|
Json::FastWriter featureValue;
|
||||||
std::string strstatisticData = featureValue.write(root);
|
std::string strstatisticData = featureValue.write(root);
|
||||||
//传感器发来的数据包中的表示设备信息的数据转化为json格式后,通过调用data_publish将数据传给mqttclient : Topic:wireless/cmd/60294D203717
|
|
||||||
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());
|
||||||
print_info("dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d\n", 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);
|
||||||
@ -828,14 +819,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
}
|
}
|
||||||
//综上代码,把静态数据,x y z轴的特征值存放到sql数据库中(如果数据原来不存在,则插入新数据;如果存在,则更新数据)
|
//综上代码,把静态数据,x y z轴的特征值存放到sql数据库中(如果数据原来不存在,则插入新数据;如果存在,则更新数据)
|
||||||
|
|
||||||
print_info("Dip : %d TemBot : %f TemBot : %f Voltage : %d\n", 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) {
|
||||||
LOG_INFO("DealDataNodeFeature end %02x%02x\n", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
zlog_info(zct,"DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,9 +877,6 @@ std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int A
|
|||||||
long iTemp = 0;
|
long iTemp = 0;
|
||||||
char buf[8] = {0x00};
|
char buf[8] = {0x00};
|
||||||
std::vector<float> vecData;
|
std::vector<float> vecData;
|
||||||
print_info("data1 = %02x\n", g_VecWaveDataX[0].Data[0]);
|
|
||||||
print_info("data2 = %02x\n", g_VecWaveDataY[0].Data[0]);
|
|
||||||
print_info("data3 = %02x\n", g_VecWaveDataZ[0].Data[0]);
|
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
std::string strShortAddr = "";
|
std::string strShortAddr = "";
|
||||||
if (iChannel == 3) {
|
if (iChannel == 3) {
|
||||||
@ -939,20 +927,18 @@ 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;
|
||||||
}
|
}
|
||||||
print_info("len = %d,data = %02x,iChannel = %d,compress = %d,count = %d\n", 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) {
|
||||||
print_info("iChannel = %d,compress = %d\n", 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);
|
||||||
print_info("lzo1x_decompress end\n");
|
zlog_info(zct,"lzo1x_decompress end");
|
||||||
if (r == LZO_E_OK) {
|
if (r == LZO_E_OK) {
|
||||||
printf("decompressed %lu bytes back into %lu bytes\n", (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);
|
||||||
LOG_INFO("iChannel = %d ,ShortAddr = %s decompressed %lu bytes back into %lu bytes\n", iChannel, strShortAddr.c_str(), (unsigned long)j * 92, (unsigned long)new_len);
|
|
||||||
} else {
|
} else {
|
||||||
/* this should NEVER happen */
|
|
||||||
printf("internal error - decompression failed: %d\n", r);
|
zlog_error(zct,"internal error - decompression failed: %d,channel = %d,ShortAddr = %s", r, iChannel, strShortAddr.c_str());
|
||||||
LOG_ERROR("internal error - decompression failed: %d,channel = %d,ShortAddr = %s\n", r, iChannel, strShortAddr.c_str());
|
|
||||||
return vecData;
|
return vecData;
|
||||||
}
|
}
|
||||||
memcpy(dealdata, outdata, new_len);
|
memcpy(dealdata, outdata, new_len);
|
||||||
@ -961,7 +947,6 @@ std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int A
|
|||||||
memcpy(dealdata, data, j * 92);
|
memcpy(dealdata, data, j * 92);
|
||||||
deallen = j * 92;
|
deallen = j * 92;
|
||||||
}
|
}
|
||||||
print_info("len = %d,dealdata = %02x\n", deallen, dealdata[0]);
|
|
||||||
for (int i = 0; i < deallen; i++) {
|
for (int i = 0; i < deallen; i++) {
|
||||||
float fTemp = 0.0;
|
float fTemp = 0.0;
|
||||||
memset(buf, 0, 8);
|
memset(buf, 0, 8);
|
||||||
@ -975,15 +960,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) { //过滤数据包结尾空数据
|
||||||
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n", 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) { //过滤数据包结尾空数据
|
||||||
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n", 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) { //过滤数据包结尾空数据
|
||||||
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
zlog_info(zct,"%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1040,7 +1025,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) {
|
||||||
print_info("m_waveCountX = %d,VecWaveData = %d\n", 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);
|
||||||
@ -1049,7 +1034,7 @@ void Uart::DealWave() {
|
|||||||
VecWaveDataX.clear();
|
VecWaveDataX.clear();
|
||||||
}
|
}
|
||||||
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
||||||
print_info("m_waveCountY = %d,VecWaveData = %d\n", 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);
|
||||||
@ -1058,7 +1043,7 @@ void Uart::DealWave() {
|
|||||||
VecWaveDataY.clear();
|
VecWaveDataY.clear();
|
||||||
}
|
}
|
||||||
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
||||||
print_info("m_waveCountZ = %d,VecWaveDataZ = %d\n", 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);
|
||||||
@ -1100,10 +1085,8 @@ float Uart::Calcoe(int ran, int iChannel, string &product, int range) {
|
|||||||
coe = 0.00048828125;
|
coe = 0.00048828125;
|
||||||
}
|
}
|
||||||
if (iChannel == 5) {
|
if (iChannel == 5) {
|
||||||
/*if(res[8] == "0.1"){
|
|
||||||
coe = 0.0034521484375;//0.03265968810083316;
|
coe = 0.00172607421875;
|
||||||
}else*/
|
|
||||||
{ coe = 0.00172607421875; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return coe;
|
return coe;
|
||||||
@ -1137,7 +1120,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);
|
||||||
print_info("fopen FIle vecData.size : %d\n", 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};
|
||||||
@ -1159,7 +1142,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
//
|
|
||||||
Json::Value valWaveData;
|
Json::Value valWaveData;
|
||||||
int length = vecData.size();
|
int length = vecData.size();
|
||||||
valWaveData["number"] = sampleRate;
|
valWaveData["number"] = sampleRate;
|
||||||
@ -1188,7 +1171,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());
|
||||||
print_info("update static data to sql\n");
|
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
|
||||||
@ -1200,12 +1183,12 @@ 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);
|
||||||
LOG_ERROR("save channlID %s dat count = %d\n", 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);
|
||||||
LOG_ERROR("send failed,filename %s,iRet = %d\n", strFileName.c_str(), iRet);
|
zlog_error(zct,"send failed,filename %s,iRet = %d", strFileName.c_str(), iRet);
|
||||||
string strFileName_failed = strFileName + "_" + nowTimetamp;
|
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());
|
||||||
@ -1229,7 +1212,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
|
|||||||
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);
|
||||||
LOG_ERROR("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());
|
||||||
@ -1238,11 +1221,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);
|
||||||
LOG_ERROR("rm dat file %s \n", tmpCmd);
|
zlog_info(zct,"rm dat file %s \n", tmpCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("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};
|
||||||
@ -1250,7 +1233,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);
|
||||||
LOG_INFO("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 ");
|
||||||
@ -1286,11 +1269,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);
|
||||||
LOG_INFO("rm dat file %s \n", tmpCmd);
|
zlog_info(zct,"rm dat file %s ", tmpCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
print_info("write data to filename %s\n", 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);
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
void Uart::openSwitch() {
|
void Uart::openSwitch() {
|
||||||
char buffer[100] = {0x00};
|
char buffer[100] = {0x00};
|
||||||
@ -45,7 +46,7 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
|||||||
if (vecResult.size() < 1) {
|
if (vecResult.size() < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("hardversion %s,softversion %s\n", 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++) {
|
||||||
@ -66,12 +67,12 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
|
|||||||
|
|
||||||
if (thisindex < 0) return false;
|
if (thisindex < 0) return false;
|
||||||
|
|
||||||
print_info("thisindex = %d\n", 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;
|
||||||
print_info("strFileName = %s\n", 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;
|
||||||
@ -84,7 +85,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};
|
||||||
print_info("thisSize = %d\n", 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;
|
||||||
@ -107,26 +108,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) {
|
||||||
LOG_DEBUG("Packge ACK send success,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_info(zct,"Packge ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Packge ACK send failed,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zzlog_error(zct,zct,"Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
}
|
}
|
||||||
string strTime = GetLocalTimeWithMs();
|
string strTime = GetLocalTimeWithMs();
|
||||||
LOG_INFO("ReadUpdatePackge strTime = %s\n", 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();
|
string strTime = GetLocalTimeWithMs();
|
||||||
LOG_INFO("UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x\n", 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)
|
||||||
perror("Error opening file");
|
{
|
||||||
else {
|
|
||||||
while (fgetc(pFile) != EOF) {
|
while (fgetc(pFile) != EOF) {
|
||||||
++thisSize;
|
++thisSize;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,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]
|
||||||
print_info("Start Update!!! file Size = %d\n", 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 +172,10 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
|
|||||||
if (time >= 150) {
|
if (time >= 150) {
|
||||||
resendCount++;
|
resendCount++;
|
||||||
if (resendCount < 5) {
|
if (resendCount < 5) {
|
||||||
LOG_INFO(" RESEND gpio_read failed shortAdd %x %x,error index %d\n", 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 {
|
||||||
LOG_INFO("gpio_read failed shortAdd %x %x,error index %d\n", 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);
|
||||||
print_red("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;
|
||||||
@ -221,8 +221,8 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
|
|||||||
time += 1;
|
time += 1;
|
||||||
} while (time < 150);
|
} while (time < 150);
|
||||||
if (time >= 150) {
|
if (time >= 150) {
|
||||||
LOG_INFO("gpio_read failed shortAdd %x %x\n", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
zlog_error(zct,"gpio_read failed shortAdd %x %x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||||
print_info("gpio_read failed \n");
|
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,7 +230,9 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
|
|||||||
}
|
}
|
||||||
memset(UpdateData, 0x00, sizeof(UpdateData));
|
memset(UpdateData, 0x00, sizeof(UpdateData));
|
||||||
}
|
}
|
||||||
print_info("Update END!!! file Size = %d\n", thisSize);
|
zlog_info(zct,"Update END!!! file Size = %d", thisSize);
|
||||||
|
}else{
|
||||||
|
zlog_error(zct,"open file failed ");
|
||||||
}
|
}
|
||||||
endUpdate:
|
endUpdate:
|
||||||
resendCount = 0;
|
resendCount = 0;
|
||||||
@ -247,7 +249,7 @@ endUpdate:
|
|||||||
|
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||||
LOG_INFO("UpdateWirelessNode end");
|
zlog_info(zct,"UpdateWirelessNode end");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
||||||
@ -258,8 +260,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") {
|
||||||
print_info("UpdateConfig\n");
|
zlog_info(zct,"UpdateConfig");
|
||||||
LOG_INFO("UpdateConfig\n");
|
|
||||||
bUpdateconfig = true;
|
bUpdateconfig = true;
|
||||||
unsigned short localAddr = 0x9999;
|
unsigned short localAddr = 0x9999;
|
||||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
|
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
|
||||||
@ -275,7 +276,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);
|
||||||
print_info("vecResult size = %d\n", vecResult.size());
|
zlog_info(zct,"vecResult size = %d", vecResult.size());
|
||||||
if (vecResult.size() < 1) {
|
if (vecResult.size() < 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -321,13 +322,11 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateData[18] = atoi(vecResult[11].c_str()) & 0xFF;
|
UpdateData[18] = atoi(vecResult[11].c_str()) & 0xFF;
|
||||||
;
|
|
||||||
UpdateData[19] = atoi(vecResult[12].c_str()) & 0xFF;
|
UpdateData[19] = atoi(vecResult[12].c_str()) & 0xFF;
|
||||||
;
|
|
||||||
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;
|
||||||
print_info("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);
|
||||||
@ -429,9 +428,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) {
|
||||||
LOG_DEBUG("updataconfig ACK send success,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_info(zct,"updataconfig ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("updataconfig ACK send failed,shortAddr = %02x%02x\n", 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") {
|
||||||
@ -472,9 +471,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) {
|
||||||
LOG_DEBUG("updataname ACK send success,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_info(zct,"updataname ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("updataname ACK send failed,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_error(zct,"updataname ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -491,7 +490,7 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /
|
|||||||
int millisecond = 0;
|
int millisecond = 0;
|
||||||
|
|
||||||
string rtcTime = GetRTC(localtimestamp, millisecond);
|
string rtcTime = GetRTC(localtimestamp, millisecond);
|
||||||
LOG_INFO("ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d \n", 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;
|
||||||
@ -517,9 +516,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) {
|
||||||
LOG_DEBUG("NodeTime ACK send success,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_info(zct,"NodeTime ACK send success,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("NodeTime ACK send failed,shortAddr = %02x%02x\n", pDestShortAddr[0], pDestShortAddr[1]);
|
zlog_error(zct,"NodeTime ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
|
||||||
}
|
}
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,37 +27,14 @@ void SearchDev::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SearchDev::GwRouteInit() {
|
void SearchDev::GwRouteInit() {
|
||||||
// system("route > scan_test");
|
|
||||||
// std::fstream fileOut;
|
|
||||||
// int find = 0;
|
|
||||||
// fileOut.open("scan_test",std::ios::in | std::ios::app);
|
|
||||||
// if (fileOut.is_open()) {//文件打开
|
|
||||||
// while (!fileOut.eof()) {
|
|
||||||
// std::string tmpStr("");
|
|
||||||
// getline(fileOut,tmpStr);
|
|
||||||
// //fileOut >> tmpStr;
|
|
||||||
// print_info("%s\n",tmpStr.c_str());
|
|
||||||
// if (strstr(tmpStr.c_str(), "224.0.0.0")) {
|
|
||||||
// find = 1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// fileOut.close();
|
|
||||||
|
|
||||||
// if (!find) {
|
|
||||||
// char cmd[128]="route add -net 224.0.0.0 netmask 224.0.0.0 dev ";
|
|
||||||
// strcat(cmd,GlobalConfig::KEthname.c_str());
|
|
||||||
// print_info("%s\n",cmd);
|
|
||||||
// system(cmd);
|
|
||||||
// }
|
|
||||||
// system("rm scan_test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
print_info("send udp error 7302\n");
|
zlog_info(zct,"send udp error 7302");
|
||||||
} else {
|
} else {
|
||||||
print_info("send udp ok 7302\n");
|
zlog_info(zct,"send udp ok 7302");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,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) {
|
||||||
print_info("mRecvBuf1 : %s\n", 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;
|
||||||
@ -88,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);
|
||||||
print_info("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));
|
||||||
}
|
}
|
||||||
@ -96,7 +73,7 @@ void SearchDev::HandleRecv_1(const boost::system::error_code& pEc, size_t pBytes
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print_error("parse error\n");
|
zlog_error(zct,"parse error\n");
|
||||||
}
|
}
|
||||||
MultiCastRecv_1();
|
MultiCastRecv_1();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
TcpCgi::TcpCgi() { print_light_green("TcpCgi Init\n"); }
|
TcpCgi::TcpCgi() { zlog_info(zbt,"TcpCgi Init"); }
|
||||||
|
|
||||||
void TcpCgi::startCgiServer() {
|
void TcpCgi::startCgiServer() {
|
||||||
int listenfd, connfd;
|
int listenfd, connfd;
|
||||||
@ -12,7 +12,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) {
|
||||||
printf("create socket error: %s(errno: %d)\n", strerror(errno), errno);
|
zlog_info(zct,"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,32 +23,31 @@ 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) {
|
||||||
printf("bind socket error: %s(errno: %d)\n", strerror(errno), errno);
|
zlog_info(zct,"bind socket error: %s(errno: %d)", strerror(errno), errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(listenfd, 10) == -1) {
|
if (listen(listenfd, 10) == -1) {
|
||||||
printf("listen socket error: %s(errno: %d)\n", strerror(errno), errno);
|
zlog_info(zct,"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) {
|
||||||
printf("accept socket error: %s(errno: %d)", strerror(errno), errno);
|
zlog_info(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) {
|
||||||
print_info("recv fail\n");
|
zlog_info(zct,("recv fail");
|
||||||
close(connfd);
|
close(connfd);
|
||||||
} else {
|
} else {
|
||||||
buff[n] = '\0';
|
buff[n] = '\0';
|
||||||
|
|
||||||
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);
|
||||||
// print_info("send cgi : %s\n length = %d\n", reqData.c_str(),reqData.length());
|
|
||||||
if (send(connfd, reqData.c_str(), reqData.length(), 0) < 0) {
|
if (send(connfd, reqData.c_str(), reqData.length(), 0) < 0) {
|
||||||
printf("send msg error: %s(errno: %d)\n", strerror(errno), errno);
|
zlog_error(zct,"send msg error: %s(errno: %d)", strerror(errno), errno);
|
||||||
}
|
}
|
||||||
close(connfd);
|
close(connfd);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
UdpSys::UdpSys():
|
UdpSys::UdpSys():
|
||||||
mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303))
|
mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303))
|
||||||
{
|
{
|
||||||
print_light_green("UdpQt Init\n");
|
zlog_info(zct,"UdpQt Init");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ void UdpSys::ClearConnect()
|
|||||||
|
|
||||||
void UdpSys::StartConnectSysUdp()
|
void UdpSys::StartConnectSysUdp()
|
||||||
{
|
{
|
||||||
print_light_green("start connect QT\n");
|
zlog_info(zct,"start connect QT");
|
||||||
if (udpSock.is_open()) {
|
if (udpSock.is_open()) {
|
||||||
boost::asio::socket_base::linger option1(true, 0);
|
boost::asio::socket_base::linger option1(true, 0);
|
||||||
udpSock.set_option(option1);
|
udpSock.set_option(option1);
|
||||||
@ -36,9 +36,9 @@ void UdpSys::handle_send_to(const boost::system::error_code& ec,
|
|||||||
size_t trans)
|
size_t trans)
|
||||||
{
|
{
|
||||||
if (ec) {
|
if (ec) {
|
||||||
print_error("send the udp to sys error! \n");
|
zlog_error(zct,"send the udp to sys error! ");
|
||||||
} else {
|
} else {
|
||||||
print_info("send the udp to sys ok! \n");
|
zlog_info(zct,"send the udp to sys ok! ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ void UdpSys::SendUdpToSingle(std::string pData)
|
|||||||
memset(mi, 0, len + 3);
|
memset(mi, 0, len + 3);
|
||||||
strcpy(mi, pData.c_str());
|
strcpy(mi, pData.c_str());
|
||||||
strcat(mi, "\r\n");
|
strcat(mi, "\r\n");
|
||||||
print_brown("sys send single : %s \n", pData.c_str());
|
zlog_info(zct,"sys send single : %s ", pData.c_str());
|
||||||
udpSock.async_send_to(boost::asio::buffer(mi,len + 3), remoteEndPoint,
|
udpSock.async_send_to(boost::asio::buffer(mi,len + 3), remoteEndPoint,
|
||||||
boost::bind(&UdpSys::handle_send_to, this,
|
boost::bind(&UdpSys::handle_send_to, this,
|
||||||
boost::asio::placeholders::error,
|
boost::asio::placeholders::error,
|
||||||
@ -94,7 +94,7 @@ void UdpSys::HandleRead(const boost::system::error_code& pEc,
|
|||||||
|
|
||||||
void UdpSys::AnalysisDataSys(std::string cmd)
|
void UdpSys::AnalysisDataSys(std::string cmd)
|
||||||
{
|
{
|
||||||
printf("%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)) {
|
||||||
@ -110,7 +110,7 @@ void UdpSys::AnalysisDataSys(std::string cmd)
|
|||||||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", strDataWatchAddedBy);
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", strDataWatchAddedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_info("strServerIp : %s \n", 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;
|
||||||
@ -127,7 +127,7 @@ void UdpSys::AnalysisDataSys(std::string cmd)
|
|||||||
JsonVal["status"] = "ACK";
|
JsonVal["status"] = "ACK";
|
||||||
Json::FastWriter fw;
|
Json::FastWriter fw;
|
||||||
std::string str = fw.write(JsonVal);
|
std::string str = fw.write(JsonVal);
|
||||||
print_info("send info : %s \n", 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,
|
udpSock.async_send_to(boost::asio::buffer(str),remoteEP,
|
||||||
@ -160,7 +160,7 @@ void UdpSys::AnalysisDataSys(std::string cmd)
|
|||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
print_error("json parse failed");
|
zlog_error(zct,"json parse failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
#include "dial.h"
|
#include "dial.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
// #include <fcntl.h>
|
|
||||||
// #include <unistd.h>
|
|
||||||
// #include <termios.h>
|
|
||||||
// #include <sys/types.h>
|
|
||||||
// #include <sys/stat.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <zlog.h>
|
||||||
#include "common/common_func.hpp"
|
#include "common/common_func.hpp"
|
||||||
|
|
||||||
|
|
||||||
@ -20,12 +16,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);
|
||||||
print_info("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) {
|
||||||
print_info("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;
|
||||||
@ -49,10 +45,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());
|
||||||
print_info("NetStatus = %s,NetSignal = %d\n", 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:
|
||||||
print_info("m_curState Event_QNETDEVCTL = %d\n", 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;
|
||||||
}
|
}
|
||||||
@ -93,7 +89,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;
|
||||||
print_info("NR5GTemp = %s\n", GlobalConfig::NR5GTemp.c_str());
|
zlog_info(zct,"NR5GTemp = %s", GlobalConfig::NR5GTemp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -126,49 +122,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));
|
||||||
print_purple("strQENG = %s\n", 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));
|
||||||
print_purple("strQNETDEVCTL = %s\n", 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));
|
||||||
print_purple("strQICSGP = %s\n", 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));
|
||||||
print_purple("strQNETDEVSTATUS = %s\n", 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));
|
||||||
print_purple("strQCFG = %s\n", 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));
|
||||||
print_purple("strCPIN = %s\n", 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));
|
||||||
print_purple("strQTEMP = %s\n", 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));
|
||||||
print_purple("strERROR = %s\n", 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);
|
||||||
@ -180,10 +176,10 @@ int Dial::recvData() {
|
|||||||
}
|
}
|
||||||
mssleep(100);
|
mssleep(100);
|
||||||
} else if (ret > 0) {
|
} else if (ret > 0) {
|
||||||
print_info("ret = %d,buff = %s\n", 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;
|
||||||
print_info("szbuffer = %s\n", szbuffer);
|
zlog_info(zct,"szbuffer = %s", szbuffer);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
mssleep(500000);
|
mssleep(500000);
|
||||||
@ -200,7 +196,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);
|
||||||
print_info("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); }
|
||||||
@ -209,7 +205,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);
|
||||||
print_info("conncectUSB = %d\n", iRet);
|
zlog_info(zct,"conncectUSB = %d\n", iRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dial::dial5G() {
|
int Dial::dial5G() {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <zlog.h>
|
||||||
|
|
||||||
namespace wifi {
|
namespace wifi {
|
||||||
|
|
||||||
@ -125,7 +126,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) {
|
||||||
print_error("open wpa failed\n");
|
zlog_error(zct,"open wpa failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SetConnStatus(STEP_SCAN);
|
SetConnStatus(STEP_SCAN);
|
||||||
@ -180,7 +181,7 @@ int WPAClient::GetWiFiRssi() {
|
|||||||
}
|
}
|
||||||
char temp[1024] = {0};
|
char temp[1024] = {0};
|
||||||
strcpy(temp, recv.data());
|
strcpy(temp, recv.data());
|
||||||
print_info("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) {
|
||||||
@ -200,27 +201,27 @@ bool WPAClient::ConnectWiFi(const std::string &ssid, const std::string &password
|
|||||||
if (!CleanAllWiFi()) {
|
if (!CleanAllWiFi()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("CleanAllWiFi \n");
|
zlog_info(zct,"CleanAllWiFi ");
|
||||||
if (!AddWiFi(net_id)) {
|
if (!AddWiFi(net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("AddWiFi \n");
|
zlog_info(zct,"AddWiFi ");
|
||||||
if (!SetSSID(ssid, net_id)) {
|
if (!SetSSID(ssid, net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("SetSSID \n");
|
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;
|
||||||
}
|
}
|
||||||
print_info("SetProtocol\n");
|
zlog_info(zct,"SetProtocol");
|
||||||
SetScanSSID(net_id);
|
SetScanSSID(net_id);
|
||||||
if (!EnableWiFi(net_id)) {
|
if (!EnableWiFi(net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("EnableWiFi\n");
|
zlog_info(zct,"EnableWiFi");
|
||||||
return CheckCommandWithOk("SAVE_CONFIG");
|
return CheckCommandWithOk("SAVE_CONFIG");
|
||||||
// return true;
|
// return true;
|
||||||
}
|
}
|
||||||
@ -231,24 +232,24 @@ bool WPAClient::ConnectWiFiWithNoPassword(const std::string &ssid) {
|
|||||||
if (!CleanAllWiFi()) {
|
if (!CleanAllWiFi()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("CleanAllWiFi\n");
|
zlog_info(zct,"CleanAllWiFi");
|
||||||
if (!AddWiFi(net_id)) {
|
if (!AddWiFi(net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("AddWiFi\n");
|
zlog_info(zct,"AddWiFi");
|
||||||
if (!SetSSID(ssid, net_id)) {
|
if (!SetSSID(ssid, net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("SetSSID\n");
|
zlog_info(zct,"SetSSID");
|
||||||
if (!SetProtocol(net_id, 0)) {
|
if (!SetProtocol(net_id, 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("SetProtocol\n");
|
zlog_info(zct,"SetProtocol");
|
||||||
SetScanSSID(net_id);
|
SetScanSSID(net_id);
|
||||||
if (!EnableWiFi(net_id)) {
|
if (!EnableWiFi(net_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_info("EnableWiFi\n");
|
zlog_info(zct,"EnableWiFi");
|
||||||
|
|
||||||
return CheckCommandWithOk("SAVE_CONFIG");
|
return CheckCommandWithOk("SAVE_CONFIG");
|
||||||
}
|
}
|
||||||
@ -311,7 +312,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) {
|
||||||
print_error("malloc failed\n");
|
zlog_error(zct,"malloc failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(ctrl, 0, sizeof(struct WPAContext));
|
memset(ctrl, 0, sizeof(struct WPAContext));
|
||||||
@ -321,7 +322,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) {
|
||||||
print_error("socket failed\n");
|
zlog_error(zct,"socket failed");
|
||||||
free(ctrl);
|
free(ctrl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -334,7 +335,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)) {
|
||||||
print_error("snprintf failed\n");
|
zlog_error(zct,"snprintf failed");
|
||||||
close(ctrl->s);
|
close(ctrl->s);
|
||||||
free(ctrl);
|
free(ctrl);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -351,7 +352,7 @@ try_again:
|
|||||||
unlink(ctrl->local.sun_path);
|
unlink(ctrl->local.sun_path);
|
||||||
goto try_again;
|
goto try_again;
|
||||||
}
|
}
|
||||||
print_error("bind failed\n");
|
zlog_error(zct,"bind failed");
|
||||||
close(ctrl->s);
|
close(ctrl->s);
|
||||||
free(ctrl);
|
free(ctrl);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -364,7 +365,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) {
|
||||||
print_error("connect failed\n");
|
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);
|
||||||
@ -390,7 +391,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) {
|
||||||
print_error("wpa_context_ is null\n");
|
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) {
|
||||||
@ -425,10 +426,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)) {
|
||||||
print_error("send cmd falied\n");
|
zlog_error(zct,"send cmd falied");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print_error("recv cmd %s\n", 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