fix web and wave parse
This commit is contained in:
parent
3411823f8a
commit
f271ae369f
@ -220,6 +220,8 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
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["kurtosis"] = atof(arrRes[j][21].c_str());
|
||||
jsChannelData["IntegratRMSMENS"] = atof(arrRes[j][22].c_str());
|
||||
jsChannelData["TimeStamp"] = atof(arrRes[j][17].c_str());
|
||||
jsSensor.append(jsChannelData);
|
||||
}
|
||||
@ -371,7 +373,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
||||
jsonVal["content"] = (jsStaticData);
|
||||
}
|
||||
jsonVal["Static"] = param.strStatic;
|
||||
zlog_info(zct, "vecRes = %zu,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
||||
zlog_info(zct, "vecRes = %zu,channelID = %s", vecRes.size(), vecRes[0][1].c_str());
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
|
||||
@ -26,7 +26,7 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
char looseValue[10] = {0x00};
|
||||
char whereCon[100] = {0};
|
||||
std::string effect = "" ,rssi = "",batteryPower = "";
|
||||
std::string effect = "" ,rssi = "0",batteryPower = "";
|
||||
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
||||
Json::Value jsArray;
|
||||
array_t arrRes;
|
||||
@ -108,10 +108,44 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
std::vector<std::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];
|
||||
jsSensorData["RSSI"] = atof(vParamRSSI[1].c_str()) / 255.0;
|
||||
} else {
|
||||
jsSensorData["RSSI"] = "0," + arrRes[j][40];
|
||||
jsSensorData["RSSI"] = arrRes[j][40];
|
||||
rssi = arrRes[j][40];
|
||||
}
|
||||
zlog_info(zct,"1arrRes[j][43] = %s",arrRes[j][43].c_str());
|
||||
batteryPower = arrRes[j][43];
|
||||
std::vector<std::string> vParamBatteryPower;
|
||||
float fBatteryPower = 100.0;
|
||||
if(batteryPower != ""){
|
||||
boost::split(vParamBatteryPower, batteryPower, boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamBatteryPower.size() > 0) {
|
||||
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
|
||||
}
|
||||
}
|
||||
zlog_info(zct,"2arrRes[j][43] = %s",arrRes[j][43].c_str());
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon,"shortAddr = '%s' ",arrRes[j][30].c_str());
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon);
|
||||
if (vecResult.size() == 0)
|
||||
{
|
||||
effect = "0";
|
||||
}else{
|
||||
effect = vecResult[5];
|
||||
}
|
||||
|
||||
|
||||
//同时满足时的优先级:低电量>低信号>停机
|
||||
if(effect == "1"){
|
||||
jsSensorData["waveStatus"] = 0; //灰色
|
||||
}
|
||||
if(lowSignal == 1 && atof(rssi.c_str()) < signalThreshold){
|
||||
jsSensorData["waveStatus"] = 1;//红色
|
||||
}
|
||||
if(lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold){
|
||||
jsSensorData["waveStatus"] = 2;//红色
|
||||
}
|
||||
|
||||
jsSensorData["update"] = atoi(arrRes[j][41].c_str());
|
||||
jsSensorData["MeasurementID"] = arrRes[j][44];
|
||||
jsSensorData["battery"] = arrRes[j][43];
|
||||
@ -558,7 +592,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
zlog_info(zct,"LF vecWave size %zu",vecWave.size());
|
||||
zlog_info(zct,"LF vecWave size %zu,filename = %s",vecWave.size(),filename.c_str());
|
||||
//进行傅立叶变换
|
||||
Calculation::FFTSpec(vecWave, fftWave);
|
||||
sampleRateReference = 1024;
|
||||
|
||||
@ -420,7 +420,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kTransducerUpgrade:{
|
||||
JsonData jd;
|
||||
Param_60 param;
|
||||
std::string type = recvBody["cmd"].asString();
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("UPDATE")) {
|
||||
param.mMode = 0;
|
||||
param.fileName = recvBody["fileName"].asString();
|
||||
|
||||
290
main.cpp
290
main.cpp
@ -4,179 +4,179 @@
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <boost/thread.hpp>
|
||||
// #include <string.h>
|
||||
// #include <sys/types.h>
|
||||
// #include <sys/wait.h>
|
||||
// #include <boost/thread.hpp>
|
||||
#include <zlog.h>
|
||||
#include "platform/platform_init.hpp"
|
||||
#include "common/common_func.hpp"
|
||||
#include "common/global.hpp"
|
||||
#include "threadfunc/thread_func.hpp"
|
||||
#include "utility/secure.hpp"
|
||||
#include "utility/aes.h"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
#include "uart/uart.hpp"
|
||||
#include "minilzo/minilzo.h"
|
||||
// #include "platform/platform_init.hpp"
|
||||
// #include "common/common_func.hpp"
|
||||
// #include "common/global.hpp"
|
||||
// #include "threadfunc/thread_func.hpp"
|
||||
// #include "utility/secure.hpp"
|
||||
// #include "utility/aes.h"
|
||||
// #include "dbaccess/sql_db.hpp"
|
||||
// #include "uart/uart.hpp"
|
||||
// #include "minilzo/minilzo.h"
|
||||
|
||||
extern std::vector<RecvData> g_VecWaveDataX;
|
||||
extern std::vector<RecvData> g_VecWaveDataY;
|
||||
extern std::vector<RecvData> g_VecWaveDataZ;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolX;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolY;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolZ;
|
||||
// extern std::vector<RecvData> g_VecWaveDataX;
|
||||
// extern std::vector<RecvData> g_VecWaveDataY;
|
||||
// extern std::vector<RecvData> g_VecWaveDataZ;
|
||||
// extern std::vector<RecvData> g_VecWaveDataVolX;
|
||||
// extern std::vector<RecvData> g_VecWaveDataVolY;
|
||||
// extern std::vector<RecvData> g_VecWaveDataVolZ;
|
||||
zlog_category_t *zct = NULL;
|
||||
zlog_category_t *zbt = NULL;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc = zlog_init("/opt/configenv/wlg.conf");
|
||||
if (rc) {
|
||||
printf("init failed\n");
|
||||
return -1;
|
||||
}
|
||||
// int rc = zlog_init("/opt/configenv/wlg.conf");
|
||||
// if (rc) {
|
||||
// printf("init failed\n");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
zct = zlog_get_category("wlg");
|
||||
zbt = zlog_get_category("cfg");
|
||||
if (!zct || !zbt) {
|
||||
printf("get category fail\n");
|
||||
zlog_fini();
|
||||
return -2;
|
||||
}
|
||||
// zct = zlog_get_category("wlg");
|
||||
// zbt = zlog_get_category("cfg");
|
||||
// if (!zct || !zbt) {
|
||||
// printf("get category fail\n");
|
||||
// zlog_fini();
|
||||
// return -2;
|
||||
// }
|
||||
|
||||
zlog_info(zbt, " Firmware compile time:%s %s,version %s", __DATE__, __TIME__, GlobalConfig::Version.c_str());
|
||||
zlog_info(zbt, "####CIDNSOFT start####");
|
||||
GlobalConfig::Version += " " + std::string(__DATE__) ;
|
||||
g_VecWaveDataX.reserve(1000);
|
||||
g_VecWaveDataY.reserve(1000);
|
||||
g_VecWaveDataZ.reserve(1500);
|
||||
g_VecWaveDataVolX.reserve(1000);
|
||||
g_VecWaveDataVolY.reserve(1000);
|
||||
g_VecWaveDataVolZ.reserve(1500);
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_stack_size(1024 * 1024);
|
||||
// zlog_info(zbt, " Firmware compile time:%s %s,version %s", __DATE__, __TIME__, GlobalConfig::Version.c_str());
|
||||
// zlog_info(zbt, "####CIDNSOFT start####");
|
||||
// GlobalConfig::Version += " " + std::string(__DATE__) ;
|
||||
// g_VecWaveDataX.reserve(1000);
|
||||
// g_VecWaveDataY.reserve(1000);
|
||||
// g_VecWaveDataZ.reserve(1500);
|
||||
// g_VecWaveDataVolX.reserve(1000);
|
||||
// g_VecWaveDataVolY.reserve(1000);
|
||||
// g_VecWaveDataVolZ.reserve(1500);
|
||||
// boost::thread::attributes attrs;
|
||||
// attrs.set_stack_size(1024 * 1024);
|
||||
|
||||
PlatformInit::Init();
|
||||
// PlatformInit::Init();
|
||||
|
||||
sqlite_db_ctrl::instance().InintGateway();
|
||||
char localtimestamp[32] = { 0 };
|
||||
char insertSql[128] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '3','CIDNSOFT start','%s'",localtimestamp);
|
||||
sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
// sqlite_db_ctrl::instance().InintGateway();
|
||||
// char localtimestamp[32] = { 0 };
|
||||
// char insertSql[128] = { 0 };
|
||||
// GetTimeNet(localtimestamp, 1);
|
||||
// memset(insertSql,0,sizeof(insertSql));
|
||||
// sprintf(insertSql, " '3','CIDNSOFT start','%s'",localtimestamp);
|
||||
// sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
|
||||
uart_inst::instance().InitZigbeeHW();
|
||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
boost::thread searchT(SearchThread);
|
||||
searchT.detach();
|
||||
// uart_inst::instance().InitZigbeeHW();
|
||||
// // UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
// boost::thread searchT(SearchThread);
|
||||
// searchT.detach();
|
||||
|
||||
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||||
boost::thread uartReadTh(UartStart);
|
||||
uartReadTh.detach();
|
||||
// // 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||||
// boost::thread uartReadTh(UartStart);
|
||||
// uartReadTh.detach();
|
||||
|
||||
boost::thread uartTestReadTh(TestUart);
|
||||
uartReadTh.detach();
|
||||
// boost::thread uartTestReadTh(TestUart);
|
||||
// uartReadTh.detach();
|
||||
|
||||
// boost::thread InitModuleReadTh(InitModule);
|
||||
// InitModuleReadTh.detach();
|
||||
// // boost::thread InitModuleReadTh(InitModule);
|
||||
// // InitModuleReadTh.detach();
|
||||
|
||||
InitModule();
|
||||
// InitModule();
|
||||
|
||||
// 休眠2秒,等待串口线程初始化完毕
|
||||
sleep(2);
|
||||
// // 休眠2秒,等待串口线程初始化完毕
|
||||
// sleep(2);
|
||||
|
||||
// 串口数据处理,读取传感器原始波形数据
|
||||
boost::thread uartWaveReadTh(UartStartWave);
|
||||
uartWaveReadTh.detach();
|
||||
//启动 RUN LED
|
||||
boost::thread startRunLED(RunLED);
|
||||
startRunLED.detach();
|
||||
// // 串口数据处理,读取传感器原始波形数据
|
||||
// boost::thread uartWaveReadTh(UartStartWave);
|
||||
// uartWaveReadTh.detach();
|
||||
// //启动 RUN LED
|
||||
// boost::thread startRunLED(RunLED);
|
||||
// startRunLED.detach();
|
||||
|
||||
|
||||
#ifdef NR5G_MODULE
|
||||
zlog_info(zbt,"NR5G_MODULE \n");
|
||||
// 5G
|
||||
boost::thread startCSQ(GetCSQ);
|
||||
startCSQ.detach();
|
||||
#ifndef NR5G_MEIGE
|
||||
boost::thread startDial(Dial5G);
|
||||
startDial.detach();
|
||||
#endif
|
||||
#endif
|
||||
// #ifdef NR5G_MODULE
|
||||
// zlog_info(zbt,"NR5G_MODULE \n");
|
||||
// // 5G
|
||||
// boost::thread startCSQ(GetCSQ);
|
||||
// startCSQ.detach();
|
||||
// #ifndef NR5G_MEIGE
|
||||
// boost::thread startDial(Dial5G);
|
||||
// startDial.detach();
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
#ifdef Q4G_MODULE
|
||||
boost::thread startCSQ(GetCSQ);
|
||||
startCSQ.detach();
|
||||
zlog_info(zbt, "4G_MODULE");
|
||||
// #ifdef Q4G_MODULE
|
||||
// boost::thread startCSQ(GetCSQ);
|
||||
// startCSQ.detach();
|
||||
// zlog_info(zbt, "4G_MODULE");
|
||||
|
||||
#endif
|
||||
#ifdef WIFI_MODULE
|
||||
zlog_info(zbt,"WiFi_MODULE");
|
||||
#endif
|
||||
// #endif
|
||||
// #ifdef WIFI_MODULE
|
||||
// zlog_info(zbt,"WiFi_MODULE");
|
||||
// #endif
|
||||
|
||||
//通过UDP接收数据
|
||||
boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||
StartConnectSys.detach();
|
||||
// //通过UDP接收数据
|
||||
// boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||
// StartConnectSys.detach();
|
||||
|
||||
//循环检测线程
|
||||
boost::thread normalCheckThread(attrs, CheckThread);
|
||||
normalCheckThread.detach();
|
||||
// //循环检测线程
|
||||
// boost::thread normalCheckThread(attrs, CheckThread);
|
||||
// normalCheckThread.detach();
|
||||
|
||||
//启动cgi server
|
||||
boost::thread startTcpCgi(attrs, StartCgiServer);
|
||||
startTcpCgi.detach();
|
||||
// //启动cgi server
|
||||
// boost::thread startTcpCgi(attrs, StartCgiServer);
|
||||
// startTcpCgi.detach();
|
||||
|
||||
sleep(5);
|
||||
uart_inst::instance().ZigbeeParameterConfig();
|
||||
sleep(1);
|
||||
uart_inst::instance().UpdateZigbeeInfoCtrl();
|
||||
// sleep(5);
|
||||
// uart_inst::instance().ZigbeeParameterConfig();
|
||||
// sleep(1);
|
||||
// uart_inst::instance().UpdateZigbeeInfoCtrl();
|
||||
|
||||
//启动 mqtt客户端
|
||||
boost::thread startMqtt(StartMqttClient);
|
||||
startMqtt.detach();
|
||||
// //启动 mqtt客户端
|
||||
// boost::thread startMqtt(StartMqttClient);
|
||||
// startMqtt.detach();
|
||||
|
||||
//启动 mqtt 心跳
|
||||
boost::thread startHeart(HeartRep);
|
||||
startHeart.detach();
|
||||
// //启动 mqtt 心跳
|
||||
// boost::thread startHeart(HeartRep);
|
||||
// startHeart.detach();
|
||||
|
||||
boost::thread DiskCheck(attrs, DiskSpaceCheck);
|
||||
DiskCheck.detach();
|
||||
#ifdef BLUETEETH_MODULE
|
||||
//启动蓝牙扫描
|
||||
boost::thread startScanBlueteeth(attrs, ScanBlueteethDevice);
|
||||
startScanBlueteeth.detach();
|
||||
#endif // BLUETEETH_MODULE
|
||||
//启动CMT server
|
||||
boost::thread startTcpCmt(attrs, StartCMTServer);
|
||||
startTcpCmt.detach();
|
||||
// boost::thread DiskCheck(attrs, DiskSpaceCheck);
|
||||
// DiskCheck.detach();
|
||||
// #ifdef BLUETEETH_MODULE
|
||||
// //启动蓝牙扫描
|
||||
// boost::thread startScanBlueteeth(attrs, ScanBlueteethDevice);
|
||||
// startScanBlueteeth.detach();
|
||||
// #endif // BLUETEETH_MODULE
|
||||
// //启动CMT server
|
||||
// boost::thread startTcpCmt(attrs, StartCMTServer);
|
||||
// startTcpCmt.detach();
|
||||
|
||||
if (lzo_init() != LZO_E_OK) {
|
||||
zlog_error(zbt, "internal error - lzo_init() failed !!!");
|
||||
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
|
||||
}
|
||||
int fd = OpenWatchDog();
|
||||
int count = 0;
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 1);
|
||||
usleep(20000);
|
||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0);
|
||||
WriteWatchDog(fd);
|
||||
sleep(20);
|
||||
if (GlobalConfig::threadStatus == 0) {
|
||||
count++;
|
||||
} else if (GlobalConfig::threadStatus == 1) {
|
||||
GlobalConfig::threadStatus = 0;
|
||||
count = 0;
|
||||
}
|
||||
if (count >= 30) {
|
||||
zlog_error(zbt, "===========threadStatus ========failed");
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '1','CheckThread failed','%s'",localtimestamp);
|
||||
sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if (lzo_init() != LZO_E_OK) {
|
||||
// zlog_error(zbt, "internal error - lzo_init() failed !!!");
|
||||
// zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
|
||||
// }
|
||||
// int fd = OpenWatchDog();
|
||||
// int count = 0;
|
||||
// while (GlobalConfig::QuitFlag_G) {
|
||||
// gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 1);
|
||||
// usleep(20000);
|
||||
// gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0);
|
||||
// WriteWatchDog(fd);
|
||||
// sleep(20);
|
||||
// if (GlobalConfig::threadStatus == 0) {
|
||||
// count++;
|
||||
// } else if (GlobalConfig::threadStatus == 1) {
|
||||
// GlobalConfig::threadStatus = 0;
|
||||
// count = 0;
|
||||
// }
|
||||
// if (count >= 30) {
|
||||
// zlog_error(zbt, "===========threadStatus ========failed");
|
||||
// char localtimestamp[32] = { 0 };
|
||||
// GetTimeNet(localtimestamp, 1);
|
||||
// memset(insertSql,0,sizeof(insertSql));
|
||||
// sprintf(insertSql, " '1','CheckThread failed','%s'",localtimestamp);
|
||||
// sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -492,6 +492,8 @@ int Uart::WaveSendCondition(char* shortAddr){
|
||||
if (vParamBatteryPower.size() > 0) {
|
||||
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
|
||||
}
|
||||
memset(whereCon, 0, sizeof(whereCon));
|
||||
sprintf(whereCon,"shortAddr = '%s' ",shortAddr);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon);
|
||||
effect = vecResult[5];
|
||||
if((lowSignal == 1 && atof(rssi.c_str()) < signalThreshold) || (lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold) || effect == "1"){
|
||||
@ -629,16 +631,6 @@ int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
if (vParamRSSI.size() > 0) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), pData[7] & 0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1502,14 +1494,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// char tmp[23] = {0x00};
|
||||
// char tmp2[23] = {0x00};
|
||||
// for (int j = 0; j < 23; j++) {
|
||||
// sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||
// strcat(tmp2, tmp);
|
||||
// }
|
||||
// zlog_info(zct, "str = %s", tmp2);
|
||||
DealRecvData(RecvBuf);
|
||||
} else if (command == 35) {
|
||||
char signalNode[10] = {0x00};
|
||||
@ -1529,14 +1513,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char *)vecDataNodeNo[0].c_str(), strTimetamp.c_str());
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamRSSI.size() > 0) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1609,18 +1585,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
} else {
|
||||
jsBody["looseStatus"] = "0";
|
||||
}
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[2], boost::is_any_of(","), boost::token_compress_on);
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
if (vParamRSSI.size() == 1) {
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[0].c_str());
|
||||
|
||||
} else if (vParamRSSI.size() == 2) {
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[1].c_str());
|
||||
}
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
|
||||
jsonVal["cmd"] = "52";
|
||||
jsBody["timeStamp"] = strTimetamp;
|
||||
|
||||
@ -69,6 +69,10 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
|
||||
actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位:KB/s
|
||||
}
|
||||
float comprehensiveRSSI = (zigbeeSignal + zigbeeSignalNode) * (actualRate / standardRate);
|
||||
if (comprehensiveRSSI > 1.0f) {
|
||||
comprehensiveRSSI = 1.0f; //综合信号强度最大为1
|
||||
}
|
||||
|
||||
zlog_info(zct, "dataNodeNo='%s',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f", strLongAddr.c_str(), wave_dataLen, dataStatic.nodeSendTime, actualRate);
|
||||
//更新综合信号强度到数据库
|
||||
char updateSql[256] = {0};
|
||||
@ -941,15 +945,15 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
memcpy(dealdata, data, j * 92);
|
||||
deallen = j * 92;
|
||||
}
|
||||
if(iChannel == WAVE_LF_X){
|
||||
for (size_t i = 0; i < 200; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
printf("%s ", buf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// if(iChannel == WAVE_LF_X){
|
||||
// for (size_t i = 0; i < 200; i++) {
|
||||
// float fTemp = 0.0f;
|
||||
// memset(buf, 0, 8);
|
||||
// sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
// printf("%s ", buf);
|
||||
// }
|
||||
// printf("\n");
|
||||
// }
|
||||
for (size_t i = 0; i < deallen; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
@ -996,13 +1000,13 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
if (vecData.size() == 24000 && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_LF_X) { //过滤数据包结尾空数据
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_LF_Y) { //过滤数据包结尾空数据
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_Y) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_LF_Z) { //过滤数据包结尾空数据
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1289,67 +1293,8 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
default: break;
|
||||
}
|
||||
FILE *fp = fopen(strFileName.c_str(), "w");
|
||||
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
|
||||
zlog_info(zct, " vecData.size : %zu,start ", vecData.size());
|
||||
int id = 0;
|
||||
|
||||
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 1) ||
|
||||
(iChannel == WAVE_Z && version == 1) ||
|
||||
((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 0)){
|
||||
sampleRate = 25600;
|
||||
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
||||
size_t outSize = 25600;
|
||||
std::vector<float> outputData,outputData2;
|
||||
float epsilon = 1e-6f;
|
||||
if (std::fabs(ACCSampleTime - 1) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(std::fabs(ACCSampleTime - 2) < epsilon){
|
||||
std::vector<float> first_wave = std::vector<float>(vecData.begin(), vecData.begin() + vecData.size()/2);
|
||||
std::vector<float> second_wave = std::vector<float>(vecData.begin() + vecData.size()/2, vecData.end());
|
||||
outputData = Calculation::fftInterpolate(first_wave, outSize);
|
||||
outputData2 = Calculation::fftInterpolate(second_wave, outSize);
|
||||
for (size_t i = 0; i < outputData2.size(); i++)
|
||||
{
|
||||
outputData.push_back(outputData2[i]);
|
||||
}
|
||||
}else if(std::fabs(ACCSampleTime - 1.28) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(std::fabs(ACCSampleTime - 3.2) < epsilon){
|
||||
outSize = 2560;
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}
|
||||
zlog_info(zct, " outputData_size %zu ", outputData.size());
|
||||
float mean = Calculation::mean(outputData);
|
||||
memset(mqttData,0,sizeof(mqttData));
|
||||
id = 0;
|
||||
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;
|
||||
}else if (iChannel == WAVE_LF_X){
|
||||
wave_vol_channel.WaveChannelVolX[i] = frTemp;
|
||||
}else if (iChannel == WAVE_LF_Y){
|
||||
wave_vol_channel.WaveChannelVolY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_LF_Z){
|
||||
wave_vol_channel.WaveChannelVolZ[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));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
|
||||
for (size_t i = 0; i < vecData.size(); i++) {
|
||||
frTemp = vecData[i] - mean;
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
@ -1377,8 +1322,56 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
strncpy(mqttData + id ,buf,strlen(buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
zlog_info(zct, " vecData.size : %zu,start ", vecData.size());
|
||||
|
||||
zlog_info(zct, " product = %s,version = %d ,iChannel = %d", product.c_str(),version,iChannel);
|
||||
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 1) ||
|
||||
(iChannel == WAVE_Z && version == 0) ||
|
||||
((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 0)){
|
||||
sampleRate = 25600;
|
||||
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
||||
size_t outSize = 25600;
|
||||
std::vector<float> outputData,outputData2;
|
||||
float epsilon = 1e-6f;
|
||||
if (std::fabs(ACCSampleTime - 1) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(std::fabs(ACCSampleTime - 2) < epsilon){
|
||||
std::vector<float> first_wave = std::vector<float>(vecData.begin(), vecData.begin() + vecData.size()/2);
|
||||
std::vector<float> second_wave = std::vector<float>(vecData.begin() + vecData.size()/2, vecData.end());
|
||||
outputData = Calculation::fftInterpolate(first_wave, outSize);
|
||||
outputData2 = Calculation::fftInterpolate(second_wave, outSize);
|
||||
for (size_t i = 0; i < outputData2.size(); i++)
|
||||
{
|
||||
outputData.push_back(outputData2[i]);
|
||||
}
|
||||
}else if(std::fabs(ACCSampleTime - 1.28) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime);
|
||||
}else if(std::fabs(ACCSampleTime - 3.2) < epsilon){
|
||||
outSize = 8192;
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime);
|
||||
}
|
||||
zlog_info(zct, " outputData_size %zu ", outputData.size());
|
||||
float mean = Calculation::mean(outputData);
|
||||
memset(mqttData,0,sizeof(mqttData));
|
||||
id = 0;
|
||||
for (size_t i = 0; i < outputData.size(); i++) {
|
||||
frTemp = outputData[i] - mean;
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%.2f", 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zlog_info(zct, "fopen file vecData.size : %zu end ", vecData.size());
|
||||
wave_channel.wave_timestamp = nowTimetamp;
|
||||
g_mapWaveChannel[strMeasurementID] = wave_channel;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "common/common_func.hpp"
|
||||
#include "minilzo/minilzo.h"
|
||||
#include "scheduler/wave_feature_set.hpp"
|
||||
#include "scheduler/schedule.hpp"
|
||||
|
||||
extern zlog_category_t* zct;
|
||||
extern zlog_category_t* zbt;
|
||||
@ -53,9 +54,9 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
char wherecon[512] = {0};
|
||||
sprintf(wherecon," short_Addr = '%02x%02x' and status = 3 and start_timestamp > ( SELECT MAX(submit_timestamp) FROM firmware_upgrade ) order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon);
|
||||
if (atoi(spend_count.c_str()) >= 10){
|
||||
//if (atoi(spend_count.c_str()) >= 12)
|
||||
{
|
||||
zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
return ;
|
||||
}
|
||||
if (spend_count == "")spend_count = "0";
|
||||
|
||||
@ -140,7 +141,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
// zlog_warn(zct,"This block contains incompressible data.out_len = %lu,thisSize = %lu",out_len,thisSize);
|
||||
// memcpy(fw_senddata,buffer,thisSize);
|
||||
// }
|
||||
memcpy(fw_senddata,buffer,thisSize);
|
||||
//memcpy(fw_senddata,buffer,thisSize);
|
||||
unsigned char Data[100] = {0x00};
|
||||
unsigned char size[4] = {0x00};
|
||||
zlog_info(zct, "thisSize = %d", (int)thisSize);
|
||||
@ -195,7 +196,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
UpdateData[4]=UINT16_LOW(shortAdd);
|
||||
UpdateData[5]=0x10;
|
||||
UpdateData[6]=0xff & j;
|
||||
memcpy(&UpdateData[7],fw_senddata + 92 * j,92);
|
||||
memcpy(&UpdateData[7],buffer + 92 * j,92);
|
||||
tmp = 0x00;
|
||||
for(int k = 0; k < 99;k++){
|
||||
tmp +=UpdateData[k];
|
||||
@ -215,6 +216,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
if(time >= 150){
|
||||
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x,index = %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),j);
|
||||
zlog_warn(zct, "gpio_read failed \n");
|
||||
scheduler::instance().UpgradeResult(shortAdd,kRecvDataLenError);
|
||||
bUpdate = false;
|
||||
upgrade_status = 3;
|
||||
goto endUpdate;
|
||||
@ -235,7 +237,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
UpdateData[4] = UINT16_LOW(shortAdd);
|
||||
UpdateData[5] = 0x10;
|
||||
UpdateData[6] = 0xff & Count;
|
||||
memcpy(&UpdateData[7], fw_senddata + 92 * Count, lastSize);
|
||||
memcpy(&UpdateData[7], buffer + 92 * Count, lastSize);
|
||||
tmp = 0x00;
|
||||
for (int k = 0; k < 99; k++) {
|
||||
tmp += UpdateData[k];
|
||||
@ -259,6 +261,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
if (time >= 150) {
|
||||
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
zlog_warn(zct, "gpio_read failed \n");
|
||||
scheduler::instance().UpgradeResult(shortAdd,kRecvDataLenError);
|
||||
bUpdate = false;
|
||||
upgrade_status = 3;
|
||||
goto endUpdate;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user