2788 lines
100 KiB
C++
2788 lines
100 KiB
C++
#include "SH_JsonCmd.hpp"
|
||
#include "../dbaccess/SH_SqlDB.hpp"
|
||
#include "../platform/SH_PlatformInit.hpp"
|
||
#include "../MD5/md5.h"
|
||
|
||
namespace{
|
||
PlatformInit *platform = PlatformInit::instance();
|
||
Calculation *pCalculation = Calculation::instance();
|
||
Uart *pUart = Uart::instance();
|
||
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_20(Param_20 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
if (0 == param.mMode) {
|
||
char localtimestamp[32] = { 0 };
|
||
GetTimeNet(localtimestamp, 1);
|
||
std::string nowTimetamp = std::string(localtimestamp);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", param.mDataWatchName);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", param.mDataWatchAssetId);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", param.mDataWatchAddedBy);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate", nowTimetamp);
|
||
}
|
||
|
||
std::string boardtype = GetFileContent(BOARDTYPE, 1);
|
||
std::string ip = IpAddrInit();
|
||
std::string sn = GetFileContent(SN, 1);
|
||
jsonVal[JSON_FIELD_CMD] = "20";
|
||
jsonVal[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
|
||
Json::Value jsSystemInfo;
|
||
Json::Value jsBody;
|
||
|
||
string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||
string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||
string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||
|
||
jsSystemInfo["WebVersion"] = strwebVersion;
|
||
jsSystemInfo["SystemVersion"] = strsystemVersion;
|
||
jsSystemInfo["GateWayVersion"] = strGatewayVersion;
|
||
|
||
jsSystemInfo[JSON_FIELD_NAME] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName");
|
||
jsSystemInfo[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G;
|
||
jsSystemInfo[JSON_FIELD_ASSETID] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId");
|
||
jsSystemInfo[JSON_FIELD_ADDEDBY] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy");
|
||
jsSystemInfo[JSON_FIELD_ADDEDDATE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate");
|
||
jsSystemInfo[JSON_FIELD_DEVICETYPE] = boardtype;
|
||
jsSystemInfo[JSON_FIELD_IPADDRESS] = ip;
|
||
jsSystemInfo[JSON_FIELD_SN] = sn;
|
||
jsSystemInfo[JSON_FIELD_VERSION] = GlobalConfig::Version;
|
||
jsSystemInfo[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||
jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID;
|
||
jsSystemInfo["zigbeeChannel"] = GlobalConfig::ZigbeeInfo_G.Channel;
|
||
jsSystemInfo["zigbeeAddr"] = GlobalConfig::ZigbeeInfo_G.MyAddr;
|
||
jsSystemInfo[JSON_FIELD_SERVERIP] = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||
jsSystemInfo[JSON_FIELD_SERVERPORT] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||
jsSystemInfo[JSON_FIELD_CommMode] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||
jsBody["SystemInfo"] = jsSystemInfo;
|
||
|
||
std::string dataBody = showValue.write(jsBody);
|
||
jsonVal["cmdBody"] = dataBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_22(Param_22 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
if (0 == param.mMode) {
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "timezone", param.mTimeZone);
|
||
}
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "22";
|
||
jsonVal[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
|
||
Json::Value jsSystemSetting;
|
||
Json::Value jsBody;
|
||
jsBody[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||
|
||
std::string dataBody = showValue.write(jsBody);
|
||
jsonVal["cmdBody"] = dataBody;
|
||
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_23(Param_23 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
if (0 == param.mMode) {
|
||
|
||
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", param.mServerIp);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", param.mPort);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "CommMode", param.mCommMode);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "Password", param.mPassword);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "UserName", param.mUserName);
|
||
print_info("param.mCommMode = %s\n",param.mCommMode.c_str());
|
||
if("1" == param.mCommMode){//有线连接
|
||
system("mv /etc/init.d/S91quectel-CM.sh /etc/init.d/wireless.sh");
|
||
system("mv /etc/init.d/S95check5G /etc/init.d/wireless5G");
|
||
}else if("2" == param.mCommMode){//无线连接 4G
|
||
system("mv /etc/init.d/wireless4G /etc/init.d/S91check4G");
|
||
system("mv /etc/init.d/S95check5G /etc/init.d/wireless5G");
|
||
}else if("3" == param.mCommMode){//无线连接 5G
|
||
system("mv /etc/init.d/wireless5G /etc/init.d/S95check5G");
|
||
system("mv /etc/init.d/S91check4G /etc/init.d/wireless4G");
|
||
}
|
||
sleep(1);
|
||
system("reboot");
|
||
}
|
||
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "23";
|
||
jsonVal[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
|
||
Json::Value jsSystemSetting;
|
||
Json::Value jsBody;
|
||
|
||
Json::Value jsHeart;
|
||
Json::FastWriter fw;
|
||
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsHeart["status"] = "online_V3.0";
|
||
std::string strJson = fw.write(jsHeart);
|
||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||
if(iRet == 0){
|
||
jsBody["status"] = 0;
|
||
}else{
|
||
jsBody["status"] = -1;
|
||
}
|
||
|
||
jsBody[JSON_FIELD_SERVERIP] = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||
jsBody[JSON_FIELD_SERVERPORT] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||
jsBody[JSON_FIELD_CommMode] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||
jsBody["Password"] = (ReadStrByOpt(SERVERCONFIG, "Server", "Password"));
|
||
jsBody["UserName"] = (ReadStrByOpt(SERVERCONFIG, "Server", "UserName"));
|
||
std::string dataBody = showValue.write(jsBody);
|
||
jsonVal["cmdBody"] = dataBody;
|
||
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
|
||
|
||
std::string JsonData::JsonCmd_25(Param_25 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
jsonVal["cmd"] = "25";
|
||
bool bFlag1 = CheckIP(param.mGateway.c_str());
|
||
bool bFlag2 = IsValidMask(param.mSubnetMask);
|
||
bool bFlag3 = CheckIP(param.mIp.c_str());
|
||
bool bFlag4 = false;
|
||
if(param.mDnsName.size()>0){
|
||
bFlag4 = CheckIP(param.mDnsName.c_str());
|
||
}else{
|
||
bFlag4 = true;
|
||
}
|
||
print_info("bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d\n",bFlag1,bFlag2,bFlag3,bFlag4);
|
||
#ifdef IMX6UL_GATEWAY
|
||
param.mNet = "Net";
|
||
#endif
|
||
if (0 == param.mMode &&(bFlag1 && bFlag2 && bFlag3 && bFlag4) && param.mNetworkPortStatus == "STATIC") {
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", param.mDnsName);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "networkPortStatus", param.mNetworkPortStatus);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "gateway", param.mGateway);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "subnetMask", param.mSubnetMask);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", param.mIp);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", param.mHostName);
|
||
|
||
#ifdef IMX6UL_GATEWAY
|
||
char GateWay[100]={0x00};
|
||
sprintf(GateWay,"sed -i '7c route add default gw %s' /etc/init.d/S90start_userapp.sh",param.mGateway.c_str());
|
||
print_info("GateWay = %s\n",GateWay);
|
||
system(GateWay);
|
||
#endif
|
||
platform->EquipIpInit(param.mNet);
|
||
|
||
}else if(0 == param.mMode && param.mNetworkPortStatus == "DHCP"){
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "networkPortStatus", param.mNetworkPortStatus);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "gateway", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "subnetMask", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", "");
|
||
|
||
#ifdef IMX6UL_GATEWAY
|
||
system("sed -i '7c udhcpc -i eth0 > /dev/null &' /etc/init.d/S90start_userapp.sh");
|
||
#endif
|
||
platform->EquipIpInit(param.mNet);
|
||
|
||
}else if(0 == param.mMode &&(!bFlag1 || !bFlag2 || !bFlag3 || !bFlag4) && param.mNetworkPortStatus == "STATIC"){
|
||
jsonVal["success"] = false;
|
||
}
|
||
|
||
jsonVal["content"]["dnsName"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "dnsName");
|
||
jsonVal["content"]["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "networkPortStatus");
|
||
jsonVal["content"]["gateway"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "gateway");
|
||
jsonVal["content"]["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "subnetMask");
|
||
jsonVal["content"]["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "ipAddress");
|
||
jsonVal["content"]["hostName"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "hostName");
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_26(Param_26 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "26";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "查询成功";
|
||
Json::Value jsArray;
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||
int iResult = arrRes.size();
|
||
if (iResult > 0) {
|
||
for (int j = 0; j < iResult; j++) {
|
||
Json::Value jsSensorData;
|
||
jsSensorData["dataNodeNo"] = arrRes[j][44];
|
||
jsSensorData["dataNodeName"] = arrRes[j][1];
|
||
jsSensorData["initFlag"] = atoi(arrRes[j][2].c_str());
|
||
jsSensorData["accFlag"] = atoi(arrRes[j][3].c_str());
|
||
jsSensorData["zigbeeFlag"] = atoi(arrRes[j][4].c_str());
|
||
jsSensorData["temTopFlag"] = atoi(arrRes[j][5].c_str());
|
||
jsSensorData["temBotFlag"] = atoi(arrRes[j][6].c_str());
|
||
jsSensorData["equipsta"] = atoi(arrRes[j][7].c_str());
|
||
jsSensorData["hardVersion"] = arrRes[j][8];
|
||
jsSensorData["softVersion"] = arrRes[j][9];
|
||
jsSensorData["bpNo"] = arrRes[j][10];
|
||
jsSensorData["serialNo"] = arrRes[j][11];
|
||
jsSensorData["firstPowerTime"] = arrRes[j][12];
|
||
jsSensorData["WakeupTime"] = atoi(arrRes[j][13].c_str());
|
||
jsSensorData["StaticTime"] = atoi(arrRes[j][14].c_str());
|
||
jsSensorData["WaveTime"] = atoi(arrRes[j][15].c_str());
|
||
jsSensorData["BateryV"] = arrRes[j][16];
|
||
jsSensorData["ProductNo"] = arrRes[j][17];
|
||
jsSensorData["configFlag"] = atoi(arrRes[j][18].c_str());
|
||
jsSensorData["startBrands"] = arrRes[j][19];
|
||
jsSensorData["stopBrands"] = arrRes[j][20];
|
||
jsSensorData["featureInterVal"] = (arrRes[j][21]);
|
||
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
||
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
||
// jsSensorData["scope"] = atoi(arrRes[j][24]);
|
||
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
||
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
||
jsSensorData["faultFrequency"] = arrRes[j][27];
|
||
jsSensorData["zigbeePanId"] = arrRes[j][28];
|
||
jsSensorData["zigbeeChannel"] = (arrRes[j][29]);
|
||
jsSensorData["zigbeeAddr"] = arrRes[j][30];
|
||
jsSensorData["zigbeeLongAddr"] = arrRes[j][31];
|
||
jsSensorData["zigbeeDesAddr"] = arrRes[j][32];
|
||
jsSensorData["ZigbeePower"] = atoi(arrRes[j][33].c_str());
|
||
jsSensorData["ZigbeeRetry"] = atoi(arrRes[j][34].c_str());
|
||
jsSensorData["ZigbeeRetryGap"] = atoi(arrRes[j][35].c_str());
|
||
jsSensorData["ACCSampleTime"] = atoi(arrRes[j][36].c_str());
|
||
jsSensorData["status"] = atoi(arrRes[j][37].c_str());
|
||
jsSensorData["timeStamp"] = arrRes[j][38];
|
||
jsSensorData["viff"] = atoi(arrRes[j][39].c_str());
|
||
jsSensorData["RSSI"] = atoi(arrRes[j][40].c_str());
|
||
jsSensorData["Update"] = atoi(arrRes[j][41].c_str());
|
||
jsSensorData["Update"] = atoi(arrRes[j][41].c_str());
|
||
jsArray.append(jsSensorData);
|
||
}
|
||
} else {
|
||
jsArray.resize(0);
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "查询失败";
|
||
}
|
||
|
||
Json::Value jsBody;
|
||
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsBody["dataNodeArray"] = jsArray;
|
||
std::string dataBody = showValue.write(jsBody);
|
||
jsonVal["cmdBody"] = dataBody;
|
||
return showValue.write(jsonVal);
|
||
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_27(Json::Value & recvBody)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
jsonVal["cmd"] = "27";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
|
||
int nSize = recvBody["dataNodeArray"].size();
|
||
|
||
if (nSize > 0) {
|
||
for (int i = 0; i < nSize; i++) {
|
||
char whereCon[128] = { 0 };
|
||
sprintf(whereCon, "%s= '%s'", "MeasurementID", recvBody["dataNodeArray"][i].asString().c_str());
|
||
sql_ctl->DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATANODE_TIME(TNAME), whereCon);
|
||
}
|
||
} else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "没有传感器号";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_50(Json::Value & recvBody)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
jsonVal["cmd"] = "50";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
|
||
std::string updateDevice = recvBody["updateDevice"].asString();//1 DataNode 2 GateWay
|
||
std::string updateURL = recvBody["updateURL"].asString();
|
||
std::string updateName = recvBody["updateName"].asString();
|
||
std::string md5 = recvBody["MD5"].asString();
|
||
std::string strResponse;
|
||
updateName = "/opt/" + updateName;
|
||
if (access(updateName.c_str(), 0) == 0){
|
||
char cmd[100]={0x00};
|
||
sprintf(cmd,"rm -rf %s",updateName.c_str());
|
||
system(cmd);
|
||
}
|
||
sleep(2);
|
||
// int iRet = pDataTrans->download( (char*)updateName.c_str(),updateURL, strResponse, bDownload);
|
||
int iRet = pDataTrans->dl_curl_post_req( updateURL,"",updateName);
|
||
if(iRet != 0){
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "download failed";
|
||
return showValue.write(jsonVal);
|
||
}
|
||
string md5Val = md5file(updateName.c_str());
|
||
printf("md5Val = %s\n",md5Val.c_str());
|
||
printf("md5 = %s\n",md5.c_str());
|
||
if(md5 != md5Val){
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "download file check failed";
|
||
return showValue.write(jsonVal);
|
||
}
|
||
if(updateDevice == "1"){
|
||
string strcmd = "tar xvf ";
|
||
strcmd = strcmd + updateName;
|
||
strcmd = strcmd + " -C /opt/";
|
||
system(strcmd.c_str());
|
||
}else if (updateDevice == "2"){
|
||
/* string strcmd = "tar xvf ";
|
||
strcmd = strcmd + updateName;
|
||
strcmd = strcmd + " -C /opt/update/";
|
||
system(strcmd.c_str());*/
|
||
sleep(3);
|
||
system("/opt/opt.sh");
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_51(Json::Value & recvBody)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
jsonVal["cmd"] = "51";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
std::string DataNodeNo = recvBody["dataNodeNo"].asString();
|
||
std::string DataNodeName = recvBody["dataNodeName"].asString();
|
||
char szSql[100]={0x00};
|
||
sprintf(szSql,"update %s set dataNodeName = '%s' where MeasurementID = '%s' ",T_SENSOR_INFO(TNAME),\
|
||
DataNodeName.c_str(),DataNodeNo.c_str());
|
||
int iRet = sql_ctl->UpdateTableData(szSql);
|
||
if(iRet != 0){
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "updata dataNodeName failed";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_52()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
char whereCon[512] = {};
|
||
std::string strTimeStamp = "";
|
||
char selectCon[128] = { 0 };
|
||
memcpy(selectCon,"sendMsg = '0'",sizeof(selectCon));
|
||
int count = sql_ctl->GetTableRows(T_DATASTATIC_INFO(TNAME), selectCon);
|
||
if(count < 1){
|
||
return "";
|
||
}
|
||
for(int i = 0 ; i < count ;i++)
|
||
{
|
||
Json::Value jsSensor;
|
||
std::string strDataNodeNo = "";
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "52";
|
||
memcpy(whereCon, "sendMsg = '0' ORDER BY timeStamp DESC LIMIT 0,3",sizeof(whereCon));
|
||
// 自数据库获取传感器特征数据
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLine(T_DATA_INFO(TNAME), "*", whereCon);
|
||
int iResult = arrRes.size();
|
||
if (iResult > 0) {
|
||
for (int j = 0; j < iResult; j++) {
|
||
Json::Value jsChannelData;
|
||
strDataNodeNo = arrRes[j][0];
|
||
jsChannelData["ChannelId"] = arrRes[j][1];
|
||
jsChannelData["ChannelType"] = "ACCELEROMETER";
|
||
jsChannelData["DiagnosisPeak"] = atof(arrRes[j][2].c_str());
|
||
jsChannelData["IntegratPk2Pk/2"] = atof(arrRes[j][3].c_str());
|
||
jsChannelData["IntegratRMS"] = atof(arrRes[j][4].c_str());
|
||
jsChannelData["RMSValues"] = atof(arrRes[j][5].c_str());
|
||
jsChannelData["EnvelopEnergy"] = atof(arrRes[j][6].c_str());
|
||
jsChannelData["1xAmp"] = atof(arrRes[j][7].c_str());
|
||
jsChannelData["2xAmp"] = atof(arrRes[j][8].c_str());
|
||
jsChannelData["3xAmp"] = atof(arrRes[j][9].c_str());
|
||
jsChannelData["4xAmp"] = atof(arrRes[j][10].c_str());
|
||
jsChannelData["5xAmp"] = atof(arrRes[j][11].c_str());
|
||
jsChannelData["1xPhase"] = atof(arrRes[j][12].c_str());
|
||
jsChannelData["2xPhase"] = atof(arrRes[j][13].c_str());
|
||
jsChannelData["3xPhase"] = atof(arrRes[j][14].c_str());
|
||
jsChannelData["4xPhase"] = atof(arrRes[j][15].c_str());
|
||
jsChannelData["TimeStamp"] = atof(arrRes[j][17].c_str());
|
||
strTimeStamp = std::string(arrRes[j][16]);
|
||
jsSensor.append(jsChannelData);
|
||
}
|
||
}
|
||
|
||
memset(selectCon,0x00,sizeof(selectCon));
|
||
sprintf(selectCon, "dataNodeNo='%s' and sendMsg = '0' ORDER BY timeStamp DESC LIMIT 0,1", strDataNodeNo.c_str());
|
||
vec_t vecRes = sql_ctl->GetDataSingleLine(T_DATASTATIC_INFO(TNAME), "*", selectCon);
|
||
Json::Value jsStaticData;
|
||
if(vecRes.size()>0){
|
||
jsStaticData["TemperatureTop"] = atof(vecRes[2].c_str());
|
||
jsStaticData["TemperatureBot"] = atof(vecRes[3].c_str());
|
||
jsStaticData["Dip"] = atof(vecRes[4].c_str());
|
||
jsStaticData["Voltage"] = atof(vecRes[5].c_str());
|
||
jsStaticData["ChannelType"] = "STATUS";
|
||
jsStaticData["ChannelId"] = vecRes[1];
|
||
jsStaticData["TimeStamp"] = vecRes[7];
|
||
jsStaticData["dataNodeNo"] = strDataNodeNo;
|
||
}
|
||
|
||
jsSensor.append(jsStaticData);
|
||
|
||
jsonVal["content"].append(jsSensor);
|
||
std::string data = showValue.write(jsonVal);
|
||
memset(whereCon,0x00,sizeof(whereCon));
|
||
sprintf(whereCon,"sendMsg = '0' and timeStamp = '%s'",strTimeStamp.c_str());
|
||
int iRet = data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||
if(iRet == 0){
|
||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME),whereCon,0);
|
||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME),whereCon,0);
|
||
}
|
||
usleep(100);
|
||
}
|
||
return "";
|
||
}
|
||
std::string JsonData::JsonCmd_53(Json::Value & recvBody)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
jsonVal["cmd"] = "53";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
std::string looseValue = recvBody["looseValue"].asString();
|
||
|
||
int iRet = writeStringVlaue("config", "loose",(char*)looseValue.c_str(),(char*)GlobalConfig::Config_G.c_str());
|
||
if(iRet != 0){
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "update failed";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_29(Param_29 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
Json::Value jsBody;
|
||
Json::Value SystemSetting;
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "29";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
// jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||
int iResult = arrRes.size();
|
||
// LOG_INFO("iResult = %d",iResult);
|
||
if (iResult > 0) {
|
||
for (int i = 0; i < iResult; i++) {
|
||
Json::Value jsDataNode;
|
||
jsDataNode["dataNodeNo"] = arrRes[i][0];
|
||
jsDataNode["status"] = atoi(arrRes[i][37].c_str());
|
||
jsBody["dataNodeArray"].append(jsDataNode);
|
||
}
|
||
}
|
||
|
||
std::string strBody = showValue.write(jsBody);
|
||
jsonVal["cmdBody"] = strBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
|
||
void JsonData::JsonCmd_38(Json::Value &recvBody)
|
||
{
|
||
Json::Value jsChannel = recvBody["channelArray"];
|
||
print_info("jsChannel size : %d\n", jsChannel.size());
|
||
if (jsChannel.isArray()) {
|
||
for (int i = 0; i < jsChannel.size(); i++) {
|
||
std::string strChannelid = jsChannel[i].asString();
|
||
WAVE_GENERAL wavedata;
|
||
|
||
WAVE_CONTAIN wave;
|
||
memset(wave.channelId, 0, 16);
|
||
sprintf(wave.channelId, "%s", strChannelid.c_str());
|
||
|
||
memset(wave.SensorEngineeringUnit, 0, 32);
|
||
sprintf(wave.SensorEngineeringUnit,"%s", wavedata.SensorEngineeringUnit.c_str());
|
||
|
||
wave.total = 1;
|
||
wave.count = 1;
|
||
wave.type = 0;
|
||
wave.flag = 0;
|
||
wave.number = wavedata.number;
|
||
memcpy(wave.waveData, wavedata.waveData, wavedata.number * sizeof(float));
|
||
// data_publish_wave(&wave, GlobalConfig::Topic_G.mPubSecond.c_str());
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//
|
||
void JsonData::JsonCmd_39(Json::Value &recvBody)
|
||
{
|
||
|
||
}
|
||
void JsonData::DataNodeStatusCheck()
|
||
{
|
||
array_t vetRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||
int nSize = vetRes.size();
|
||
|
||
char localtimestamp[32] = { 0 };
|
||
GetTimeNet(localtimestamp, 1);
|
||
std::string nowTimetamp = std::string(localtimestamp);
|
||
int lNowTime = atoi(nowTimetamp.c_str());
|
||
int onlineCheck = readIntValue( "config", "online",(char*)GlobalConfig::Config_G.c_str());
|
||
int loseTime = readIntValue( "config", "loseTime",(char*)GlobalConfig::Config_G.c_str());
|
||
if (nSize > 0) {
|
||
for (int i = 0; i < nSize; i++) {
|
||
std::string strDataNodeNo = vetRes[i][0];
|
||
std::string strMeasurementID = vetRes[i][44];
|
||
std::string strChannelId = strMeasurementID + "-X";
|
||
char whereCon[512] = {0x00},tablename[128]={0x00};
|
||
sprintf(whereCon, "dataNodeNo='%s' and channelID='%s' ORDER BY timeStamp DESC LIMIT 0,1", strDataNodeNo.c_str(), strChannelId.c_str());
|
||
sprintf(tablename,"t_data_%s",strDataNodeNo.c_str());
|
||
std::string strTimeRes = sql_ctl->GetData(tablename, "timeStamp", whereCon);
|
||
if (strTimeRes.length() > 0) {
|
||
int llastTime = atoi(strTimeRes.c_str());
|
||
int lTimeTemp = lNowTime - llastTime;
|
||
lTimeTemp = abs(lTimeTemp);
|
||
if (lTimeTemp > onlineCheck){
|
||
LOG_DEBUG("离线 DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s\n",lNowTime,llastTime,vetRes[i][21].c_str());
|
||
char whereCon[32] = { 0 };
|
||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon);
|
||
}
|
||
// }else if(lTimeTemp > (loseTime * atoi(vetRes[i][21].c_str()) * 60)){
|
||
// LOG_DEBUG("掉线 DataNodeStatusCheck lNowTime = %d,llastTime = %d,interval = %s\n",lNowTime,llastTime,vetRes[i][21].c_str());
|
||
// char whereCon[32] = { 0 };
|
||
// sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||
// sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='2'", whereCon);
|
||
// }
|
||
else {
|
||
char whereCon[32] = { 0 };
|
||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
/***************************嵌入式Web协议******************************/
|
||
|
||
std::string JsonData::JsonCmd_Cgi_01(Param_01 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
Json::Value jsBody;
|
||
jsonVal.clear();
|
||
std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName");
|
||
std::string adminPassword = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "adminPassword");
|
||
std::string userPassword = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "userPassword");
|
||
std::string message = " ";
|
||
bool success = true;
|
||
|
||
if (0 == param.mMode) {
|
||
jsBody["type"] = "login";
|
||
if (0 != param.mUserName.compare(userName)) {
|
||
message = "0101";
|
||
success = false;
|
||
} else {
|
||
if (0 == param.mPassWord.compare(adminPassword) || 0 == param.mPassWord.compare(userPassword)) {
|
||
|
||
} else {
|
||
message = "0102";
|
||
success = false;
|
||
}
|
||
}
|
||
} else if (1 == param.mMode) {
|
||
jsBody["type"] = "upDate";
|
||
if (0 != param.mUserName.compare(userName)) {
|
||
message = "0101";
|
||
} else {
|
||
if (0 == param.mPassWord.compare(adminPassword) || 0 == param.mPassWord.compare(userPassword)) {
|
||
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", param.mPassWordNew);
|
||
} else {
|
||
message = "0103";
|
||
success = false;
|
||
}
|
||
}
|
||
} else {
|
||
message = "格式错误";
|
||
success = false;
|
||
}
|
||
|
||
jsonVal["cmd"] = "01";
|
||
jsonVal["success"] = success;
|
||
jsonVal["message"] = message;
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "校时成功";
|
||
|
||
jsonVal["cmd"] = "02";
|
||
if (0 == param.mMode) {
|
||
jsonVal["type"] = "SET";
|
||
if(param.mMode == 0){//本地校时
|
||
SetTime((unsigned long)param.mTimeStamp);
|
||
usleep(200);
|
||
system("hwclock -w");
|
||
}else if(param.mMode == 1){//与服务器校时
|
||
char buf[256] = {0};
|
||
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}",
|
||
GlobalConfig::MacAddr_G.c_str());
|
||
std::string str = std::string(buf);
|
||
int iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||
}
|
||
} else if (1 == param.mMode) {
|
||
char cmd[256] = { 0 };
|
||
char localtimestamp[32] = { 0 };
|
||
GetTimeNet(localtimestamp, 1);
|
||
std::string nowTimetamp = std::string(localtimestamp);
|
||
jsonVal["type"] = "GET";
|
||
jsonVal["timeStamp"] = atoi(nowTimetamp.c_str());
|
||
}
|
||
return showValue.write(jsonVal);
|
||
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_07()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
std::string sysStatus = GetSysStatus();
|
||
|
||
print_info("sysStatus : %s\n", sysStatus.c_str());
|
||
Json::Features f = Json::Features::strictMode();
|
||
Json::Reader recvReader(f);
|
||
Json::Value recvSys;
|
||
jsonVal[JSON_FIELD_CMD] = "07";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
if (recvReader.parse(sysStatus, recvSys)){
|
||
jsonVal["content"] = recvSys;
|
||
} else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "状态获取失败";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_07()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
std::string sysStatus = GetSysStatus();
|
||
|
||
print_info("sysStatus : %s\n", sysStatus.c_str());
|
||
Json::Features f = Json::Features::strictMode();
|
||
Json::Reader recvReader(f);
|
||
Json::Value recvSys;
|
||
jsonVal[JSON_FIELD_CMD] = "07";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
if (recvReader.parse(sysStatus, recvSys)){
|
||
jsonVal["cmdBody"] = sysStatus;
|
||
} else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "状态获取失败";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_Cgi_08()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
std::string sysStatus = GetSysStatus();
|
||
|
||
Json::Features f = Json::Features::strictMode();
|
||
Json::Reader recvReader(f);
|
||
Json::Value recvSys;
|
||
jsonVal[JSON_FIELD_CMD] = "08";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m)
|
||
{
|
||
//LOG_INFO("09 start\n");
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "09";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
char localtimestamp[32] = { 0 };
|
||
GetTimeNet(localtimestamp, 1);
|
||
std::string nowTimetamp = std::string(localtimestamp);
|
||
char looseValue[10]={0x00};
|
||
readStringValue("config", "loose",looseValue,(char*)GlobalConfig::Config_G.c_str());
|
||
|
||
array_t arrResAll = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID ", NULL);
|
||
int nSize = arrResAll.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;
|
||
}
|
||
|
||
printf("09 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n",packgeNo,packgeNum,lastSize,index);
|
||
for (int i = packgeNo * 10; i < packgeNum; i++) {
|
||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@vetRes=%s\n",arrResAll[i][1].c_str());
|
||
Json::Value jsSensor;
|
||
std::string strMeasurementID = arrResAll[i][1];
|
||
char whereCon[512] = {};
|
||
sprintf(whereCon, "channelID like '%%%s%%' ORDER BY timeStamp DESC LIMIT 0,3", strMeasurementID.c_str());
|
||
// 自数据库获取传感器特征数据
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||
int iResult = arrRes.size();
|
||
if (iResult > 0) {
|
||
for (int j = 0; j < iResult; j++) {
|
||
Json::Value jsChannelData;
|
||
jsChannelData["ChannelId"] = arrRes[j][1];
|
||
jsChannelData["ChannelType"] = "ACCELEROMETER";
|
||
jsChannelData["DiagnosisPeak"] = atof(arrRes[j][2].c_str());
|
||
jsChannelData["IntegratPk2Pk/2"] = atof(arrRes[j][3].c_str());
|
||
jsChannelData["IntegratRMS"] = atof(arrRes[j][4].c_str());
|
||
jsChannelData["RMSValues"] = atof(arrRes[j][5].c_str());
|
||
jsChannelData["EnvelopEnergy"] = atof(arrRes[j][6].c_str());
|
||
jsChannelData["1xAmp"] = atof(arrRes[j][7].c_str());
|
||
jsChannelData["2xAmp"] = atof(arrRes[j][8].c_str());
|
||
jsChannelData["3xAmp"] = atof(arrRes[j][9].c_str());
|
||
jsChannelData["4xAmp"] = atof(arrRes[j][10].c_str());
|
||
jsChannelData["5xAmp"] = atof(arrRes[j][11].c_str());
|
||
jsChannelData["1xPhase"] = atof(arrRes[j][12].c_str());
|
||
jsChannelData["2xPhase"] = atof(arrRes[j][13].c_str());
|
||
jsChannelData["3xPhase"] = atof(arrRes[j][14].c_str());
|
||
jsChannelData["4xPhase"] = atof(arrRes[j][15].c_str());
|
||
jsChannelData["TimeStamp"] = atof(arrRes[j][17].c_str());
|
||
jsSensor.append(jsChannelData);
|
||
}
|
||
}
|
||
|
||
char selectCon[128] = { 0 };
|
||
char column[128]={0};
|
||
char tablename[256]={0};
|
||
sprintf(selectCon, " t_sensor_info.MeasurementID='%s' ",strMeasurementID.c_str());
|
||
sprintf(column," %s.*,t_sensor_info.status,t_sensor_info.LooseValue,t_sensor_info.batteryPower ",T_DATASTATIC_INFO(TNAME));
|
||
sprintf(tablename," %s LEFT JOIN t_sensor_info \
|
||
ON %s.channelID like '%%%s%%' ",T_DATASTATIC_INFO(TNAME),T_DATASTATIC_INFO(TNAME),strMeasurementID.c_str());
|
||
|
||
vec_t vecRes = sql_ctl->GetDataSingleLine(tablename,column, selectCon);
|
||
Json::Value jsStaticData;
|
||
if(vecRes.size()>0){
|
||
jsStaticData["TemperatureTop"] = atof(vecRes[2].c_str());
|
||
jsStaticData["TemperatureBot"] = atof(vecRes[3].c_str());
|
||
jsStaticData["Dip"] = atof(vecRes[4].c_str());
|
||
jsStaticData["Voltage"] = atof(vecRes[5].c_str());
|
||
jsStaticData["ChannelType"] = "STATUS";
|
||
jsStaticData["ChannelId"] = vecRes[1];
|
||
jsStaticData["TimeStamp"] = vecRes[8];
|
||
jsStaticData["battery"] = vecRes[13];
|
||
jsStaticData["MeasurementID"] = strMeasurementID;
|
||
jsStaticData["dataNodeNo"] = arrResAll[i][0];
|
||
jsStaticData["status"] = vecRes[11];
|
||
jsStaticData["loose"] = "0";
|
||
|
||
}else{
|
||
jsStaticData["TemperatureTop"] = "";
|
||
jsStaticData["TemperatureBot"] = "";
|
||
jsStaticData["Dip"] = "";
|
||
jsStaticData["Voltage"] = "";
|
||
jsStaticData["ChannelType"] = "STATUS";
|
||
jsStaticData["ChannelId"] = "";
|
||
jsStaticData["TimeStamp"] = "";
|
||
jsStaticData["battery"] = "";
|
||
jsStaticData["MeasurementID"] = strMeasurementID;
|
||
jsStaticData["dataNodeNo"] = arrResAll[i][0];
|
||
jsStaticData["status"] = "0";
|
||
jsStaticData["loose"] = "0";
|
||
}
|
||
jsSensor.append(jsStaticData);
|
||
jsonVal["content"].append(jsSensor);
|
||
}
|
||
|
||
} else {
|
||
jsonVal["success"] = true;
|
||
jsonVal["content"].resize(0);
|
||
}
|
||
//LOG_INFO("09 end\n");
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "10";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
vec_t vetRes = sql_ctl->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, "%s,channelID,timeStamp",param.strStatic.c_str());
|
||
|
||
if(param.straxis == "S")
|
||
{
|
||
sprintf(szTableName,"t_dataStatic_%s",param.strDataNode.c_str());
|
||
}else{
|
||
sprintf(szTableName,"t_data_%s",param.strDataNode.c_str());
|
||
}
|
||
if(param.timeEnd == ""){
|
||
|
||
sprintf(whereCon,"channelID like '%%%s%%' and %s <> ''",\
|
||
param.MeasurementID.c_str(),param.strStatic.c_str());
|
||
|
||
}else{
|
||
|
||
sprintf(whereCon," channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' ",\
|
||
param.MeasurementID.c_str(),param.strStatic.c_str(),param.timeEnd.c_str(),param.timeStart.c_str());
|
||
|
||
}
|
||
|
||
int rows = sql_ctl->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;
|
||
}
|
||
|
||
//printf("10 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n",packgeNo,packgeNum,lastSize,index);
|
||
memset(whereCon,0x00,sizeof(whereCon));
|
||
|
||
if(param.timeEnd == ""){
|
||
sprintf(whereCon,"channelID like '%%%s%%' and %s <> '' order by timeStamp asc LIMIT %d OFFSET %d",\
|
||
param.MeasurementID.c_str(),param.strStatic.c_str(),550,packgeNum);
|
||
}else{
|
||
sprintf(whereCon,"channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d",\
|
||
param.MeasurementID.c_str(),param.strStatic.c_str(),param.timeEnd.c_str(),param.timeStart.c_str(),550,packgeNum);
|
||
}
|
||
array_t vecRes;
|
||
|
||
vecRes = sql_ctl->GetDataMultiLine(szTableName, selectCon,whereCon);
|
||
print_info("vecRes = %d\n",vecRes.size());
|
||
if(vecRes.size() > 0){
|
||
Json::Value jsStaticData;
|
||
for(int i = 0 ; i < vecRes.size(); i++){
|
||
Json::Value iTem;
|
||
if(vecRes[i][1] == param.MeasurementID + "-X"){
|
||
iTem.append(vecRes[i][0]);
|
||
iTem.append(vecRes[i][2]);
|
||
jsStaticData["X"].append(iTem);
|
||
}if(vecRes[i][1] == param.MeasurementID + "-Y"){
|
||
iTem.append(vecRes[i][0]);
|
||
iTem.append(vecRes[i][2]);
|
||
jsStaticData["Y"].append(iTem);
|
||
}if(vecRes[i][1] == param.MeasurementID + "-Z"){
|
||
iTem.append(vecRes[i][0]);
|
||
iTem.append(vecRes[i][2]);
|
||
jsStaticData["Z"].append(iTem);
|
||
}
|
||
if(vecRes[i][1] == param.MeasurementID + "-S"){
|
||
iTem.append(vecRes[i][0]);
|
||
iTem.append(vecRes[i][2]);
|
||
jsStaticData["S"].append(iTem);
|
||
}
|
||
}
|
||
if(jsStaticData.size() == 0){
|
||
jsonVal["success"] = false;
|
||
jsonVal["content"].resize(0);
|
||
}
|
||
else{
|
||
jsonVal["content"] = (jsStaticData);
|
||
}
|
||
jsonVal["Static"] = param.strStatic;
|
||
print_info("vecRes = %d,channelID = %s\n",vecRes.size(),vecRes[0][0].c_str());
|
||
}else{
|
||
jsonVal["success"] = false;
|
||
jsonVal["content"].resize(0);
|
||
}
|
||
}else{
|
||
jsonVal["success"] = false;
|
||
jsonVal["content"].resize(0);
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_11(Param_11 ¶m)
|
||
{
|
||
Json::Value jsonVal,jsSensor;
|
||
jsonVal.clear();
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "11";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
char whereCon[512] = {};
|
||
sprintf(whereCon, "dataNodeNo='%s' ORDER BY timeStamp DESC LIMIT 0,3", param.DataNodeNo.c_str());
|
||
// 自数据库获取传感器特征数据
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||
int iResult = arrRes.size();
|
||
print_info("iResult = %d\n",iResult);
|
||
if (iResult > 0) {
|
||
for (int j = 0; j < iResult; j++) {
|
||
Json::Value jsChannelData;
|
||
jsChannelData["ChannelId"] = arrRes[j][1];
|
||
jsChannelData["ChannelType"] = "ACCELEROMETER";
|
||
jsChannelData["DiagnosisPeak"] = atof(arrRes[j][2].c_str());
|
||
jsChannelData["IntegratPk2Pk/2"] = atof(arrRes[j][3].c_str());
|
||
jsChannelData["IntegratRMS"] = atof(arrRes[j][4].c_str());
|
||
jsChannelData["RMSValues"] = atof(arrRes[j][5].c_str());
|
||
jsChannelData["EnvelopEnergy"] = atof(arrRes[j][6].c_str());
|
||
jsChannelData["1xAmp"] = atof(arrRes[j][7].c_str());
|
||
jsChannelData["2xAmp"] = atof(arrRes[j][8].c_str());
|
||
jsChannelData["3xAmp"] = atof(arrRes[j][9].c_str());
|
||
jsChannelData["4xAmp"] = atof(arrRes[j][10].c_str());
|
||
jsChannelData["5xAmp"] = atof(arrRes[j][11].c_str());
|
||
jsChannelData["1xPhase"] = atof(arrRes[j][12].c_str());
|
||
jsChannelData["2xPhase"] = atof(arrRes[j][13].c_str());
|
||
jsChannelData["3xPhase"] = atof(arrRes[j][14].c_str());
|
||
jsChannelData["4xPhase"] = atof(arrRes[j][15].c_str());
|
||
jsChannelData["TimeStamp"] = atof(arrRes[j][17].c_str());
|
||
jsSensor.append(jsChannelData);
|
||
}
|
||
}else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["content"].resize(0);
|
||
}
|
||
jsonVal["content"] = jsSensor;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶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, "SystemInfo", "dataNodeGatewayName", param.mDataWatchName);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", param.mDataWatchAssetId);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", param.mDataWatchAddedBy);
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate", nowTimetamp);
|
||
}
|
||
|
||
std::string boardtype = GetFileContent(BOARDTYPE, 1);
|
||
std::string ip = IpAddrInit();
|
||
std::string sn = GetFileContent(SN, 1);
|
||
jsonVal[JSON_FIELD_CMD] = "20";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
|
||
Json::Value jsSystemInfo;
|
||
Json::Value jsBody;
|
||
|
||
jsSystemInfo[JSON_FIELD_NAME] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName");
|
||
jsSystemInfo["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsSystemInfo[JSON_FIELD_ASSETID] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId");
|
||
jsSystemInfo[JSON_FIELD_ADDEDBY] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy");
|
||
jsSystemInfo[JSON_FIELD_ADDEDDATE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate");
|
||
jsSystemInfo[JSON_FIELD_DEVICETYPE] = boardtype;
|
||
jsSystemInfo[JSON_FIELD_IPADDRESS] = ip;
|
||
jsSystemInfo[JSON_FIELD_SN] = sn;
|
||
jsSystemInfo[JSON_FIELD_VERSION] = GlobalConfig::Version;
|
||
jsSystemInfo[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||
jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID;
|
||
jsSystemInfo["zigbeeChannel"] = GlobalConfig::ZigbeeInfo_G.Channel;
|
||
jsSystemInfo["zigbeeAddr"] = GlobalConfig::ZigbeeInfo_G.MyAddr;
|
||
jsSystemInfo["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||
jsSystemInfo["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||
jsSystemInfo["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||
jsSystemInfo["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
|
||
jsSystemInfo["GateWayProduct"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayProduct");
|
||
jsSystemInfo["serverStatus"] = GlobalConfig::serverStatus ;
|
||
|
||
if(GlobalConfig::NetType == "\"NR5G-SA\"" || GlobalConfig::NetType == "\"NR5G-NSA\"" ||
|
||
GlobalConfig::NetType == "\"NR5G\""){
|
||
GlobalConfig::NetType = "5G";
|
||
}else if(GlobalConfig::NetType == "\"LTE\""){
|
||
GlobalConfig::NetType = "4G";
|
||
}
|
||
if(GlobalConfig::NetStatus == "\"NOCONN\"" || GlobalConfig::NetStatus == "\"CONNECT\""){
|
||
|
||
if(GlobalConfig::NetSignal == 0){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",未知";
|
||
}
|
||
else if(GlobalConfig::NetSignal > -80){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",优";
|
||
}else if(GlobalConfig::NetSignal > -90 && GlobalConfig::NetSignal < -80){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",良";
|
||
}else if(GlobalConfig::NetSignal > -105 && GlobalConfig::NetSignal < -90){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",一般";
|
||
}else if(GlobalConfig::NetSignal < -105){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",弱";
|
||
}else if(GlobalConfig::NetSignal < -115){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",不稳定";
|
||
}
|
||
|
||
}else if(GlobalConfig::NetStatus == "\"SEARCH\""){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",搜索网络";
|
||
}else if(GlobalConfig::NetStatus == "\"LIMSRV\""){
|
||
jsSystemInfo["communicationSignal"] = GlobalConfig::NetType + ",未插卡";
|
||
}else{
|
||
jsSystemInfo["communicationSignal"] = "未知";
|
||
}
|
||
|
||
|
||
jsBody["SystemInfo"] = jsSystemInfo;
|
||
|
||
// std::string dataBody = showValue.write(jsBody);
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_22(Param_22 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
if (0 == param.mMode) {
|
||
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "timezone", param.mTimeZone);
|
||
}
|
||
|
||
jsonVal[JSON_FIELD_CMD] = "22";
|
||
jsonVal[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
Json::Value jsSystemSetting;
|
||
Json::Value jsBody;
|
||
jsSystemSetting[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone");
|
||
jsBody["SystemSettings"] = jsSystemSetting;
|
||
|
||
jsonVal["content"] = jsBody;
|
||
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_23(Param_23 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal[JSON_FIELD_CMD] = "23";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["cmdSerial"] = param.mCmdSerial;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
// SET 指令,则param.mMode = 0,将设置的数据写入配置文件中 SERVERCONFIG "/opt/configenv/ServerConfig.json"
|
||
|
||
if (0 == param.mMode && CheckIP(param.mServerIp.c_str())) {
|
||
|
||
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", param.mServerIp);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", param.mPort);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "CommMode", /*param.mCommMode*/"2");
|
||
WriteStr2Config(SERVERCONFIG, "Server", "UserName", param.mUserName);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "Password", param.mPassword);
|
||
WriteStr2Config(SERVERCONFIG, "Server", "APN", param.mAPN);
|
||
char APN[100]={0x00};
|
||
sprintf(APN,"sed -i '15c \t\t\t\t/opt/quectel-CM/quectel-CM -s %s > /dev/null &' /etc/init.d/S95check5G",param.mAPN.c_str());
|
||
system(APN);
|
||
system("reboot");
|
||
}else if(0 == param.mMode && !(CheckIP(param.mServerIp.c_str()))){
|
||
jsonVal["success"] = false;
|
||
}
|
||
|
||
Json::Value jsSystemSetting;
|
||
Json::Value jsBody;
|
||
|
||
jsSystemSetting["ServerIpAddress"] = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||
jsSystemSetting["ServerPort"] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||
jsSystemSetting["CommMode"] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||
jsSystemSetting["ServerStatus"] = 1;
|
||
jsSystemSetting["UserName"] = ReadStrByOpt(SERVERCONFIG, "Server", "UserName");
|
||
jsSystemSetting["Password"] = ReadStrByOpt(SERVERCONFIG, "Server", "Password");
|
||
jsSystemSetting["APN"] = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||
jsBody["SystemSettings"] = jsSystemSetting;
|
||
jsonVal["content"] = jsBody;
|
||
|
||
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_25(Param_25 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
Json::Value jsonValnet;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
jsonVal["cmd"] = "25";
|
||
string strNet = "";
|
||
bool bFlag1 = CheckIP(param.mGateway.c_str());
|
||
bool bFlag2 = IsValidMask(param.mSubnetMask);
|
||
bool bFlag3 = CheckIP(param.mIp.c_str());
|
||
bool bFlag4 = false;
|
||
if(param.mDnsName.size()>0){
|
||
bFlag4 = CheckIP(param.mDnsName.c_str());
|
||
}else{
|
||
bFlag4 = true;
|
||
}
|
||
print_info("bFlag1 = %d,bFlag2 = %d,bFlag3 = %d,bFlag4 = %d\n",bFlag1,bFlag2,bFlag3,bFlag4);
|
||
#ifdef IMX6UL_GATEWAY
|
||
strNet = param.mNet;
|
||
param.mNet = "Net";
|
||
#endif
|
||
if (0 == param.mMode &&(bFlag1 && bFlag2 && bFlag3 && bFlag4) && param.mNetworkPortStatus == "STATIC") {
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", param.mDnsName);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "networkPortStatus", param.mNetworkPortStatus);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "gateway", param.mGateway);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "subnetMask", param.mSubnetMask);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", param.mIp);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", param.mHostName);
|
||
|
||
#ifdef IMX6UL_GATEWAY
|
||
char GateWay[100]={0x00};
|
||
sprintf(GateWay,"sed -i '7c route add default gw %s' /etc/init.d/S90start_userapp.sh",param.mGateway.c_str());
|
||
print_info("GateWay = %s\n",GateWay);
|
||
system(GateWay);
|
||
#endif
|
||
platform->EquipIpInit(param.mNet);
|
||
|
||
}else if(0 == param.mMode && param.mNetworkPortStatus == "DHCP"){
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "dnsName", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "networkPortStatus", param.mNetworkPortStatus);
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "gateway", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "subnetMask", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "ipAddress", "");
|
||
WriteStr2Config(NETWORKCONFIG, param.mNet, "hostName", "");
|
||
|
||
#ifdef IMX6UL_GATEWAY
|
||
system("sed -i '7c udhcpc -i eth0 > /dev/null &' /etc/init.d/S90start_userapp.sh");
|
||
#endif
|
||
platform->EquipIpInit(param.mNet);
|
||
|
||
}else if(0 == param.mMode &&(!bFlag1 || !bFlag2 || !bFlag3 || !bFlag4) && param.mNetworkPortStatus == "STATIC"){
|
||
jsonVal["success"] = false;
|
||
}
|
||
|
||
jsonValnet["dnsName"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "dnsName");
|
||
jsonValnet["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "networkPortStatus");
|
||
jsonValnet["gateway"] = ReadStrByOpt(NETWORKCONFIG, param.mNet ,"gateway");
|
||
jsonValnet["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "subnetMask");
|
||
jsonValnet["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "ipAddress");
|
||
jsonValnet["hostName"] = ReadStrByOpt(NETWORKCONFIG, param.mNet, "hostName");
|
||
jsonVal["content"]["eth0"] = jsonValnet;
|
||
jsonVal["content"]["gatewaytype"] = 0;
|
||
|
||
#ifdef G2UL_GATEWAY
|
||
jsonValnet["dnsName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "dnsName");
|
||
jsonValnet["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "networkPortStatus");
|
||
jsonValnet["gateway"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "gateway");
|
||
jsonValnet["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "subnetMask");
|
||
jsonValnet["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "ipAddress");
|
||
jsonValnet["hostName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "hostName");
|
||
jsonVal["content"]["eth1"] =jsonValnet;
|
||
jsonVal["content"]["gatewaytype"] = 1;
|
||
#endif
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m)
|
||
{
|
||
//LOG_INFO("26 start\n");
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "26";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
char looseValue[10]={0x00};
|
||
readStringValue("config", "loose",looseValue,(char*)GlobalConfig::Config_G.c_str());
|
||
//print_debug("loose = %f \n",atof(looseValue));
|
||
Json::Value jsArray;
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||
int iResult = arrRes.size();
|
||
if (iResult > 0) {
|
||
int packgeNo = param.mPackageFlag;
|
||
int packgeMax = 0;
|
||
int packgeNum = 0;
|
||
jsonVal["package"] = packgeNo;
|
||
int lastSize = iResult % 10;
|
||
int index = iResult / 10;
|
||
if(lastSize > 0 && index > 0){
|
||
packgeMax = index +1;
|
||
if(packgeNo +1 == packgeMax){
|
||
packgeNum = iResult;
|
||
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;
|
||
}
|
||
|
||
printf("26 packgeNo = %d,packgeNum = %d,lastSize = %d,index = %d\n",packgeNo,packgeNum,lastSize,index);
|
||
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
||
Json::Value jsSensorData;
|
||
jsSensorData["dataNodeNo"] = arrRes[j][0];
|
||
jsSensorData["dataNodeName"] = arrRes[j][1];
|
||
jsSensorData["initFlag"] = atoi(arrRes[j][2].c_str());
|
||
jsSensorData["accFlag"] = atoi(arrRes[j][3].c_str());
|
||
jsSensorData["zigbeeFlag"] = atoi(arrRes[j][4].c_str());
|
||
jsSensorData["temTopFlag"] = atoi(arrRes[j][5].c_str());
|
||
jsSensorData["temBotFlag"] = atoi(arrRes[j][6].c_str());
|
||
jsSensorData["hardVersion"] = arrRes[j][8];
|
||
jsSensorData["softVersion"] = arrRes[j][9];
|
||
jsSensorData["bpNo"] = arrRes[j][10];
|
||
jsSensorData["serialNo"] = arrRes[j][11];
|
||
jsSensorData["firstPowerTime"] = arrRes[j][12];
|
||
jsSensorData["WakeupTime"] = atoi(arrRes[j][13].c_str());
|
||
jsSensorData["StaticTime"] = atoi(arrRes[j][14].c_str());
|
||
jsSensorData["WaveTime"] = atoi(arrRes[j][15].c_str());
|
||
jsSensorData["BateryV"] = arrRes[j][16];
|
||
jsSensorData["ProductNo"] = arrRes[j][17];
|
||
jsSensorData["configFlag"] = atoi(arrRes[j][18].c_str());
|
||
jsSensorData["startBrands"] = arrRes[j][19];
|
||
jsSensorData["stopBrands"] = arrRes[j][20];
|
||
jsSensorData["featureInterVal"] = atoi(arrRes[j][21].c_str());
|
||
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
|
||
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
|
||
// jsSensorData["scope"] = atoi(arrRes[j][24]);
|
||
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
|
||
jsSensorData["envelopeBandPass"] = arrRes[j][26];
|
||
jsSensorData["faultFrequency"] = arrRes[j][27];
|
||
jsSensorData["zigbeePanId"] = arrRes[j][28];
|
||
jsSensorData["zigbeeChannel"] = (arrRes[j][29]);
|
||
jsSensorData["zigbeeAddr"] = arrRes[j][30];
|
||
jsSensorData["zigbeeLongAddr"] = arrRes[j][31];
|
||
jsSensorData["zigbeeDesAddr"] = arrRes[j][32];
|
||
jsSensorData["ZigbeePower"] = atoi(arrRes[j][33].c_str());
|
||
jsSensorData["ZigbeeRetry"] = atoi(arrRes[j][34].c_str());
|
||
jsSensorData["ZigbeeRetryGap"] = atoi(arrRes[j][35].c_str());
|
||
jsSensorData["ACCSampleTime"] = atoi(arrRes[j][36].c_str());
|
||
jsSensorData["status"] = atoi(arrRes[j][37].c_str());
|
||
jsSensorData["timeStamp"] = arrRes[j][38];
|
||
jsSensorData["viff"] = atoi(arrRes[j][39].c_str());
|
||
vector<string> vParam;
|
||
|
||
print_info("loose = %s\n",arrRes[j][42].c_str());
|
||
boost::split( vParam, arrRes[j][42], boost::is_any_of( "," ), boost::token_compress_on );
|
||
|
||
if(vParam.size() > 1)
|
||
jsSensorData["loose"] = vParam[1];
|
||
else
|
||
jsSensorData["loose"] = "0";
|
||
|
||
vector<string> vParamRSSI;
|
||
boost::split( vParamRSSI, arrRes[j][40], boost::is_any_of( "," ), boost::token_compress_on );
|
||
if(vParamRSSI.size() > 1){
|
||
jsSensorData["RSSI"] = arrRes[j][40];
|
||
}else{
|
||
jsSensorData["RSSI"] = "0," + arrRes[j][40];
|
||
}
|
||
|
||
jsSensorData["update"] = atoi(arrRes[j][41].c_str());
|
||
jsSensorData["MeasurementID"] = arrRes[j][44];
|
||
jsSensorData["battery"] = arrRes[j][43];
|
||
jsArray.append(jsSensorData);
|
||
}
|
||
} else {
|
||
jsArray.resize(0);
|
||
jsonVal["success"] = true;
|
||
}
|
||
//LOG_INFO("26 end\n");
|
||
jsonVal["gatewayMac"] = GlobalConfig::MacAddr_G ;
|
||
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G ;
|
||
jsonVal["content"]["dataNodeArray"] = jsArray;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "54";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
Json::Value jsArray,nodeArray,gatewayArray;
|
||
array_t arrRes;
|
||
arrRes = sql_ctl->GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
|
||
int iResult = arrRes.size();
|
||
if (iResult > 0) {
|
||
int packgeNo = param.mPackageFlag;
|
||
int packgeMax = 0;
|
||
int packgeNum = 0;
|
||
jsonVal["package"] = packgeNo;
|
||
int lastSize = iResult % 10;
|
||
int index = iResult / 10;
|
||
if(lastSize > 0 && index > 0){
|
||
packgeMax = index +1;
|
||
if(packgeNo +1 == packgeMax){
|
||
packgeNum = iResult;
|
||
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;
|
||
}
|
||
|
||
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
||
Json::Value nodeArray;
|
||
char hex[100];
|
||
nodeArray.append(arrRes[j][0]);
|
||
stringToHex(arrRes[j][1].c_str(),hex);
|
||
print_info("hex = %s\n",hex);
|
||
nodeArray.append(hex);
|
||
nodeArray.append(arrRes[j][2]);
|
||
nodeArray.append(arrRes[j][3]);
|
||
nodeArray.append(arrRes[j][4]);
|
||
nodeArray.append(arrRes[j][5]);
|
||
nodeArray.append(arrRes[j][6]);
|
||
nodeArray.append(arrRes[j][7]);
|
||
nodeArray.append(arrRes[j][8]);
|
||
nodeArray.append(arrRes[j][9]);
|
||
nodeArray.append(arrRes[j][10]);
|
||
nodeArray.append(arrRes[j][11]);
|
||
nodeArray.append(arrRes[j][12]);
|
||
nodeArray.append(arrRes[j][13]);
|
||
nodeArray.append(arrRes[j][14]);
|
||
nodeArray.append(arrRes[j][15]);
|
||
nodeArray.append(arrRes[j][16]);
|
||
nodeArray.append(arrRes[j][17]);
|
||
nodeArray.append(arrRes[j][18]);
|
||
nodeArray.append(arrRes[j][19]);
|
||
nodeArray.append(arrRes[j][20]);
|
||
nodeArray.append(arrRes[j][21]);
|
||
nodeArray.append(arrRes[j][22]);
|
||
nodeArray.append(arrRes[j][23]);
|
||
nodeArray.append(arrRes[j][24]);
|
||
nodeArray.append(arrRes[j][25]);
|
||
nodeArray.append(arrRes[j][26]);
|
||
nodeArray.append(arrRes[j][27]);
|
||
nodeArray.append(arrRes[j][28]);
|
||
nodeArray.append(arrRes[j][29]);
|
||
nodeArray.append(arrRes[j][30]);
|
||
nodeArray.append(arrRes[j][31]);
|
||
nodeArray.append(arrRes[j][32]);
|
||
nodeArray.append(arrRes[j][33]);
|
||
nodeArray.append(arrRes[j][34]);
|
||
nodeArray.append(arrRes[j][35]);
|
||
nodeArray.append(arrRes[j][36]);
|
||
nodeArray.append(arrRes[j][37]);
|
||
nodeArray.append(arrRes[j][38]);
|
||
nodeArray.append(arrRes[j][39]);
|
||
nodeArray.append(arrRes[j][40]);
|
||
nodeArray.append(arrRes[j][41]);
|
||
nodeArray.append(arrRes[j][42]);
|
||
nodeArray.append(arrRes[j][43]);
|
||
nodeArray.append(arrRes[j][44]);
|
||
jsArray.append(nodeArray);
|
||
|
||
}
|
||
|
||
} else {
|
||
jsArray.resize(0);
|
||
jsonVal["success"] = true;
|
||
}
|
||
Json::Value jsSystemSetting,jsonValnet,jsonValnet1,jsSystemInfo,jsonValZigbee;
|
||
Json::Value jsBody;
|
||
|
||
jsSystemSetting["ServerIpAddress"] = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||
jsSystemSetting["ServerPort"] = (ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||
jsSystemSetting["CommMode"] = (ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||
jsSystemSetting["UserName"] = ReadStrByOpt(SERVERCONFIG, "Server", "UserName");
|
||
jsSystemSetting["Password"] = ReadStrByOpt(SERVERCONFIG, "Server", "Password");
|
||
jsSystemSetting["APN"] = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||
jsBody["ServerConfig"] = jsSystemSetting;
|
||
jsonVal["content"] = jsBody;
|
||
|
||
#ifdef G2UL_GATEWAY
|
||
jsonValnet1["dnsName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "dnsName");
|
||
jsonValnet1["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "networkPortStatus");
|
||
jsonValnet1["gateway"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "gateway");
|
||
jsonValnet1["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "subnetMask");
|
||
jsonValnet1["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "ipAddress");
|
||
jsonValnet1["hostName"] = ReadStrByOpt(NETWORKCONFIG, "eth1", "hostName");
|
||
jsonVal["content"]["eth1"] =jsonValnet1;
|
||
jsonVal["content"]["gatewaytype"] = 1;
|
||
#endif
|
||
|
||
jsSystemInfo["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||
jsSystemInfo["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||
jsSystemInfo["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||
jsSystemInfo["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
|
||
jsSystemInfo["GateWayProduct"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayProduct");
|
||
jsonVal["content"]["SystemInfo"] =jsSystemInfo;
|
||
|
||
jsonValZigbee["channel"] = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
|
||
jsonValZigbee["PanID"] = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "PanID");
|
||
jsonVal["content"]["zigbee"] =jsonValZigbee;
|
||
|
||
jsonVal["gatewayMac"] = GlobalConfig::MacAddr_G ;
|
||
jsonVal["gatewayIP"] = GlobalConfig::IpAddr_G ;
|
||
jsonVal["content"]["dataNodeArray"] = jsArray;
|
||
jsonVal["content"]["gateWay"] = gatewayArray;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "27";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
char whereCon[128] = { 0 };
|
||
char localtimestamp[32] = { 0 };
|
||
if (param.mDataNodeNo.length() > 0 && param.mType == "DELETE") {
|
||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||
sql_ctl->DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_DATANODE_TIME(TNAME), whereCon);
|
||
sql_ctl->DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||
char szTableName[50]={0x00};
|
||
sprintf(szTableName,"DROP TABLE t_data_%s",param.mDataNodeNo.c_str());
|
||
sql_ctl->CreateTable(szTableName, 0);
|
||
memset(szTableName,0x00,sizeof(szTableName));
|
||
sprintf(szTableName,"DROP TABLE t_dataStatic_%s",param.mDataNodeNo.c_str());
|
||
sql_ctl->CreateTable(szTableName, 0);
|
||
}else if(param.mDataNodeNo.length() > 0 && param.mType == "CORRECT"){
|
||
char updateSql[1024] = { 0 };
|
||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||
GetTimeNet(localtimestamp, 1);
|
||
sprintf(updateSql,"LooseValue = '0,2,");
|
||
string strUpdateSql = string(updateSql) + string(localtimestamp) + "' " ;
|
||
print_info("updateSql = %s\n",strUpdateSql.c_str());
|
||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME),strUpdateSql.c_str(),whereCon);
|
||
} else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "没有传感器号";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_28(Param_28 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "28";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
|
||
if (param.mDataNodeNo.length() > 0) {
|
||
char updateColumn[128] = { 0 };
|
||
char whereCon[64] = { 0 };
|
||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||
sprintf(updateColumn, "dataNodeName='%s'", param.mDataNodeName.c_str());
|
||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateColumn, whereCon);
|
||
} else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "没有传感器号";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
Json::Value jsBody;
|
||
Json::Value SystemSetting;
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "29";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
std::vector<float> vecWave;
|
||
/* 新增代码 */
|
||
char whereCon[64] = {};
|
||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||
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(),ios::in|ios::binary);
|
||
if (!inFile) {
|
||
print_error("read channel data error\n");
|
||
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);
|
||
}
|
||
//测试正弦波
|
||
//pCalculation->GenerateSin(vecWave);
|
||
|
||
//添加汉宁窗
|
||
/*pCalculation->Hanning(vecWave, hanningWave);
|
||
for(int i = 0; i < vecWave.size();i++){
|
||
vecWave[i] = (vecWave[i]*hanningWave[i]);
|
||
}*/
|
||
|
||
int flag = param.mPackageFlag;
|
||
flag = (flag + 1) * 1024;
|
||
int number = vecWave.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", vecWave[i]);
|
||
std::string waveTemp(buf);
|
||
strWaveData = waveTemp;
|
||
|
||
} else {
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%.2f", vecWave[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;
|
||
print_info("vecWave.size() = %d,sample = %d,second = %f\n",vecWave.size(),atoi(res[23].c_str()),float(vecWave.size()/atoi(res[23].c_str())));
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos && res[17]=="02"){
|
||
jsBody["second"] = float((float)vecWave.size()/(float)atoi(res[23].c_str()));
|
||
}else if(res[17]=="01"){
|
||
jsBody["second"] = float((float)vecWave.size()/(float)atoi(res[23].c_str()));
|
||
}else{
|
||
jsBody["second"] = 1;
|
||
}
|
||
|
||
jsBody["Data"] = strWaveData;
|
||
jsBody["timestamp"] = string(localtimestamp);
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m)
|
||
{
|
||
|
||
Json::Value jsonVal;
|
||
Json::Value jsBody;
|
||
Json::Value SystemSetting;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "30";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
int i = 0;
|
||
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;
|
||
int sampleRateReference = 0;
|
||
/* 新增代码 */
|
||
char whereCon[64] = {};
|
||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||
if (access(filename.c_str(), 0) >= 0)
|
||
{
|
||
std::ifstream inFile(filename.c_str(),ios::in|ios::binary);
|
||
if(!inFile)
|
||
{
|
||
print_error("read channel data error\n");
|
||
jsonVal["success"] = "false";
|
||
jsonVal["message"] = "error";
|
||
}else{
|
||
float fTemp = 0;
|
||
|
||
|
||
inFile.read((char *)localtimestamp,sizeof(localtimestamp));
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos && res[17]=="02") {
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}
|
||
//进行傅立叶变换
|
||
pCalculation->FFTSpec(vecWave, fftWave);
|
||
sampleRateReference = 1000;
|
||
|
||
}else{
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{ // 取8K进行计算
|
||
//if(i < 8192)
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}
|
||
// else{
|
||
// break;
|
||
// }
|
||
// i++;
|
||
}
|
||
//测试正弦波
|
||
//pCalculation->GenerateSin(vecWave);
|
||
|
||
// if(vecWave.size() < 8192){
|
||
// for(int i = vecWave.size(); i < 8192;i++){
|
||
// vecWave.push_back(0);
|
||
// }
|
||
// }
|
||
//添加汉宁窗
|
||
// pCalculation->Hanning(vecWave, hanningWave);
|
||
// for(int i = 0; i < vecWave.size();i++){
|
||
// addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
||
// }
|
||
|
||
//进行傅立叶变换
|
||
pCalculation->FFTSpec(vecWave, fftWave);
|
||
sampleRateReference = 1024;
|
||
|
||
}
|
||
/*for(int i = 0; i < fftWave.size();i++){
|
||
fftWave[i] = fftWave[i]*2;
|
||
}*/
|
||
printf("2---------------------------------------------->vecWave = %d,fftWave = %d\n",vecWave.size(),fftWave.size());
|
||
|
||
int flag = param.mPackageFlag;
|
||
flag = (flag + 1) * sampleRateReference;
|
||
int number = fftWave.size();
|
||
printf("number---------------------------------------------->%d\n",number);
|
||
int start = param.mPackageFlag * sampleRateReference;
|
||
printf("param.mPackageFlag = %d\n",param.mPackageFlag);
|
||
printf("param.start = %d\n",start);
|
||
printf("param.flag = %d\n",flag);
|
||
if (number < sampleRateReference) {
|
||
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;
|
||
print_info("max = %d\n",max);
|
||
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"] = string(localtimestamp);
|
||
jsBody["Data"] = strWaveData;
|
||
|
||
double resolution = 0.0;
|
||
int SampleRate =0;
|
||
print_info("sensor type %s\n",res[17].c_str());
|
||
if(res[17]=="01"){
|
||
SampleRate = atoi(res[23].c_str());
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1000)*1016)/ vecWave.size();
|
||
//resolution = (double)SampleRate/vecWave.size();
|
||
|
||
}else if(res[17]=="02"){
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos) {
|
||
SampleRate = atoi(res[23].c_str());
|
||
resolution = (double)SampleRate/vecWave.size();
|
||
//resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||
}else{
|
||
SampleRate = 8192;
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
if (vecWave.size() < 8192)
|
||
{
|
||
resolution = (double)SampleRate/ vecWave.size();
|
||
}else{
|
||
|
||
resolution = (double)SampleRate/ 8192;
|
||
}
|
||
}
|
||
}
|
||
|
||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n",SampleRate,resolution);
|
||
char buf[32];
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%f", resolution);
|
||
jsBody["resolution"] = std::string(buf);
|
||
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m)
|
||
{
|
||
|
||
Json::Value jsonVal;
|
||
Json::Value jsBody;
|
||
Json::Value SystemSetting;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "40";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
int i = 0;
|
||
int sampleRateReference = 0;
|
||
std::vector<float> vecWave;
|
||
/* 新增代码 */
|
||
char whereCon[64] = {};
|
||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||
std::string strWaveData;
|
||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||
char localtimestamp[32] = { 0 };
|
||
if (access(filename.c_str(), 0) >= 0)
|
||
{
|
||
std::ifstream inFile(filename.c_str(),ios::in|ios::binary);
|
||
if(!inFile)
|
||
{
|
||
print_error("read channel data error\n");
|
||
jsonVal["success"] = "false";
|
||
jsonVal["message"] = "error";
|
||
}else{
|
||
float fTemp = 0;
|
||
|
||
std::vector<float> envWave;
|
||
std::vector<float> hanningWave;
|
||
std::vector<float> addhanningWave;
|
||
inFile.read((char *)localtimestamp,sizeof(localtimestamp));
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos && res[17]=="02") {
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}
|
||
//添加汉宁窗
|
||
pCalculation->Hanning(vecWave, hanningWave);
|
||
for(int i = 0; i < vecWave.size();i++){
|
||
addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
||
}
|
||
|
||
//进行傅立叶变换
|
||
if(param.StartFrequency == 0){
|
||
param.StartFrequency = 3000;
|
||
param.EndFrequency = 5000;
|
||
}
|
||
|
||
pCalculation->envSpec(addhanningWave, envWave,param.StartFrequency,param.EndFrequency);
|
||
sampleRateReference = 1000;
|
||
|
||
}else{
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{ // 取8K进行计算
|
||
if(i < 8192)
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}else{
|
||
break;
|
||
}
|
||
i++;
|
||
}
|
||
if(vecWave.size() < 8192){
|
||
for(int i = vecWave.size(); i < 8192;i++){
|
||
vecWave.push_back(0);
|
||
}
|
||
}
|
||
|
||
//添加汉宁窗
|
||
pCalculation->Hanning(vecWave, hanningWave);
|
||
for(int i = 0; i < vecWave.size();i++){
|
||
addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
||
}
|
||
|
||
//进行傅立叶变换
|
||
if(param.StartFrequency == 0){
|
||
param.StartFrequency = 3000;
|
||
param.EndFrequency = 5000;
|
||
}
|
||
|
||
pCalculation->envSpec(addhanningWave, envWave,param.StartFrequency,param.EndFrequency);
|
||
sampleRateReference = 1024;
|
||
}
|
||
/*for(int i = 0; i < envWave.size();i++){
|
||
envWave[i] = envWave[i]*2;
|
||
}*/
|
||
|
||
printf("2---------------------------------------------->%d\n",envWave.size());
|
||
printf("2---------------------------------------------->%f\n",envWave[10]);
|
||
|
||
print_info("after fft--------------------------------------------------->fftWave.size()=%d\n", envWave.size());
|
||
|
||
int flag = param.mPackageFlag;
|
||
flag = (flag + 1) * sampleRateReference;
|
||
int number = envWave.size();
|
||
int start = param.mPackageFlag * sampleRateReference;
|
||
printf("param.mPackageFlag = %d\n",param.mPackageFlag);
|
||
printf("param.start = %d\n",start);
|
||
printf("param.flag = %d\n",flag);
|
||
if (number < sampleRateReference) {
|
||
flag = number;
|
||
start = 0;
|
||
}
|
||
char buf[32];
|
||
for (int i = start; i < flag; i++) {
|
||
if ( i == start ) {
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%.6f", envWave[i]);
|
||
std::string waveTemp(buf);
|
||
strWaveData = waveTemp;
|
||
|
||
} else {
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%.6f", envWave[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"] = string(localtimestamp);
|
||
jsBody["Data"] = strWaveData;
|
||
|
||
double resolution = 0.0;
|
||
int SampleRate =0;
|
||
print_info("sensor type %s\n",res[17].c_str());
|
||
if(res[17]=="01"){
|
||
SampleRate = atoi(res[23].c_str());
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1000)*1016)/ 8192;
|
||
}else if(res[17]=="02"){
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos) {
|
||
SampleRate = atoi(res[23].c_str());
|
||
|
||
resolution = (double)SampleRate/vecWave.size();
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||
}else{
|
||
SampleRate = 8000;
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1000)*1024)/ 8192;
|
||
}
|
||
}
|
||
|
||
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n",SampleRate,resolution);
|
||
char buf[32];
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%f", resolution);
|
||
jsBody["resolution"] = std::string(buf);
|
||
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_41(std::vector<Param_41> ¶m,int isServer)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "41";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = " ";
|
||
|
||
char whereCon[1024] = {0};
|
||
char updateSql[1024] = { 0 };
|
||
//int WaveInteerVal = param.mwaveInterVal/param.mfeatureInterVal;
|
||
|
||
for(int i = 0; i < param.size();i++){
|
||
char dataNodeName[100]={0x00};
|
||
hexToAscii(param[i].mdataNodeName.c_str(),dataNodeName);
|
||
print_info("str = %s\n",dataNodeName);
|
||
print_info("dataNodeName = %s\n",param[i].mdataNodeName.c_str());
|
||
int dataNodeNameLength = param[i].mdataNodeName.length();
|
||
if(dataNodeNameLength != 0 ){
|
||
sprintf(updateSql, "dataNodeName = '%s',ZigbeePower = '%d',ZigbeeRetry = '%d',featureInterVal='%d',waveInterVal='%d',range='%d',samplingRate='%d',AccSampleTime = '%d',\
|
||
startBrands = '%s',stopBrands = '%s',envelopeBandPass = '%s',viff = '%d',faultFrequency = '%s' ,MeasurementID = '%s' ,UpdateFlag = -1",
|
||
dataNodeName,param[i].ZigbeePower,param[i].ZigbeeRetry,param[i].mfeatureInterVal, param[i].mwaveInterVal,param[i].mrange,\
|
||
param[i].msamplingRate,param[i].mAccSampleTime, param[i].mstartBrands.c_str(),\
|
||
param[i].mstopBrands.c_str(),param[i].menvelopeBandPass.c_str(),param[i].mviff,param[i].mfaultFrequency.c_str(),param[i].mMeasurementID.c_str());
|
||
}else if(dataNodeNameLength == 0 ){
|
||
sprintf(updateSql, "ZigbeePower = '%d',ZigbeeRetry = '%d',featureInterVal='%d',waveInterVal='%d',range='%d',samplingRate='%d',AccSampleTime = '%d',\
|
||
startBrands = '%s',stopBrands = '%s',envelopeBandPass = '%s',viff = '%d',faultFrequency = '%s',MeasurementID = '%s',UpdateFlag = 0",
|
||
param[i].ZigbeePower,param[i].ZigbeeRetry,param[i].mfeatureInterVal, param[i].mwaveInterVal,param[i].mrange,\
|
||
param[i].msamplingRate,param[i].mAccSampleTime, param[i].mstartBrands.c_str(),\
|
||
param[i].mstopBrands.c_str(),param[i].menvelopeBandPass.c_str(),param[i].mviff,param[i].mfaultFrequency.c_str(),param[i].mMeasurementID.c_str());
|
||
}
|
||
if(!isServer)
|
||
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
|
||
else
|
||
sprintf(whereCon, "MeasurementID ='%s'", param[i].mdataNodeNo.c_str());
|
||
|
||
int iRet = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||
memset(whereCon,0x00,sizeof(whereCon));
|
||
memset(updateSql,0x00,sizeof(updateSql));
|
||
if(iRet != 0)
|
||
jsonVal["success"] = false;
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "42";
|
||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "上传成功!";
|
||
char cmd[100]={0x00};
|
||
strcpy(cmd,"rm -rf /tmp/cgic*");
|
||
system(cmd);
|
||
if(param.fileName == "DataNode.tar"){
|
||
string strcmd = "tar xvf /opt/";
|
||
strcmd = strcmd + param.fileName;
|
||
strcmd = strcmd + " -C /opt/";
|
||
print_info("strcmd = %s\n",strcmd.c_str());
|
||
system(strcmd.c_str());
|
||
}else if(param.fileName == "rfsbu.tar"){
|
||
LOG_INFO("update rfsbu.tar\n");
|
||
sleep(3);
|
||
print_info("strcmd = %s\n",param.fileName.c_str());
|
||
system("/opt/opt.sh");
|
||
}else if(param.fileName == "update.json"){
|
||
print_info("strcmd = %s\n",param.fileName.c_str());
|
||
|
||
ReadStrConfig("/opt/update.json");
|
||
}else if(param.fileName == "backup.json"){
|
||
ImportConfig("/opt/backup.json");
|
||
}else if(param.fileName == "DataNode.csv"){
|
||
print_info("strcmd = %s\n",param.fileName.c_str());
|
||
|
||
int iRet = UpdataDataNodeConfig("/opt/DataNode.csv");
|
||
string str = to_string(iRet) + "个传感器更新成功";
|
||
if(iRet < 0){
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "更新失败!";
|
||
}else{
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = str;
|
||
}
|
||
|
||
}else {
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "文件名错误!";
|
||
}
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
std::string JsonData::JsonCmd_Cgi_31(Param_31 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["cmd"] = "31";
|
||
if(0 == param.mMode)
|
||
{
|
||
/*char buf[32];
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%d", param.mChannelId);
|
||
print_red("@@@@@@@@@@@@@@@@,,,,,%s\n",buf);
|
||
WriteStr2Config(ZIGBEECONFIG, "Zigbee", "channel", std::string(buf));*/
|
||
WriteStr2Config(ZIGBEECONFIG, "Zigbee", "channel", param.mChannelId);
|
||
WriteStr2Config(ZIGBEECONFIG, "Zigbee", "PanID", param.mPanID);
|
||
//pUart->ZigbeeInit();
|
||
//pUart->UpdateZigbeeInfoCtrl();
|
||
}
|
||
Json::Value jsBody;
|
||
jsonVal["message"] = "设置完成";
|
||
jsonVal["success"] = true;
|
||
jsBody["channel"] = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
|
||
jsBody["panID"] = GlobalConfig::ZigbeeInfo_G.PanID;
|
||
jsBody["RetryNum"] = GlobalConfig::ZigbeeInfo_G.RetryNum;
|
||
jsBody["TranTimeout"] = GlobalConfig::ZigbeeInfo_G.TranTimeout;
|
||
jsBody["status"] = "1";
|
||
jsonVal["content"] = jsBody;
|
||
|
||
return showValue.write(jsonVal);
|
||
|
||
}
|
||
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_32(Param_32 ¶m)
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
|
||
jsonVal["cmd"] = "32";
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
Json::Value jsBody;
|
||
std::string strWaveData;
|
||
// if (GlobalConfig::WaveFFtCgi.flag == 1) {
|
||
// int number = GlobalConfig::WaveFFtCgi.number;
|
||
// char buf[32];
|
||
// int flag = param.mPackageFlag;
|
||
// flag = (flag + 1) * 1024;
|
||
// int start = param.mPackageFlag * 1024;
|
||
// if ( number < 1024) {
|
||
// flag = number;
|
||
// start = 0;
|
||
// }
|
||
// for (int i = start; i < flag; i++) {
|
||
// if ( i == start ) {
|
||
// strWaveData = (boost::lexical_cast<std::string>(GlobalConfig::WaveFFtCgi.waveData[i])).substr(0.4);
|
||
// } else {
|
||
// memset(buf, 0, 32);
|
||
// sprintf(buf, "%.2f", GlobalConfig::WaveFFtCgi.waveData[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;
|
||
jsBody["Data"] = strWaveData;
|
||
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_43()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = true;
|
||
jsonVal["message"] = "";
|
||
|
||
// int flag = CheckNic("eth0");
|
||
// Json::Value jsBody;
|
||
// if (0 == flag) {
|
||
// jsBody["status"] = 1;
|
||
// } else {
|
||
// jsBody["status"] = 0;
|
||
// }
|
||
// jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|
||
|
||
|
||
std::string JsonData::JsonCmd_Cgi_default()
|
||
{
|
||
Json::Value jsonVal;
|
||
jsonVal.clear();
|
||
jsonVal["success"] = false;
|
||
jsonVal["message"] = "功能不支持";
|
||
|
||
return showValue.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 showValue.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 showValue.write(jsonVal);
|
||
}
|
||
|
||
return showValue.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 showValue.write(jsonVal);
|
||
}
|
||
|
||
return showValue.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 showValue.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 };
|
||
string gatewayLocation = "";
|
||
|
||
sprintf(updateSql, "gatewayLocation='%s'",
|
||
param.strGateWayLocation.c_str());
|
||
sprintf(whereCon, "gatewayMAC='%s'", param.strGateWayMAC.c_str());
|
||
if(param.mMode == 0){
|
||
int iRet = sql_ctl->UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||
if(iRet != 0)
|
||
jsonVal["success"] = false;
|
||
}else{
|
||
gatewayLocation = sql_ctl->GetData(T_GATEWAY_INFO(TNAME) ,"gatewayLocation", NULL);
|
||
jsBody["gateWayLocation"] = gatewayLocation;
|
||
}
|
||
|
||
|
||
|
||
jsonVal["content"] = jsBody;
|
||
|
||
return showValue.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";
|
||
print_info("netssid : %s %d\n", 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) { // 设置
|
||
print_info("set WiFi\n");
|
||
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 showValue.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(int 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 = sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||
memset(whereCon,0x00,sizeof(whereCon));
|
||
memset(updateSql,0x00,sizeof(updateSql));
|
||
if(iRet != 0)
|
||
jsonVal["success"] = false;
|
||
}
|
||
return showValue.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 = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||
int SampleRate =0;
|
||
double resolution = 0.0;
|
||
SampleRate = atoi(res[23].c_str());
|
||
print_info("sensor type %s\n",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(),ios::in|ios::binary);
|
||
if (!inFile) {
|
||
print_error("read channel data error\n");
|
||
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"){
|
||
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1000)*1016)/ 8192;
|
||
|
||
}else if(res[17]=="02"){
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos) {
|
||
resolution = (double)SampleRate/vecWave.size();
|
||
//resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||
}else{
|
||
SampleRate = 8000;
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1024)*1024)/ 8192;
|
||
}
|
||
}
|
||
|
||
//积分
|
||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||
|
||
//测试正弦波
|
||
// pCalculation->GenerateSin(vecWave);
|
||
// pCalculation->Integration(vecWave, IntegrationWave);
|
||
|
||
//添加汉宁窗
|
||
/*pCalculation->Hanning(vecWave, hanningWave);
|
||
for(int i = 0; i < vecWave.size();i++){
|
||
vecWave[i] = (vecWave[i]*hanningWave[i]);
|
||
}*/
|
||
|
||
int flag = param.mPackageFlag;
|
||
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;
|
||
print_info("vecWave.size() = %d,sample = %d,second = %f\n",IntegrationWave.size(),atoi(res[23].c_str()),float(IntegrationWave.size()/atoi(res[23].c_str())));
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != 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"] = string(localtimestamp);
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.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"] = "";
|
||
int i = 0;
|
||
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] = {};
|
||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||
int SampleRate =0;
|
||
double resolution = 0.0;
|
||
SampleRate = atoi(res[23].c_str());
|
||
print_info("sensor type %s\n",res[17].c_str());
|
||
|
||
|
||
if (access(filename.c_str(), 0) >= 0)
|
||
{
|
||
std::ifstream inFile(filename.c_str(),ios::in|ios::binary);
|
||
if(!inFile)
|
||
{
|
||
print_error("read channel data error\n");
|
||
jsonVal["success"] = "false";
|
||
jsonVal["message"] = "error";
|
||
}else{
|
||
float fTemp = 0;
|
||
|
||
|
||
inFile.read((char *)localtimestamp,sizeof(localtimestamp));
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos && res[17]=="02") {
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}
|
||
//积分
|
||
resolution = (double)SampleRate/vecWave.size();
|
||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||
sampleRateReference = 1000;
|
||
|
||
}else{
|
||
while(inFile.read((char *)&fTemp,sizeof(fTemp)))
|
||
{ // 取8K进行计算
|
||
//if(i < 8192)
|
||
{
|
||
vecWave.push_back(fTemp);
|
||
}
|
||
// else{
|
||
// break;
|
||
// }
|
||
// i++;
|
||
}
|
||
if(res[17]=="01"){
|
||
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
resolution = (((double)SampleRate/1000)*1016)/ vecWave.size();
|
||
//resolution = (double)SampleRate/vecWave.size();
|
||
|
||
}else if(res[17]=="02"){
|
||
string::size_type comper = param.mChannelId.find("Z");
|
||
if (comper != string::npos) {
|
||
SampleRate = atoi(res[23].c_str());
|
||
resolution = (double)SampleRate/vecWave.size();
|
||
//resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||
}else{
|
||
SampleRate = 8192;
|
||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||
if (vecWave.size() < 8192)
|
||
{
|
||
resolution = (double)SampleRate/ vecWave.size();
|
||
}else{
|
||
resolution = (double)SampleRate/ 8192;
|
||
}
|
||
}
|
||
}
|
||
//测试正弦波
|
||
//pCalculation->GenerateSin(vecWave);
|
||
|
||
// if(vecWave.size() < 8192){
|
||
// for(int i = vecWave.size(); i < 8192;i++){
|
||
// vecWave.push_back(0);
|
||
// }
|
||
// }
|
||
// //添加汉宁窗
|
||
// pCalculation->Hanning(vecWave, hanningWave);
|
||
// for(int i = 0; i < vecWave.size();i++){
|
||
// addhanningWave.push_back(vecWave[i]*hanningWave[i]);
|
||
// }
|
||
|
||
// //积分
|
||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||
|
||
sampleRateReference = 1024;
|
||
}
|
||
/*for(int i = 0; i < fftWave.size();i++){
|
||
fftWave[i] = fftWave[i]*2;
|
||
}*/
|
||
printf("2---------------------------------------------->vecWave = %d,fftWave = %d\n",vecWave.size(),fftWave.size());
|
||
|
||
int flag = param.mPackageFlag;
|
||
flag = (flag + 1) * sampleRateReference;
|
||
int number = fftWave.size();
|
||
printf("number---------------------------------------------->%d\n",number);
|
||
int start = param.mPackageFlag * sampleRateReference;
|
||
printf("param.mPackageFlag = %d\n",param.mPackageFlag);
|
||
printf("param.start = %d\n",start);
|
||
printf("param.flag = %d\n",flag);
|
||
if (number < sampleRateReference) {
|
||
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"] = string(localtimestamp);
|
||
jsBody["Data"] = strWaveData;
|
||
|
||
|
||
|
||
|
||
|
||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n",SampleRate,resolution);
|
||
char buf[32];
|
||
memset(buf, 0, 32);
|
||
sprintf(buf, "%f", resolution);
|
||
jsBody["resolution"] = std::string(buf);
|
||
|
||
jsonVal["content"] = jsBody;
|
||
return showValue.write(jsonVal);
|
||
}
|
||
|