WLG/jsonparse/web_cmd_parse3.cpp

1090 lines
41 KiB
C++
Raw Normal View History

2024-10-22 19:04:25 +08:00
#include "communication_cmd.hpp"
2024-10-24 16:01:21 +08:00
#include <fstream>
#include <boost/algorithm/string.hpp>
2024-10-23 20:33:05 +08:00
#include <zlog.h>
2024-10-24 16:01:21 +08:00
#include "common/global.hpp"
2024-10-22 20:56:21 +08:00
#include "dbaccess/sql_db.hpp"
#include "platform/platform_init.hpp"
2024-10-23 09:22:06 +08:00
#include "utility/md5.h"
2024-10-24 16:01:21 +08:00
#include "wifi_5g/wpa_client.h"
#include "utility/calculation.hpp"
#include "scheduler/schedule.hpp"
2024-10-23 20:33:05 +08:00
extern zlog_category_t *zct;
2024-10-24 16:34:11 +08:00
extern const char *JSON_FIELD_CMD;
2024-10-22 19:04:25 +08:00
std::string JsonData::JsonCmd_Cgi_default() {
Json::Value jsonVal;
jsonVal.clear();
jsonVal["success"] = false;
jsonVal["message"] = "功能不支持";
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_45(Param_45 &param) {
Json::Value jsonVal;
jsonVal.clear();
if (0 == param.mMode) {
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
std::string nowTimetamp = std::string(localtimestamp);
WriteStr2Config(SYSTEMINFOFILE, "Area", "countryId", param.mCountryId);
WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", param.mProvincesId);
WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", param.mCityListId);
}
jsonVal[JSON_FIELD_CMD] = "45";
jsonVal["success"] = true;
jsonVal["message"] = "区域配置成功";
Json::Value jsBody;
jsBody["countryId"] = ReadStrByOpt(SYSTEMINFOFILE, "Area", "countryId");
jsBody["provincesId"] = ReadStrByOpt(SYSTEMINFOFILE, "Area", "provincesId");
jsBody["cityListId"] = ReadStrByOpt(SYSTEMINFOFILE, "Area", "cityListId");
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_46(Param_46 &param) {
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "46";
jsonVal["success"] = true;
jsonVal["message"] = "升级失败";
std::string strFile = "/var/" + param.mFileName;
if (access(strFile.c_str(), 0) >= 0) {
std::string strCmd = "mv " + strFile + " /tmp/upgrade.tar.gz";
system(strCmd.c_str());
system("/etc/init.d/sysupgrade.sh");
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有升级包";
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_47(Param_47 &param) {
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "47";
jsonVal["success"] = true;
jsonVal["message"] = "logo配置成功";
std::string strFile = "/var/" + param.mFileName;
if (access(strFile.c_str(), 0) >= 0) {
std::string strCmd = "mv " + strFile + " /var/www/html/static/media/logo.svg";
system(strCmd.c_str());
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有找到logo";
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
2024-10-22 20:56:21 +08:00
2024-10-22 19:04:25 +08:00
std::string JsonData::JsonCmd_Cgi_50() {
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "50";
jsonVal["success"] = true;
jsonVal["message"] = "";
std::string strFileName = "", strSoftVersion = "";
Json::Value root;
Json::Value jsBody;
Json::Reader reader;
std::vector<std::string> value;
std::vector<DataNodeUpdate> vecDataNodeUpdate;
DataNodeUpdate datanodeUpdate;
std::fstream is;
is.open("/opt/DataNode/config.json", std::ios::in);
if (reader.parse(is, root)) {
jsBody["sensor"] = root;
}
2024-11-14 18:48:45 +08:00
jsBody["GateWayVersion"] = GlobalConfig::Version;
2024-10-22 19:04:25 +08:00
jsBody["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
jsBody["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_51(Param_51 &param) {
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "51";
jsonVal["success"] = true;
jsonVal["message"] = "";
char whereCon[1024] = {0};
char updateSql[1024] = {0};
2024-10-23 20:33:05 +08:00
std::string gatewayLocation = "";
2024-10-22 19:04:25 +08:00
sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str());
sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str());
if (param.mMode == 0) {
2024-10-22 20:56:21 +08:00
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
2024-10-22 19:04:25 +08:00
if (iRet != 0) jsonVal["success"] = false;
} else {
2024-10-22 20:56:21 +08:00
gatewayLocation = sqlite_db_ctrl::instance().GetData(T_GATEWAY_INFO(TNAME), "gatewayLocation", NULL);
2024-10-22 19:04:25 +08:00
jsBody["gateWayLocation"] = gatewayLocation;
}
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
2024-10-22 20:56:21 +08:00
2024-10-22 19:04:25 +08:00
std::string JsonData::JsonCmd_Cgi_52(Param_52 &param) {
Json::Value jsonVal;
Json::Value jsBody;
jsonVal.clear();
jsonVal["cmd"] = "52";
jsonVal["dataWatchNo"] = GlobalConfig::MacAddr_G;
jsonVal["cmdSerial"] = param.mCmdSerial;
jsonVal["success"] = true;
jsonVal["message"] = " ";
2024-11-14 18:48:45 +08:00
#ifndef WIFI_MODULE
jsonVal["success"] = false;
jsonVal["message"] = " ";
jsonVal["enable"] = false;
return show_value_.write(jsonVal);
#endif
jsonVal["enable"] = true;
2024-10-22 19:04:25 +08:00
if (0 == param.mMode) { // 扫描
wifi::WPAClient wpa;
std::string netssid = wpa.GetNetSsid();
std::vector<std::string> vecSsid;
boost::split(vecSsid, netssid, boost::is_any_of("\n"), boost::token_compress_off);
jsBody["type"] = "SCAN";
2025-03-13 17:46:29 +08:00
zlog_info(zct,"netssid : %s ==== %d", netssid.c_str(), vecSsid.size());
2024-10-22 19:04:25 +08:00
for (unsigned int i = 1; i < vecSsid.size() - 1; i++) {
std::vector<std::string> data;
boost::split(data, vecSsid[i], boost::is_any_of("\t"), boost::token_compress_off);
Json::Value wifiInfo;
wifiInfo["bssid"] = data[0];
wifiInfo["frequency"] = data[1];
wifiInfo["signallevel"] = data[2];
wifiInfo["secure"] = data[3];
wifiInfo["ssid"] = data[4];
jsBody["wifilist"].append(wifiInfo);
}
} else if (1 == param.mMode) { // 设置
2024-10-23 19:51:01 +08:00
zlog_info(zct,"set WiFi");
2024-10-22 19:04:25 +08:00
wifi::WPAClient wpa;
jsBody["ssid"] = param.mSsid;
if (param.mPassWord.length() > 0) {
if (wpa.ConnectWiFi(param.mSsid.c_str(), param.mPassWord.c_str())) {
jsBody["status"] = true;
} else {
jsBody["status"] = false;
}
} else {
if (wpa.ConnectWiFiWithNoPassword(param.mSsid.c_str())) {
jsBody["status"] = true;
} else {
jsBody["status"] = false;
}
}
} else if (2 == param.mMode) { // 获取
wifi::WPAClient wpa;
std::string ssid = " ";
int rssi = 0;
ssid = wpa.GetCurrentSSID();
rssi = wpa.GetWiFiRssi();
jsBody["ssid"] = ssid;
jsBody["rssi"] = rssi;
} else if (3 == param.mMode) {
wifi::WPAClient wpa;
if (wpa.CleanWifi()) {
jsonVal["message"] = "wifi断开成功";
} else {
jsonVal["message"] = "wifi断开失败";
}
}
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_53(std::vector<Param_53> &param) {
Json::Value jsonVal;
jsonVal.clear();
jsonVal["cmd"] = "53";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsonVal["success"] = true;
jsonVal["message"] = " ";
char whereCon[1024] = {0};
char updateSql[1024] = {0};
2024-10-24 16:01:21 +08:00
for (size_t i = 0; i < param.size(); i++) {
2024-11-15 19:47:21 +08:00
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
std::string zigbeeShortAddr = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
uint16_t short_addr;
char *end_ptr = NULL;
short_addr = strtol(zigbeeShortAddr.c_str(), &end_ptr, 16);
int res = scheduler::instance().UpdateSensorConfig(short_addr);
if (res != 0){
jsonVal["success"] = false;
jsonVal["message"] = "update config error";
return show_value_.write(jsonVal);
}
2024-10-22 19:04:25 +08:00
if (param[i].mUpdateKey2 == "") {
sprintf(updateSql, "%s='%s',UpdateFlag = 0", param[i].mUpdateKey.c_str(), param[i].mUpdateValue.c_str());
} else if (param[i].mUpdateKey3 == "" && param[i].mUpdateKey2 != "") {
sprintf(updateSql, "%s='%s',%s='%s',UpdateFlag = 0", param[i].mUpdateKey.c_str(), param[i].mUpdateValue.c_str(), param[i].mUpdateKey2.c_str(), param[i].mUpdateValue2.c_str());
} else if (param[i].mUpdateKey3 != "" && param[i].mUpdateKey2 != "") {
sprintf(updateSql, "%s='%s',%s='%s',%s='%s',UpdateFlag = 0", param[i].mUpdateKey.c_str(), param[i].mUpdateValue.c_str(), param[i].mUpdateKey2.c_str(), param[i].mUpdateValue2.c_str(), param[i].mUpdateKey3.c_str(), param[i].mUpdateValue3.c_str());
}
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
2024-10-22 20:56:21 +08:00
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
2024-10-22 19:04:25 +08:00
memset(whereCon, 0x00, sizeof(whereCon));
memset(updateSql, 0x00, sizeof(updateSql));
if (iRet != 0) jsonVal["success"] = false;
}
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_55(Param_55 &param) {
Json::Value jsonVal;
Json::Value jsBody;
Json::Value SystemSetting;
jsonVal.clear();
jsonVal["cmd"] = "55";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsonVal["success"] = true;
jsonVal["message"] = " ";
std::vector<float> vecWave;
std::vector<float> IntegrationWave;
char whereCon[64] = {};
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
2024-10-22 20:56:21 +08:00
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
2024-10-22 19:04:25 +08:00
int SampleRate = 0;
double resolution = 0.0;
SampleRate = atoi(res[23].c_str());
2024-10-23 19:51:01 +08:00
zlog_info(zct,"sensor type %s", res[17].c_str());
2024-10-22 19:04:25 +08:00
char localtimestamp[32] = {0};
std::string strWaveData = "";
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
if (access(filename.c_str(), 0) >= 0) {
2024-10-24 16:01:21 +08:00
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
2024-10-22 19:04:25 +08:00
if (!inFile) {
2024-10-24 16:01:21 +08:00
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
2024-10-22 19:04:25 +08:00
jsonVal["success"] = false;
jsonVal["message"] = "error";
} else {
float fTemp = 0;
std::vector<float> hanningWave;
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
vecWave.push_back(fTemp);
}
if (res[17] == "01") {
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d", SampleRate);
2024-10-22 19:04:25 +08:00
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
} else if (res[17] == "02") {
2024-10-24 16:01:21 +08:00
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos) {
2024-10-22 19:04:25 +08:00
resolution = (double)SampleRate / vecWave.size();
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
2024-10-22 19:04:25 +08:00
} else {
SampleRate = 8000;
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d", SampleRate);
2024-10-22 19:04:25 +08:00
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
}
}
//积分
2024-10-24 16:01:21 +08:00
Calculation::Integration(vecWave, IntegrationWave, resolution);
2024-10-22 19:04:25 +08:00
int flag = param.mPackageFlag;
flag = (flag + 1) * 1024;
int number = IntegrationWave.size();
int start = param.mPackageFlag * 1024;
if (number < 1024) {
flag = number;
start = 0;
}
char buf[32];
for (int i = start; i < flag; i++) {
if (i == start) {
memset(buf, 0, 32);
sprintf(buf, "%.2f", IntegrationWave[i]);
std::string waveTemp(buf);
strWaveData = waveTemp;
} else {
memset(buf, 0, 32);
sprintf(buf, "%.2f", IntegrationWave[i]);
std::string waveTemp(buf);
strWaveData = strWaveData + "," + waveTemp;
}
}
int max = number / 1024;
if (max == 0 && number > 0) {
max = 1;
}
jsBody["packageMax"] = max;
}
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有数据文件";
}
jsBody["channelId"] = param.mChannelId;
jsBody["package"] = param.mPackageFlag;
2024-10-23 19:51:01 +08:00
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())));
2024-10-24 16:01:21 +08:00
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos && res[17] == "02") {
2024-10-22 19:04:25 +08:00
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
} else if (res[17] == "01") {
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
} else {
jsBody["second"] = 1;
}
jsBody["Data"] = strWaveData;
2024-10-24 16:01:21 +08:00
jsBody["timestamp"] = std::string(localtimestamp);
2024-10-22 19:04:25 +08:00
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_56(Param_56 &param) {
Json::Value jsonVal;
Json::Value jsBody;
Json::Value SystemSetting;
jsonVal.clear();
jsonVal["cmd"] = "56";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsonVal["success"] = true;
jsonVal["message"] = "";
std::string strWaveData;
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
char localtimestamp[32] = {0};
std::vector<float> vecWave;
std::vector<float> hanningWave;
std::vector<float> addhanningWave;
std::vector<float> fftWave;
std::vector<float> IntegrationWave;
int sampleRateReference = 0;
2024-10-23 19:51:01 +08:00
char whereCon[64] = {0};
2024-10-22 19:04:25 +08:00
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
2024-10-22 20:56:21 +08:00
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
2024-10-22 19:04:25 +08:00
int SampleRate = 0;
double resolution = 0.0;
SampleRate = atoi(res[23].c_str());
2024-10-23 19:51:01 +08:00
zlog_info(zct,"sensor type %s", res[17].c_str());
2024-10-22 19:04:25 +08:00
if (access(filename.c_str(), 0) >= 0) {
2024-10-24 16:01:21 +08:00
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
2024-10-22 19:04:25 +08:00
if (!inFile) {
2024-10-24 16:01:21 +08:00
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
2024-10-22 19:04:25 +08:00
jsonVal["success"] = "false";
jsonVal["message"] = "error";
} else {
float fTemp = 0;
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
2024-10-24 16:01:21 +08:00
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos && res[17] == "02") {
2024-10-22 19:04:25 +08:00
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
vecWave.push_back(fTemp);
}
//积分
resolution = (double)SampleRate / vecWave.size();
2024-10-24 16:01:21 +08:00
Calculation::Integration(vecWave, IntegrationWave, resolution);
Calculation::FFTSpec(IntegrationWave, fftWave);
2024-10-22 19:04:25 +08:00
sampleRateReference = 1000;
} else {
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
2024-10-23 19:51:01 +08:00
vecWave.push_back(fTemp);
2024-10-22 19:04:25 +08:00
}
if (res[17] == "01") {
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d", SampleRate);
2024-10-22 19:04:25 +08:00
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
} else if (res[17] == "02") {
2024-10-24 16:01:21 +08:00
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos) {
2024-10-22 19:04:25 +08:00
SampleRate = atoi(res[23].c_str());
resolution = (double)SampleRate / vecWave.size();
2024-10-23 19:51:01 +08:00
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
2024-10-22 19:04:25 +08:00
} else {
SampleRate = 8192;
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d", SampleRate);
2024-10-22 19:04:25 +08:00
if (vecWave.size() < 8192) {
resolution = (double)SampleRate / vecWave.size();
} else {
resolution = (double)SampleRate / 8192;
}
}
}
2024-10-23 19:51:01 +08:00
// 积分
2024-10-24 16:01:21 +08:00
Calculation::Integration(vecWave, IntegrationWave, resolution);
Calculation::FFTSpec(IntegrationWave, fftWave);
2024-10-22 19:04:25 +08:00
sampleRateReference = 1024;
}
2024-10-23 19:51:01 +08:00
zlog_info(zct,"2---------------------------------------------->vecWave = %d,fftWave = %d", vecWave.size(), fftWave.size());
2024-10-22 19:04:25 +08:00
int flag = param.mPackageFlag;
flag = (flag + 1) * sampleRateReference;
int number = fftWave.size();
2024-10-23 19:51:01 +08:00
zlog_info(zct,"number---------------------------------------------->%d", number);
2024-10-22 19:04:25 +08:00
int start = param.mPackageFlag * sampleRateReference;
2024-10-23 19:51:01 +08:00
zlog_info(zct,"param.mPackageFlag = %d", param.mPackageFlag);
zlog_info(zct,"param.start = %d", start);
zlog_info(zct,"param.flag = %d", flag);
2024-10-22 19:04:25 +08:00
if (number < sampleRateReference) {
flag = number;
start = 0;
}
char buf[32];
for (int i = start; i < flag; i++) {
if (i == start) {
memset(buf, 0, 32);
sprintf(buf, "%.6f", fftWave[i]);
std::string waveTemp(buf);
strWaveData = waveTemp;
} else {
memset(buf, 0, 32);
sprintf(buf, "%.6f", fftWave[i]);
std::string waveTemp(buf);
strWaveData = strWaveData + "," + waveTemp;
}
}
int max = number / sampleRateReference;
if (max == 0 && number > 0) {
max = 1;
}
jsBody["packageMax"] = max;
}
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有数据文件";
}
jsBody["channelId"] = param.mChannelId;
jsBody["package"] = param.mPackageFlag;
2024-10-24 16:01:21 +08:00
jsBody["timestamp"] = std::string(localtimestamp);
2024-10-22 19:04:25 +08:00
jsBody["Data"] = strWaveData;
2024-10-25 18:45:26 +08:00
zlog_info(zct,"the sample rate is %d,the resolution %f", SampleRate, resolution);
2024-10-22 19:04:25 +08:00
char buf[32];
memset(buf, 0, 32);
sprintf(buf, "%f", resolution);
jsBody["resolution"] = std::string(buf);
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-22 19:04:25 +08:00
}
std::string JsonData::JsonCmd_Cgi_57(Param_57 &param) {
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "57";
jsonVal["success"] = true;
jsonVal["message"] = "";
int zigbeepowerEnable = -1;
if (param.mMode == 1) {
zigbeepowerEnable = writeIntValue("config", "zigbeepowerEnable", param.mZigbeePowerEnable, (char *)GlobalConfig::Config_G.c_str());
} else if (param.mMode == 0) {
zigbeepowerEnable = readIntValue("config", "zigbeepowerEnable", (char *)GlobalConfig::Config_G.c_str());
}
jsBody["zigbeepowerEnable"] = zigbeepowerEnable;
jsonVal["content"] = jsBody;
2024-10-22 20:56:21 +08:00
return show_value_.write(jsonVal);
2024-10-24 16:01:21 +08:00
}
std::string JsonData::JsonCmd_Cgi_58(Param_58 &param) {
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "58";
jsonVal["success"] = true;
jsonVal["message"] = "";
2024-11-14 18:48:45 +08:00
int ret = 0,sensorCount = 0;
2024-11-08 09:17:35 +08:00
std::string error_msg = "";
2024-11-06 10:59:22 +08:00
if (param.mMode == 1)
{
2024-11-08 09:17:35 +08:00
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum,error_msg);
2024-11-06 10:59:22 +08:00
}else if (param.mMode == 0)
{
2024-11-14 18:48:45 +08:00
sensorCount = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
2024-11-06 10:59:22 +08:00
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
}
if (ret == 0)
{
2024-11-06 10:59:22 +08:00
jsBody["featureInterVal"] = param.featureInterVal;
jsBody["featureInterTime"] = param.featureInterTime;
jsBody["waveInterVal"] = param.waveInterVal;
jsBody["waveInterTime"] = param.waveInterTime;
jsBody["maxSensorNum"] = param.maxSensorNum;
2024-11-14 18:48:45 +08:00
jsBody["sensorCount"] = sensorCount;
2024-11-06 10:59:22 +08:00
}else{
jsonVal["success"] = false;
2024-11-08 09:17:35 +08:00
jsonVal["message"] = error_msg;
}
2024-11-08 09:17:35 +08:00
jsonVal["content"] = jsBody;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_59(Param_59 &param) {
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "59";
jsonVal["success"] = true;
jsonVal["message"] = "";
char table_name[50] ={0};
2024-11-06 10:59:22 +08:00
char sql[1024]={0};
2024-11-14 18:48:45 +08:00
int featureInterVal = 0;
int featureInterTime = 0;
int waveInterVal = 0;
int waveInterTime = 0;
int maxSensorNum = 0;
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
if (param.mMode == 1)
{
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
2024-11-06 10:59:22 +08:00
snprintf(sql, sizeof(sql),
"WITH CTE AS ("
" SELECT timestamp, "
" LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp "
" FROM %s"
") "
"SELECT timestamp, "
" prev_timestamp, "
" timestamp - prev_timestamp AS interval_seconds "
"FROM CTE "
"WHERE prev_timestamp IS NOT NULL "
" AND (timestamp - prev_timestamp) > %d;",
2024-11-14 18:48:45 +08:00
table_name,featureInterVal + 6);
}else if (param.mMode == 2)
{
sprintf(table_name,"t_data_waveSend");
2024-11-06 10:59:22 +08:00
snprintf(sql, sizeof(sql),
"WITH CTE AS ("
" SELECT timestamp, "
" LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp "
2024-11-06 10:59:22 +08:00
" FROM %s WHERE channelID = '%s-%s'"
") "
"SELECT timestamp, "
" prev_timestamp, "
" timestamp - prev_timestamp AS interval_seconds "
"FROM CTE "
"WHERE prev_timestamp IS NOT NULL "
" AND (timestamp - prev_timestamp) > %d;",
2024-11-14 18:48:45 +08:00
table_name,param.DataNodeNo.c_str(),param.straxis.c_str(),waveInterVal + 40);
2024-11-06 10:59:22 +08:00
jsonVal["Raxis"] = param.straxis;
}
array_t arrResult = sqlite_db_ctrl::instance().GetDataMultiLine(sql);
Json::Value valData;
if (arrResult.size() > 0)
{
for (size_t i = 0; i < arrResult.size(); i++)
{
Json::Value iTem;
iTem.append(arrResult[i][1]);
2024-11-13 17:50:54 +08:00
iTem.append(arrResult[i][0]);
2025-01-23 20:07:10 +08:00
int time = 0;
int lost_data_time = atol(arrResult[i][1].c_str()) - atol(arrResult[i][1].c_str());
if (param.mMode == 1){
time = abs(lost_data_time/featureInterVal);
}else if(param.mMode == 2){
time = abs(lost_data_time/waveInterVal);
}
iTem.append(time);
valData.append(iTem);
}
jsonVal["content"] = valData;
2024-11-06 10:59:22 +08:00
}else{
jsonVal["success"] = false;
jsonVal["message"] = "获取数据失败!";
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}
2024-11-08 09:17:35 +08:00
std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "60";
jsonVal["success"] = true;
jsonVal["message"] = "";
char file_path[64]={0};
char cmd[64]={0};
2024-11-08 16:55:14 +08:00
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
2024-11-08 09:17:35 +08:00
system(cmd);
2024-11-11 20:51:40 +08:00
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
zlog_info(zct,"file_path = %s",file_path);
2024-11-08 09:17:35 +08:00
FILE * pFile=NULL;
size_t thisSize = 0;
char *buffer=NULL;
pFile = fopen (file_path,"rb");
2024-11-11 20:51:40 +08:00
if (pFile==NULL) {
zlog_error(zct,"Error opening file");
jsonVal["success"] = false;
jsonVal["message"] = "Error opening file";
return show_value_.write(jsonVal);
}
2024-11-08 09:17:35 +08:00
else
{
while (fgetc(pFile) != EOF) {
++thisSize;
}
rewind(pFile);
buffer = (char*)malloc(thisSize);
fread (buffer, sizeof (char), thisSize, pFile);
fclose (pFile);
}
2024-11-11 20:51:40 +08:00
zlog_info(zct,"Read %zu bytes", thisSize);
2024-11-09 16:15:39 +08:00
char sensor_type[6] = {0};
char sf_version[10] = {0};
memcpy(sensor_type, buffer, 5);
2024-11-11 20:51:40 +08:00
zlog_info(zct,"model:%s", sensor_type);
if (param.product == 1 ){
if (strcmp(sensor_type,"DN101") != 0){
jsonVal["success"] = false;
jsonVal["message"] = "product error";
free(buffer);
return show_value_.write(jsonVal);
}
}else if(param.product == 2){
if (strcmp(sensor_type,"DN102") != 0){
jsonVal["success"] = false;
jsonVal["message"] = "product error";
free(buffer);
return show_value_.write(jsonVal);
}
}
2024-11-09 16:15:39 +08:00
char c[2] = {0};
c[0] = buffer[5];
uint8_t hw_ver = atoi(c);
c[0] = buffer[6];
uint8_t sf_ver_m = atoi(c);
c[0] = buffer[7];
uint8_t sf_ver_s = atoi(c);
sprintf(sf_version,"%d.%d",sf_ver_m,sf_ver_s);
unsigned char ch_crc = 0x00;
2024-11-08 09:17:35 +08:00
int packgeSize = 0;
2024-11-09 16:15:39 +08:00
ch_crc = buffer[12];
2024-11-08 09:17:35 +08:00
packgeSize = BUILD_UINT32(buffer[8],buffer[9],buffer[10],buffer[11]);
2024-11-13 17:50:54 +08:00
zlog_info(zct,"sf_ver_m = %d",sf_ver_m);
zlog_info(zct,"sf_ver_s = %d",sf_ver_s);
zlog_info(zct,"hw_ver = %d",hw_ver);
zlog_info(zct,"sensor_type = %s",sensor_type);
zlog_info(zct,"packgeSize = %d",packgeSize);
zlog_info(zct,"ch_crc = %02x",ch_crc);
2024-11-08 09:17:35 +08:00
unsigned char sum = 0x00;
for(size_t i = 13; i < thisSize;i++){
sum += buffer[i];
}
2024-11-09 16:15:39 +08:00
if (sum % 256 != ch_crc)
{
jsonVal["success"] = false;
jsonVal["message"] = "package CRC error";
2024-11-10 19:22:16 +08:00
free(buffer);
2024-11-09 16:15:39 +08:00
return show_value_.write(jsonVal);
}
2024-11-13 17:50:54 +08:00
zlog_info(zct,"sum = %x\n",sum % 256);
2024-11-08 09:17:35 +08:00
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
2024-11-09 16:15:39 +08:00
char wherecon[100] = {0};
char insertSql[200] = {0};
2024-11-11 20:51:40 +08:00
char updateSql[100] = {0};
2024-11-09 16:15:39 +08:00
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str());
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon);
if (hw_ver != atoi(vecResult[0].c_str()))
{
jsonVal["success"] = false;
jsonVal["message"] = "hardVersion error";
2024-11-10 19:22:16 +08:00
free(buffer);
2024-11-09 16:15:39 +08:00
return show_value_.write(jsonVal);
}
2024-11-10 16:43:15 +08:00
sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),param.fileName.c_str());
2024-11-09 16:15:39 +08:00
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
2024-11-11 20:51:40 +08:00
//0 默认状态1 升级中2 升级成功,3 升级失败
memset(wherecon,0,sizeof(wherecon));
memset(updateSql,0,sizeof(updateSql));
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
sprintf(updateSql, " upgradeStatus = %d ", 1);
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
uint16_t short_addr;
char *end_ptr = NULL;
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
2024-11-14 18:48:45 +08:00
int res = scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version));
if (res != 0)
{
jsonVal["success"] = false;
jsonVal["message"] = "UpgradeSensor error";
free(buffer);
return show_value_.write(jsonVal);
}
2024-11-09 16:15:39 +08:00
}
2024-11-10 19:22:16 +08:00
free(buffer);
return show_value_.write(jsonVal);
2024-11-08 09:17:35 +08:00
2024-11-09 16:15:39 +08:00
}
std::string JsonData::JsonCmd_Cgi_61(Param_61 &param){
Json::Value jsonVal;
jsonVal.clear();
2024-11-10 16:43:15 +08:00
jsonVal[JSON_FIELD_CMD] = "61";
2024-11-09 16:15:39 +08:00
jsonVal["success"] = true;
jsonVal["message"] = " ";
vec_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), NULL);
int nSize = vetRes.size();
if (nSize > 0) {
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
sprintf(selectCon, " channelID,timeStamp,sendMsg,error_code ");
sprintf(szTableName, "t_data_waveSend");
if (param.timeEnd == "") {
sprintf(whereCon, "channelID = '%s-%s'", param.MeasurementID.c_str(),param.straxis.c_str());
} else {
sprintf(whereCon, " channelID = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
}
2024-11-08 09:17:35 +08:00
2024-11-09 16:15:39 +08:00
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
int packgeNo = param.mPackageFlag;
int packgeMax = 0;
int packgeNum = 0;
jsonVal["package"] = packgeNo;
int lastSize = rows % 550;
int index = rows / 550;
if (lastSize > 0 && index > 0) {
packgeMax = index + 1;
if (packgeNo + 1 == packgeMax) {
packgeNum = rows - lastSize;
jsonVal["packageMax"] = index + 1;
} else {
packgeNum = (packgeNo)*550;
jsonVal["packageMax"] = index + 1;
}
} else if (lastSize == 0 && index > 0) {
packgeNum = (packgeNo + 1) * 550;
packgeMax = index;
jsonVal["packageMax"] = index;
} else if (lastSize > 0 && index == 0) {
packgeNum = 0;
packgeMax = index + 1;
jsonVal["packageMax"] = index;
}
memset(whereCon, 0x00, sizeof(whereCon));
if (param.timeEnd == "") {
sprintf(whereCon, "channelID = '%s-%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.straxis.c_str(), 550, packgeNum);
} else {
sprintf(whereCon, "channelID = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
}
array_t vecRes;
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
zlog_info(zct, "vecRes = %d", vecRes.size());
if (vecRes.size() > 0) {
Json::Value jsStaticData;
for (size_t i = 0; i < vecRes.size(); i++) {
Json::Value iTem;
if (vecRes[i][0] == param.MeasurementID + "-X") {
iTem.append(vecRes[i][1]);
iTem.append(vecRes[i][2]);
2024-11-14 18:48:45 +08:00
if (vecRes[i][3] == "4"){
iTem.append("MOSQ_ERR_NO_CONN");
}else if (vecRes[i][3] == "14"){
iTem.append("MOSQ_ERR_ERRNO");
}else{
iTem.append(vecRes[i][3]);
}
2024-11-09 16:15:39 +08:00
jsStaticData["X"].append(iTem);
}
if (vecRes[i][0] == param.MeasurementID + "-Y") {
iTem.append(vecRes[i][1]);
iTem.append(vecRes[i][2]);
2024-11-14 18:48:45 +08:00
if (vecRes[i][3] == "4"){
iTem.append("MOSQ_ERR_NO_CONN");
}else if (vecRes[i][3] == "14"){
iTem.append("MOSQ_ERR_ERRNO");
}else{
iTem.append(vecRes[i][3]);
}
2024-11-09 16:15:39 +08:00
jsStaticData["Y"].append(iTem);
}
if (vecRes[i][0] == param.MeasurementID + "-Z") {
iTem.append(vecRes[i][1]);
iTem.append(vecRes[i][2]);
2024-11-14 18:48:45 +08:00
if (vecRes[i][3] == "4"){
iTem.append("MOSQ_ERR_NO_CONN");
}else if (vecRes[i][3] == "14"){
iTem.append("MOSQ_ERR_ERRNO");
}else{
iTem.append(vecRes[i][3]);
}
2024-11-09 16:15:39 +08:00
jsStaticData["Z"].append(iTem);
}
}
if (jsStaticData.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = (jsStaticData);
}
zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
2024-11-08 09:17:35 +08:00
}
2024-11-12 20:04:43 +08:00
std::string JsonData::JsonCmd_Cgi_62(Param_62 &param){
Json::Value jsonVal;
jsonVal.clear();
2024-11-13 17:50:54 +08:00
jsonVal[JSON_FIELD_CMD] = "62";
2024-11-12 20:04:43 +08:00
jsonVal["success"] = true;
jsonVal["message"] = " ";
vec_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), NULL);
int nSize = vetRes.size();
if (nSize > 0) {
2025-04-08 14:25:54 +08:00
char szTableName[100] = {0x00}, whereCon[256] = {0x00},selectCon[100] = {0x00};
if (param.mMode == 1){
2025-04-10 15:51:47 +08:00
sprintf(selectCon," dataNodeNo,channelID,timeStamp,sendMsg,sendMsg,nodeResend ");
2025-04-08 14:25:54 +08:00
sprintf(szTableName,"t_data_%s",param.MeasurementID.c_str());
}else{
sprintf(selectCon," * ");
sprintf(szTableName, " receive_wave_status ");
}
2024-11-12 20:04:43 +08:00
2025-04-08 14:25:54 +08:00
if(param.straxis == ""){
if (param.mMode == 1){
2025-04-10 15:51:47 +08:00
sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}else{
sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
}
}
else{
if (param.mMode == 1){
2025-04-10 15:51:47 +08:00
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}else{
sprintf(whereCon, " data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
}
}
2024-11-12 20:04:43 +08:00
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
int packgeNo = param.mPackageFlag;
int packgeMax = 0;
int packgeNum = 0;
jsonVal["package"] = packgeNo;
int lastSize = rows % 550;
int index = rows / 550;
if (lastSize > 0 && index > 0) {
packgeMax = index + 1;
if (packgeNo + 1 == packgeMax) {
packgeNum = rows - lastSize;
jsonVal["packageMax"] = index + 1;
} else {
packgeNum = (packgeNo)*550;
jsonVal["packageMax"] = index + 1;
}
} else if (lastSize == 0 && index > 0) {
packgeNum = (packgeNo + 1) * 550;
packgeMax = index;
jsonVal["packageMax"] = index;
} else if (lastSize > 0 && index == 0) {
packgeNum = 0;
packgeMax = index + 1;
jsonVal["packageMax"] = index;
}
memset(whereCon, 0x00, sizeof(whereCon));
2025-03-24 17:13:44 +08:00
if(param.straxis == "")
{
2025-04-08 14:25:54 +08:00
if (param.mMode == 1){
2025-04-10 15:51:47 +08:00
sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
2025-04-08 14:25:54 +08:00
}else{
sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
}
2025-03-24 17:13:44 +08:00
}else{
2025-04-08 14:25:54 +08:00
if (param.mMode == 1){
2025-04-10 15:51:47 +08:00
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
2025-04-08 14:25:54 +08:00
}else{
2025-04-10 15:51:47 +08:00
sprintf(whereCon, "data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
2025-04-08 14:25:54 +08:00
}
2025-03-24 17:13:44 +08:00
}
2024-11-12 20:04:43 +08:00
array_t vecRes;
2025-04-08 14:25:54 +08:00
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
2024-11-12 20:04:43 +08:00
zlog_info(zct, "vecRes = %d", vecRes.size());
if (vecRes.size() > 0) {
Json::Value jsStaticData;
for (size_t i = 0; i < vecRes.size(); i++) {
Json::Value iTem;
iTem.append(vecRes[i][2]);
iTem.append(vecRes[i][4]);
iTem.append(vecRes[i][5]);
jsStaticData.append(iTem);
}
if (jsStaticData.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = (jsStaticData);
}
zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}
2025-01-04 15:10:54 +08:00
std::string JsonData::JsonCmd_Cgi_63(Param_63 &param)
{
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "63";
jsonVal["success"] = true;
jsonVal["message"] = "";
if (param.mMode == 0)
{
std::vector<FeatureEntryUploadCfg> cfg;
wave_feature_set_inst::instance().GetAllFeatureCfg(cfg);
if (cfg.size() > 0)
{
for (size_t i = 0; i < cfg.size(); i++)
{
Json::Value xyz_status;
xyz_status.append(cfg[i].x);
xyz_status.append(cfg[i].y);
xyz_status.append(cfg[i].z);
if (cfg[i].short_addr == 0)
{
jsBody["global"] = xyz_status;
}else{
char buf[8] = {0};
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(cfg[i].short_addr), UINT16_LOW(cfg[i].short_addr));
jsBody[buf] = xyz_status;
}
}
}else{
jsonVal["success"] = false;
jsonVal["message"] = "";
}
}else if(param.mMode == 1){
if (param.partial)
{
zlog_info(zct, "63 short_addr = %d,x = %d,y = %d,z = %d", param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
wave_feature_set_inst::instance().SetFeatureCfg(param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
}else{
wave_feature_set_inst::instance().SetAllFeatureCfg(param.cfg);
}
}
jsonVal["cmdBody"] = jsBody;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_64(Param_64 &param)
{
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "64";
jsonVal["success"] = true;
jsonVal["message"] = "";
if (param.mMode == 0)
{
std::vector<FeatureEntryUploadCfg> cfg;
wave_feature_set_inst::instance().GetAllWaveCfg(cfg);
zlog_info(zct,"cfg size = %d",cfg.size());
if (cfg.size() > 0)
{
for (size_t i = 0; i < cfg.size(); i++)
{
Json::Value xyz_status;
xyz_status.append(cfg[i].x);
xyz_status.append(cfg[i].y);
xyz_status.append(cfg[i].z);
if (cfg[i].short_addr == 0)
{
jsBody["global"] = xyz_status;
}else{
char buf[8] = {0};
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(cfg[i].short_addr), UINT16_LOW(cfg[i].short_addr));
jsBody[buf] = xyz_status;
}
}
}else{
jsonVal["success"] = false;
jsonVal["message"] = "";
}
}else if(param.mMode == 1){
if (param.partial)
{
zlog_info(zct, "64 short_addr = %d,x = %d,y = %d,z = %d", param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
wave_feature_set_inst::instance().SetWaveCfg(param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
}else{
wave_feature_set_inst::instance().SetAllWaveCfg(param.cfg);
}
}
jsonVal["cmdBody"] = jsBody;
return show_value_.write(jsonVal);
2025-03-24 17:13:44 +08:00
}