modify a little.

This commit is contained in:
pandx 2024-10-23 20:33:05 +08:00
parent 6a7f2712e4
commit 4ddc9e8285
19 changed files with 485 additions and 544 deletions

View File

@ -40,7 +40,6 @@ public:
std::string JsonCmd_51(Json::Value &recvBody); std::string JsonCmd_51(Json::Value &recvBody);
std::string JsonCmd_52(); // upload static data std::string JsonCmd_52(); // upload static data
std::string JsonCmd_53(Json::Value &recvBody); std::string JsonCmd_53(Json::Value &recvBody);
void JsonCmd_38(Json::Value &recvBody); //获取原始数据
// web command parse // web command parse
std::string JsonCmd_Cgi_01(Param_01 &param); //用户操作处理 std::string JsonCmd_Cgi_01(Param_01 &param); //用户操作处理

View File

@ -1,8 +1,11 @@
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include <zlog.h>
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "platform/platform_init.hpp" #include "platform/platform_init.hpp"
#include "utility/md5.h" #include "utility/md5.h"
#include <zlog.h>
extern zlog_category_t *zct;
std::string JsonData::JsonCmd_20(Param_20 &param) { std::string JsonData::JsonCmd_20(Param_20 &param) {
Json::Value jsonVal; Json::Value jsonVal;
@ -29,9 +32,9 @@ std::string JsonData::JsonCmd_20(Param_20 &param) {
Json::Value jsSystemInfo; Json::Value jsSystemInfo;
Json::Value jsBody; Json::Value jsBody;
string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion"); std::string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); std::string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); std::string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
jsSystemInfo["WebVersion"] = strwebVersion; jsSystemInfo["WebVersion"] = strwebVersion;
jsSystemInfo["SystemVersion"] = strsystemVersion; jsSystemInfo["SystemVersion"] = strsystemVersion;
@ -172,7 +175,7 @@ std::string JsonData::JsonCmd_25(Param_25 &param) {
print_info("GateWay = %s\n", GateWay); print_info("GateWay = %s\n", GateWay);
system(GateWay); system(GateWay);
#endif #endif
platform->EquipIpInit(param.mNet); PlatformInit::EquipIpInit(param.mNet);
} else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") { } else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") {
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", ""); WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", "");
@ -328,7 +331,7 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
jsonVal["message"] = "download failed"; jsonVal["message"] = "download failed";
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
string md5Val = md5file(updateName.c_str()); std::string md5Val = md5file(updateName.c_str());
zlog_info(zct, "md5Val = %s", md5Val.c_str()); zlog_info(zct, "md5Val = %s", md5Val.c_str());
zlog_info(zct, "md5 = %s", md5.c_str()); zlog_info(zct, "md5 = %s", md5.c_str());
if (md5 != md5Val) { if (md5 != md5Val) {
@ -337,7 +340,7 @@ std::string JsonData::JsonCmd_50(Json::Value &recvBody) {
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
if (updateDevice == "1") { // update sensor if (updateDevice == "1") { // update sensor
string strcmd = "tar xvf "; std::string strcmd = "tar xvf ";
strcmd = strcmd + updateName; strcmd = strcmd + updateName;
strcmd = strcmd + " -C /opt/"; strcmd = strcmd + " -C /opt/";
system(strcmd.c_str()); system(strcmd.c_str());
@ -488,31 +491,6 @@ std::string JsonData::JsonCmd_29(Param_29 &param) {
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();

View File

@ -1,8 +1,10 @@
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include <zlog.h>
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "platform/platform_init.hpp" #include "platform/platform_init.hpp"
#include "utility/md5.h" #include "utility/md5.h"
#include <zlog.h>
extern zlog_category_t *zct;
std::string JsonData::JsonCmd_Cgi_01(Param_01 &param) { std::string JsonData::JsonCmd_Cgi_01(Param_01 &param) {
Json::Value jsonVal; Json::Value jsonVal;
@ -137,7 +139,6 @@ std::string JsonData::JsonCmd_Cgi_08() {
} }
std::string JsonData::JsonCmd_Cgi_09(Param_09 &param) { std::string JsonData::JsonCmd_Cgi_09(Param_09 &param) {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
@ -262,6 +263,7 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 &param) {
} }
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
std::string JsonData::JsonCmd_Cgi_10(Param_10 &param) { std::string JsonData::JsonCmd_Cgi_10(Param_10 &param) {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
@ -594,7 +596,7 @@ std::string JsonData::JsonCmd_Cgi_25(Param_25 &param) {
zlog_info(zct, "GateWay = %s", GateWay); zlog_info(zct, "GateWay = %s", GateWay);
system(GateWay); system(GateWay);
#endif #endif
platform->EquipIpInit(param.mNet); Platform::EquipIpInit(param.mNet);
} else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") { } else if (0 == param.mMode && param.mNetworkPortStatus == "DHCP") {
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", ""); WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", "");

View File

@ -1,8 +1,10 @@
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include <zlog.h>
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "platform/platform_init.hpp" #include "platform/platform_init.hpp"
#include "utility/md5.h" #include "utility/md5.h"
#include <zlog.h>
extern zlog_category_t *zct;
std::string JsonData::JsonCmd_Cgi_26(Param_26 &param) { std::string JsonData::JsonCmd_Cgi_26(Param_26 &param) {
Json::Value jsonVal; Json::Value jsonVal;
@ -84,7 +86,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 &param) {
jsSensorData["status"] = atoi(arrRes[j][37].c_str()); jsSensorData["status"] = atoi(arrRes[j][37].c_str());
jsSensorData["timeStamp"] = arrRes[j][38]; jsSensorData["timeStamp"] = arrRes[j][38];
jsSensorData["viff"] = atoi(arrRes[j][39].c_str()); jsSensorData["viff"] = atoi(arrRes[j][39].c_str());
vector<string> vParam; std::vector<std::string> vParam;
boost::split(vParam, arrRes[j][42], boost::is_any_of(","), boost::token_compress_on); boost::split(vParam, arrRes[j][42], boost::is_any_of(","), boost::token_compress_on);
if (vParam.size() > 1) if (vParam.size() > 1)
@ -92,7 +94,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 &param) {
else else
jsSensorData["loose"] = "0"; jsSensorData["loose"] = "0";
vector<string> vParamRSSI; std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, arrRes[j][40], boost::is_any_of(","), boost::token_compress_on); boost::split(vParamRSSI, arrRes[j][40], boost::is_any_of(","), boost::token_compress_on);
if (vParamRSSI.size() > 1) { if (vParamRSSI.size() > 1) {
jsSensorData["RSSI"] = arrRes[j][40]; jsSensorData["RSSI"] = arrRes[j][40];
@ -279,7 +281,7 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 &param) {
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str()); sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
sprintf(updateSql, "LooseValue = '0,2,"); sprintf(updateSql, "LooseValue = '0,2,");
string strUpdateSql = string(updateSql) + string(localtimestamp) + "' "; std::string strUpdateSql = std::string(updateSql) + std::string(localtimestamp) + "' ";
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon); sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon);
} else { } else {
jsonVal["success"] = false; jsonVal["success"] = false;
@ -436,7 +438,6 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 &param) {
} else { } else {
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算 while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
vecWave.push_back(fTemp); vecWave.push_back(fTemp);
} }
//进行傅立叶变换 //进行傅立叶变换
@ -517,6 +518,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 &param) {
jsonVal["content"] = jsBody; jsonVal["content"] = jsBody;
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
std::string JsonData::JsonCmd_Cgi_40(Param_40 &param) { std::string JsonData::JsonCmd_Cgi_40(Param_40 &param) {
Json::Value jsonVal; Json::Value jsonVal;
Json::Value jsBody; Json::Value jsBody;
@ -724,6 +726,7 @@ std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> &param, int isServer)
} }
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
std::string JsonData::JsonCmd_Cgi_42(Param_42 &param) { std::string JsonData::JsonCmd_Cgi_42(Param_42 &param) {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
@ -735,7 +738,7 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 &param) {
strcpy(cmd, "rm -rf /tmp/cgic*"); strcpy(cmd, "rm -rf /tmp/cgic*");
system(cmd); system(cmd);
if (param.fileName == "DataNode.tar") { if (param.fileName == "DataNode.tar") {
string strcmd = "tar xvf /opt/"; std::string strcmd = "tar xvf /opt/";
strcmd = strcmd + param.fileName; strcmd = strcmd + param.fileName;
strcmd = strcmd + " -C /opt/"; strcmd = strcmd + " -C /opt/";
zlog_info(zct, "strcmd = %s", strcmd.c_str()); zlog_info(zct, "strcmd = %s", strcmd.c_str());
@ -759,7 +762,7 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 &param) {
zlog_info(zct, "strcmd = %s", param.fileName.c_str()); zlog_info(zct, "strcmd = %s", param.fileName.c_str());
int iRet = UpdataDataNodeConfig("/opt/DataNode.csv"); int iRet = UpdataDataNodeConfig("/opt/DataNode.csv");
string str = to_string(iRet) + "个传感器更新成功"; std::string str = std::to_string(iRet) + "个传感器更新成功";
if (iRet < 0) { if (iRet < 0) {
jsonVal["success"] = false; jsonVal["success"] = false;
jsonVal["message"] = "更新失败!"; jsonVal["message"] = "更新失败!";

View File

@ -1,8 +1,10 @@
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include <zlog.h>
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "platform/platform_init.hpp" #include "platform/platform_init.hpp"
#include "utility/md5.h" #include "utility/md5.h"
#include <zlog.h>
extern zlog_category_t *zct;
std::string JsonData::JsonCmd_Cgi_default() { std::string JsonData::JsonCmd_Cgi_default() {
Json::Value jsonVal; Json::Value jsonVal;
@ -118,7 +120,7 @@ std::string JsonData::JsonCmd_Cgi_51(Param_51 &param) {
char whereCon[1024] = {0}; char whereCon[1024] = {0};
char updateSql[1024] = {0}; char updateSql[1024] = {0};
string gatewayLocation = ""; std::string gatewayLocation = "";
sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str()); sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str());
sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str()); sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str());

View File

@ -1,8 +1,10 @@
#include "local_server.hpp" #include "local_server.hpp"
#include <zlog.h>
#include <json/json.h> #include <json/json.h>
#include "utility/secure.hpp" #include "utility/secure.hpp"
#include "jsonparse/communication_cmd.hpp" #include "jsonparse/communication_cmd.hpp"
#include <zlog.h>
extern zlog_category_t *zct;
LocalServer::LocalServer() {} LocalServer::LocalServer() {}
@ -31,7 +33,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
} else { } else {
std::string cmdBody = recvValue["cmdBody"].asString(); std::string cmdBody = recvValue["cmdBody"].asString();
if (!recvReader.parse(cmdBody, recvBody)) { if (!recvReader.parse(cmdBody, recvBody)) {
zlog_error(zct,"recv body error"); zlog_error(zct, "recv body error, content:[%s]", cmdBody.c_str());
return; return;
} }
} }
@ -202,6 +204,6 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
zlog_info(zct, "cmdType : %d ", cmdType); zlog_info(zct, "cmdType : %d ", cmdType);
} else { } else {
zlog_error(zct,"parase fail"); zlog_error(zct, "parse fail, content:[%s]", pData.c_str());
} }
} }

View File

@ -1,10 +1,12 @@
#include "platform_init.hpp" #include "platform_init.hpp"
#include <fstream>
#include <zlog.h> #include <zlog.h>
#include <fstream>
#include "common/global.hpp" #include "common/global.hpp"
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
/*********************全局变量声明***********************/ extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int GlobalConfig::RUN_MODE = 0; int GlobalConfig::RUN_MODE = 0;
int GlobalConfig::QuitFlag_G = 1; int GlobalConfig::QuitFlag_G = 1;
int GlobalConfig::LinkStatus_G = 0; int GlobalConfig::LinkStatus_G = 0;
@ -25,7 +27,7 @@ int GlobalConfig::ServerPort = 0;
int GlobalConfig::threadStatus = 1; int GlobalConfig::threadStatus = 1;
int GlobalConfig::day = 0; int GlobalConfig::day = 0;
extern map<string, compressWaveChannel> g_mapCompress; extern std::map<std::string, compressWaveChannel> g_mapCompress;
TopicList GlobalConfig::Topic_G; TopicList GlobalConfig::Topic_G;
ZigbeeInfo GlobalConfig::ZigbeeInfo_G; ZigbeeInfo GlobalConfig::ZigbeeInfo_G;
@ -92,7 +94,7 @@ void PlatformInit::Init() {
} }
#endif #endif
} catch (...) { } catch (...) {
print_error("PlatFormInit exception happend.\n"); zlog_error(zbt, "PlatFormInit exception happend.");
std::string errorinfo = "系统初始化异常"; std::string errorinfo = "系统初始化异常";
} }
vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL); vec_t vecResult = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", NULL);
@ -104,35 +106,20 @@ void PlatformInit::Init() {
void PlatformInit::TopicInit() { void PlatformInit::TopicInit() {
GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G; //
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfo/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfo/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubWaveData = "wireless/realTimeData/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubWaveData = "wireless/realTimeData/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G; // GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G; //
GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G; GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G;
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi"; GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver"; GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver";
GlobalConfig::Topic_G.mPubLocalWaveQt = "up/" + GlobalConfig::MacAddr_G + "/recive/waveqt"; GlobalConfig::Topic_G.mPubLocalWaveQt = "up/" + GlobalConfig::MacAddr_G + "/recive/waveqt";
GlobalConfig::Topic_G.mPubLocalConfig = "up/" + GlobalConfig::MacAddr_G + "/recive/config"; GlobalConfig::Topic_G.mPubLocalConfig = "up/" + GlobalConfig::MacAddr_G + "/recive/config";
GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger"; GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger";
GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd"; GlobalConfig::Topic_G.mPubLocalCmd = "up/" + GlobalConfig::MacAddr_G + "/recive/cmd";
} }
@ -209,13 +196,14 @@ void PlatformInit::GPIOInit() {
GlobalConfig::GPIO_G.errorLed = 130; GlobalConfig::GPIO_G.errorLed = 130;
#endif #endif
} }
void PlatformInit::SystemInfoInit() { void PlatformInit::SystemInfoInit() {
std::ifstream ifileOut(SYSTEMINFOFILE); std::ifstream ifileOut(SYSTEMINFOFILE);
Json::Reader recvReader; Json::Reader recvReader;
Json::Value Systeminfo; Json::Value Systeminfo;
//从配置文件中读取json数据 //从配置文件中读取json数据
if (ifileOut.is_open()) { if (ifileOut.is_open()) {
zlog_info(zbt,"open %s\n", SYSTEMINFOFILE); zlog_info(zbt, "open %s", SYSTEMINFOFILE);
} }
if (!recvReader.parse(ifileOut, Systeminfo, false)) { if (!recvReader.parse(ifileOut, Systeminfo, false)) {
if (ifileOut.is_open()) { if (ifileOut.is_open()) {

View File

@ -13,6 +13,8 @@
#include "common/common_func.hpp" #include "common/common_func.hpp"
#include "wifi_5g/wpa_client.h" #include "wifi_5g/wpa_client.h"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
void CheckThread() { void CheckThread() {
zlog_info(zbt, "ENTER CHECK THREAD "); zlog_info(zbt, "ENTER CHECK THREAD ");

View File

@ -15,7 +15,9 @@
#include <zlog.h> #include <zlog.h>
#include "utility/serial.h" #include "utility/serial.h"
char g_UartRecvBuf[GENERAL_BUF_SIZE]; extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int offSize = 0; int offSize = 0;
pTestRecvCallBack pTestRecv; pTestRecvCallBack pTestRecv;
@ -373,6 +375,7 @@ void Uart::UpdateZigbeeInfo(const char *pData) {
WriteTranTimeout2Zigbee(TranTimeout); WriteTranTimeout2Zigbee(TranTimeout);
} }
} }
void int2bytes(int i, unsigned char *bytes, int size) { void int2bytes(int i, unsigned char *bytes, int size) {
memset(bytes, 0, sizeof(unsigned char) * size); memset(bytes, 0, sizeof(unsigned char) * size);
bytes[0] = (unsigned char)(0xff & i); bytes[0] = (unsigned char)(0xff & i);
@ -413,7 +416,7 @@ void Uart::DealRecvData(const char *pData) {
void Uart::DealDataNodeName(const char *pData) { void Uart::DealDataNodeName(const char *pData) {
bSendTimeStamp = false; bSendTimeStamp = false;
zlog_info(zct, "DealDataNodeName "); zlog_info(zct, "DealDataNodeName ");
string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
char szShortAdd[8] = {0x00}; char szShortAdd[8] = {0x00};
char shortAdd[8] = {0x00}; char shortAdd[8] = {0x00};
char NodeName[64] = {0x00}; char NodeName[64] = {0x00};
@ -455,8 +458,8 @@ void Uart::DealDataNodeName(const char *pData) {
} }
} }
} }
string hardVersion = vecRes[0][2]; std::string hardVersion = vecRes[0][2];
string softVersion = vecRes[0][3]; std::string softVersion = vecRes[0][3];
if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)) { if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)) {
memcpy(MeasurementID, vecRes[0][0].c_str(), sizeof(MeasurementID)); memcpy(MeasurementID, vecRes[0][0].c_str(), sizeof(MeasurementID));
} }
@ -464,12 +467,12 @@ void Uart::DealDataNodeName(const char *pData) {
zlog_info(zct, "strNodeName = %s", strNodeName.c_str()); zlog_info(zct, "strNodeName = %s", strNodeName.c_str());
solve(gbkNodeName, NodeName); solve(gbkNodeName, NodeName);
zlog_info(zct, "gbkNodeName = %s", gbkNodeName); zlog_info(zct, "gbkNodeName = %s", gbkNodeName);
string utfNodeName = GBKToUTF8(gbkNodeName); std::string utfNodeName = GBKToUTF8(gbkNodeName);
zlog_info(zct, "NodeName = %s", NodeName); zlog_info(zct, "NodeName = %s", NodeName);
zlog_info(zct, "whereCon = %s", whereCon); zlog_info(zct, "whereCon = %s", whereCon);
sprintf(uplCon, "dataNodeName = '%s' , MeasurementID = '%s',NodeWaveSend = '%s'", gbkNodeName, MeasurementID, nodeWaveSend); sprintf(uplCon, "dataNodeName = '%s' , MeasurementID = '%s',NodeWaveSend = '%s'", gbkNodeName, MeasurementID, nodeWaveSend);
iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0); iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), uplCon, whereCon, 0);
string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon); std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
iRet = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); iRet = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
} }
@ -565,7 +568,7 @@ void Uart::DealDataNodeInfo(const char *pData) {
unsigned char shortAddr[2] = {0x00}; unsigned char shortAddr[2] = {0x00};
memcpy(shortAddr, (unsigned char *)&pRecvData->Data[46], 2); memcpy(shortAddr, (unsigned char *)&pRecvData->Data[46], 2);
modify_DistAddr(shortAddr); //修改目标地址 modify_DistAddr(shortAddr); //修改目标地址
string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
memset(buf, 0, 32); memset(buf, 0, 32);
sprintf(buf, "%02x%02x", pRecvData->Data[48], pRecvData->Data[49]); // Zigbee 目标地址 2 byte sprintf(buf, "%02x%02x", pRecvData->Data[48], pRecvData->Data[49]); // Zigbee 目标地址 2 byte
@ -814,7 +817,7 @@ void Uart::ZigbeeParameterConfig() {
} }
int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
char head1[] = {0xAB, 0xBC, 0xCD}; char head1[] = {0xAB, 0xBC, 0xCD};
char head2[] = {0xDE, 0xDF, 0xEF}; char head2[] = {0xDE, 0xDF, 0xEF};
int lastSize = 0; int lastSize = 0;

