662 lines
23 KiB
C++
662 lines
23 KiB
C++
#include "communication_cmd.hpp"
|
|
#include <fstream>
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <zlog.h>
|
|
#include "common/global.hpp"
|
|
#include "dbaccess/sql_db.hpp"
|
|
#include "platform/platform_init.hpp"
|
|
#include "utility/md5.h"
|
|
#include "wifi_5g/wpa_client.h"
|
|
#include "utility/calculation.hpp"
|
|
#include "scheduler/schedule.hpp"
|
|
|
|
extern zlog_category_t *zct;
|
|
extern const char *JSON_FIELD_CMD;
|
|
|
|
std::string JsonData::JsonCmd_Cgi_default() {
|
|
Json::Value jsonVal;
|
|
jsonVal.clear();
|
|
jsonVal["success"] = false;
|
|
jsonVal["message"] = "功能不支持";
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_45(Param_45 ¶m) {
|
|
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;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_46(Param_46 ¶m) {
|
|
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"] = "没有升级包";
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_47(Param_47 ¶m) {
|
|
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";
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
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;
|
|
}
|
|
jsBody["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
|
jsBody["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
|
jsBody["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
|
jsonVal["content"] = jsBody;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_51(Param_51 ¶m) {
|
|
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};
|
|
std::string gatewayLocation = "";
|
|
|
|
sprintf(updateSql, "gatewayLocation='%s'", param.strGateWayLocation.c_str());
|
|
sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str());
|
|
if (param.mMode == 0) {
|
|
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
|
if (iRet != 0) jsonVal["success"] = false;
|
|
} else {
|
|
gatewayLocation = sqlite_db_ctrl::instance().GetData(T_GATEWAY_INFO(TNAME), "gatewayLocation", NULL);
|
|
jsBody["gateWayLocation"] = gatewayLocation;
|
|
}
|
|
|
|
jsonVal["content"] = jsBody;
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
|
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"] = " ";
|
|
|
|
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";
|
|
zlog_info(zct,"netssid : %s %d", netssid.c_str(), vecSsid.size());
|
|
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) { // 设置
|
|
zlog_info(zct,"set WiFi");
|
|
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;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_53(std::vector<Param_53> ¶m) {
|
|
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};
|
|
for (size_t i = 0; i < param.size(); i++) {
|
|
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());
|
|
|
|
int iRet = sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
|
memset(whereCon, 0x00, sizeof(whereCon));
|
|
memset(updateSql, 0x00, sizeof(updateSql));
|
|
if (iRet != 0) jsonVal["success"] = false;
|
|
}
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|
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());
|
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
|
int SampleRate = 0;
|
|
double resolution = 0.0;
|
|
SampleRate = atoi(res[23].c_str());
|
|
zlog_info(zct,"sensor type %s", res[17].c_str());
|
|
|
|
char localtimestamp[32] = {0};
|
|
std::string strWaveData = "";
|
|
std::string 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") {
|
|
zlog_info(zct,"sample_rate=%d", SampleRate);
|
|
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;
|
|
}
|
|
}
|
|
|
|
//积分
|
|
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"] = "没有数据文件";
|
|
}
|
|
|
|
jsBody["channelId"] = param.mChannelId;
|
|
jsBody["package"] = param.mPackageFlag;
|
|
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())));
|
|
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;
|
|
}
|
|
|
|
jsBody["Data"] = strWaveData;
|
|
jsBody["timestamp"] = std::string(localtimestamp);
|
|
jsonVal["content"] = jsBody;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|
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;
|
|
char whereCon[64] = {0};
|
|
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
|
int SampleRate = 0;
|
|
double resolution = 0.0;
|
|
SampleRate = atoi(res[23].c_str());
|
|
zlog_info(zct,"sensor type %s", res[17].c_str());
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
} else {
|
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
|
|
|
vecWave.push_back(fTemp);
|
|
|
|
}
|
|
if (res[17] == "01") {
|
|
zlog_info(zct,"sample_rate=%d", SampleRate);
|
|
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());
|
|
resolution = (double)SampleRate / vecWave.size();
|
|
|
|
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
|
|
} else {
|
|
SampleRate = 8192;
|
|
zlog_info(zct,"sample_rate=%d", SampleRate);
|
|
if (vecWave.size() < 8192) {
|
|
resolution = (double)SampleRate / vecWave.size();
|
|
} else {
|
|
resolution = (double)SampleRate / 8192;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 积分
|
|
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
|
Calculation::FFTSpec(IntegrationWave, fftWave);
|
|
|
|
sampleRateReference = 1024;
|
|
}
|
|
zlog_info(zct,"2---------------------------------------------->vecWave = %d,fftWave = %d", 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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
jsBody["timestamp"] = std::string(localtimestamp);
|
|
jsBody["Data"] = strWaveData;
|
|
|
|
zlog_info(zct,"the sample rate is %d,the resolution %f", SampleRate, resolution);
|
|
char buf[32];
|
|
memset(buf, 0, 32);
|
|
sprintf(buf, "%f", resolution);
|
|
jsBody["resolution"] = std::string(buf);
|
|
|
|
jsonVal["content"] = jsBody;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_57(Param_57 ¶m) {
|
|
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;
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
|
Json::Value jsonVal;
|
|
jsonVal.clear();
|
|
Json::Value jsBody;
|
|
jsonVal[JSON_FIELD_CMD] = "58";
|
|
jsonVal["success"] = true;
|
|
jsonVal["message"] = "";
|
|
int ret = 0;
|
|
std::string error_msg = "";
|
|
if (param.mMode == 1)
|
|
{
|
|
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum,error_msg);
|
|
}else if (param.mMode == 0)
|
|
{
|
|
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
|
|
}
|
|
if (ret == 0)
|
|
{
|
|
jsBody["featureInterVal"] = param.featureInterVal;
|
|
jsBody["featureInterTime"] = param.featureInterTime;
|
|
jsBody["waveInterVal"] = param.waveInterVal;
|
|
jsBody["waveInterTime"] = param.waveInterTime;
|
|
jsBody["maxSensorNum"] = param.maxSensorNum;
|
|
}else{
|
|
jsonVal["success"] = false;
|
|
jsonVal["message"] = error_msg;
|
|
}
|
|
jsonVal["content"] = jsBody;
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
|
Json::Value jsonVal;
|
|
jsonVal.clear();
|
|
Json::Value jsBody;
|
|
jsonVal[JSON_FIELD_CMD] = "59";
|
|
jsonVal["success"] = true;
|
|
jsonVal["message"] = "";
|
|
char table_name[50] ={0};
|
|
int interval = 0;
|
|
char sql[1024]={0};
|
|
if (param.mMode == 1)
|
|
{
|
|
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
|
|
interval = 10;
|
|
|
|
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;",
|
|
table_name,interval);
|
|
}else if (param.mMode == 2)
|
|
{
|
|
sprintf(table_name,"t_data_waveSend");
|
|
interval = 20;
|
|
snprintf(sql, sizeof(sql),
|
|
"WITH CTE AS ("
|
|
" SELECT timestamp, "
|
|
" LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp "
|
|
" 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;",
|
|
table_name,param.DataNodeNo.c_str(),param.straxis.c_str(),interval);
|
|
|
|
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][0]);
|
|
iTem.append(arrResult[i][1]);
|
|
valData.append(iTem);
|
|
}
|
|
jsonVal["content"] = valData;
|
|
|
|
|
|
}else{
|
|
jsonVal["success"] = false;
|
|
jsonVal["message"] = "获取数据失败!";
|
|
jsonVal["content"].resize(0);
|
|
}
|
|
|
|
return show_value_.write(jsonVal);
|
|
}
|
|
|
|
std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
|
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};
|
|
sprintf(cmd,"mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
|
system(cmd);
|
|
sprintf(file_path,"/opt/DataNodeNo/%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");
|
|
else
|
|
{
|
|
while (fgetc(pFile) != EOF) {
|
|
++thisSize;
|
|
}
|
|
rewind(pFile);
|
|
buffer = (char*)malloc(thisSize);
|
|
fread (buffer, sizeof (char), thisSize, pFile);
|
|
fclose (pFile);
|
|
}
|
|
char head[9]={0};
|
|
int packgeSize = 0;
|
|
memcpy(head,buffer,8);
|
|
packgeSize = BUILD_UINT32(buffer[8],buffer[9],buffer[10],buffer[11]);
|
|
zlog_info(zct,"head = %s\n",head);
|
|
zlog_info(zct,"packgeSize = %d\n",packgeSize);
|
|
unsigned char sum = 0x00;
|
|
for(size_t i = 13; i < thisSize;i++){
|
|
sum += buffer[i];
|
|
}
|
|
printf("sum = %x\n",sum % 256);
|
|
return show_value_.write(jsonVal);
|
|
char localtimestamp[32] = {0};
|
|
GetTimeNet(localtimestamp, 1);
|
|
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
|
|
{
|
|
//char insertSql[1024] = {0};
|
|
|
|
//sprintf(insertSql, " '%s','%s','%d','%d','%d','%d','%d','%d','%d'",param.dataNodeNo[i].c_str(),localtimestamp);
|
|
}
|
|
|
|
|
|
}
|