add wave convert to 25600

This commit is contained in:
zhangsheng 2024-11-25 10:20:28 +08:00
parent fad8c2928c
commit 6440866aa8
16 changed files with 150 additions and 63 deletions

BIN
Cidn-SH

Binary file not shown.

View File

@ -42,7 +42,6 @@
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/xpressive/xpressive_dynamic.hpp> #include <boost/xpressive/xpressive_dynamic.hpp>
#include <json/json.h>
#include <zlog.h> #include <zlog.h>
#include "global.hpp" #include "global.hpp"
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
@ -1046,7 +1045,7 @@ int getSysIntValue(char *key) {
return value; return value;
} }
std::string GetSysStatus() { std::string GetSysStatus(Json::Value &jsData) {
long mem_used = -1; long mem_used = -1;
long mem_free = -1; long mem_free = -1;
long mem_total = -1; long mem_total = -1;
@ -1098,7 +1097,6 @@ std::string GetSysStatus() {
sprintf(key, "/sys/class/thermal/thermal_zone0/temp"); sprintf(key, "/sys/class/thermal/thermal_zone0/temp");
int temp = getSysIntValue(key); int temp = getSysIntValue(key);
Json::Value jsData;
Json::FastWriter fw; Json::FastWriter fw;
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsData["cpuUserUse"] = rateUser; jsData["cpuUserUse"] = rateUser;

View File

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <json/json.h>
typedef struct statfs DISK, *pDISK; typedef struct statfs DISK, *pDISK;
@ -378,7 +379,7 @@ void ZoneConfig(std::string zoneid);
* @brief * @brief
* @return std::string CPU MEM DISK info * @return std::string CPU MEM DISK info
*/ */
std::string GetSysStatus(); std::string GetSysStatus(Json::Value &jsData);
bool CheckIP(const char* ip); bool CheckIP(const char* ip);

View File

@ -11,7 +11,7 @@ public:
void DataNodeStatusCheck(); void DataNodeStatusCheck();
// mqtt command // mqtt command
std::string JsonCmd_07(); //获取系统内存温度硬盘等信息 int JsonCmd_07(); //获取系统内存温度硬盘等信息
std::string JsonCmd_20(Param_20 &param); std::string JsonCmd_20(Param_20 &param);
std::string JsonCmd_22(Param_22 &param); //时区配置 std::string JsonCmd_22(Param_22 &param); //时区配置
std::string JsonCmd_23(Param_23 &param); //服务器配置 std::string JsonCmd_23(Param_23 &param); //服务器配置

View File

@ -480,13 +480,12 @@ std::string JsonData::JsonCmd_53(Json::Value &recvBody) {
int JsonData::JsonCmd_29() { int JsonData::JsonCmd_29() {
Json::Value jsonVal; Json::Value jsonVal;
Json::Value jsBody; Json::Value jsBody;
Json::Value jsSystemSetting;
jsonVal.clear(); jsonVal.clear();
jsonVal["cmd"] = "29"; jsonVal["cmd"] = "29";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsSystemSetting["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion"); jsonVal["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
jsSystemSetting["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); jsonVal["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
jsSystemSetting["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); jsonVal["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
jsBody["localIP"] = GlobalConfig::IpAddr_G; jsBody["localIP"] = GlobalConfig::IpAddr_G;
jsBody["dataNodeGatewayType"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayProduct"); jsBody["dataNodeGatewayType"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayProduct");
jsBody["CommMode"] = "有线"; jsBody["CommMode"] = "有线";
@ -500,8 +499,7 @@ int JsonData::JsonCmd_29() {
jsBody["CommMode"] = "WiFi"; jsBody["CommMode"] = "WiFi";
#endif #endif
jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion"); jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -528,8 +526,7 @@ int JsonData::JsonCmd_30(){
jsSensorData["dataNodeName"] = arrRes[j][1]; jsSensorData["dataNodeName"] = arrRes[j][1];
jsSensorData["acc"] = atoi(arrRes[j][3].c_str()); jsSensorData["acc"] = atoi(arrRes[j][3].c_str());
jsSensorData["zigbee"] = atoi(arrRes[j][4].c_str()); jsSensorData["zigbee"] = atoi(arrRes[j][4].c_str());
jsSensorData["temTop"] = atoi(arrRes[j][5].c_str());
jsSensorData["temBot"] = atoi(arrRes[j][6].c_str());
jsSensorData["hwVersion"] = arrRes[j][8]; jsSensorData["hwVersion"] = arrRes[j][8];
jsSensorData["softVersion"] = arrRes[j][9]; jsSensorData["softVersion"] = arrRes[j][9];
jsSensorData["bpNo"] = arrRes[j][10]; jsSensorData["bpNo"] = arrRes[j][10];
@ -588,6 +585,18 @@ int JsonData::JsonCmd_30(){
} else { } else {
jsSensorData["battery"] = 0.99; jsSensorData["battery"] = 0.99;
} }
char whereCon[50]={0x00};
sprintf(whereCon,"dataNodeNo = '%s'",arrRes[j][44].c_str());
vec_t vecRes = sqlite_db_ctrl::instance().GetDataSingleLine(T_DATASTATIC_INFO(TNAME), "temTop,temBot",whereCon);
if (vecRes.size() > 0)
{
jsSensorData["temTop"] = atof(vecRes[0].c_str());
jsSensorData["temBot"] = atof(vecRes[1].c_str());
}else{
jsSensorData["temTop"] = 200.0;
jsSensorData["temBot"] = 200.0;
}
jsArray.append(jsSensorData); jsArray.append(jsSensorData);
} }
} else { } else {
@ -596,8 +605,7 @@ int JsonData::JsonCmd_30(){
} }
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsBody["dataNodeArray"] = jsArray; jsBody["dataNodeArray"] = jsArray;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -612,7 +620,7 @@ int JsonData::JsonCmd_31(){
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
Json::Value jsBody; Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "31"; jsonVal["cmd"] = "31";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = ""; jsonVal["message"] = "";
int sensorCount = 0; int sensorCount = 0;
@ -630,8 +638,7 @@ int JsonData::JsonCmd_31(){
jsBody["waveInterTime"] = waveInterTime; jsBody["waveInterTime"] = waveInterTime;
jsBody["maxSensorNum"] = maxSensorNum; jsBody["maxSensorNum"] = maxSensorNum;
jsBody["sensorCount"] = sensorCount; jsBody["sensorCount"] = sensorCount;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -646,7 +653,7 @@ int JsonData::JsonCmd_32(std::string MeasurementID,int status,int type,std::str
jsonVal.clear(); jsonVal.clear();
Json::Value jsBody; Json::Value jsBody;
Json::FastWriter show_value_; Json::FastWriter show_value_;
jsonVal["CMD"] = "32"; jsonVal["cmd"] = "32";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = ""; jsonVal["message"] = "";
jsBody["dataNodeNo"] = MeasurementID; jsBody["dataNodeNo"] = MeasurementID;
@ -654,8 +661,7 @@ int JsonData::JsonCmd_32(std::string MeasurementID,int status,int type,std::str
jsBody["errorType"] = type; jsBody["errorType"] = type;
jsBody["errorData"] = Data; jsBody["errorData"] = Data;
jsBody["errorMsg"] = Msg; jsBody["errorMsg"] = Msg;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char timestamp[32] = {0}; char timestamp[32] = {0};
GetTimeNet(timestamp, 1); GetTimeNet(timestamp, 1);
jsonVal["timestamp"] = timestamp; jsonVal["timestamp"] = timestamp;
@ -713,10 +719,11 @@ void JsonData::DataNodeStatusCheck() {
} }
} }
std::string JsonData::JsonCmd_07() { int JsonData::JsonCmd_07() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsData;
std::string sysStatus = GetSysStatus(jsData);
zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
@ -729,10 +736,14 @@ std::string JsonData::JsonCmd_07() {
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
if (recvReader.parse(sysStatus, recvSys)) { if (recvReader.parse(sysStatus, recvSys)) {
jsonVal["cmdBody"] = sysStatus; jsonVal["cmdBody"] = jsData;
} else { } else {
jsonVal["success"] = false; jsonVal["success"] = false;
jsonVal["message"] = "状态获取失败"; jsonVal["message"] = "状态获取失败";
} }
return show_value_.write(jsonVal); int res = data_publish(show_value_.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
if(res !=0 ){
zlog_warn(zct, "data_publish res = %d", res);
}
return 0;
} }

View File

@ -112,7 +112,8 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 &param) {
std::string JsonData::JsonCmd_Cgi_07() { std::string JsonData::JsonCmd_Cgi_07() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsBody;
std::string sysStatus = GetSysStatus(jsBody);
zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
@ -133,7 +134,8 @@ std::string JsonData::JsonCmd_Cgi_07() {
std::string JsonData::JsonCmd_Cgi_08() { std::string JsonData::JsonCmd_Cgi_08() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsBody;
std::string sysStatus = GetSysStatus(jsBody);
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
Json::Reader recvReader(f); Json::Reader recvReader(f);

View File

@ -229,6 +229,19 @@ std::string JsonData::JsonCmd_Cgi_53(std::vector<Param_53> &param) {
char whereCon[1024] = {0}; char whereCon[1024] = {0};
char updateSql[1024] = {0}; char updateSql[1024] = {0};
for (size_t i = 0; i < param.size(); i++) { for (size_t i = 0; i < param.size(); i++) {
sprintf(whereCon, "dataNodeNo='%s'", param[i].mdataNodeNo.c_str());
std::string zigbeeShortAddr = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
uint16_t short_addr;
char *end_ptr = NULL;
short_addr = strtol(zigbeeShortAddr.c_str(), &end_ptr, 16);
int res = scheduler::instance().UpdateSensorConfig(short_addr);
if (res != 0){
jsonVal["success"] = false;
jsonVal["message"] = "update config error";
return show_value_.write(jsonVal);
}
if (param[i].mUpdateKey2 == "") { if (param[i].mUpdateKey2 == "") {
sprintf(updateSql, "%s='%s',UpdateFlag = 0", param[i].mUpdateKey.c_str(), param[i].mUpdateValue.c_str()); sprintf(updateSql, "%s='%s',UpdateFlag = 0", param[i].mUpdateKey.c_str(), param[i].mUpdateValue.c_str());
} else if (param[i].mUpdateKey3 == "" && param[i].mUpdateKey2 != "") { } else if (param[i].mUpdateKey3 == "" && param[i].mUpdateKey2 != "") {

View File

@ -45,11 +45,11 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
} }
switch (cmdType) { switch (cmdType) {
case kHWStatus: { // case kHWStatus: {
JsonData jd; // JsonData jd;
std::string data = jd.JsonCmd_07(); // std::string data = jd.JsonCmd_07();
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str()); // data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
} break; // } break;
case kRebootSystem: { case kRebootSystem: {
recvValue["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; recvValue["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
recvValue["status"] = "ACK"; recvValue["status"] = "ACK";

View File

@ -205,7 +205,8 @@ int data_publish(const char *str, const char *topic) {
int ret = -1; int ret = -1;
if (mosq != NULL) { if (mosq != NULL) {
std::string strTopic = std::string(topic); std::string strTopic = std::string(topic);
if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos) { if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos || strTopic.find("status") != std::string::npos) {
zlog_info(zct,"strTopic = %s,pData = %s",strTopic.c_str(),str);
std::string pData = (std::string)str; std::string pData = (std::string)str;
char *base64_aes = new char[pData.length() * 2]; char *base64_aes = new char[pData.length() * 2];
memset(base64_aes, 0, pData.length() * 2); memset(base64_aes, 0, pData.length() * 2);

View File

@ -257,17 +257,17 @@ SensorScheduler::SensorScheduler() {
seconds_per_wave_slice_ = rest_duration / wave_slice_num_per_eigen_interval_; seconds_per_wave_slice_ = rest_duration / wave_slice_num_per_eigen_interval_;
} else { } else {
zlog_info(zbt, "use default configuration"); zlog_info(zbt, "use default configuration");
// int eigen_value_send_interval = 300; int eigen_value_send_interval = 300;
// int wave_form_send_interval = 7200; int wave_form_send_interval = 7200;
// int eigen_value_send_duration = 6;
// int wave_form_send_duration = 50;
// int max_sensor_num = 32;
int eigen_value_send_interval = 120;
int wave_form_send_interval = 240;
int eigen_value_send_duration = 6; int eigen_value_send_duration = 6;
int wave_form_send_duration = 40; int wave_form_send_duration = 50;
int max_sensor_num = 4; int max_sensor_num = 32;
// int eigen_value_send_interval = 120;
// int wave_form_send_interval = 240;
// int eigen_value_send_duration = 6;
// int wave_form_send_duration = 40;
// int max_sensor_num = 4;
std::string error_msg; std::string error_msg;
Config(eigen_value_send_interval, Config(eigen_value_send_interval,
wave_form_send_interval, wave_form_send_interval,

View File

@ -100,8 +100,7 @@ void CheckThread() {
} }
if (HardStatus == 3600) { // one hour 3600 if (HardStatus == 3600) { // one hour 3600
JsonData jd; JsonData jd;
std::string data = jd.JsonCmd_07(); jd.JsonCmd_07();
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
HardStatus = 0; HardStatus = 0;
} }
if (mqttresend == 7200) { if (mqttresend == 7200) {

View File

@ -44,7 +44,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
ret = read_data(fd, buff, BUF_LENGTH, 10); ret = read_data(fd, buff, BUF_LENGTH, 10);
if (ret <= 0) { if (ret <= 0) {
timeoutflag++; timeoutflag++;
if (timeoutflag > 100) { if (timeoutflag > 300) {
DealReviveDuration(wave_shortAddr); DealReviveDuration(wave_shortAddr);
zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr)); zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr));
zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize); zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
@ -67,7 +67,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
memcpy(mUartRecvTmpBuf + offSize, buff, ret); memcpy(mUartRecvTmpBuf + offSize, buff, ret);
offSize = offSize + ret; offSize = offSize + ret;
if (offSize > BUF_LENGTH * 15) { if (offSize > BUF_LENGTH * 15) {
zlog_info(zct, "maxSize = %d", offSize); zlog_warn(zct, "maxSize = %d", offSize);
memset(mUartRecvTmpBuf, 0, BUF_LENGTH); memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
timeoutflag = 0; timeoutflag = 0;
offSize = 0; offSize = 0;
@ -99,8 +99,17 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
zlog_info(zct, "\n"); zlog_info(zct, "\n");
timeoutflag = 0; timeoutflag = 0;
m_TimeStamp = 0; m_TimeStamp = 0;
if (offSize > sizeof(szbuffer)) {
zlog_warn(zct, "maxSize = %d", offSize);
memset(szbuffer, 0, sizeof(szbuffer));
timeoutflag = 0;
offSize = 0;
maxSize = 0;
tcflush(fd, TCIOFLUSH);
}
memcpy(szbuffer + offSize, buff, ret); memcpy(szbuffer + offSize, buff, ret);
offSize = offSize + ret; offSize = offSize + ret;
} }
} }
} }
@ -544,7 +553,13 @@ void Uart::DealRecvData(const char *pData) {
DealUpgrade(ushortAdd,2); DealUpgrade(ushortAdd,2);
scheduler::instance().UpgradeResult(ushortAdd,0); scheduler::instance().UpgradeResult(ushortAdd,0);
zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
}else{ }else if (recvcode == 5)
{
DealUpgrade(ushortAdd,2);
scheduler::instance().UpgradeResult(ushortAdd,0);
zlog_warn(zbt, "[UPGRADE ALREADY] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
}else
{
DealUpgrade(ushortAdd,3); DealUpgrade(ushortAdd,3);
scheduler::instance().UpgradeResult(ushortAdd,recvcode); scheduler::instance().UpgradeResult(ushortAdd,recvcode);
zlog_warn(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); zlog_warn(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);

View File

@ -183,7 +183,7 @@ public:
void DealWave(); void DealWave();
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct); std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
float Calcoe(int ran, int iChannel, std::string& product, int range); float Calcoe(int ran, int iChannel, std::string& product, int range);
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData); void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product);
float ScaleConvert(int highbit); float ScaleConvert(int highbit);
void DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n); void DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n);

View File

@ -10,6 +10,8 @@
#include <json/json.h> #include <json/json.h>
#include "mqttclient/mqtt_client.h" #include "mqttclient/mqtt_client.h"
#include "minilzo/minilzo.h" #include "minilzo/minilzo.h"
#include "jsonparse/communication_cmd.hpp"
#include "utility/calculation.hpp"
extern zlog_category_t *zct; extern zlog_category_t *zct;
extern zlog_category_t *zbt; extern zlog_category_t *zbt;
@ -20,9 +22,9 @@ std::vector<RecvData> g_VecWaveDataZ;
std::map<std::string, compressWaveChannel> g_mapCompress; std::map<std::string, compressWaveChannel> g_mapCompress;
std::map<std::string, WaveChannel> g_mapWaveChannel; std::map<std::string, WaveChannel> g_mapWaveChannel;
unsigned char data[1024 * 30] = {0x00}; unsigned char data[1024 * 80] = {0x00};
unsigned char outdata[1024 * 50] = {0x00}; unsigned char outdata[1024 * 80] = {0x00};
unsigned char dealdata[1024 * 30] = {0x00}; unsigned char dealdata[1024 * 80] = {0x00};
char mqttData[512000] = {0}; char mqttData[512000] = {0};
void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) { void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) {
@ -584,6 +586,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (flag == 1) { if (flag == 1) {
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
} }
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
} }
float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); } float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); }
@ -787,7 +791,7 @@ void Uart::DealWave() {
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size()); zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size());
coe = Calcoe(n, WAVE_X, strProduct, range); coe = Calcoe(n, WAVE_X, strProduct, range);
vecData = DealData(WAVE_X, coe, sampleRate, ACCSampleTime, strProduct); vecData = DealData(WAVE_X, coe, sampleRate, ACCSampleTime, strProduct);
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecData); WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecData,strProduct);
m_waveCountX = 0; m_waveCountX = 0;
g_VecWaveDataX.clear(); g_VecWaveDataX.clear();
VecWaveDataX.clear(); VecWaveDataX.clear();
@ -796,7 +800,7 @@ void Uart::DealWave() {
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size()); zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size());
coe = Calcoe(n, WAVE_Y, strProduct, range); coe = Calcoe(n, WAVE_Y, strProduct, range);
vecData = DealData(WAVE_Y, coe, sampleRate, ACCSampleTime, strProduct); vecData = DealData(WAVE_Y, coe, sampleRate, ACCSampleTime, strProduct);
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecData); WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecData,strProduct);
m_waveCountY = 0; m_waveCountY = 0;
g_VecWaveDataY.clear(); g_VecWaveDataY.clear();
VecWaveDataY.clear(); VecWaveDataY.clear();
@ -805,7 +809,7 @@ void Uart::DealWave() {
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size()); zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size());
coe = Calcoe(n, WAVE_Z, strProduct, range); coe = Calcoe(n, WAVE_Z, strProduct, range);
vecData = DealData(WAVE_Z, coe, sampleRate, ACCSampleTime, strProduct); vecData = DealData(WAVE_Z, coe, sampleRate, ACCSampleTime, strProduct);
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecData); WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecData,strProduct);
m_waveCountZ = 0; m_waveCountZ = 0;
g_VecWaveDataZ.clear(); g_VecWaveDataZ.clear();
VecWaveDataZ.clear(); VecWaveDataZ.clear();
@ -860,7 +864,7 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
return coe; return coe;
} }
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData) { void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product) {
if (vecData.size() <= 0) return; if (vecData.size() <= 0) return;
std::string strFileName = ""; std::string strFileName = "";
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
@ -918,6 +922,39 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
} }
} }
fclose(fp); fclose(fp);
if (product == "02" && sampleRate == 24000 && strMeasurementID == "8eff96feff141a88"){
size_t outSize = 25600;
std::vector<float> outputData = Calculation::fftInterpolate(vecData, outSize);
float mean = Calculation::mean(outputData);
memset(mqttData,0,sizeof(mqttData));
id = 0;
strFileName = strFileName + std::string(localtimestamp);
FILE *fp = fopen(strFileName.c_str(), "w");
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
for (size_t i = 0; i < outputData.size(); i++) {
frTemp = outputData[i] - mean;
memset(buf, 0x00, sizeof(buf));
sprintf(buf, "%.2f", frTemp);
fwrite(&frTemp,sizeof(float),1,fp);
if (iChannel == WAVE_X){
wave_channel.WaveChannelX[i] = frTemp;
}else if (iChannel == WAVE_Y){
wave_channel.WaveChannelY[i] = frTemp;
}else if (iChannel == WAVE_Z){
wave_channel.WaveChannelZ[i] = frTemp;
}
if(i != outputData.size() -1){
strncpy(mqttData + id ,buf,strlen(buf));
id = id + strlen(buf);
strncpy(mqttData + id,",",1);
id = id + 1;
}else{
strncpy(mqttData + id ,buf,strlen(buf));
}
}
fclose(fp);
}
zlog_info(zct, "fopen FIle vecData.size : %d end ", vecData.size()); zlog_info(zct, "fopen FIle vecData.size : %d end ", vecData.size());
wave_channel.wave_timestamp = nowTimetamp; wave_channel.wave_timestamp = nowTimetamp;
g_mapWaveChannel[strMeasurementID] = wave_channel; g_mapWaveChannel[strMeasurementID] = wave_channel;
@ -1000,6 +1037,8 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
system(tmpCmd); system(tmpCmd);
zlog_info(zct, "rm dat file %s \n", tmpCmd); zlog_info(zct, "rm dat file %s \n", tmpCmd);
} }
JsonData jd;
jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,"send failed");
} else { } else {
zlog_warn(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size()); zlog_warn(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size());
} }
@ -1049,5 +1088,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
} }
zlog_info(zct, "write data to filename %s", strFileName.c_str()); zlog_info(zct, "write data to filename %s", strFileName.c_str());
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,1,strChannelID,"");
sleep(1); sleep(1);
} }