View File

@ -1,6 +1,9 @@
#include "uart.hpp" #include "uart.hpp"
#include <zlog.h> #include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
void Uart::UpdateZigbeeInfoCtrl() { void Uart::UpdateZigbeeInfoCtrl() {
char command[5] = {0xab, 0xbc, 0xcd, 0xd1, 0xaa}; char command[5] = {0xab, 0xbc, 0xcd, 0xd1, 0xaa};
WriteToUart(command, 5); WriteToUart(command, 5);

View File

@ -7,10 +7,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <zlog.h> #include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
std::vector<RecvData> g_VecWaveDataX; std::vector<RecvData> g_VecWaveDataX;
std::vector<RecvData> g_VecWaveDataY; std::vector<RecvData> g_VecWaveDataY;
std::vector<RecvData> g_VecWaveDataZ; std::vector<RecvData> g_VecWaveDataZ;
map<std::string, compressWaveChannel> g_mapCompress; std::map<std::string, compressWaveChannel> g_mapCompress;
void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) { void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) {
char insertSql[1024] = {0}; char insertSql[1024] = {0};
@ -40,7 +43,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (vecResult.size() < 1) { if (vecResult.size() < 1) {
zlog_error(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); zlog_error(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
print_error("device info not found\n");
return; return;
} }
zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str()); zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str());
@ -115,7 +117,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
packed_data |= (uint64_t)buffer[i] << (8 * (5 - i)); // 从高位开始组合 packed_data |= (uint64_t)buffer[i] << (8 * (5 - i)); // 从高位开始组合
} }
// 输出结果 // 输出结果
printf("Resulting 48-bit integer: 0x%012llX\n", packed_data); zlog_info(zct, "Resulting 48-bit integer: 0x%012llX\n", packed_data);
// 提取 15 位的第一个数据 // 提取 15 位的第一个数据
tempchannel.CountX = (packed_data >> 33) & 0x7FFF; // 提取最高的 15 位 tempchannel.CountX = (packed_data >> 33) & 0x7FFF; // 提取最高的 15 位
@ -259,7 +261,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (vecResult.size() > 0) { if (vecResult.size() > 0) {
memset(whereCon, 0x00, sizeof(whereCon)); memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str()); sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str());
string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon); std::string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon);
long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60; long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60;
char tmp[10] = {0x00}; char tmp[10] = {0x00};
sprintf(tmp, "%ld", nNowTimetamp); sprintf(tmp, "%ld", nNowTimetamp);
@ -393,23 +395,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
dataDymX.Amp5 = lowbit * n; dataDymX.Amp5 = lowbit * n;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymX.EnvelopEnergy = 0; dataDymX.EnvelopEnergy = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymX.Phase1 = 0; dataDymX.Phase1 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymX.Phase2 = 0; dataDymX.Phase2 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
memset(buf, 0, 8); memset(buf, 0, 8);
dataDymX.Phase3 = 0; dataDymX.Phase3 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
sprintf(buf, "%02x%02x", pRecvData->Data[35], pRecvData->Data[34]); sprintf(buf, "%02x%02x", pRecvData->Data[35], pRecvData->Data[34]);
@ -539,23 +532,14 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
dataDymY.Amp5 = lowbit * n; dataDymY.Amp5 = lowbit * n;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymY.EnvelopEnergy = 0; dataDymY.EnvelopEnergy = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymY.Phase1 = 0; dataDymY.Phase1 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymY.Phase2 = 0; dataDymY.Phase2 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymY.Phase3 = 0; dataDymY.Phase3 = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
dataDymY.Phase4 = 0; dataDymY.Phase4 = 0;
memset(whereCon, 0, 1024); memset(whereCon, 0, 1024);
@ -776,7 +760,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str()); sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
std::string strBattery = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "batteryPower", whereCon); std::string strBattery = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "batteryPower", whereCon);
vector<std::string> vBattery; std::vector<std::string> vBattery;
vBattery.push_back("0"); vBattery.push_back("0");
vBattery.push_back("0"); vBattery.push_back("0");
if (strBattery.length() > 0) { if (strBattery.length() > 0) {
@ -937,7 +921,6 @@ std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int A
if (r == LZO_E_OK) { if (r == LZO_E_OK) {
zlog_info(zct, "iChannel = %d ,ShortAddr = %s decompressed %lu bytes back into %lu bytes", iChannel, strShortAddr.c_str(), (unsigned long)j * 92, (unsigned long)new_len); zlog_info(zct, "iChannel = %d ,ShortAddr = %s decompressed %lu bytes back into %lu bytes", iChannel, strShortAddr.c_str(), (unsigned long)j * 92, (unsigned long)new_len);
} else { } else {
zlog_error(zct, "internal error - decompression failed: %d,channel = %d,ShortAddr = %s", r, iChannel, strShortAddr.c_str()); zlog_error(zct, "internal error - decompression failed: %d,channel = %d,ShortAddr = %s", r, iChannel, strShortAddr.c_str());
return vecData; return vecData;
} }
@ -986,6 +969,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, int sampleRate, int A
} }
return vecData; return vecData;
} }
void Uart::DealWave() { void Uart::DealWave() {
std::string strShortAddr = ""; std::string strShortAddr = "";
std::string strShortAddrTemp; std::string strShortAddrTemp;
@ -1059,6 +1043,7 @@ void Uart::DealWave() {
wave_trans_ = false; wave_trans_ = false;
} }
} }
float Uart::Calcoe(int ran, int iChannel, string &product, int range) { float Uart::Calcoe(int ran, int iChannel, string &product, int range) {
float coe = 0.0; float coe = 0.0;
if (product == "01") { if (product == "01") {
@ -1085,12 +1070,12 @@ float Uart::Calcoe(int ran, int iChannel, string &product, int range) {
coe = 0.00048828125; coe = 0.00048828125;
} }
if (iChannel == 5) { if (iChannel == 5) {
coe = 0.00172607421875; coe = 0.00172607421875;
} }
} }
return coe; return coe;
} }
void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, std::vector<float> &vecData) { void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel, std::vector<float> &vecData) {
if (vecData.size() <= 0) return; if (vecData.size() <= 0) return;
std::string strFileName = ""; std::string strFileName = "";
@ -1189,7 +1174,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
sprintf(updateSql, "SendMsg = 0 "); sprintf(updateSql, "SendMsg = 0 ");
sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon); sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
zlog_error(zct, "send failed,filename %s,iRet = %d", strFileName.c_str(), iRet); zlog_error(zct, "send failed,filename %s,iRet = %d", strFileName.c_str(), iRet);
string strFileName_failed = strFileName + "_" + nowTimetamp; std::string strFileName_failed = strFileName + "_" + nowTimetamp;
char tmpCmd[128] = {0x00}; char tmpCmd[128] = {0x00};
sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str()); sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str());
system(tmpCmd); system(tmpCmd);
@ -1208,7 +1193,7 @@ void Uart::WriteDatFile(int sampleRate, string &strMeasurementID, int iChannel,
sprintf(updateSql, "sendMsg = 0"); sprintf(updateSql, "sendMsg = 0");
int iRet2 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon); int iRet2 = sqlite_db_ctrl::instance().UpdateTableData("t_data_waveSend", updateSql, whereCon);
string strFileName_failed = strFileName + "_" + nowTimetamp; std::string strFileName_failed = strFileName + "_" + nowTimetamp;
char tmpCmd[128] = {0x00}; char tmpCmd[128] = {0x00};
sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str()); sprintf(tmpCmd, "cp %s %s", strFileName.c_str(), strFileName_failed.c_str());
system(tmpCmd); system(tmpCmd);

