WLG/jsonparse/web_cmd_parse3.cpp

1741 lines
72 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"
2026-03-02 19:02:28 +08:00
#include "scheduler/wave_feature_set.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());
2026-03-02 19:02:28 +08:00
std::string softVersion = res[9];
std::string productNo = res[17];
2024-10-22 19:04:25 +08:00
char localtimestamp[32] = {0};
std::string strWaveData = "";
2026-03-02 19:02:28 +08:00
std::string filename = "";
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") {
filename = "/opt/data/" + param.mChannelId + ".dat";
if (access(filename.c_str(), 0) >= 0) {
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
if (!inFile) {
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
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);
2026-03-02 19:02:28 +08:00
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
} else if (res[17] == "02") {
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos) {
resolution = (double)SampleRate / vecWave.size();
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
} else {
SampleRate = 8000;
zlog_info(zct,"sample_rate=%d", SampleRate);
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
}
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
//积分
Calculation::Integration(vecWave, IntegrationWave, resolution);
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +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;
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
} else {
memset(buf, 0, 32);
sprintf(buf, "%.2f", IntegrationWave[i]);
std::string waveTemp(buf);
strWaveData = strWaveData + "," + waveTemp;
}
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
int max = number / 1024;
if (max == 0 && number > 0) {
max = 1;
}
jsBody["packageMax"] = max;
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有数据文件";
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
}else{
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
if (access(filename.c_str(), 0) >= 0) {
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
if (!inFile) {
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
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);
}
resolution = 1 / 3.2 ;
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
//积分
Calculation::Integration(vecWave, IntegrationWave, resolution);
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"] = "没有数据文件";
}
2024-10-22 19:04:25 +08:00
}
jsBody["channelId"] = param.mChannelId;
jsBody["package"] = param.mPackageFlag;
2026-03-02 19:02:28 +08:00
zlog_info(zct,"vecWave.size() = %zu,sample = %d,second = %f", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.size() / atoi(res[23].c_str())));
if ((res[17] == "02" && compareVersions(softVersion, "2.6") == -1) || productNo == "01") {
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos && res[17] == "02") {
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;
}
}else{
jsBody["second"] = 3.2;
2024-10-22 19:04:25 +08:00
}
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;
2026-03-02 19:02:28 +08:00
std::string softVersion = res[9];
std::string productNo = res[17];
2024-10-22 19:04:25 +08:00
SampleRate = atoi(res[23].c_str());
2024-10-23 19:51:01 +08:00
zlog_info(zct,"sensor type %s", res[17].c_str());
2026-03-02 19:02:28 +08:00
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") {
if (access(filename.c_str(), 0) >= 0) {
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
if (!inFile) {
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
jsonVal["success"] = "false";
jsonVal["message"] = "error";
2024-10-22 19:04:25 +08:00
} else {
2026-03-02 19:02:28 +08:00
float fTemp = 0;
2024-10-23 19:51:01 +08:00
2026-03-02 19:02:28 +08:00
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos && res[17] == "02") {
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
vecWave.push_back(fTemp);
}
//积分
resolution = (double)SampleRate / vecWave.size();
Calculation::Integration(vecWave, IntegrationWave, resolution);
Calculation::FFTSpec(IntegrationWave, fftWave);
sampleRateReference = 1000;
2024-10-23 19:51:01 +08:00
2026-03-02 19:02:28 +08:00
} else {
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
vecWave.push_back(fTemp);
2024-10-23 19:51:01 +08:00
2026-03-02 19:02:28 +08:00
}
if (res[17] == "01") {
2024-10-25 18:45:26 +08:00
zlog_info(zct,"sample_rate=%d", SampleRate);
2026-03-02 19:02:28 +08:00
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
} else if (res[17] == "02") {
std::string::size_type comper = param.mChannelId.find("Z");
if (comper != std::string::npos) {
SampleRate = atoi(res[23].c_str());
2024-10-22 19:04:25 +08:00
resolution = (double)SampleRate / vecWave.size();
2026-03-02 19:02:28 +08:00
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
2024-10-22 19:04:25 +08:00
} else {
2026-03-02 19:02:28 +08:00
SampleRate = 8192;
zlog_info(zct,"sample_rate=%d", SampleRate);
if (vecWave.size() < 8192) {
resolution = (double)SampleRate / vecWave.size();
} else {
resolution = (double)SampleRate / 8192;
}
2024-10-22 19:04:25 +08:00
}
}
2026-03-02 19:02:28 +08:00
// 积分
Calculation::Integration(vecWave, IntegrationWave, resolution);
Calculation::FFTSpec(IntegrationWave, fftWave);
sampleRateReference = 1024;
}
zlog_info(zct,"2---------------------------------------------->vecWave = %zu,fftWave = %zu", vecWave.size(), fftWave.size());
int flag = param.mPackageFlag;
flag = (flag + 1) * sampleRateReference;
int number = fftWave.size();
zlog_info(zct,"number---------------------------------------------->%d", number);
int start = param.mPackageFlag * sampleRateReference;
zlog_info(zct,"param.mPackageFlag = %d", param.mPackageFlag);
zlog_info(zct,"param.start = %d", start);
zlog_info(zct,"param.flag = %d", flag);
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;
}
2024-10-22 19:04:25 +08:00
}
2024-10-23 19:51:01 +08:00
2026-03-02 19:02:28 +08:00
int max = number / sampleRateReference;
if (max == 0 && number > 0) {
max = 1;
}
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
jsBody["packageMax"] = max;
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有数据文件";
}
}else{
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
if (access(filename.c_str(), 0) >= 0) {
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
if (!inFile) {
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
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);
}
resolution = 1 / 3.2 ;
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
//积分
Calculation::Integration(vecWave, IntegrationWave, resolution);
Calculation::FFTSpec(IntegrationWave, fftWave);
int flag = param.mPackageFlag;
flag = (flag + 1) * 1024;
int number = fftWave.size();
int start = param.mPackageFlag * 1024;
if (number < 1024) {
flag = number;
start = 0;
2024-10-22 19:04:25 +08:00
}
2026-03-02 19:02:28 +08:00
char buf[32];
for (int i = start; i < flag; i++) {
if (i == start) {
memset(buf, 0, 32);
sprintf(buf, "%.2f", fftWave[i]);
std::string waveTemp(buf);
strWaveData = waveTemp;
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
} else {
memset(buf, 0, 32);
sprintf(buf, "%.2f", fftWave[i]);
std::string waveTemp(buf);
strWaveData = strWaveData + "," + waveTemp;
}
}
2024-10-22 19:04:25 +08:00
2026-03-02 19:02:28 +08:00
int max = number / 1024;
if (max == 0 && number > 0) {
max = 1;
}
jsBody["packageMax"] = max;
}
} else {
jsonVal["success"] = false;
jsonVal["message"] = "没有数据文件";
2024-10-22 19:04:25 +08:00
}
}
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)
{
2026-03-02 19:02:28 +08:00
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.maxSensorNum,param.waveResendNum,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);
2026-03-02 19:02:28 +08:00
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.waveResendNum,param.maxSensorNum);
2024-11-06 10:59:22 +08:00
}
if (ret == 0)
{
2024-11-06 10:59:22 +08:00
jsBody["featureInterVal"] = param.featureInterVal;
jsBody["waveInterVal"] = param.waveInterVal;
jsBody["maxSensorNum"] = param.maxSensorNum;
2026-03-02 19:02:28 +08:00
jsBody["resend"] = param.resend;
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 waveInterVal = 0;
2026-03-02 19:02:28 +08:00
int waveResendNum = 0;
2024-11-14 18:48:45 +08:00
int maxSensorNum = 0;
2026-03-02 19:02:28 +08:00
int sensorCount = 0;
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveResendNum,maxSensorNum);
2024-11-14 18:48:45 +08:00
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"] = "";
2026-03-02 19:02:28 +08:00
char wherecon[100] = {0};
char insertSql[200] = {0};
char updateSql[100] = {0};
if(param.mMode == 0){
char file_path[64]={0};
char cmd[128]={0};
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
zlog_info(zct,"cmd = %s",cmd);
system(cmd);
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
zlog_info(zct,"file_path = %s",file_path);
FILE * pFile=NULL;
size_t thisSize = 0;
char *buffer=NULL;
pFile = fopen (file_path,"rb");
if (pFile==NULL) {
zlog_error(zct,"Error opening file");
2024-11-11 20:51:40 +08:00
jsonVal["success"] = false;
2026-03-02 19:02:28 +08:00
jsonVal["message"] = "Error opening file";
2024-11-11 20:51:40 +08:00
return show_value_.write(jsonVal);
2026-03-02 19:02:28 +08:00
}
else
{
while (fgetc(pFile) != EOF) {
++thisSize;
}
rewind(pFile);
buffer = (char*)malloc(thisSize);
fread (buffer, sizeof (char), thisSize, pFile);
fclose (pFile);
}
2024-11-09 16:15:39 +08:00
2026-03-02 19:02:28 +08:00
zlog_info(zct,"Read %zu bytes", thisSize);
char sensor_type[6] = {0};
char sf_version[10] = {0};
memcpy(sensor_type, buffer, 5);
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);
}
}
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;
int packgeSize = 0;
ch_crc = buffer[12];
packgeSize = BUILD_UINT32(buffer[8],buffer[9],buffer[10],buffer[11]);
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);
unsigned char sum = 0x00;
for(size_t i = 13; i < thisSize;i++){
sum += buffer[i];
}
if (sum % 256 != ch_crc)
2024-11-09 16:15:39 +08:00
{
jsonVal["success"] = false;
2026-03-02 19:02:28 +08:00
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);
}
2026-03-02 19:02:28 +08:00
zlog_info(zct,"sum = %x\n",sum % 256);
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
std::vector<UpgradeParameter> param_list;
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
UpgradeParameter upgrade_parameter;
memset(wherecon,0,sizeof(wherecon));
memset(insertSql,0,sizeof(insertSql));
memset(updateSql,0,sizeof(updateSql));
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";
free(buffer);
return show_value_.write(jsonVal);
}
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());
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
//0 默认状态1 升级中2 升级成功,3 升级失败 4,停止升级
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);
upgrade_parameter.short_addr = short_addr;
upgrade_parameter.sensor_type = std::string(sensor_type);
upgrade_parameter.hw_version = atoi(vecResult[0].c_str());
upgrade_parameter.current_sw_version = vecResult[1];
upgrade_parameter.upgrade_sw_version = std::string(sf_version);
param_list.push_back(upgrade_parameter);
}
int res = scheduler::instance().UpgradeSensor(param_list);
2024-11-14 18:48:45 +08:00
if (res != 0)
{
jsonVal["success"] = false;
jsonVal["message"] = "UpgradeSensor error";
free(buffer);
return show_value_.write(jsonVal);
}
2026-03-02 19:02:28 +08:00
free(buffer);
}else if(param.mMode == 1){
std::vector<uint16_t> short_addr_list;
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
UpgradeParameter upgrade_parameter;
memset(wherecon,0,sizeof(wherecon));
memset(insertSql,0,sizeof(insertSql));
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);
uint16_t short_addr;
char *end_ptr = NULL;
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
short_addr_list.push_back(short_addr);
memset(wherecon,0,sizeof(wherecon));
memset(updateSql,0,sizeof(updateSql));
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
sprintf(updateSql, " upgradeStatus = %d ", 4);
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
}
scheduler::instance().CancelUpgradeSensor(short_addr_list);
}
2024-11-10 19:22:16 +08:00
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-05-27 18:17:52 +08:00
sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' and (nodeResend = 0 or nodeResend is null)", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}else{
2025-05-27 18:17:52 +08:00
sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' and (resend = 0 or resend == '')", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}
}
else{
if (param.mMode == 1){
2025-05-27 18:17:52 +08:00
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' and (nodeResend = 0 or nodeResend is null)", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}else{
2025-05-27 18:17:52 +08:00
sprintf(whereCon, " data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' and (resend = 0 or resend == '')", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-04-08 14:25:54 +08:00
}
}
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-05-27 18:17:52 +08:00
sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' and (nodeResend = 0 or nodeResend is null) 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-05-27 18:17:52 +08:00
sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' and (resend = 0 or resend == '') 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
}
2025-03-24 17:13:44 +08:00
}else{
2025-04-08 14:25:54 +08:00
if (param.mMode == 1){
2025-05-27 18:17:52 +08:00
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' and (nodeResend = 0 or nodeResend is null) 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-05-27 18:17:52 +08:00
sprintf(whereCon, "data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' and (resend = 0 or resend == '') 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
}
2025-05-09 23:42:53 +08:00
std::string JsonData::JsonCmd_Cgi_65(Param_65 &param){
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "65";
jsonVal["success"] = true;
jsonVal["message"] = " ";
2026-03-02 19:02:28 +08:00
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID,RSSI,batteryPower ", NULL);
2025-05-09 23:42:53 +08:00
size_t nSize = vetRes.size();
std::string MeasurementID = "";
char szTableName[100] = {0x00}, whereCon[256] = {0x00};
if (nSize > 0) {
2025-05-10 11:43:22 +08:00
2025-05-09 23:42:53 +08:00
int interval = atol(param.timeEnd.c_str()) - atol(param.timeStart.c_str());
2026-03-02 19:02:28 +08:00
int featureInterVal = 0,waveInterVal = 0,waveRsendNum = 0,maxSensorNum = 0;
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveRsendNum,maxSensorNum);
2025-05-09 23:42:53 +08:00
Json::Value jsBody;
char count_sql[1024] = {0};
2025-05-20 17:47:29 +08:00
int recive_feature = 0, send_feature = 0,resend_feature = 0;
int recive_x = 0, recive_y = 0, recive_z = 0,resend_z = 0;
2026-03-02 19:02:28 +08:00
float rssi = 0.0;
2025-05-17 13:35:36 +08:00
//int send_x = 0, send_y = 0, send_z = 0;
2025-05-09 23:42:53 +08:00
for (size_t i = 0; i < nSize; i++)
{
Json::Value iTem;
MeasurementID = vetRes[i][1];
iTem.append(vetRes[i][0]);
memset(szTableName,0,sizeof(szTableName));
memset(whereCon,0,sizeof(whereCon));
sprintf(szTableName,"t_data_%s",vetRes[i][1].c_str());
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
2025-05-10 11:43:22 +08:00
2025-05-09 23:42:53 +08:00
memset(count_sql,0,sizeof(count_sql));
snprintf(count_sql,sizeof(count_sql),
"SELECT "
2025-05-21 19:21:56 +08:00
"COUNT(*) FILTER (WHERE channelID = '%s-X' and nodeResend = 0 ) AS recive_feature,"
"COUNT(*) FILTER (WHERE channelID = '%s-X' and sendMsg = 1 and nodeResend = 0 ) AS send_feature, "
"COUNT(*) FILTER (WHERE channelID = '%s-X' and nodeResend <> 0) AS resend_feature "
2025-05-09 23:42:53 +08:00
"FROM ( "
"SELECT * FROM %s "
2025-05-20 17:47:29 +08:00
"WHERE timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),szTableName,param.timeStart.c_str(),param.timeEnd.c_str());
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
if (vecResult.size() > 0)
2025-05-09 23:42:53 +08:00
{
2025-05-20 17:47:29 +08:00
recive_feature = atoi(vecResult[0].c_str());
send_feature = atoi(vecResult[1].c_str());
resend_feature = atoi(vecResult[2].c_str());
2025-05-09 23:42:53 +08:00
}
iTem.append(MeasurementID);
2025-05-10 11:43:22 +08:00
2025-05-09 23:42:53 +08:00
memset(count_sql,0,sizeof(count_sql));
snprintf(count_sql,sizeof(count_sql),
"SELECT "
"COUNT(*) FILTER (WHERE data_nodeno = '%s-X') AS recive_x,"
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Y') AS recive_y,"
2025-05-21 19:21:56 +08:00
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Z') AS recive_z, "
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Z' and resend is NOT NULL and resend <> '') AS resend_z "
2025-05-09 23:42:53 +08:00
"FROM ( "
"SELECT * FROM receive_wave_status "
2025-05-20 17:47:29 +08:00
"WHERE error_code = 1 and timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
2025-05-09 23:42:53 +08:00
vec_t vecResult2 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
if (vecResult2.size() > 0)
{
recive_x = atoi(vecResult2[0].c_str());
recive_y = atoi(vecResult2[1].c_str());
recive_z = atoi(vecResult2[2].c_str());
2025-05-20 17:47:29 +08:00
resend_z = atoi(vecResult2[3].c_str());
2025-05-10 11:43:22 +08:00
iTem.append((float(recive_feature)/(interval/featureInterVal)));
iTem.append(recive_feature);
iTem.append((float( recive_x)/(interval/waveInterVal)));
iTem.append(recive_x);
iTem.append((float(recive_y)/(interval/waveInterVal)));
iTem.append(recive_y);
iTem.append((float(recive_z)/(interval/waveInterVal)));
iTem.append(recive_z);
2025-05-20 17:47:29 +08:00
2025-05-09 23:42:53 +08:00
}
2025-05-17 13:35:36 +08:00
// memset(count_sql,0,sizeof(count_sql));
// snprintf(count_sql,sizeof(count_sql),
// "SELECT "
// "COUNT(*) FILTER (WHERE channelID = '%s-X') AS send_x,"
// "COUNT(*) FILTER (WHERE channelID = '%s-Y') AS send_y,"
// "COUNT(*) FILTER (WHERE channelID = '%s-Z') AS send_z "
// "FROM ( "
// "SELECT * FROM t_data_waveSend "
// "WHERE sendMsg = 1 and timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
// vec_t vecResult3 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
// if (vecResult3.size() > 0)
// {
// send_x = atoi(vecResult3[0].c_str());
// send_y = atoi(vecResult3[1].c_str());
// send_z = atoi(vecResult3[2].c_str());
// iTem.append((float(send_feature)/(interval/featureInterVal)));
// iTem.append(send_feature);
// iTem.append((float(send_x)/(interval/waveInterVal)));
// iTem.append(send_x);
// iTem.append((float(send_y)/(interval/waveInterVal)));
// iTem.append(send_y);
// iTem.append((float(send_z)/(interval/waveInterVal)));
// iTem.append(send_z);
//}
iTem.append(0);
iTem.append(0);
iTem.append(0);
iTem.append(0);
iTem.append(0);
iTem.append(0);
iTem.append(0);
iTem.append(0);
2026-03-02 19:02:28 +08:00
std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, vetRes[i][2], boost::is_any_of(","), boost::token_compress_on);
if (vParamRSSI.size() > 1) {
iTem.append(atof(vParamRSSI[1].c_str()) / 255.0 );
iTem.append(0);
rssi = atof(vParamRSSI[1].c_str()) / 255.0 ;
} else {
iTem.append(atof(vetRes[i][2].c_str()));
iTem.append(0);
rssi = atof(vetRes[i][2].c_str());
2025-05-12 17:29:14 +08:00
}
2026-03-02 19:02:28 +08:00
2025-05-21 19:21:56 +08:00
iTem.append(resend_feature);
iTem.append(resend_z);
2026-03-02 19:02:28 +08:00
iTem.append(rssi); //信号
iTem.append(vetRes[i][3]); //电池
sprintf(whereCon,"timeStamp <> '' order by timeStamp desc limit 0,1 ");
memset(szTableName,0,sizeof(szTableName));
sprintf(szTableName,"t_dataStatic_%s",vetRes[i][1].c_str());
std::string voltage = sqlite_db_ctrl::instance().GetData(szTableName, "voltage", whereCon);
iTem.append(voltage); //电压
2025-05-09 23:42:53 +08:00
jsBody.append(iTem);
2025-05-10 11:43:22 +08:00
2026-03-02 19:02:28 +08:00
2025-05-09 23:42:53 +08:00
}
if (jsBody.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = (jsBody);
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}
2026-03-02 19:02:28 +08:00
std::string JsonData::JsonCmd_Cgi_66(Param_66 &param) {
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "66";
jsonVal["success"] = true;
jsonVal["message"] = "";
int looseEnable = -1;
if (param.mMode == 1) {
looseEnable = writeIntValue("config", "looseEnable", param.mSensorLooseEnable, (char *)GlobalConfig::Config_G.c_str());
} else if (param.mMode == 0) {
looseEnable = readIntValue("config", "looseEnable", (char *)GlobalConfig::Config_G.c_str());
}
jsBody["looseEnable"] = looseEnable;
jsonVal["content"] = jsBody;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "67";
jsonVal["success"] = true;
jsonVal["message"] = " ";
char whereCon[512] = {0};
char selectCon[128] = {0};
char column[128] = {0};
char tablename[256] = {0};
if(param.mMode == 0){
sprintf(selectCon, " t_sensor_info.MeasurementID = t_debug_info.MeasurementID ");
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, column, selectCon);
int nSize = arrRes.size();
if (nSize > 0) {
int packgeNo = param.mPackageFlag;
int packgeMax = 0;
int packgeNum = 0;
jsonVal["package"] = packgeNo;
int lastSize = nSize % 10;
int index = nSize / 10;
if (lastSize > 0 && index > 0) {
packgeMax = index + 1;
if (packgeNo + 1 == packgeMax) {
packgeNum = nSize;
jsonVal["packageMax"] = index + 1;
} else {
packgeNum = (packgeNo + 1) * 10;
jsonVal["packageMax"] = index + 1;
}
} else if (lastSize == 0 && index > 0) {
packgeNum = (packgeNo + 1) * 10;
packgeMax = index;
jsonVal["packageMax"] = index;
} else if (lastSize > 0 && index == 0) {
packgeNum = lastSize;
packgeMax = index + 1;
jsonVal["packageMax"] = index + 1;
}
Json::Value jsSensor;
for (int j = packgeNo * 10; j < packgeNum; j++) {
Json::Value jsChannelData;
jsChannelData["dataNodeName"] = arrRes[j][10];
jsChannelData["zigbeeAddr"] = arrRes[j][1];
jsChannelData["MeasurementID"] = arrRes[j][0];
jsChannelData["status"] = atoi(arrRes[j][9].c_str());
jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str());
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
jsChannelData["minimumVoltage"] = atof(arrRes[j][5].c_str());
jsChannelData["currentBatteryLevel"] = atof(arrRes[j][6].c_str());
jsChannelData["debugStatus"] = atoi(arrRes[j][7].c_str());
jsChannelData["TimeStamp"] = arrRes[j][8];
jsSensor.append(jsChannelData);
}
if (jsSensor.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"]["dataNodeArray"] = (jsSensor);
}
}else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
}else if(param.mMode == 1){//启动传感器调试
if(param.measurementID.size() > 0){
std::vector<uint16_t> short_addr_list;
for (size_t i = 0; i < param.measurementID.size(); i++)
{
char whereCon[512] = {0};
char updateSql[256] = {0};
sprintf(whereCon, " MeasurementID = '%s' ", param.measurementID[i].c_str());
2026-03-27 14:36:09 +08:00
sprintf(updateSql, " status = '%d' ", 1);// 0 未调试1 调试中2 调试完成,3 停止调试,4 调试失败
2026-03-02 19:02:28 +08:00
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon);
uint16_t short_addr;
char *end_ptr = NULL;
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
2026-03-27 14:36:09 +08:00
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", "gatewayRSSI = '0',datanodeRSSI= '0',comprehensiveRSSI = '0',minnumVoltage = '0'", whereCon);
2026-03-02 19:02:28 +08:00
short_addr = strtol(vecResult[0].c_str(), &end_ptr, 16);
short_addr_list.push_back(short_addr);
}
scheduler::instance().OpenDebugMode(short_addr_list);
}
}else if(param.mMode == 2){ // 停止调试
char whereCon[512] = {0};
char updateSql[256] = {0};
sprintf(whereCon, " status = '1' ");
2026-03-27 14:36:09 +08:00
sprintf(updateSql, " status = '%d' ", 3);// 0 未调试1 调试中2 调试完成,3 停止调试,4 调试失败
2026-03-02 19:02:28 +08:00
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon);
scheduler::instance().CloseDebugMode();
}
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
Json::Value jsonVal;
Json::Value dataNodeArray;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "68";
jsonVal["success"] = true;
jsonVal["message"] = " ";
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1,shutdownDetection = -1;
char whereCon[512] = {0};
char updateSql[256] = {0};
if (param.mMode == 1) {
lowSignal = writeIntValue("config", "lowSignal", param.lowSignal, (char *)GlobalConfig::Config_G.c_str());
signalThreshold = writeIntValue("config", "signalThreshold", param.signalThreshold, (char *)GlobalConfig::Config_G.c_str());
lowBatteryLevel = writeIntValue("config", "lowBatteryLevel", param.lowBatteryLevel, (char *)GlobalConfig::Config_G.c_str());
batteryLevelThreshold = writeIntValue("config", "batteryLevelThreshold", param.batteryLevelThreshold, (char *)GlobalConfig::Config_G.c_str());
shutdownDetection = writeIntValue("config", "shutdownDetection", param.shutdownDetection, (char *)GlobalConfig::Config_G.c_str());
if(param.vecParam68.size() > 0){
for (size_t i = 0; i < param.vecParam68.size(); i++)
{
memset(whereCon,0,sizeof(whereCon));
memset(updateSql,0,sizeof(updateSql));
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam68[i].measurementID.c_str());
sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f'",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold);
sqlite_db_ctrl::instance().UpdateTableData(" t_shutdown_info ", updateSql, whereCon);
}
}
} else if (param.mMode == 0) {
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
shutdownDetection = readIntValue("config", "shutdownDetection", (char *)GlobalConfig::Config_G.c_str());
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_shutdown_info LEFT JOIN t_sensor_info ", " t_shutdown_info.*,t_sensor_info.dataNodeName ", "t_shutdown_info.MeasurementID = t_sensor_info.MeasurementID");
if (arrRes.size() > 0) {
for (size_t i = 0; i < arrRes.size(); i++)
{
Json::Value iTem;
iTem.append(arrRes[i][0]);
iTem.append(atoi(arrRes[i][2].c_str()));
iTem.append(atoi(arrRes[i][3].c_str()));
iTem.append(atof(arrRes[i][4].c_str()));
iTem.append(arrRes[i][6]);
dataNodeArray.append(iTem);
}
}
if (dataNodeArray.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
jsonVal["content"]["lowSignal"] = lowSignal;
jsonVal["content"]["signalThreshold"] = signalThreshold;
jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel;
jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold;
jsonVal["content"]["shutdownDetection"] = shutdownDetection;
}
jsonVal["content"]["dataNodeArray"] = dataNodeArray;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_69(Param_69 &param){
Json::Value jsonVal;
Json::Value dataNodeArray;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "69";
jsonVal["success"] = true;
jsonVal["message"] = " ";
int trigerThresholdEnable = -1;
char whereCon[512] = {0};
char updateSql[256] = {0};
if (param.mMode == 1) {
2026-03-19 14:56:38 +08:00
trigerThresholdEnable = writeIntValue("config", "trigerThresholdEnable", param.trigerThresholdEnable ? 1:0, (char *)GlobalConfig::Config_G.c_str());
2026-03-02 19:02:28 +08:00
if(param.vecParam69.size() > 0){
for (size_t i = 0; i < param.vecParam69.size(); i++)
{
memset(whereCon,0,sizeof(whereCon));
memset(updateSql,0,sizeof(updateSql));
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam69[i].measurementID.c_str());
sprintf(updateSql, " status = '%d',trigerType = '%d',statisticType = '%d', threshold = '%f'",param.vecParam69[i].status,param.vecParam69[i].trigerType,param.vecParam69[i].statisticType,param.vecParam69[i].threshold);
2026-03-10 10:24:03 +08:00
sqlite_db_ctrl::instance().UpdateTableData(" t_wave_triger_info ", updateSql, whereCon);
2026-03-02 19:02:28 +08:00
}
}
} else if (param.mMode == 0) {
trigerThresholdEnable = readIntValue("config", "trigerThresholdEnable", (char *)GlobalConfig::Config_G.c_str());
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" t_wave_triger_info LEFT JOIN t_sensor_info ", " t_wave_triger_info.*,t_sensor_info.dataNodeName ", "t_wave_triger_info.MeasurementID = t_sensor_info.MeasurementID");
if (arrRes.size() > 0) {
for (size_t i = 0; i < arrRes.size(); i++)
{
Json::Value iTem;
iTem.append(arrRes[i][0]);
iTem.append(atoi(arrRes[i][2].c_str()));
iTem.append(atoi(arrRes[i][3].c_str()));
iTem.append(atoi(arrRes[i][4].c_str()));
iTem.append(atof(arrRes[i][5].c_str()));
iTem.append(arrRes[i][7]);
dataNodeArray.append(iTem);
}
}
if (dataNodeArray.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
}
jsonVal["content"]["trigerThresholdEnable"] = trigerThresholdEnable;
jsonVal["content"]["dataNodeArray"] = dataNodeArray;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_70(Param_70 &param){
Json::Value jsonVal;
Json::Value dataNodeArray;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "70";
jsonVal["success"] = true;
jsonVal["message"] = " ";
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
sprintf(szTableName,"t_process_info");
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
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));
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
array_t vecRes;
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
zlog_info(zct, "vecRes = %zu", 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][0]);
iTem.append(vecRes[i][1]);
jsStaticData.append(iTem);
}
if (jsStaticData.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = jsStaticData;
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_71(Param_71 &param){
Json::Value jsonVal;
Json::Value dataNodeArray;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "71";
jsonVal["success"] = true;
jsonVal["message"] = " ";
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
sprintf(szTableName,"t_system_info");
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
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));
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
array_t vecRes;
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
zlog_info(zct, "vecRes = %zu", 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][10]);
iTem.append(vecRes[i][2]);
iTem.append(vecRes[i][5]);
iTem.append(vecRes[i][8]);
iTem.append(vecRes[i][9]);
jsStaticData.append(iTem);
}
if (jsStaticData.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = jsStaticData;
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}