View File

@ -297,13 +297,16 @@ void Calculation::Integration(std::vector<float> &vecData, std::vector<float> &r
} }
std::vector<double> fftInterpolate(const std::vector<double>& input, size_t outputSize) { std::vector<float> Calculation::fftInterpolate(const std::vector<float>& input, size_t outputSize) {
size_t inputSize = input.size(); size_t inputSize = input.size();
double in[inputSize];
for (int i = 0; i < inputSize; i++) {
in[i] = input[i];
}
// 1. FFTW 初始化 // 1. FFTW 初始化
fftw_complex *freqDomain = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * inputSize); fftw_complex *freqDomain = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * inputSize);
fftw_complex *paddedFreqDomain = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * outputSize); fftw_complex *paddedFreqDomain = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * outputSize);
fftw_plan forwardPlan = fftw_plan_dft_r2c_1d(inputSize, const_cast<double*>(input.data()), freqDomain, FFTW_ESTIMATE); fftw_plan forwardPlan = fftw_plan_dft_r2c_1d(inputSize, in, freqDomain, FFTW_ESTIMATE);
// 2. 执行 FFT // 2. 执行 FFT
fftw_execute(forwardPlan); fftw_execute(forwardPlan);
@ -327,17 +330,20 @@ std::vector<double> fftInterpolate(const std::vector<double>& input, size_t outp
std::vector<double> output(outputSize); std::vector<double> output(outputSize);
fftw_plan inversePlan = fftw_plan_dft_c2r_1d(outputSize, paddedFreqDomain, output.data(), FFTW_ESTIMATE); fftw_plan inversePlan = fftw_plan_dft_c2r_1d(outputSize, paddedFreqDomain, output.data(), FFTW_ESTIMATE);
fftw_execute(inversePlan); fftw_execute(inversePlan);
// 5. 缩放输出结果 // 5. 缩放输出结果
for (double& val : output) { for (double& val : output) {
val /= outputSize; val /= outputSize;
} }
std::vector<float> output2(outputSize);
for (int i = 0; i < outputSize; i++) {
output2[i] = output[i];
}
// 清理 FFTW // 清理 FFTW
fftw_destroy_plan(forwardPlan); fftw_destroy_plan(forwardPlan);
fftw_destroy_plan(inversePlan); fftw_destroy_plan(inversePlan);
fftw_free(freqDomain); fftw_free(freqDomain);
fftw_free(paddedFreqDomain); fftw_free(paddedFreqDomain);
return output; return output2;
} }

View File

@ -56,7 +56,7 @@ public:
static void Integration(std::vector<float>& vecData, std::vector<float>& retData, double& resolution); static void Integration(std::vector<float>& vecData, std::vector<float>& retData, double& resolution);
std::vector<double> fftInterpolate(const std::vector<double>& input, size_t outputSize) static std::vector<float> fftInterpolate(const std::vector<float>& input, size_t outputSize);
}; };
#endif // CALCULATION_HPP_ #endif // CALCULATION_HPP_