View File

@ -7,6 +7,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <zlog.h> #include <zlog.h>
extern zlog_category_t* zct;
extern zlog_category_t* zbt;
void Uart::openSwitch() { void Uart::openSwitch() {
char buffer[100] = {0x00}; char buffer[100] = {0x00};
int len; int len;
@ -112,12 +115,13 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr) {
} else { } else {
zzlog_error(zct, zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]); zzlog_error(zct, zct, "Packge ACK send failed,shortAddr = %02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
} }
string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str()); zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str());
return true; return true;
} }
void Uart::UpdateWirelessNode(unsigned short shortAdd) { void Uart::UpdateWirelessNode(unsigned short shortAdd) {
string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
zlog_info(zct, "UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x", strTime.c_str(), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); zlog_info(zct, "UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x", strTime.c_str(), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
FILE* pFile = NULL; FILE* pFile = NULL;
@ -125,8 +129,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
char* buffer = NULL; char* buffer = NULL;
int resendCount = 0; int resendCount = 0;
pFile = fopen(DataNodeUpdateFile.c_str(), "rb"); pFile = fopen(DataNodeUpdateFile.c_str(), "rb");
if (pFile != NULL) if (pFile != NULL) {
{
while (fgetc(pFile) != EOF) { while (fgetc(pFile) != EOF) {
++thisSize; ++thisSize;
} }
@ -184,9 +187,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd) {
} }
gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0); gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0);
mssleep(2000); mssleep(2000);
memset(UpdateData, 0x00, sizeof(UpdateData)); memset(UpdateData, 0x00, sizeof(UpdateData));
mssleep(5000); mssleep(5000);
} }
if (gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1); if (gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1);
@ -438,7 +439,7 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
unsigned short localAddr = 0x9999; unsigned short localAddr = 0x9999;
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
string strName = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon); std::string strName = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeName ", whereCon);
unsigned char UpdateData[100] = {0x00}; unsigned char UpdateData[100] = {0x00};
//帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte] //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte]
@ -477,11 +478,13 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr) {
} }
return 0; return 0;
} }
return 0;
} else { } else {
zlog_error(zct, "invalid vecResultNode[41]:%c", vecResultNode[41]);
return -1; return -1;
} }
} }
int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /*,int nodewaveindex,int nodetime,int nodeindex*/) { int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /*,int nodewaveindex,int nodetime,int nodeindex*/) {
if (modifyaddr) modify_DistAddr(pDestShortAddr); if (modifyaddr) modify_DistAddr(pDestShortAddr);
mssleep(10000); mssleep(10000);
@ -489,7 +492,7 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /
char localtimestamp[32] = {0x00}; char localtimestamp[32] = {0x00};
int millisecond = 0; int millisecond = 0;
string rtcTime = GetRTC(localtimestamp, millisecond); std::string rtcTime = GetRTC(localtimestamp, millisecond);
zlog_info(zct, "ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d ", pDestShortAddr[0], pDestShortAddr[1], rtcTime.c_str(), localtimestamp, millisecond, bSendTimeStamp); zlog_info(zct, "ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d ", pDestShortAddr[0], pDestShortAddr[1], rtcTime.c_str(), localtimestamp, millisecond, bSendTimeStamp);
unsigned char UpdateData[100] = {0x00}; unsigned char UpdateData[100] = {0x00};

View File

@ -48,6 +48,7 @@ void Calculation::iFFT(int n, fftw_complex *in, fftw_complex *out) {
fftw_destroy_plan(p); fftw_destroy_plan(p);
fftw_cleanup(); fftw_cleanup();
} }
void Calculation::_iFFT(std::vector<float> &vecrealData, std::vector<float> &vecimageData, std::vector<float> &veciFFTData) { void Calculation::_iFFT(std::vector<float> &vecrealData, std::vector<float> &vecimageData, std::vector<float> &veciFFTData) {
fftw_complex *inFFt, *outFFt; fftw_complex *inFFt, *outFFt;
int N = vecrealData.size(); int N = vecrealData.size();
@ -67,6 +68,7 @@ void Calculation::_iFFT(std::vector<float> &vecrealData, std::vector<float> &vec
fftw_free(inFFt); fftw_free(inFFt);
fftw_free(outFFt); fftw_free(outFFt);
} }
void Calculation::_FFT(std::vector<float> &vecData, std::vector<float> &vecFFTrealData, std::vector<float> &vecFFTimageData) { void Calculation::_FFT(std::vector<float> &vecData, std::vector<float> &vecFFTrealData, std::vector<float> &vecFFTimageData) {
fftw_complex *inHilFFt, *outHilFFt; fftw_complex *inHilFFt, *outHilFFt;
inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size()); inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size());

View File

@ -2,9 +2,11 @@
#include <unistd.h> #include <unistd.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <zlog.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
extern zlog_category_t *zct;
static const char* MULTICAST_HOST_NAME1 = "224.0.0.1"; //组播接收平台搜索信号地址 static const char* MULTICAST_HOST_NAME1 = "224.0.0.1"; //组播接收平台搜索信号地址
static const int MULTICAST_PORT_RECV1 = 7301; //组播接收端口 static const int MULTICAST_PORT_RECV1 = 7301; //组播接收端口
@ -26,9 +28,7 @@ void SearchDev::Init() {
} }
} }
void SearchDev::GwRouteInit() { void SearchDev::GwRouteInit() {}
}
void SearchDev::HandleSend_1(const char* pMsg, const boost::system::error_code& pEc) { void SearchDev::HandleSend_1(const char* pMsg, const boost::system::error_code& pEc) {
if (pEc) { if (pEc) {

View File

@ -1,3 +1,4 @@
#include "secure.hpp"
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -5,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "SH_Secure.hpp"
#define AES_ENCRYPT 2 #define AES_ENCRYPT 2
#define AES_DECRYPT 0 #define AES_DECRYPT 0

View File

@ -1,6 +1,8 @@
#include "tcp_cgi.hpp" #include "tcp_cgi.hpp"
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
TcpCgi::TcpCgi() { zlog_info(zbt, "TcpCgi Init"); } TcpCgi::TcpCgi() { zlog_info(zbt, "TcpCgi Init"); }
@ -12,7 +14,7 @@ void TcpCgi::startCgiServer() {
char buff[40960]; char buff[40960];
int n; int n;
if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
zlog_info(zct,"create socket error: %s(errno: %d)", strerror(errno), errno); zlog_error(zbt, "create socket error: %s(errno: %d)", strerror(errno), errno);
return; return;
} }
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&mw_optval, sizeof(mw_optval)); setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&mw_optval, sizeof(mw_optval));
@ -23,23 +25,23 @@ void TcpCgi::startCgiServer() {
servaddr.sin_port = htons(7305); servaddr.sin_port = htons(7305);
if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
zlog_info(zct,"bind socket error: %s(errno: %d)", strerror(errno), errno); zlog_error(zbt, "bind socket error: %s(errno: %d)", strerror(errno), errno);
return; return;
} }
if (listen(listenfd, 10) == -1) { if (listen(listenfd, 10) == -1) {
zlog_info(zct,"listen socket error: %s(errno: %d)", strerror(errno), errno); zlog_error(zbt, "listen socket error: %s(errno: %d)", strerror(errno), errno);
return; return;
} }
while (1) { while (1) {
if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) == -1) { if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) == -1) {
zlog_info(zct,"accept socket error: %s(errno: %d)", strerror(errno), errno); zlog_error(zct, "accept socket error: %s(errno: %d)", strerror(errno), errno);
continue; continue;
} }
n = recv(connfd, buff, 40960, 0); n = recv(connfd, buff, 40960, 0);
if (n <= 0) { if (n <= 0) {
zlog_info(zct,("recv fail"); zlog_info(zct, "recv 0 and will close");
close(connfd); close(connfd);
} else { } else {
buff[n] = '\0'; buff[n] = '\0';

View File

@ -1,25 +1,19 @@
#include "udp_scan.hpp" #include "udp_scan.hpp"
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <zlog.h>
#include "common/common_func.hpp" #include "common/common_func.hpp"
#include "common/global.hpp" #include "common/global.hpp"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
UdpSys::UdpSys(): UdpSys::UdpSys() : mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303)) { zlog_info(zct, "UdpQt Init"); }
mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303))
{
zlog_info(zct,"UdpQt Init");
}
void UdpSys::ClearConnect() { remoteIp.clear(); }
void UdpSys::ClearConnect() void UdpSys::StartConnectSysUdp() {
{ zlog_info(zbt, "start connect QT");
remoteIp.clear();
}
void UdpSys::StartConnectSysUdp()
{
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);
@ -32,9 +26,7 @@ void UdpSys::StartConnectSysUdp()
} }
} }
void UdpSys::handle_send_to(const boost::system::error_code& ec, void UdpSys::handle_send_to(const boost::system::error_code& ec, size_t trans) {
size_t trans)
{
if (ec) { if (ec) {
zlog_error(zct, "send the udp to sys error! "); zlog_error(zct, "send the udp to sys error! ");
} else { } else {
@ -42,36 +34,22 @@ void UdpSys::handle_send_to(const boost::system::error_code& ec,
} }
} }
void UdpSys::SendUdpToSingle(std::string pData) void UdpSys::SendUdpToSingle(std::string pData) {
{
boost::mutex::scoped_lock lock(udpMutex); boost::mutex::scoped_lock lock(udpMutex);
int len = pData.length(); int len = pData.length();
if (len <= 0) if (len <= 0) return;
return ;
char* mi = new char[len + 3]; char* mi = new char[len + 3];
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");
zlog_info(zct, "sys send single : %s ", 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::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
boost::bind(&UdpSys::handle_send_to, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
delete[] mi; delete[] mi;
} }
void UdpSys::recvUdpData() void UdpSys::recvUdpData() { udpSock.async_receive_from(boost::asio::buffer(m_buffer), senderEndPoint, boost::bind(&UdpSys::HandleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); }
{
udpSock.async_receive_from(boost::asio::buffer(m_buffer), senderEndPoint,
boost::bind(&UdpSys::HandleRead, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
void UdpSys::HandleRead(const boost::system::error_code& pEc, std::size_t pBytesTransferred) {
void UdpSys::HandleRead(const boost::system::error_code& pEc,
std::size_t pBytesTransferred)
{
std::string ip = senderEndPoint.address().to_string(); std::string ip = senderEndPoint.address().to_string();
if (pEc) { if (pEc) {
std::cerr << pEc.value() << std::endl; std::cerr << pEc.value() << std::endl;
@ -92,8 +70,7 @@ void UdpSys::HandleRead(const boost::system::error_code& pEc,
recvUdpData(); recvUdpData();
} }
void UdpSys::AnalysisDataSys(std::string cmd) void UdpSys::AnalysisDataSys(std::string cmd) {
{
zlog_info(zct, "%s", cmd.c_str()); zlog_info(zct, "%s", cmd.c_str());
Json::Reader recvReader; Json::Reader recvReader;
Json::Value JsonVal; Json::Value JsonVal;
@ -111,8 +88,7 @@ void UdpSys::AnalysisDataSys(std::string cmd)
} }
zlog_info(zct, "strServerIp : %s ", strServerIp.c_str()); zlog_info(zct, "strServerIp : %s ", strServerIp.c_str());
if (strServerIp.compare(GlobalConfig::ServerIP) != 0 || localServerPort != GlobalConfig::ServerPort) if (strServerIp.compare(GlobalConfig::ServerIP) != 0 || localServerPort != GlobalConfig::ServerPort) {
{
GlobalConfig::ServerIP = strServerIp; GlobalConfig::ServerIP = strServerIp;
GlobalConfig::ServerPort = localServerPort; GlobalConfig::ServerPort = localServerPort;
@ -128,44 +104,31 @@ void UdpSys::AnalysisDataSys(std::string cmd)
Json::FastWriter fw; Json::FastWriter fw;
std::string str = fw.write(JsonVal); std::string str = fw.write(JsonVal);
zlog_info(zct, "send info : %s ", str.c_str()); zlog_info(zct, "send info : %s ", str.c_str());
boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), MULTICAST_PORT_SEND);
MULTICAST_PORT_SEND); udpSock.async_send_to(boost::asio::buffer(str), remoteEP, boost::bind(&UdpSys::handle_send_to, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
udpSock.async_send_to(boost::asio::buffer(str),remoteEP,
boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
} else { } else {
//TODO: add log here zlog_info(zbt, "server ip and port not change");
} }
} } break;
break;
case 4: { case 4: {
Json::FastWriter fw; Json::FastWriter fw;
std::string status = JsonVal["status"].asString(); std::string status = JsonVal["status"].asString();
if(status.compare("REQ") == 0) if (status.compare("REQ") == 0) {
{
JsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G.c_str(); JsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G.c_str();
JsonVal["localServerIpAddress"] = GlobalConfig::ServerIP; JsonVal["localServerIpAddress"] = GlobalConfig::ServerIP;
JsonVal["status"] = "ACK"; JsonVal["status"] = "ACK";
std::string data = fw.write(JsonVal); std::string data = fw.write(JsonVal);
boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()), MULTICAST_PORT_SEND);
MULTICAST_PORT_SEND); udpSock.async_send_to(boost::asio::buffer(data), remoteEP, boost::bind(&UdpSys::handle_send_to, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
udpSock.async_send_to(boost::asio::buffer(data),remoteEP,
boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
} }
} break;
default: break;
} }
break; } else {
default:
break;
}
}else
{
zlog_error(zct, "json parse failed"); zlog_error(zct, "json parse failed");
} }
} }
UdpSys::~UdpSys() UdpSys::~UdpSys() {
{ if (udpSock.is_open()) udpSock.close();
if (udpSock.is_open())
udpSock.close();
} }

View File

@ -4,6 +4,7 @@
#include <zlog.h> #include <zlog.h>
#include "common/common_func.hpp" #include "common/common_func.hpp"
extern zlog_category_t *zct;
Dial::Dial() { Dial::Dial() {
m_fd = 0; m_fd = 0;

View File

@ -16,6 +16,8 @@
#include <unistd.h> #include <unistd.h>
#include <zlog.h> #include <zlog.h>
extern zlog_category_t *zct;
namespace wifi { namespace wifi {
size_t strlcpy(char *dst, const char *src, size_t dst_sz) { size_t strlcpy(char *dst, const char *src, size_t dst_sz) {