fix compile warning and some bugs
This commit is contained in:
parent
c32db761d8
commit
42d759fe29
@ -102,13 +102,13 @@ int code_convert(const char *from_charset, const char *to_charset, char *inbuf,
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
iconv_close(cd);
|
iconv_close(cd);
|
||||||
*pout = '\0';
|
*pout = (char*)'\0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InitGpio(unsigned int gpioN, unsigned int inout) {
|
int InitGpio(unsigned int gpioN, unsigned int inout) {
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
char tmp[100] = {0};
|
char tmp[256] = {0};
|
||||||
// 闂佺懓鐏氶幐鍝ユ閹辩倍io闁荤姳鐒﹂崕鎶剿囬鍕闁搞儻闄勯锟<EE9495>
|
// 闂佺懓鐏氶幐鍝ユ閹辩倍io闁荤姳鐒﹂崕鎶剿囬鍕闁搞儻闄勯锟<EE9495>
|
||||||
fd = open("/sys/class/gpio/export", O_WRONLY);
|
fd = open("/sys/class/gpio/export", O_WRONLY);
|
||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
@ -189,7 +189,7 @@ int InitGpio(unsigned int gpioN, unsigned int inout) {
|
|||||||
|
|
||||||
int gpio_set(unsigned int gpioN, char x) {
|
int gpio_set(unsigned int gpioN, char x) {
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
char tmp[100] = {0};
|
char tmp[256] = {0};
|
||||||
char tmp2[100] = {0};
|
char tmp2[100] = {0};
|
||||||
if (gpioN == 507)
|
if (gpioN == 507)
|
||||||
memcpy(tmp2, "P18_3", 5);
|
memcpy(tmp2, "P18_3", 5);
|
||||||
@ -253,7 +253,7 @@ int gpio_read(unsigned int gpioN) {
|
|||||||
int fd = 0;
|
int fd = 0;
|
||||||
char value;
|
char value;
|
||||||
|
|
||||||
char tmp[100] = {0};
|
char tmp[256] = {0};
|
||||||
|
|
||||||
char tmp2[100] = {0};
|
char tmp2[100] = {0};
|
||||||
if (gpioN == 507)
|
if (gpioN == 507)
|
||||||
@ -1139,7 +1139,7 @@ std::string GetSysStatus(Json::Value &jsData) {
|
|||||||
std::string strJson = fw.write(jsData);
|
std::string strJson = fw.write(jsData);
|
||||||
return strJson;
|
return strJson;
|
||||||
}
|
}
|
||||||
int GetSysStatusCMT(int& cpu_use,int& mem_use,int& disk_remain,int& cpu_temp)
|
void GetSysStatusCMT(int& cpu_use,int& mem_use,int& disk_remain,int& cpu_temp)
|
||||||
{
|
{
|
||||||
long mem_used = -1;
|
long mem_used = -1;
|
||||||
long mem_free = -1;
|
long mem_free = -1;
|
||||||
@ -1203,11 +1203,11 @@ unsigned char hexCharToByte(char c) {
|
|||||||
int hexStringToBytes(const char *hexStr, unsigned char *bytes, size_t bytesSize) {
|
int hexStringToBytes(const char *hexStr, unsigned char *bytes, size_t bytesSize) {
|
||||||
size_t hexLen = strlen(hexStr);
|
size_t hexLen = strlen(hexStr);
|
||||||
if (hexLen % 2 != 0) {
|
if (hexLen % 2 != 0) {
|
||||||
zlog_error(zct, "hexLen:%d is odd", hexLen);
|
zlog_error(zct, "hexLen:%zu is odd", hexLen);
|
||||||
return -1; // Hex闁诲孩绋掗〃鍫ヮ敄娴e湱鈻旈柡灞诲劜濮f劙骞栨潏鍓х暠缂併劏灏欓幏鐘诲Ψ閿斿彨锕傛煕鐎n厼鐓愰柡鍡嫹
|
return -1; // Hex闁诲孩绋掗〃鍫ヮ敄娴e湱鈻旈柡灞诲劜濮f劙骞栨潏鍓х暠缂併劏灏欓幏鐘诲Ψ閿斿彨锕傛煕鐎n厼鐓愰柡鍡嫹
|
||||||
}
|
}
|
||||||
if (bytesSize < hexLen / 2) {
|
if (bytesSize < hexLen / 2) {
|
||||||
zlog_error(zct, "bytesSize:%d < hexLen:%d", bytesSize, hexLen);
|
zlog_error(zct, "bytesSize:%zu < hexLen:%zu", bytesSize, hexLen);
|
||||||
return -1; // 闁诲孩绋掗〃澶嬩繆椤撱垹鏋侀柟娈垮枤閻鏌i妸銉ヮ仼闁靛洤娲ㄦ禍姝岀疀鎼达絿鎲归柣鈩冨笒閸樻牗绂嶉幒鏂哄亾閻熺増璐¢柟鎯у悑濞碱亪顢楁担绋跨哎闂佸憡鑹惧ù宄扳枔閹寸姭鍋撳☉娆樻畽濠碘槄鎷<E6A784>
|
return -1; // 闁诲孩绋掗〃澶嬩繆椤撱垹鏋侀柟娈垮枤閻鏌i妸銉ヮ仼闁靛洤娲ㄦ禍姝岀疀鎼达絿鎲归柣鈩冨笒閸樻牗绂嶉幒鏂哄亾閻熺増璐¢柟鎯у悑濞碱亪顢楁担绋跨哎闂佸憡鑹惧ù宄扳枔閹寸姭鍋撳☉娆樻畽濠碘槄鎷<E6A784>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -420,7 +420,7 @@ void ZoneConfig(std::string zoneid);
|
|||||||
* @return std::string CPU MEM DISK info
|
* @return std::string CPU MEM DISK info
|
||||||
*/
|
*/
|
||||||
std::string GetSysStatus(Json::Value &jsData);
|
std::string GetSysStatus(Json::Value &jsData);
|
||||||
int GetSysStatusCMT(int& cpu_use,int& mem_use,int& disk_remain,int& cpu_temp);
|
void GetSysStatusCMT(int& cpu_use,int& mem_use,int& disk_remain,int& cpu_temp);
|
||||||
bool CheckIP(const char* ip);
|
bool CheckIP(const char* ip);
|
||||||
|
|
||||||
bool IsValidMask(std::string mask);
|
bool IsValidMask(std::string mask);
|
||||||
|
|||||||
@ -116,7 +116,7 @@ struct Param_28 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Param_29 {
|
struct Param_29 {
|
||||||
int mMode;
|
int mMode; // 0: HIGH 1: LOW
|
||||||
std::string mCmdSerial;
|
std::string mCmdSerial;
|
||||||
std::string mChannelId;
|
std::string mChannelId;
|
||||||
std::string mDataNodeNo;
|
std::string mDataNodeNo;
|
||||||
@ -185,15 +185,20 @@ struct Param_32 {
|
|||||||
|
|
||||||
struct Param_33 {
|
struct Param_33 {
|
||||||
int mMode;
|
int mMode;
|
||||||
std::string mUnit;
|
std::string mCmdSerial;
|
||||||
Param_33() : mMode(0), mUnit(""){};
|
std::string mChannelId;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
int mPackageFlag;
|
||||||
|
Param_33() : mMode(0), mCmdSerial(""), mChannelId(""), mDataNodeNo(""), mPackageFlag(0){};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Param_34 {
|
struct Param_34 {
|
||||||
int mMode;
|
int mMode;
|
||||||
std::string mBeforeTime;
|
std::string mCmdSerial;
|
||||||
std::string mAfterTime;
|
std::string mChannelId;
|
||||||
Param_34() : mMode(0), mBeforeTime(""), mAfterTime(""){};
|
std::string mDataNodeNo;
|
||||||
|
int mPackageFlag;
|
||||||
|
Param_34() : mMode(0), mCmdSerial(""), mChannelId(""), mDataNodeNo(""), mPackageFlag(0){};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Param_35 {
|
struct Param_35 {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ static size_t OnWriteData(void *buffer, size_t size, size_t nmemb, void *lpVoid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||||
zlog_debug(zct, "size = %d", size);
|
zlog_debug(zct, "size = %zu", size);
|
||||||
struct DownloadFile *out = (struct DownloadFile *)stream;
|
struct DownloadFile *out = (struct DownloadFile *)stream;
|
||||||
if (out && !out->stream) {
|
if (out && !out->stream) {
|
||||||
out->stream = fopen(out->filename, "wb");
|
out->stream = fopen(out->filename, "wb");
|
||||||
|
|||||||
@ -206,10 +206,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
|||||||
if(iRet == 0){
|
if(iRet == 0){
|
||||||
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'nodeTimeStamp'");
|
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'nodeTimeStamp'");
|
||||||
}
|
}
|
||||||
iRet = GetTableRows(" sqlite_master "," name = 't_datastatic_info' and sql LIKE '%comprehensiveRSSI%' ");
|
|
||||||
if(iRet == 0){
|
|
||||||
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'comprehensiveRSSI'");
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(sql_exec, 0, 2048);
|
memset(sql_exec, 0, 2048);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@ -918,7 +915,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
sprintf(selectSql, " MeasurementID,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower ");
|
sprintf(selectSql, " MeasurementID,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower ");
|
||||||
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||||
zlog_info(zct, "Size = %d", vecRes.size());
|
zlog_info(zct, "Size = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
float capacity = 0.0, startCapacity = 0.0;
|
float capacity = 0.0, startCapacity = 0.0;
|
||||||
@ -966,7 +963,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
zlog_info(zct, "capacity = %f", capacity);
|
zlog_info(zct, "capacity = %f", capacity);
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][0].c_str(), vecResSig[8].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][0].c_str(), vecResSig[8].c_str());
|
||||||
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
zlog_info(zct, "vecResbattery size = %d", vecResbattery.size());
|
zlog_info(zct, "vecResbattery size = %zu", vecResbattery.size());
|
||||||
if (vecResbattery.size() <= 0) {
|
if (vecResbattery.size() <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -981,7 +978,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
std::vector<long> vecworkTime;
|
std::vector<long> vecworkTime;
|
||||||
std::vector<long> vecsendTime;
|
std::vector<long> vecsendTime;
|
||||||
float to_math = 0.0;
|
float to_math = 0.0;
|
||||||
zlog_info(zct, "vecResbattery = %d,temp = %s", vecResbattery.size(), vecResbattery[0][2].c_str());
|
zlog_info(zct, "vecResbattery = %zu,temp = %s", vecResbattery.size(), vecResbattery[0][2].c_str());
|
||||||
|
|
||||||
for (size_t j = 0; j < vecResbattery.size(); j++) {
|
for (size_t j = 0; j < vecResbattery.size(); j++) {
|
||||||
float b = 2 - 25 * k;
|
float b = 2 - 25 * k;
|
||||||
@ -1079,12 +1076,11 @@ int SqliteDB::CalculateDip() {
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
||||||
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), " * ", NULL);
|
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), " * ", NULL);
|
||||||
zlog_info(zct, "vecRes111 = %d", vecRes.size());
|
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
std::vector<std::string> vParam;
|
std::vector<std::string> vParam;
|
||||||
zlog_info(zct, "vecRes = %s", vecRes[i][42].c_str());
|
zlog_info(zct, "vecRes = %s", vecRes[i][42].c_str());
|
||||||
boost::split(vParam, vecRes[i][42], boost::is_any_of(","), boost::token_compress_on);
|
boost::split(vParam, vecRes[i][42], boost::is_any_of(","), boost::token_compress_on);
|
||||||
zlog_info(zct, "vParam size = %d", vParam.size());
|
zlog_info(zct, "vParam size = %zu", vParam.size());
|
||||||
if (vParam.size() < 2) {
|
if (vParam.size() < 2) {
|
||||||
sprintf(updateSql, "LooseValue = '%f,0' ", atof(vParam[0].c_str()));
|
sprintf(updateSql, "LooseValue = '%f,0' ", atof(vParam[0].c_str()));
|
||||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
||||||
@ -1307,7 +1303,7 @@ int SqliteDB::QueryofflineData() {
|
|||||||
sprintf(StaticTableName, "t_dataStatic_%s", arrRetdataNode[i][0].c_str());
|
sprintf(StaticTableName, "t_dataStatic_%s", arrRetdataNode[i][0].c_str());
|
||||||
|
|
||||||
array_t arrRetData = GetDataMultiLine(StaticTableName, "*", "sendMsg = '0' order by timeStamp asc");
|
array_t arrRetData = GetDataMultiLine(StaticTableName, "*", "sendMsg = '0' order by timeStamp asc");
|
||||||
zlog_info(zct, "mqttresend check datanodeNo %s,data count %d", arrRetdataNode[i][0].c_str(), arrRetData.size());
|
zlog_info(zct, "mqttresend check datanodeNo %s,data count %zu", arrRetdataNode[i][0].c_str(), arrRetData.size());
|
||||||
if (arrRetData.size() < 1) continue;
|
if (arrRetData.size() < 1) continue;
|
||||||
for (size_t j = 0; j < arrRetData.size(); j++) {
|
for (size_t j = 0; j < arrRetData.size(); j++) {
|
||||||
char dataTableName[50] = {0x00};
|
char dataTableName[50] = {0x00};
|
||||||
@ -1389,7 +1385,7 @@ int SqliteDB::QueryofflineData() {
|
|||||||
char buf[30]={0};
|
char buf[30]={0};
|
||||||
sprintf(whereCon, " SendMsg = 0 ");
|
sprintf(whereCon, " SendMsg = 0 ");
|
||||||
array_t arrRetData = GetDataMultiLine("t_data_waveSend", "*", whereCon);
|
array_t arrRetData = GetDataMultiLine("t_data_waveSend", "*", whereCon);
|
||||||
zlog_info(zct, "mqttresend check wave count %d", arrRetData.size());
|
zlog_info(zct, "mqttresend check wave count %zu", arrRetData.size());
|
||||||
if (arrRetData.size() > 0) {
|
if (arrRetData.size() > 0) {
|
||||||
for (size_t i = 0; i < arrRetData.size(); i++) {
|
for (size_t i = 0; i < arrRetData.size(); i++) {
|
||||||
std::string strWaveData = "";
|
std::string strWaveData = "";
|
||||||
@ -1455,9 +1451,9 @@ int SqliteDB::QueryofflineData() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
int SqliteDB::ClearExpireData(){
|
int SqliteDB::ClearExpireData(){
|
||||||
char whereCon[1024] = {0};
|
char whereCon[128] = {0};
|
||||||
char deleteSql[1024] = {0};
|
char deleteSql[1024] = {0};
|
||||||
char selectSql[1024] = {0};
|
char selectSql[128] = {0};
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
memset(deleteSql, 0x00, sizeof(deleteSql));
|
memset(deleteSql, 0x00, sizeof(deleteSql));
|
||||||
memset(selectSql, 0x00, sizeof(selectSql));
|
memset(selectSql, 0x00, sizeof(selectSql));
|
||||||
@ -1475,7 +1471,7 @@ int SqliteDB::ClearExpireData(){
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int SqliteDB::SaveSystemHardStatus(){
|
void SqliteDB::SaveSystemHardStatus(){
|
||||||
Json::Value jsData;
|
Json::Value jsData;
|
||||||
std::string sysStatus = GetSysStatus(jsData);
|
std::string sysStatus = GetSysStatus(jsData);
|
||||||
char insertSql[1024] = {0};
|
char insertSql[1024] = {0};
|
||||||
@ -1511,7 +1507,7 @@ int SqliteDB::SaveSystemHardStatus(){
|
|||||||
Vw_min : 电池型号相关,如ER34615C=2.8V
|
Vw_min : 电池型号相关,如ER34615C=2.8V
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int SqliteDB::NewBatteryIdentify(){
|
void SqliteDB::NewBatteryIdentify(){
|
||||||
char localtimestamp[32] = { 0 };
|
char localtimestamp[32] = { 0 };
|
||||||
GetTimeNet(localtimestamp, 1);
|
GetTimeNet(localtimestamp, 1);
|
||||||
float capacity = 0.0, startCapacity = 0.0;
|
float capacity = 0.0, startCapacity = 0.0;
|
||||||
@ -1546,7 +1542,7 @@ int SqliteDB::NewBatteryIdentify(){
|
|||||||
if(voltage_data_new.size() > 0){
|
if(voltage_data_new.size() > 0){
|
||||||
int voltage_diff = (atoi(voltage_data_new[0].c_str()) + atoi(voltage_data_new[1].c_str()) + atoi(voltage.c_str())) - mean_voltage;
|
int voltage_diff = (atoi(voltage_data_new[0].c_str()) + atoi(voltage_data_new[1].c_str()) + atoi(voltage.c_str())) - mean_voltage;
|
||||||
zlog_info(zct,"mean_voltage = %d,voltage = %d,instantaneousBatteryVoltage = %d,instantaneousBatteryVoltage_s = %d diff = %d ",
|
zlog_info(zct,"mean_voltage = %d,voltage = %d,instantaneousBatteryVoltage = %d,instantaneousBatteryVoltage_s = %d diff = %d ",
|
||||||
mean_voltage,atoi(voltage_data_new[0].c_str()),atoi(voltage_data_new[1].c_str()),voltage_diff);
|
mean_voltage,atoi(voltage.c_str()),atoi(voltage_data_new[0].c_str()),atoi(voltage_data_new[1].c_str()),voltage_diff);
|
||||||
if(voltage_diff > 600 && (atoi(voltage_data_new[1].c_str()) > 2800)){
|
if(voltage_diff > 600 && (atoi(voltage_data_new[1].c_str()) > 2800)){
|
||||||
memset(whereCon,0,sizeof(whereCon));
|
memset(whereCon,0,sizeof(whereCon));
|
||||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), arrRes[i][44].c_str());
|
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), arrRes[i][44].c_str());
|
||||||
@ -1570,7 +1566,7 @@ int SqliteDB::NewBatteryIdentify(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int SqliteDB::ShutdownCheck(){
|
void SqliteDB::ShutdownCheck(){
|
||||||
int checkNumber = readIntValue("config", "shutdownNumber", (char *)GlobalConfig::Config_G.c_str());
|
int checkNumber = readIntValue("config", "shutdownNumber", (char *)GlobalConfig::Config_G.c_str());
|
||||||
char whereCon[1024] = {0};
|
char whereCon[1024] = {0};
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
@ -1584,6 +1580,11 @@ int SqliteDB::ShutdownCheck(){
|
|||||||
sprintf(tablename,"t_data_%s",arrRes[i][44].c_str());
|
sprintf(tablename,"t_data_%s",arrRes[i][44].c_str());
|
||||||
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
||||||
vec_t shutdownCheck = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info", " * ", whereCon);
|
vec_t shutdownCheck = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info", " * ", whereCon);
|
||||||
|
if (shutdownCheck.size() < 1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
array_t arrData;
|
array_t arrData;
|
||||||
if(shutdownCheck[2] == "1"){
|
if(shutdownCheck[2] == "1"){
|
||||||
if (shutdownCheck[3] == "0")//加速度有效值
|
if (shutdownCheck[3] == "0")//加速度有效值
|
||||||
|
|||||||
@ -72,9 +72,9 @@ public:
|
|||||||
int InintGateway();
|
int InintGateway();
|
||||||
int QueryofflineData();
|
int QueryofflineData();
|
||||||
int ClearExpireData();
|
int ClearExpireData();
|
||||||
int SaveSystemHardStatus();
|
void SaveSystemHardStatus();
|
||||||
int NewBatteryIdentify();
|
void NewBatteryIdentify();
|
||||||
int ShutdownCheck();
|
void ShutdownCheck();
|
||||||
std::string GetNodeConfigureInfor(const char *whereCon);
|
std::string GetNodeConfigureInfor(const char *whereCon);
|
||||||
int CloseDB();
|
int CloseDB();
|
||||||
|
|
||||||
|
|||||||
@ -184,7 +184,7 @@ void JsonData::CmtCmd_81(char* recv_body,int& count,char* send_data,int& send_le
|
|||||||
}
|
}
|
||||||
memcpy(send_data,&sensor_info,sizeof(SensorInfo) * j);
|
memcpy(send_data,&sensor_info,sizeof(SensorInfo) * j);
|
||||||
send_length = sizeof(SensorInfo) * j;
|
send_length = sizeof(SensorInfo) * j;
|
||||||
zlog_info(zct,"sizeof(SensorInfo) = %d",sizeof(SensorInfo)*j);
|
zlog_info(zct,"sizeof(SensorInfo) = %zu",sizeof(SensorInfo)*j);
|
||||||
zlog_info(zct,"send_length = %d",send_length);
|
zlog_info(zct,"send_length = %d",send_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ void JsonData::CmtCmd_83(char* recv_body,int& count,char* send_data,int& send_le
|
|||||||
{
|
{
|
||||||
array_t arrRes;
|
array_t arrRes;
|
||||||
std::string filename = "";
|
std::string filename = "";
|
||||||
char whereCon[128]={0};
|
char whereCon[512]={0};
|
||||||
if (recv_body){
|
if (recv_body){
|
||||||
printf("count = %d\n",count);
|
printf("count = %d\n",count);
|
||||||
char MeasurementID_[256]={0};
|
char MeasurementID_[256]={0};
|
||||||
@ -589,7 +589,7 @@ void JsonData::CmtCmd_88(char* recv_body,int& count,char* send_data,int& send_l
|
|||||||
{
|
{
|
||||||
if (recv_body != NULL)
|
if (recv_body != NULL)
|
||||||
{
|
{
|
||||||
char wherecon[100] = {0};
|
char wherecon[512] = {0};
|
||||||
char updateSql[100] = {0};
|
char updateSql[100] = {0};
|
||||||
printf("count = %d\n",count);
|
printf("count = %d\n",count);
|
||||||
char short_addr_[256]={0};
|
char short_addr_[256]={0};
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public:
|
|||||||
std::string JsonCmd_Cgi_53(std::vector<Param_53> ¶m);
|
std::string JsonCmd_Cgi_53(std::vector<Param_53> ¶m);
|
||||||
std::string JsonCmd_Cgi_54(Param_54 ¶m);
|
std::string JsonCmd_Cgi_54(Param_54 ¶m);
|
||||||
|
|
||||||
std::string JsonCmd_Cgi_55(Param_55 ¶m);
|
std::string JsonCmd_Cgi_55(Param_55 ¶m);// 算积分只用低频加速度
|
||||||
std::string JsonCmd_Cgi_56(Param_56 ¶m);
|
std::string JsonCmd_Cgi_56(Param_56 ¶m);
|
||||||
std::string JsonCmd_Cgi_57(Param_57 ¶m);
|
std::string JsonCmd_Cgi_57(Param_57 ¶m);
|
||||||
std::string JsonCmd_Cgi_58(Param_58 ¶m);
|
std::string JsonCmd_Cgi_58(Param_58 ¶m);
|
||||||
|
|||||||
@ -692,13 +692,14 @@ void JsonData::DataNodeStatusCheck() {
|
|||||||
std::string strMeasurementID = vetRes[i][44];
|
std::string strMeasurementID = vetRes[i][44];
|
||||||
std::string strChannelId = strMeasurementID + "-X";
|
std::string strChannelId = strMeasurementID + "-X";
|
||||||
char whereCon[512] = {0x00}, tablename[128] = {0x00};
|
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(whereCon, "dataNodeNo='%s' and channelID='%s' ORDER BY timeStamp DESC LIMIT 0,1", strMeasurementID.c_str(), strChannelId.c_str());
|
||||||
sprintf(tablename, "t_data_%s", strDataNodeNo.c_str());
|
sprintf(tablename, "t_data_%s", strMeasurementID.c_str());
|
||||||
std::string strTimeRes = sqlite_db_ctrl::instance().GetData(tablename, "timeStamp", whereCon);
|
std::string strTimeRes = sqlite_db_ctrl::instance().GetData(tablename, "timeStamp", whereCon);
|
||||||
if (strTimeRes.length() > 0) {
|
if (strTimeRes.length() > 0) {
|
||||||
int llastTime = atoi(strTimeRes.c_str());
|
int llastTime = atoi(strTimeRes.c_str());
|
||||||
int lTimeTemp = lNowTime - llastTime;
|
int lTimeTemp = lNowTime - llastTime;
|
||||||
lTimeTemp = abs(lTimeTemp);
|
lTimeTemp = abs(lTimeTemp);
|
||||||
|
zlog_info(zct,"llastTime = %d lNowTime = %d lTimeTemp = %d onlineCheck = %d MeasurementID = %s",llastTime,lNowTime,lTimeTemp,onlineCheck,strMeasurementID.c_str());
|
||||||
if (lTimeTemp > onlineCheck) {
|
if (lTimeTemp > onlineCheck) {
|
||||||
zlog_warn(zct, "offline DataNodeStatusCheck DataNodeNo = %s lNowTime = %d,llastTime = %d,interval = %s", strDataNodeNo.c_str(),lNowTime, llastTime, vetRes[i][21].c_str());
|
zlog_warn(zct, "offline DataNodeStatusCheck DataNodeNo = %s lNowTime = %d,llastTime = %d,interval = %s", strDataNodeNo.c_str(),lNowTime, llastTime, vetRes[i][21].c_str());
|
||||||
char whereCon[32] = {0};
|
char whereCon[32] = {0};
|
||||||
@ -741,7 +742,7 @@ void JsonData::DataNodeStatusCheck() {
|
|||||||
int lTimeTemp = lNowTime - llastTime;
|
int lTimeTemp = lNowTime - llastTime;
|
||||||
lTimeTemp = abs(lTimeTemp);
|
lTimeTemp = abs(lTimeTemp);
|
||||||
if (lTimeTemp > onlineCheck) {
|
if (lTimeTemp > onlineCheck) {
|
||||||
zlog_warn(zct, "offline DataNodeStatusCheck mac = %s lNowTime = %d,llastTime = %d,interval = %s", mac.c_str(),lNowTime, llastTime);
|
zlog_warn(zct, "offline DataNodeStatusCheck mac = %s lNowTime = %d,llastTime = %d", mac.c_str(),lNowTime, llastTime);
|
||||||
char whereCon[32] = {0};
|
char whereCon[32] = {0};
|
||||||
sprintf(whereCon, "mac='%s'", mac.c_str());
|
sprintf(whereCon, "mac='%s'", mac.c_str());
|
||||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_BT_INFO(TNAME), "status='0'", whereCon);
|
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_BT_INFO(TNAME), "status='0'", whereCon);
|
||||||
|
|||||||
@ -338,7 +338,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
|||||||
array_t vecRes;
|
array_t vecRes;
|
||||||
|
|
||||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
Json::Value jsStaticData;
|
Json::Value jsStaticData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
@ -371,7 +371,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) {
|
|||||||
jsonVal["content"] = (jsStaticData);
|
jsonVal["content"] = (jsStaticData);
|
||||||
}
|
}
|
||||||
jsonVal["Static"] = param.strStatic;
|
jsonVal["Static"] = param.strStatic;
|
||||||
zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
zlog_info(zct, "vecRes = %zu,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
||||||
} else {
|
} else {
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
|
|||||||
@ -312,64 +312,132 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
|||||||
char localtimestamp[32] = {0};
|
char localtimestamp[32] = {0};
|
||||||
std::string strWaveData = "";
|
std::string strWaveData = "";
|
||||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||||
if (access(filename.c_str(), 0) >= 0) {
|
std::string softVersion = res[9];
|
||||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
std::string productNo = res[17];
|
||||||
if (!inFile) {
|
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") // DN101所有版本和DN102 2.6以前版本
|
||||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
{
|
||||||
jsonVal["success"] = false;
|
if (access(filename.c_str(), 0) >= 0 && param.mMode == 0) {
|
||||||
jsonVal["message"] = "error";
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
} else {
|
if (!inFile) {
|
||||||
float fTemp = 0.0f;
|
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
jsonVal["success"] = false;
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
jsonVal["message"] = "error";
|
||||||
vecWave.push_back(fTemp);
|
} else {
|
||||||
}
|
float fTemp = 0.0f;
|
||||||
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
int flag = param.mPackageFlag;
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
flag = (flag + 1) * 1024;
|
vecWave.push_back(fTemp);
|
||||||
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 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;
|
||||||
}
|
}
|
||||||
int max = number / 1024;
|
|
||||||
if (max == 0 && number > 0) {
|
} else {
|
||||||
max = 1;
|
jsonVal["success"] = false;
|
||||||
}
|
jsonVal["message"] = "没有数据文件";
|
||||||
jsBody["packageMax"] = max;
|
}
|
||||||
|
|
||||||
|
zlog_info(zct, "vecWave.size() = %zu,sample = %d,second = %f", vecWave.size(), atoi(res[23].c_str()), float(vecWave.size() / atoi(res[23].c_str())));
|
||||||
|
std::string::size_type comper = param.mChannelId.find("Z");
|
||||||
|
if (comper != std::string::npos && res[17] == "02") {
|
||||||
|
jsBody["second"] = float((float)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;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (param.mMode == 1) // DN102 有高频和低频
|
||||||
|
{
|
||||||
|
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
|
||||||
|
jsBody["second"] = 3.2;
|
||||||
|
}else{
|
||||||
|
std::string::size_type comper = param.mChannelId.find("Z");
|
||||||
|
if (comper != std::string::npos ) {
|
||||||
|
jsBody["second"] = 1.28;
|
||||||
|
} else {
|
||||||
|
jsBody["second"] = 1.6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zlog_info(zct,"filename %s",filename.c_str());
|
||||||
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
|
if (!inFile) {
|
||||||
|
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "error";
|
||||||
|
} else {
|
||||||
|
float fTemp = 0.0f;
|
||||||
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
|
vecWave.push_back(fTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
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"] = "没有数据文件";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
jsonVal["success"] = false;
|
|
||||||
jsonVal["message"] = "没有数据文件";
|
|
||||||
}
|
}
|
||||||
jsBody["channelId"] = param.mChannelId;
|
jsBody["channelId"] = param.mChannelId;
|
||||||
jsBody["package"] = param.mPackageFlag;
|
jsBody["package"] = param.mPackageFlag;
|
||||||
zlog_info(zct, "vecWave.size() = %d,sample = %d,second = %f", vecWave.size(), atoi(res[23].c_str()), float(vecWave.size() / atoi(res[23].c_str())));
|
|
||||||
std::string::size_type comper = param.mChannelId.find("Z");
|
|
||||||
if (comper != std::string::npos && res[17] == "02") {
|
|
||||||
jsBody["second"] = float((float)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["Data"] = strWaveData;
|
||||||
jsBody["timestamp"] = std::string(localtimestamp);
|
jsBody["timestamp"] = std::string(localtimestamp);
|
||||||
@ -399,69 +467,130 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
char whereCon[64] = {};
|
char whereCon[64] = {};
|
||||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||||
if (access(filename.c_str(), 0) >= 0) {
|
std::string softVersion = res[9];
|
||||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
std::string productNo = res[17];
|
||||||
if (!inFile) {
|
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") // DN101所有版本和DN102 2.6以前版本
|
||||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
{
|
||||||
jsonVal["success"] = "false";
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
jsonVal["message"] = "error";
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
} else {
|
if (!inFile) {
|
||||||
float fTemp = 0.0f;
|
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||||
|
jsonVal["success"] = "false";
|
||||||
|
jsonVal["message"] = "error";
|
||||||
|
} else {
|
||||||
|
float fTemp = 0.0f;
|
||||||
|
|
||||||
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
|
std::string::size_type comper = param.mChannelId.find("Z");
|
||||||
|
if (comper != std::string::npos && res[17] == "02") {
|
||||||
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
|
vecWave.push_back(fTemp);
|
||||||
|
}
|
||||||
|
//进行傅立叶变换
|
||||||
|
Calculation::FFTSpec(vecWave, fftWave);
|
||||||
|
sampleRateReference = 1000;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
||||||
|
vecWave.push_back(fTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//进行傅立叶变换
|
||||||
|
Calculation::FFTSpec(vecWave, fftWave);
|
||||||
|
sampleRateReference = 1024;
|
||||||
|
}
|
||||||
|
int flag = param.mPackageFlag;
|
||||||
|
flag = (flag + 1) * sampleRateReference;
|
||||||
|
int number = fftWave.size();
|
||||||
|
int start = param.mPackageFlag * sampleRateReference;
|
||||||
|
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"] = "没有数据文件";
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (param.mMode == 1 && productNo == "02") // DN102 有高频和低频
|
||||||
|
{
|
||||||
|
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
|
||||||
|
}
|
||||||
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
|
if (!inFile) {
|
||||||
|
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||||
|
jsonVal["success"] = "false";
|
||||||
|
jsonVal["message"] = "error";
|
||||||
|
} else {
|
||||||
|
float fTemp = 0.0f;
|
||||||
|
|
||||||
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
|
|
||||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
|
||||||
std::string::size_type comper = param.mChannelId.find("Z");
|
|
||||||
if (comper != std::string::npos && res[17] == "02") {
|
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
vecWave.push_back(fTemp);
|
vecWave.push_back(fTemp);
|
||||||
}
|
}
|
||||||
//进行傅立叶变换
|
|
||||||
Calculation::FFTSpec(vecWave, fftWave);
|
|
||||||
sampleRateReference = 1000;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
|
||||||
vecWave.push_back(fTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//进行傅立叶变换
|
//进行傅立叶变换
|
||||||
Calculation::FFTSpec(vecWave, fftWave);
|
Calculation::FFTSpec(vecWave, fftWave);
|
||||||
sampleRateReference = 1024;
|
sampleRateReference = 1024;
|
||||||
}
|
|
||||||
int flag = param.mPackageFlag;
|
|
||||||
flag = (flag + 1) * sampleRateReference;
|
|
||||||
int number = fftWave.size();
|
|
||||||
int start = param.mPackageFlag * sampleRateReference;
|
|
||||||
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 {
|
int flag = param.mPackageFlag;
|
||||||
memset(buf, 0, 32);
|
flag = (flag + 1) * sampleRateReference;
|
||||||
sprintf(buf, "%.6f", fftWave[i]);
|
int number = fftWave.size();
|
||||||
std::string waveTemp(buf);
|
int start = param.mPackageFlag * sampleRateReference;
|
||||||
strWaveData = strWaveData + "," + waveTemp;
|
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;
|
||||||
|
|
||||||
int max = number / sampleRateReference;
|
} else {
|
||||||
if (max == 0 && number > 0) {
|
memset(buf, 0, 32);
|
||||||
max = 1;
|
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;
|
||||||
}
|
}
|
||||||
jsBody["packageMax"] = max;
|
} else {
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "没有数据文件";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
jsonVal["success"] = false;
|
|
||||||
jsonVal["message"] = "没有数据文件";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsBody["channelId"] = param.mChannelId;
|
jsBody["channelId"] = param.mChannelId;
|
||||||
jsBody["package"] = param.mPackageFlag;
|
jsBody["package"] = param.mPackageFlag;
|
||||||
jsBody["timestamp"] = std::string(localtimestamp);
|
jsBody["timestamp"] = std::string(localtimestamp);
|
||||||
@ -475,7 +604,8 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
zlog_info(zct, "sample_rate=%d", SampleRate);
|
zlog_info(zct, "sample_rate=%d", SampleRate);
|
||||||
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
||||||
|
|
||||||
} else if (res[17] == "02") {
|
}
|
||||||
|
if ((res[17] == "02" && compareVersions(softVersion, "2.6") == -1) || productNo == "01") {
|
||||||
std::string::size_type comper = param.mChannelId.find("Z");
|
std::string::size_type comper = param.mChannelId.find("Z");
|
||||||
if (comper != std::string::npos) {
|
if (comper != std::string::npos) {
|
||||||
SampleRate = atoi(res[23].c_str());
|
SampleRate = atoi(res[23].c_str());
|
||||||
@ -490,6 +620,8 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
|||||||
resolution = (double)SampleRate / 8192;
|
resolution = (double)SampleRate / 8192;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
resolution = 1 / 3.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "the sample rate is %d,the resolution %f", SampleRate, resolution);
|
zlog_info(zct, "the sample rate is %d,the resolution %f", SampleRate, resolution);
|
||||||
@ -588,10 +720,10 @@ std::string JsonData::JsonCmd_Cgi_40(Param_40 ¶m) {
|
|||||||
envWave[i] = envWave[i]*2;
|
envWave[i] = envWave[i]*2;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
zlog_info(zct, "2---------------------------------------------->%d", envWave.size());
|
zlog_info(zct, "2---------------------------------------------->%zu", envWave.size());
|
||||||
zlog_info(zct, "2---------------------------------------------->%f", envWave[10]);
|
zlog_info(zct, "2---------------------------------------------->%f", envWave[10]);
|
||||||
|
|
||||||
zlog_info(zct, "after fft--------------------------------------------------->fftWave.size()=%d", envWave.size());
|
zlog_info(zct, "after fft--------------------------------------------------->fftWave.size()=%zu", envWave.size());
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * sampleRateReference;
|
flag = (flag + 1) * sampleRateReference;
|
||||||
|
|||||||
@ -163,7 +163,7 @@ std::string JsonData::JsonCmd_Cgi_52(Param_52 ¶m) {
|
|||||||
boost::split(vecSsid, netssid, boost::is_any_of("\n"), boost::token_compress_off);
|
boost::split(vecSsid, netssid, boost::is_any_of("\n"), boost::token_compress_off);
|
||||||
jsBody["type"] = "SCAN";
|
jsBody["type"] = "SCAN";
|
||||||
jsBody["enable"] = true;
|
jsBody["enable"] = true;
|
||||||
zlog_info(zct,"netssid : %s === %d", netssid.c_str(), vecSsid.size());
|
zlog_info(zct,"netssid : %s === %zu", netssid.c_str(), vecSsid.size());
|
||||||
for (unsigned int i = 1; i < vecSsid.size() - 1; i++) {
|
for (unsigned int i = 1; i < vecSsid.size() - 1; i++) {
|
||||||
std::vector<std::string> data;
|
std::vector<std::string> data;
|
||||||
boost::split(data, vecSsid[i], boost::is_any_of("\t"), boost::token_compress_off);
|
boost::split(data, vecSsid[i], boost::is_any_of("\t"), boost::token_compress_off);
|
||||||
@ -274,11 +274,12 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
SampleRate = atoi(res[23].c_str());
|
SampleRate = atoi(res[23].c_str());
|
||||||
zlog_info(zct,"sensor type %s", res[17].c_str());
|
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||||
std::string softVersion = res[9];
|
std::string softVersion = res[9];
|
||||||
|
std::string productNo = res[17];
|
||||||
char localtimestamp[32] = {0};
|
char localtimestamp[32] = {0};
|
||||||
std::string strWaveData = "";
|
std::string strWaveData = "";
|
||||||
if (compareVersions(softVersion, "2.6") == -1) {
|
std::string filename = "";
|
||||||
|
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") {
|
||||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||||
if (access(filename.c_str(), 0) >= 0) {
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
if (!inFile) {
|
if (!inFile) {
|
||||||
@ -347,7 +348,7 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
jsonVal["message"] = "没有数据文件";
|
jsonVal["message"] = "没有数据文件";
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
std::string filename = "/opt/data/" + param.mChannelId + "-VOL.dat";
|
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
|
||||||
if (access(filename.c_str(), 0) >= 0) {
|
if (access(filename.c_str(), 0) >= 0) {
|
||||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||||
if (!inFile) {
|
if (!inFile) {
|
||||||
@ -355,15 +356,20 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "error";
|
jsonVal["message"] = "error";
|
||||||
} else {
|
} else {
|
||||||
float fTemp = 0.0f;
|
float fTemp = 0;
|
||||||
|
std::vector<float> hanningWave;
|
||||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||||
vecWave.push_back(fTemp);
|
vecWave.push_back(fTemp);
|
||||||
}
|
}
|
||||||
|
resolution = 1 / 3.2 ;
|
||||||
|
|
||||||
|
//积分
|
||||||
|
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * 1024;
|
flag = (flag + 1) * 1024;
|
||||||
int number = vecWave.size();
|
int number = IntegrationWave.size();
|
||||||
int start = param.mPackageFlag * 1024;
|
int start = param.mPackageFlag * 1024;
|
||||||
if (number < 1024) {
|
if (number < 1024) {
|
||||||
flag = number;
|
flag = number;
|
||||||
@ -373,24 +379,24 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
for (int i = start; i < flag; i++) {
|
for (int i = start; i < flag; i++) {
|
||||||
if (i == start) {
|
if (i == start) {
|
||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
sprintf(buf, "%.2f", vecWave[i]);
|
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||||
std::string waveTemp(buf);
|
std::string waveTemp(buf);
|
||||||
strWaveData = waveTemp;
|
strWaveData = waveTemp;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
sprintf(buf, "%.2f", vecWave[i]);
|
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||||
std::string waveTemp(buf);
|
std::string waveTemp(buf);
|
||||||
strWaveData = strWaveData + "," + waveTemp;
|
strWaveData = strWaveData + "," + waveTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int max = number / 1024;
|
int max = number / 1024;
|
||||||
if (max == 0 && number > 0) {
|
if (max == 0 && number > 0) {
|
||||||
max = 1;
|
max = 1;
|
||||||
}
|
}
|
||||||
jsBody["packageMax"] = max;
|
jsBody["packageMax"] = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "没有数据文件";
|
jsonVal["message"] = "没有数据文件";
|
||||||
@ -399,14 +405,18 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
|||||||
|
|
||||||
jsBody["channelId"] = param.mChannelId;
|
jsBody["channelId"] = param.mChannelId;
|
||||||
jsBody["package"] = param.mPackageFlag;
|
jsBody["package"] = param.mPackageFlag;
|
||||||
zlog_info(zct,"vecWave.size() = %d,sample = %d,second = %f", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.size() / atoi(res[23].c_str())));
|
zlog_info(zct,"vecWave.size() = %zu,sample = %d,second = %f", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.size() / atoi(res[23].c_str())));
|
||||||
std::string::size_type comper = param.mChannelId.find("Z");
|
if ((res[17] == "02" && compareVersions(softVersion, "2.6") == -1) || productNo == "01") {
|
||||||
if (comper != std::string::npos && res[17] == "02") {
|
std::string::size_type comper = param.mChannelId.find("Z");
|
||||||
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
if (comper != std::string::npos && res[17] == "02") {
|
||||||
} else if (res[17] == "01") {
|
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
||||||
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
} else if (res[17] == "01") {
|
||||||
} else {
|
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
||||||
jsBody["second"] = 1;
|
} else {
|
||||||
|
jsBody["second"] = 1;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
jsBody["second"] = 3.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsBody["Data"] = strWaveData;
|
jsBody["Data"] = strWaveData;
|
||||||
@ -497,7 +507,7 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
|||||||
|
|
||||||
sampleRateReference = 1024;
|
sampleRateReference = 1024;
|
||||||
}
|
}
|
||||||
zlog_info(zct,"2---------------------------------------------->vecWave = %d,fftWave = %d", vecWave.size(), fftWave.size());
|
zlog_info(zct,"2---------------------------------------------->vecWave = %zu,fftWave = %zu", vecWave.size(), fftWave.size());
|
||||||
|
|
||||||
int flag = param.mPackageFlag;
|
int flag = param.mPackageFlag;
|
||||||
flag = (flag + 1) * sampleRateReference;
|
flag = (flag + 1) * sampleRateReference;
|
||||||
@ -891,7 +901,7 @@ std::string JsonData::JsonCmd_Cgi_61(Param_61 ¶m){
|
|||||||
array_t vecRes;
|
array_t vecRes;
|
||||||
|
|
||||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
Json::Value jsStaticData;
|
Json::Value jsStaticData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
@ -940,7 +950,7 @@ std::string JsonData::JsonCmd_Cgi_61(Param_61 ¶m){
|
|||||||
jsonVal["content"] = (jsStaticData);
|
jsonVal["content"] = (jsStaticData);
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
zlog_info(zct, "vecRes = %zu,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
||||||
} else {
|
} else {
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
@ -1030,7 +1040,7 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){
|
|||||||
array_t vecRes;
|
array_t vecRes;
|
||||||
|
|
||||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, selectCon, whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
Json::Value jsStaticData;
|
Json::Value jsStaticData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
@ -1048,7 +1058,7 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){
|
|||||||
jsonVal["content"] = (jsStaticData);
|
jsonVal["content"] = (jsStaticData);
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
zlog_info(zct, "vecRes = %zu,channelID = %s", vecRes.size(), vecRes[0][0].c_str());
|
||||||
} else {
|
} else {
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
@ -1117,7 +1127,7 @@ std::string JsonData::JsonCmd_Cgi_64(Param_64 ¶m)
|
|||||||
{
|
{
|
||||||
std::vector<FeatureEntryUploadCfg> cfg;
|
std::vector<FeatureEntryUploadCfg> cfg;
|
||||||
wave_feature_set_inst::instance().GetAllWaveCfg(cfg);
|
wave_feature_set_inst::instance().GetAllWaveCfg(cfg);
|
||||||
zlog_info(zct,"cfg size = %d",cfg.size());
|
zlog_info(zct,"cfg size = %zu",cfg.size());
|
||||||
if (cfg.size() > 0)
|
if (cfg.size() > 0)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < cfg.size(); i++)
|
for (size_t i = 0; i < cfg.size(); i++)
|
||||||
@ -1271,7 +1281,7 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
|||||||
iTem.append(resend_z);
|
iTem.append(resend_z);
|
||||||
iTem.append(60); //信号
|
iTem.append(60); //信号
|
||||||
iTem.append(vetRes[i][3]); //电池
|
iTem.append(vetRes[i][3]); //电池
|
||||||
sprintf(whereCon,"timeStamp <> '' order by timeStamp desc limit 0,1 ",MeasurementID.c_str());
|
sprintf(whereCon,"timeStamp <> '' order by timeStamp desc limit 0,1 ");
|
||||||
memset(szTableName,0,sizeof(szTableName));
|
memset(szTableName,0,sizeof(szTableName));
|
||||||
sprintf(szTableName,"t_dataStatic_%s",vetRes[i][1].c_str());
|
sprintf(szTableName,"t_dataStatic_%s",vetRes[i][1].c_str());
|
||||||
std::string voltage = sqlite_db_ctrl::instance().GetData(szTableName, "voltage", whereCon);
|
std::string voltage = sqlite_db_ctrl::instance().GetData(szTableName, "voltage", whereCon);
|
||||||
@ -1456,7 +1466,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
|||||||
iTem.append(atoi(arrRes[i][2].c_str()));
|
iTem.append(atoi(arrRes[i][2].c_str()));
|
||||||
iTem.append(atoi(arrRes[i][3].c_str()));
|
iTem.append(atoi(arrRes[i][3].c_str()));
|
||||||
iTem.append(atof(arrRes[i][4].c_str()));
|
iTem.append(atof(arrRes[i][4].c_str()));
|
||||||
iTem.append(arrRes[i][5]);
|
iTem.append(arrRes[i][6]);
|
||||||
dataNodeArray.append(iTem);
|
dataNodeArray.append(iTem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1509,7 +1519,7 @@ std::string JsonData::JsonCmd_Cgi_69(Param_69 ¶m){
|
|||||||
iTem.append(atoi(arrRes[i][3].c_str()));
|
iTem.append(atoi(arrRes[i][3].c_str()));
|
||||||
iTem.append(atoi(arrRes[i][4].c_str()));
|
iTem.append(atoi(arrRes[i][4].c_str()));
|
||||||
iTem.append(atof(arrRes[i][5].c_str()));
|
iTem.append(atof(arrRes[i][5].c_str()));
|
||||||
iTem.append(arrRes[i][6]);
|
iTem.append(arrRes[i][7]);
|
||||||
dataNodeArray.append(iTem);
|
dataNodeArray.append(iTem);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1562,7 +1572,7 @@ std::string JsonData::JsonCmd_Cgi_70(Param_70 ¶m){
|
|||||||
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
||||||
array_t vecRes;
|
array_t vecRes;
|
||||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
Json::Value jsStaticData;
|
Json::Value jsStaticData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
@ -1623,7 +1633,7 @@ std::string JsonData::JsonCmd_Cgi_71(Param_71 ¶m){
|
|||||||
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
sprintf(whereCon, "timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
||||||
array_t vecRes;
|
array_t vecRes;
|
||||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
Json::Value jsStaticData;
|
Json::Value jsStaticData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
|
|||||||
@ -119,7 +119,7 @@ std::string JsonData::JsonCmd_Cgi_101(Param_101 ¶m){
|
|||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "mac = '%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.mac.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 400, packgeNum);
|
sprintf(whereCon, "mac = '%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.mac.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 400, packgeNum);
|
||||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" blueteeth_info ", "blueteeth_temp,chip_temp,volt,rssi_percent,timestamp", whereCon);
|
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" blueteeth_info ", "blueteeth_temp,chip_temp,volt,rssi_percent,timestamp", whereCon);
|
||||||
zlog_info(zct, "arrRes size = %d", arrRes.size());
|
zlog_info(zct, "arrRes size = %zu", arrRes.size());
|
||||||
if (arrRes.size() > 0) {
|
if (arrRes.size() > 0) {
|
||||||
Json::Value jsSensorData;
|
Json::Value jsSensorData;
|
||||||
Json::Value iTem1, iTem2, iTem3,iTem4;
|
Json::Value iTem1, iTem2, iTem3,iTem4;
|
||||||
@ -153,7 +153,10 @@ std::string JsonData::JsonCmd_Cgi_102(){
|
|||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["message"] = "获取传感器信息成功";
|
jsonVal["message"] = "获取传感器信息成功";
|
||||||
Json::Value jsBody;
|
Json::Value jsBody;
|
||||||
for (const auto& [mac, info] : device_map) {
|
for (auto it = device_map.begin(); it != device_map.end(); it++)
|
||||||
|
{
|
||||||
|
std::string mac = it->first;
|
||||||
|
DeviceInfo info = it->second;
|
||||||
std::cout << mac << " RSSI: " << info.rssi << "\n";
|
std::cout << mac << " RSSI: " << info.rssi << "\n";
|
||||||
|
|
||||||
Json::Value item;
|
Json::Value item;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ void CMTSession::set_data(char *data, int len) {
|
|||||||
}
|
}
|
||||||
void CMTSession::do_write(std::size_t length) {
|
void CMTSession::do_write(std::size_t length) {
|
||||||
auto self(shared_from_this());
|
auto self(shared_from_this());
|
||||||
zlog_debug(zct, "[CMT] response len = %d", length);
|
zlog_debug(zct, "[CMT] response len = %zu", length);
|
||||||
boost::asio::async_write(socket_, boost::asio::buffer(data_, length), [this, self](boost::system::error_code ec, std::size_t /*length*/) {
|
boost::asio::async_write(socket_, boost::asio::buffer(data_, length), [this, self](boost::system::error_code ec, std::size_t /*length*/) {
|
||||||
if (ec) {
|
if (ec) {
|
||||||
zlog_error(zct, "[CMT] fail to send data, %s, %d", ec.category().name(), ec.value());
|
zlog_error(zct, "[CMT] fail to send data, %s, %d", ec.category().name(), ec.value());
|
||||||
@ -57,14 +57,14 @@ void CMTSession::do_read() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (length < 6 || data_[0] != 0xAA || data_[1] != 0x55 || data_[2] != 0xAA) {
|
if (length < 6 || data_[0] != 0xAA || data_[1] != 0x55 || data_[2] != 0xAA) {
|
||||||
zlog_warn(zct, "[CMT] invalid data package, len:%d", length);
|
zlog_warn(zct, "[CMT] invalid data package, len:%zu", length);
|
||||||
do_read();
|
do_read();
|
||||||
}
|
}
|
||||||
uint8_t cmd = data_[3];
|
uint8_t cmd = data_[3];
|
||||||
int payload_len = 0;
|
int payload_len = 0;
|
||||||
memcpy((char*)&payload_len, (char*)&data_[4], 4);
|
memcpy((char*)&payload_len, (char*)&data_[4], 4);
|
||||||
payload_len = htonl(payload_len);
|
payload_len = htonl(payload_len);
|
||||||
zlog_debug(zct, "[CMT] cmd: %d, message len: %d, payload len: %d, head:%2x-%2x-%2x", cmd, length, payload_len, data_[0], data_[1], data_[2]);
|
zlog_debug(zct, "[CMT] cmd: %d, message len: %zu, payload len: %d, head:%2x-%2x-%2x", cmd, length, payload_len, data_[0], data_[1], data_[2]);
|
||||||
zlog_debug(zct, "[CMT] payload bytes %d, %d", data_[4], data_[5]);
|
zlog_debug(zct, "[CMT] payload bytes %d, %d", data_[4], data_[5]);
|
||||||
int send_data_len = 0;
|
int send_data_len = 0;
|
||||||
char send_data[96100] = {0};
|
char send_data[96100] = {0};
|
||||||
|
|||||||
@ -197,6 +197,12 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
case kGetTimeDomainWave: {
|
case kGetTimeDomainWave: {
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
Param_29 param;
|
Param_29 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (type == "HIGH") {
|
||||||
|
param.mMode = 0;
|
||||||
|
} else if (type == "LOW") {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
param.mChannelId = recvBody["channelId"].asString();
|
param.mChannelId = recvBody["channelId"].asString();
|
||||||
param.mPackageFlag = recvBody["package"].asInt();
|
param.mPackageFlag = recvBody["package"].asInt();
|
||||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
@ -206,6 +212,12 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
case kGetFreqDomainWave: {
|
case kGetFreqDomainWave: {
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
Param_30 param;
|
Param_30 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (type == "HIGH") {
|
||||||
|
param.mMode = 0;
|
||||||
|
} else if (type == "LOW") {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
param.mChannelId = recvBody["channelId"].asString();
|
param.mChannelId = recvBody["channelId"].asString();
|
||||||
param.mPackageFlag = recvBody["package"].asInt();
|
param.mPackageFlag = recvBody["package"].asInt();
|
||||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
|
|||||||
@ -165,22 +165,41 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
|
|||||||
else {
|
else {
|
||||||
if (slice_sensor_id_[nth_wave_slice] == 0) { // idle time
|
if (slice_sensor_id_[nth_wave_slice] == 0) { // idle time
|
||||||
zlog_debug(zbt, "[%d:%x] in idle time", id, short_addr);
|
zlog_debug(zbt, "[%d:%x] in idle time", id, short_addr);
|
||||||
|
if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) {
|
||||||
|
auto iter = trigger_wave_record_.find(short_addr);
|
||||||
|
if (iter->second.first != 0) {
|
||||||
|
current_request_ = kScheduleWaveForm;
|
||||||
|
z = true;
|
||||||
|
zlog_debug(zbt, "[%d:%x] trigger z wave time", id, short_addr);
|
||||||
|
iter->second.first = 0;
|
||||||
|
WriteTriggerWaveRecord();
|
||||||
|
return kScheduleWaveForm;
|
||||||
|
} else if (iter->second.second != 0) {
|
||||||
|
current_request_ = kScheduleWaveForm;
|
||||||
|
z = false;
|
||||||
|
iter->second.second = 0;
|
||||||
|
WriteTriggerWaveRecord();
|
||||||
|
zlog_debug(zbt, "[%d:%x] trigger xy wave time", id, short_addr);
|
||||||
|
return kScheduleWaveForm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ZRetransferWave(short_addr)) {
|
if (ZRetransferWave(short_addr)) {
|
||||||
zlog_debug(zbt, "[%d:%x] z retransfer wave time", id, short_addr);
|
zlog_debug(zbt, "[%d:%x] z retransfer wave time", id, short_addr);
|
||||||
current_request_ = kScheduleWaveForm;
|
current_request_ = kScheduleWaveForm;
|
||||||
z = true;
|
z = true;
|
||||||
return kScheduleWaveForm;
|
return kScheduleWaveForm;
|
||||||
} else if (XYRetransferWave(short_addr)) {
|
|
||||||
zlog_debug(zbt, "[%d:%x] xy retransfer wave time", id, short_addr);
|
|
||||||
current_request_ = kScheduleWaveForm;
|
|
||||||
z = false;
|
|
||||||
return kScheduleWaveForm;
|
|
||||||
} else if (ZMissedWave(short_addr)) {
|
} else if (ZMissedWave(short_addr)) {
|
||||||
zlog_debug(zbt, "[%d:%x] z patch wave time", id, short_addr);
|
zlog_debug(zbt, "[%d:%x] z patch wave time", id, short_addr);
|
||||||
current_request_ = kScheduleWaveForm;
|
current_request_ = kScheduleWaveForm;
|
||||||
z = true;
|
z = true;
|
||||||
z_patch_set_.erase(short_addr);
|
z_patch_set_.erase(short_addr);
|
||||||
return kScheduleWaveForm;
|
return kScheduleWaveForm;
|
||||||
|
} else if (XYRetransferWave(short_addr)) {
|
||||||
|
zlog_debug(zbt, "[%d:%x] xy retransfer wave time", id, short_addr);
|
||||||
|
current_request_ = kScheduleWaveForm;
|
||||||
|
z = false;
|
||||||
|
return kScheduleWaveForm;
|
||||||
} else if (XYMissedWave(short_addr)) {
|
} else if (XYMissedWave(short_addr)) {
|
||||||
zlog_debug(zbt, "[%d:%x] xy patch wave time", id, short_addr);
|
zlog_debug(zbt, "[%d:%x] xy patch wave time", id, short_addr);
|
||||||
current_request_ = kScheduleWaveForm;
|
current_request_ = kScheduleWaveForm;
|
||||||
@ -287,49 +306,81 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_z && !ZMissedWave(short_addr) && send_wave_ts == 0 && z_success_set_.count(short_addr) == 0) {
|
if ((g_z || g_x || g_y) && send_wave_ts == 0) {
|
||||||
// add for patch wave
|
if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) {
|
||||||
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1;
|
auto iter = trigger_wave_record_.find(short_addr);
|
||||||
auto wave_slice_iter = sensor_id_nth_slice_.find(id);
|
if (iter->second.first != 0 || iter->second.second != 0) {
|
||||||
if (wave_slice_iter != sensor_id_nth_slice_.end()) {
|
for (int i = forward_wave_slice_num+1; i <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_; ++i) {
|
||||||
if (nth_wave_slice > wave_slice_iter->second.first) {
|
if (slice_sensor_id_[i] == 0) {
|
||||||
if (z_success_set_.count(short_addr) == 0 && !ZRetransferWave(short_addr)) {
|
send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60;
|
||||||
zlog_debug(zbt, "[Nxt] [%d:%x] add z to patch set", id, short_addr);
|
|
||||||
z_patch_set_.insert(short_addr);
|
if (free_slice_ocuppied_.count(send_wave_ts) == 0) {
|
||||||
z = true;
|
available_ts = send_wave_ts;
|
||||||
}
|
free_slice_ocuppied_.insert(available_ts);
|
||||||
}
|
next_task_id = kScheduleWaveForm;
|
||||||
}
|
if (iter->second.first != 0) {
|
||||||
} else if ((g_x || g_y) && !XYMissedWave(short_addr) && send_wave_ts == 0 && xy_success_set_.count(short_addr) == 0) {
|
z = true;
|
||||||
// add for patch wave
|
} else {
|
||||||
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1;
|
z = false;
|
||||||
auto wave_slice_iter = sensor_id_nth_slice_.find(id);
|
}
|
||||||
if (wave_slice_iter != sensor_id_nth_slice_.end()) {
|
|
||||||
if (nth_wave_slice > wave_slice_iter->second.second) {
|
zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to trigger wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
|
||||||
if (xy_success_set_.count(short_addr) == 0 && !XYRetransferWave(short_addr)) {
|
break;
|
||||||
zlog_debug(zbt, "[Nxt] [%d:%x] add xy to patch set", id, short_addr);
|
} else {
|
||||||
xy_patch_set_.insert(short_addr);
|
send_wave_ts = 0;
|
||||||
z = false;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZRetransferWave(short_addr) || XYRetransferWave(short_addr) || ZMissedWave(short_addr) || XYMissedWave(short_addr)) {
|
if (send_wave_ts == 0) {
|
||||||
for (int i = 1; i <= wave_slice_num_per_eigen_interval_; ++i) {
|
if (g_z && !ZMissedWave(short_addr) && z_success_set_.count(short_addr) == 0) {
|
||||||
if (slice_sensor_id_[i+forward_wave_slice_num] == 0) {
|
// add for patch wave
|
||||||
// 判断此空闲位置是否被占用
|
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1;
|
||||||
long current_wave_slice_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-1) * seconds_per_wave_slice_;
|
auto wave_slice_iter = sensor_id_nth_slice_.find(id);
|
||||||
if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) {
|
if (wave_slice_iter != sensor_id_nth_slice_.end()) {
|
||||||
available_ts = current_wave_slice_ts;
|
if (nth_wave_slice > wave_slice_iter->second.first) {
|
||||||
free_slice_ocuppied_.insert(available_ts);
|
if (z_success_set_.count(short_addr) == 0 && !ZRetransferWave(short_addr)) {
|
||||||
if (ZRetransferWave(short_addr) || ZMissedWave(short_addr)) {
|
zlog_debug(zbt, "[Nxt] [%d:%x] add z to patch set", id, short_addr);
|
||||||
|
z_patch_set_.insert(short_addr);
|
||||||
z = true;
|
z = true;
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((g_x || g_y) && !XYMissedWave(short_addr) && xy_success_set_.count(short_addr) == 0) {
|
||||||
|
// add for patch wave
|
||||||
|
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1;
|
||||||
|
auto wave_slice_iter = sensor_id_nth_slice_.find(id);
|
||||||
|
if (wave_slice_iter != sensor_id_nth_slice_.end()) {
|
||||||
|
if (nth_wave_slice > wave_slice_iter->second.second) {
|
||||||
|
if (xy_success_set_.count(short_addr) == 0 && !XYRetransferWave(short_addr)) {
|
||||||
|
zlog_debug(zbt, "[Nxt] [%d:%x] add xy to patch set", id, short_addr);
|
||||||
|
xy_patch_set_.insert(short_addr);
|
||||||
z = false;
|
z = false;
|
||||||
}
|
}
|
||||||
zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer or patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
|
}
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ZRetransferWave(short_addr) || XYRetransferWave(short_addr) || ZMissedWave(short_addr) || XYMissedWave(short_addr)) {
|
||||||
|
for (int i = 1; i <= wave_slice_num_per_eigen_interval_; ++i) {
|
||||||
|
if (slice_sensor_id_[i+forward_wave_slice_num] == 0) {
|
||||||
|
// 判断此空闲位置是否被占用
|
||||||
|
long current_wave_slice_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-1) * seconds_per_wave_slice_;
|
||||||
|
if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) {
|
||||||
|
available_ts = current_wave_slice_ts;
|
||||||
|
free_slice_ocuppied_.insert(available_ts);
|
||||||
|
if (ZRetransferWave(short_addr) || ZMissedWave(short_addr)) {
|
||||||
|
z = true;
|
||||||
|
} else {
|
||||||
|
z = false;
|
||||||
|
}
|
||||||
|
zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer or patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,6 +472,13 @@ int SensorScheduler::GetNextDuration(uint16_t short_addr, bool &z, int &next_tas
|
|||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SensorScheduler::TriggerWave(uint16_t short_addr, uint8_t z, uint8_t xy) {
|
||||||
|
zlog_debug(zbt, "[%x] trigger wave z:%d, xy:%d", short_addr, z, xy);
|
||||||
|
std::pair<uint8_t, uint8_t> p = {z, xy};
|
||||||
|
trigger_wave_record_[short_addr] = p;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 仅返回下一次特征值的时间,用于Debug/Upgrade模式
|
// 仅返回下一次特征值的时间,用于Debug/Upgrade模式
|
||||||
int SensorScheduler::GetDebugUpgradeNextDuration(uint16_t short_addr) {
|
int SensorScheduler::GetDebugUpgradeNextDuration(uint16_t short_addr) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
@ -473,6 +531,7 @@ long SensorScheduler::GetDebugUpgradeNextTS(uint16_t short_addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SensorScheduler::SensorScheduler() {
|
SensorScheduler::SensorScheduler() {
|
||||||
|
ReadTriggerWaveRecord();
|
||||||
current_schedule_status_ = get_schedule_status();
|
current_schedule_status_ = get_schedule_status();
|
||||||
slice_sensor_id_ = NULL;
|
slice_sensor_id_ = NULL;
|
||||||
zlog_debug(zbt, "current schedule status:%s", get_status_desc(current_schedule_status_).c_str());
|
zlog_debug(zbt, "current schedule status:%s", get_status_desc(current_schedule_status_).c_str());
|
||||||
@ -1394,3 +1453,65 @@ std::string SensorScheduler::GetUTCTime(long ts) {
|
|||||||
std::string world_time = str;
|
std::string world_time = str;
|
||||||
return world_time;
|
return world_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorScheduler::WriteTriggerWaveRecord() {
|
||||||
|
Json::Value root;
|
||||||
|
for (auto it = trigger_wave_record_.begin(); it != trigger_wave_record_.end(); ) {
|
||||||
|
// 检查 pair 中两个值是否都是 0
|
||||||
|
if (it->second.first == 0 && it->second.second == 0) {
|
||||||
|
// 使用 erase 方法删除当前元素
|
||||||
|
it = trigger_wave_record_.erase(it); // erase 返回指向下一个元素的迭代器
|
||||||
|
} else {
|
||||||
|
++it; // 继续迭代
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& entry : trigger_wave_record_) {
|
||||||
|
uint16_t key = entry.first;
|
||||||
|
const auto& value = entry.second;
|
||||||
|
// if (value.first == 0 && value.second == 0) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
Json::Value item;
|
||||||
|
item["first"] = value.first;
|
||||||
|
item["second"] = value.second;
|
||||||
|
|
||||||
|
root[std::to_string(key)] = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::StyledStreamWriter writer;
|
||||||
|
std::ofstream outFile(TRIGGER_WAVE_CONFIG);
|
||||||
|
|
||||||
|
if (!outFile.is_open()) {
|
||||||
|
zlog_warn(zbt, "Failed to open %s file", TRIGGER_WAVE_CONFIG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write(outFile, root);
|
||||||
|
outFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorScheduler::ReadTriggerWaveRecord() {
|
||||||
|
Json::Value root;
|
||||||
|
std::ifstream inFile(TRIGGER_WAVE_CONFIG);
|
||||||
|
|
||||||
|
if (!inFile.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Reader reader;
|
||||||
|
if (!reader.parse(inFile, root, false)) {
|
||||||
|
inFile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
inFile.close();
|
||||||
|
for (const auto& key : root.getMemberNames()) {
|
||||||
|
uint16_t uint16Key = static_cast<uint16_t>(std::stoi(key));
|
||||||
|
auto value = root[key];
|
||||||
|
|
||||||
|
uint8_t first = static_cast<uint8_t>(value["first"].asUInt());
|
||||||
|
uint8_t second = static_cast<uint8_t>(value["second"].asUInt());
|
||||||
|
|
||||||
|
trigger_wave_record_[uint16Key] = std::make_pair(first, second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -14,8 +14,7 @@
|
|||||||
#define SCHEDULE_CONFIG "/opt/configenv/schedule.json"
|
#define SCHEDULE_CONFIG "/opt/configenv/schedule.json"
|
||||||
#define DEBUG_SCHEDULE_CONFIG "/opt/configenv/debug_schedule.json"
|
#define DEBUG_SCHEDULE_CONFIG "/opt/configenv/debug_schedule.json"
|
||||||
#define UPGRADE_SCHEDULE_CONFIG "/opt/configenv/upgrade_schedule.json"
|
#define UPGRADE_SCHEDULE_CONFIG "/opt/configenv/upgrade_schedule.json"
|
||||||
|
#define TRIGGER_WAVE_CONFIG "/opt/configenv/trigger_wave.json"
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kScheduleResultNone = 0,
|
kScheduleResultNone = 0,
|
||||||
@ -55,6 +54,14 @@ public:
|
|||||||
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
||||||
int StartSchedule(uint16_t short_addr, int &next_duration, bool &z, int &next_task_id);
|
int StartSchedule(uint16_t short_addr, int &next_duration, bool &z, int &next_task_id);
|
||||||
int GetNextDuration(uint16_t short_addr, bool &z, int &next_task_id);
|
int GetNextDuration(uint16_t short_addr, bool &z, int &next_task_id);
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param short_addr
|
||||||
|
* @param z 如果需要触发z轴波形,此参数为1, 否则为0
|
||||||
|
* @param xy 如果需要触发xy轴波形,此参数为1, 否则为0
|
||||||
|
*/
|
||||||
|
int TriggerWave(uint16_t short_addr, uint8_t z, uint8_t xy);
|
||||||
|
|
||||||
// z用于说明是z轴波形,还是xy轴波形
|
// z用于说明是z轴波形,还是xy轴波形
|
||||||
int WaveError(uint16_t short_addr, bool z);
|
int WaveError(uint16_t short_addr, bool z);
|
||||||
@ -198,6 +205,10 @@ private:
|
|||||||
std::unordered_set<uint16_t> upgrade_list_;
|
std::unordered_set<uint16_t> upgrade_list_;
|
||||||
uint16_t *upgrade_slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
uint16_t *upgrade_slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
||||||
void GenerateUpgradeSchedule();
|
void GenerateUpgradeSchedule();
|
||||||
|
|
||||||
|
std::map<uint16_t, std::pair<uint8_t, uint8_t>> trigger_wave_record_;
|
||||||
|
void WriteTriggerWaveRecord();
|
||||||
|
void ReadTriggerWaveRecord();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler;
|
typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler;
|
||||||
|
|||||||
@ -158,6 +158,7 @@ void CheckThread() {
|
|||||||
}else if(statistics == 1 && hour < 13){
|
}else if(statistics == 1 && hour < 13){
|
||||||
writeIntValue("config", "statistics",0,(char*)GlobalConfig::Config_G.c_str());
|
writeIntValue("config", "statistics",0,(char*)GlobalConfig::Config_G.c_str());
|
||||||
}
|
}
|
||||||
|
sqlite_db_ctrl::instance().ShutdownCheck();
|
||||||
}
|
}
|
||||||
if(checkNet0 == 5){
|
if(checkNet0 == 5){
|
||||||
checkNet0 = 0;
|
checkNet0 = 0;
|
||||||
|
|||||||
@ -373,7 +373,7 @@ void CleanLogFile(std::string log_dir, size_t retain) {
|
|||||||
if (vec.size() > 0) {
|
if (vec.size() > 0) {
|
||||||
std::sort(vec.begin(), vec.end());
|
std::sort(vec.begin(), vec.end());
|
||||||
if (vec.size() <= retain) {
|
if (vec.size() <= retain) {
|
||||||
zlog_warn(zct, "[DiskSpaceCheck] there is no enough file to clean:%d", vec.size());
|
zlog_warn(zct, "[DiskSpaceCheck] there is no enough file to clean:%zu", vec.size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int total = vec.size();
|
int total = vec.size();
|
||||||
@ -395,7 +395,7 @@ void DiskSpaceCheck() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
boost::filesystem::space_info si = boost::filesystem::space("/opt");
|
boost::filesystem::space_info si = boost::filesystem::space("/opt");
|
||||||
if (si.free <= 512000000) {
|
if (si.free <= 512000000) {
|
||||||
zlog_warn(zct, "disk free space:%llu for /opt", si.free);
|
zlog_warn(zct, "disk free space:%lu for /opt", si.free);
|
||||||
CleanLogFile(directory, 10);
|
CleanLogFile(directory, 10);
|
||||||
CleanLogFile(directory_data, 100);
|
CleanLogFile(directory_data, 100);
|
||||||
boost::filesystem::space_info si1 = boost::filesystem::space("/opt");
|
boost::filesystem::space_info si1 = boost::filesystem::space("/opt");
|
||||||
|
|||||||
@ -148,15 +148,16 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
|||||||
VecWaveDataX.reserve(1000);
|
VecWaveDataX.reserve(1000);
|
||||||
VecWaveDataY.reserve(1000);
|
VecWaveDataY.reserve(1000);
|
||||||
VecWaveDataZ.reserve(1500);
|
VecWaveDataZ.reserve(1500);
|
||||||
m_waveCountVolX = 0;
|
m_waveCountLowFreX = 0;
|
||||||
m_waveCountVolY = 0;
|
m_waveCountLowFreY = 0;
|
||||||
m_waveCountVolZ = 0;
|
m_waveCountLowFreZ = 0;
|
||||||
VecWaveDataVolX.reserve(1000);
|
VecWaveDataLowFreX.reserve(1000);
|
||||||
VecWaveDataVolY.reserve(1000);
|
VecWaveDataLowFreY.reserve(1000);
|
||||||
VecWaveDataVolZ.reserve(1500);
|
VecWaveDataLowFreZ.reserve(1500);
|
||||||
memset(send_data, 0, sizeof(send_data));
|
memset(send_data, 0, sizeof(send_data));
|
||||||
last_short_addr = 0;
|
last_short_addr = 0;
|
||||||
last_time = 0;
|
last_time = 0;
|
||||||
|
current_z = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uart::~Uart() {
|
Uart::~Uart() {
|
||||||
@ -379,6 +380,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
ScheduleTask scheduleTask;
|
ScheduleTask scheduleTask;
|
||||||
bool z = false;
|
bool z = false;
|
||||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
|
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
|
||||||
|
current_z = z;
|
||||||
zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
|
zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
|
||||||
if (taskID == kScheduleConfigSensor)
|
if (taskID == kScheduleConfigSensor)
|
||||||
{
|
{
|
||||||
@ -508,9 +510,11 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
|||||||
now_task = WAVE_CMD;
|
now_task = WAVE_CMD;
|
||||||
std::string strShortAddr = std::string(shortAdd);
|
std::string strShortAddr = std::string(shortAdd);
|
||||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAdd);
|
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAdd);
|
||||||
std::string softVersion = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "softVersion", whereCon);
|
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||||
|
std::string softVersion = res[9];
|
||||||
|
std::string productNo = res[17];
|
||||||
compressWaveChannel tempchannel;
|
compressWaveChannel tempchannel;
|
||||||
if (compareVersions(softVersion, "2.6") == -1){
|
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01"){ // DN101所有版本和DN102 2.6以前版本
|
||||||
WaveResp(ushortAdd);
|
WaveResp(ushortAdd);
|
||||||
tempchannel.compressChannelX = pData[7];
|
tempchannel.compressChannelX = pData[7];
|
||||||
tempchannel.compressChannelY = pData[8];
|
tempchannel.compressChannelY = pData[8];
|
||||||
@ -584,7 +588,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
|||||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d,vol X = %d,vol Y = %d,vol X = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ,tempchannel.CountVolX,tempchannel.CountVolY,tempchannel.CountVolZ);
|
zlog_info(zct, "count X = %d,Y = %d,Z = %d,vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ,tempchannel.CountVolX,tempchannel.CountVolY,tempchannel.CountVolZ);
|
||||||
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
|
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
|
||||||
zlog_info(zct, "compress vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.compressChannelVolX, tempchannel.compressChannelVolY, tempchannel.compressChannelVolZ);
|
zlog_info(zct, "compress vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.compressChannelVolX, tempchannel.compressChannelVolY, tempchannel.compressChannelVolZ);
|
||||||
zlog_info(zct, "samplerate X = %d,Y = %d,Z = %d ", tempchannel.samplerateX, tempchannel.samplerateY, tempchannel.samplerateZ);
|
zlog_info(zct, "samplerate X = %d,Y = %d,Z = %d ", tempchannel.samplerateX, tempchannel.samplerateY, tempchannel.samplerateZ);
|
||||||
@ -844,14 +848,14 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
sprintf(szShortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF);
|
sprintf(szShortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF);
|
||||||
memcpy(NodeName, &pData[7], 64);
|
memcpy(NodeName, &pData[7], 64);
|
||||||
memcpy(shortAdd, &pData[3], 2);
|
memcpy(shortAdd, &pData[3], 2);
|
||||||
char whereCon[64] = {0};
|
char whereCon[512] = {0};
|
||||||
char uplCon[200] = {0x00};
|
char uplCon[512] = {0x00};
|
||||||
char nodeWaveSend[10] = {0x00};
|
char nodeWaveSend[10] = {0x00};
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
sprintf(&NodeName[i * 2], "%02X", pData[7 + i] & 0xFF);
|
sprintf(&NodeName[i * 2], "%02X", pData[7 + i] & 0xFF);
|
||||||
}
|
}
|
||||||
char MeasurementID[100] = {0x00};
|
char MeasurementID[50] = {0x00};
|
||||||
sprintf(MeasurementID, "%02x%02x%02x%02x%02x%02x%02x%02x", pData[71], pData[72], pData[73], pData[74], pData[75], pData[76], pData[77], pData[78]);
|
sprintf(MeasurementID, "%02x%02x%02x%02x%02x%02x%02x%02x", pData[71], pData[72], pData[73], pData[74], pData[75], pData[76], pData[77], pData[78]);
|
||||||
|
|
||||||
|
|
||||||
@ -859,7 +863,7 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
|
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
|
||||||
zlog_info(zct, "whereCon = %s", whereCon);
|
zlog_info(zct, "whereCon = %s", whereCon);
|
||||||
array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||||
if (vecRes.size() > 1) {
|
if (vecRes.size() > 1) {
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||||
if (vecRes[i][1] != "") {//删除短地址重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
if (vecRes[i][1] != "") {//删除短地址重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
||||||
@ -876,7 +880,7 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
memset(whereCon,0,sizeof(whereCon));
|
memset(whereCon,0,sizeof(whereCon));
|
||||||
sprintf(whereCon, "MeasurementID='%s'", MeasurementID);
|
sprintf(whereCon, "MeasurementID='%s'", MeasurementID);
|
||||||
array_t vecRes2 = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
array_t vecRes2 = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
||||||
zlog_info(zct, "vecRes2 = %d", vecRes2.size());
|
zlog_info(zct, "vecRes2 = %zu", vecRes2.size());
|
||||||
if (vecRes2.size() > 1) {
|
if (vecRes2.size() > 1) {
|
||||||
for (size_t i = 0; i < vecRes2.size(); i++) {
|
for (size_t i = 0; i < vecRes2.size(); i++) {
|
||||||
if (vecRes2[i][1] != "") {//删除通道ID重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
if (vecRes2[i][1] != "") {//删除通道ID重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
||||||
@ -894,7 +898,7 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||||
|
|
||||||
char szTableName[50] = {0x00};
|
char szTableName[100] = {0x00};
|
||||||
sprintf(szTableName, "t_data_%s", MeasurementID);
|
sprintf(szTableName, "t_data_%s", MeasurementID);
|
||||||
memset(whereCon,0,sizeof(whereCon));
|
memset(whereCon,0,sizeof(whereCon));
|
||||||
sprintf(whereCon,"type='table' and name = '%s'",szTableName);
|
sprintf(whereCon,"type='table' and name = '%s'",szTableName);
|
||||||
@ -1252,7 +1256,7 @@ void Uart::DealDataNodeInfo(const char *pData) {
|
|||||||
if (g_mapCompress.find(dataNodeInfo.ZigbeeShortAddr) == g_mapCompress.end()) {
|
if (g_mapCompress.find(dataNodeInfo.ZigbeeShortAddr) == g_mapCompress.end()) {
|
||||||
compressWaveChannel tempchannel;
|
compressWaveChannel tempchannel;
|
||||||
g_mapCompress.insert(std::make_pair(dataNodeInfo.ZigbeeShortAddr, tempchannel));
|
g_mapCompress.insert(std::make_pair(dataNodeInfo.ZigbeeShortAddr, tempchannel));
|
||||||
zlog_info(zct, "new Node,size = %d", g_mapCompress.size());
|
zlog_info(zct, "new Node,size = %zu", g_mapCompress.size());
|
||||||
}
|
}
|
||||||
zlog_info(zct, "DealDataNodeInfo %s ", dataNodeInfo.ZigbeeShortAddr.c_str());
|
zlog_info(zct, "DealDataNodeInfo %s ", dataNodeInfo.ZigbeeShortAddr.c_str());
|
||||||
}
|
}
|
||||||
@ -1339,19 +1343,19 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && \
|
if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && \
|
||||||
(command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_VOL_X || command == WAVE_VOL_Y || command == WAVE_VOL_Z) && \
|
(command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_LF_X || command == WAVE_LF_Y|| command == WAVE_LF_Z) && \
|
||||||
now_task == WAVE_CMD) {
|
now_task == WAVE_CMD) {
|
||||||
mPackgeIndex = UartRecvBuf[i + 6] & 0xFF;
|
mPackgeIndex = UartRecvBuf[i + 6] & 0xFF;
|
||||||
} else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && \
|
} else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && \
|
||||||
(command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_VOL_X || command == WAVE_VOL_Y || command == WAVE_VOL_Z) && \
|
(command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_LF_X || command == WAVE_LF_Y|| command == WAVE_LF_Z) && \
|
||||||
now_task == WAVE_CMD) {
|
now_task == WAVE_CMD) {
|
||||||
zlog_warn(zct, "mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str());
|
zlog_warn(zct, "mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str());
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
} else if ((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_VOL_X || command == WAVE_VOL_Y || command == WAVE_VOL_Z) && now_task == WAVE_CMD) {
|
} else if ((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_LF_X || command == WAVE_LF_Y|| command == WAVE_LF_Z) && now_task == WAVE_CMD) {
|
||||||
|
|
||||||
zlog_warn(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ,now_task = %d", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str(),now_task);
|
zlog_error(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ,now_task = %d", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str(),now_task);
|
||||||
zlog_warn(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str());
|
zlog_error(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str());
|
||||||
|
|
||||||
char tmp[10] = {0x00};
|
char tmp[10] = {0x00};
|
||||||
char tmp2[10] = {0x00};
|
char tmp2[10] = {0x00};
|
||||||
@ -1359,7 +1363,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||||
strcat(tmp2, tmp);
|
strcat(tmp2, tmp);
|
||||||
}
|
}
|
||||||
zlog_warn(zct, "error str = %s", tmp2);
|
zlog_error(zct, "error str = %s", tmp2);
|
||||||
char insertSql[100] = {0x00};
|
char insertSql[100] = {0x00};
|
||||||
char whereCon[50] = {0x00};
|
char whereCon[50] = {0x00};
|
||||||
std::string error_msg = "";
|
std::string error_msg = "";
|
||||||
@ -1391,9 +1395,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now_task == WAVE_CMD && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_VOL_X || command == WAVE_VOL_Y || command == WAVE_VOL_Z)) {
|
if (now_task == WAVE_CMD && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z || command == WAVE_LF_X || command == WAVE_LF_Y|| command == WAVE_LF_Z)) {
|
||||||
if (!CheckCrc(&UartRecvBuf[i], 99)) {
|
if (!CheckCrc(&UartRecvBuf[i], 99)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command);
|
||||||
char tmp[10] = {0x00};
|
char tmp[10] = {0x00};
|
||||||
char tmp2[10] = {0x00};
|
char tmp2[10] = {0x00};
|
||||||
for (int j = 0; j < 100; j++) {
|
for (int j = 0; j < 100; j++) {
|
||||||
@ -1453,7 +1457,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
{
|
{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 8);
|
memcpy(RecvBuf, &UartRecvBuf[i], 8);
|
||||||
if (!CheckCrc(RecvBuf, 7)) {
|
if (!CheckCrc(RecvBuf, 7)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1461,7 +1465,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
{
|
{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 9);
|
memcpy(RecvBuf, &UartRecvBuf[i], 9);
|
||||||
if (!CheckCrc(RecvBuf, 8)) {
|
if (!CheckCrc(RecvBuf, 8)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1469,14 +1473,14 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
{
|
{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||||
if (!CheckCrc(RecvBuf, 99)) {
|
if (!CheckCrc(RecvBuf, 99)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||||
char tmp[10] = {0x00};
|
char tmp[10] = {0x00};
|
||||||
char tmp2[10] = {0x00};
|
char tmp2[10] = {0x00};
|
||||||
for (int j = 0; j < 100; j++) {
|
for (int j = 0; j < 100; j++) {
|
||||||
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||||
strcat(tmp2, tmp);
|
strcat(tmp2, tmp);
|
||||||
}
|
}
|
||||||
zlog_warn(zct, " crc error str = %s", tmp2);
|
zlog_error(zct, " crc error str = %s", tmp2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1487,13 +1491,13 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
{
|
{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||||
if (!CheckCrc(RecvBuf, 99)) {
|
if (!CheckCrc(RecvBuf, 99)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
||||||
if (!CheckCrc(RecvBuf, 23)) {
|
if (!CheckCrc(RecvBuf, 23)) {
|
||||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,9 +32,9 @@ enum InteractiveCommand {
|
|||||||
UPGRADE_FIRMWARE = 16, //固件升级内容
|
UPGRADE_FIRMWARE = 16, //固件升级内容
|
||||||
UPGRADE_ASK = 17, //固件升级请求
|
UPGRADE_ASK = 17, //固件升级请求
|
||||||
WAVE_RESP = 18, // 波形数据回复
|
WAVE_RESP = 18, // 波形数据回复
|
||||||
WAVE_VOL_X = 19,
|
WAVE_LF_X = 19,
|
||||||
WAVE_VOL_Y = 20,
|
WAVE_LF_Y = 20,
|
||||||
WAVE_VOL_Z = 21
|
WAVE_LF_Z = 21
|
||||||
};
|
};
|
||||||
|
|
||||||
// 无线传感器请求任务
|
// 无线传感器请求任务
|
||||||
@ -194,7 +194,7 @@ public:
|
|||||||
|
|
||||||
// feature parse
|
// feature parse
|
||||||
int DealDataNodeFeature(const char* pData, int flag);
|
int DealDataNodeFeature(const char* pData, int flag);
|
||||||
void DealTriger(std::string & measurementID);
|
void DealTriger(uint16_t ushortAdd,std::string & measurementID);
|
||||||
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
||||||
void DealDataNodeWave(const char* pData, int comand);
|
void DealDataNodeWave(const char* pData, int comand);
|
||||||
void DealWaveThread();
|
void DealWaveThread();
|
||||||
@ -270,19 +270,20 @@ private:
|
|||||||
int m_waveCountX;
|
int m_waveCountX;
|
||||||
int m_waveCountY;
|
int m_waveCountY;
|
||||||
int m_waveCountZ;
|
int m_waveCountZ;
|
||||||
int m_waveCountVolX;
|
int m_waveCountLowFreX;
|
||||||
int m_waveCountVolY;
|
int m_waveCountLowFreY;
|
||||||
int m_waveCountVolZ;
|
int m_waveCountLowFreZ;
|
||||||
std::vector<RecvData> VecWaveDataX;
|
std::vector<RecvData> VecWaveDataX;
|
||||||
std::vector<RecvData> VecWaveDataY;
|
std::vector<RecvData> VecWaveDataY;
|
||||||
std::vector<RecvData> VecWaveDataZ;
|
std::vector<RecvData> VecWaveDataZ;
|
||||||
std::vector<RecvData> VecWaveDataVolX;
|
std::vector<RecvData> VecWaveDataLowFreX;
|
||||||
std::vector<RecvData> VecWaveDataVolY;
|
std::vector<RecvData> VecWaveDataLowFreY;
|
||||||
std::vector<RecvData> VecWaveDataVolZ;
|
std::vector<RecvData> VecWaveDataLowFreZ;
|
||||||
|
|
||||||
uint8_t send_data[100];
|
uint8_t send_data[100];
|
||||||
uint16_t last_short_addr;
|
uint16_t last_short_addr;
|
||||||
long last_time;
|
long last_time;
|
||||||
|
bool current_z;
|
||||||
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -79,30 +79,48 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
|
|||||||
zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI);
|
zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Uart::DealTriger(std::string & measurementID){
|
void Uart::DealTriger(uint16_t ushortAdd,std::string & measurementID){
|
||||||
vec_t vecTrigger;
|
vec_t vecTrigger;
|
||||||
char whereCon[256] = {0},tablename[128] = {0};
|
char whereCon[256] = {0},tablename[128] = {0};
|
||||||
sprintf(whereCon, "MeasurementID='%s' and status ='1' ", measurementID.c_str());
|
sprintf(whereCon, "MeasurementID='%s' and status ='1' ", measurementID.c_str());
|
||||||
sprintf(tablename,"t_data_%s",measurementID.c_str());
|
sprintf(tablename,"t_data_%s",measurementID.c_str());
|
||||||
vecTrigger = sqlite_db_ctrl::instance().GetDataSingleLine(" t_wave_triger_info ", " * ", whereCon);
|
vecTrigger = sqlite_db_ctrl::instance().GetDataSingleLine(" t_wave_triger_info ", " * ", whereCon);
|
||||||
if (vecTrigger.size() > 0){
|
if (vecTrigger.size() > 0){// 加速度有效值
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,1;",measurementID);
|
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,3;",measurementID.c_str());
|
||||||
if(vecTrigger[3] == "0"){
|
if(vecTrigger[3] == "0"){
|
||||||
std::string rmsValue = sqlite_db_ctrl::instance().GetData(tablename, " rmsValues ", whereCon);
|
array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,rmsValues ", whereCon);
|
||||||
float rmsValue_f = atof(rmsValue.c_str());
|
if(arrValue.size()){
|
||||||
if (rmsValue_f >= atof(vecTrigger[4].c_str())) {
|
for (size_t i = 0; i < arrValue.size(); i++)
|
||||||
zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f", measurementID.c_str(), rmsValue_f);
|
{
|
||||||
|
float rmsValue_f = atof(arrValue[i][1].c_str());
|
||||||
|
if (rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos || arrValue[i][0].find("Y") != std::string::npos)) {
|
||||||
|
zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd);
|
||||||
|
scheduler::instance().TriggerWave(ushortAdd, 0, 1);
|
||||||
|
}else if (rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos))
|
||||||
|
{
|
||||||
|
zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd);
|
||||||
|
scheduler::instance().TriggerWave(ushortAdd, 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}else if (vecTrigger[3] == "1"){// 速度有效值
|
||||||
}else if (vecTrigger[3] == "1"){
|
array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,integratRMS ", whereCon);
|
||||||
std::string integratRMS = sqlite_db_ctrl::instance().GetData(tablename, " integratRMS ", whereCon);
|
if(arrValue.size()){
|
||||||
float integratRMS_f = atof(integratRMS.c_str());
|
for (size_t i = 0; i < arrValue.size(); i++)
|
||||||
if (integratRMS_f >= atof(vecTrigger[4].c_str())) {
|
{
|
||||||
zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f", measurementID.c_str(), integratRMS_f);
|
float integratRMS_f = atof(arrValue[i][1].c_str());
|
||||||
|
if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos || arrValue[i][0].find("Y") != std::string::npos)) {
|
||||||
|
zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd);
|
||||||
|
scheduler::instance().TriggerWave(ushortAdd, 0, 1);
|
||||||
|
}else if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos))
|
||||||
|
{
|
||||||
|
zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd);
|
||||||
|
scheduler::instance().TriggerWave(ushortAdd, 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) {
|
void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) {
|
||||||
@ -235,7 +253,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
sprintf(buf, "%02x%02x", pRecvData->Data[81]);
|
sprintf(buf, "%02x", pRecvData->Data[81]);
|
||||||
iTemp = (int)strtol(buf, NULL, 8);
|
iTemp = (int)strtol(buf, NULL, 8);
|
||||||
dataStatic.minmumBatteryVoltageType = iTemp;
|
dataStatic.minmumBatteryVoltageType = iTemp;
|
||||||
|
|
||||||
@ -344,7 +362,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
|
|
||||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
||||||
char insertSql[1024] = {0};
|
char insertSql[1024] = {0};
|
||||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d,%s,'%d'", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend,nodetimestamp);
|
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d,%s", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend,nodetimestamp);
|
||||||
sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql);
|
||||||
sqlite_db_ctrl::instance().CalculateBattery();
|
sqlite_db_ctrl::instance().CalculateBattery();
|
||||||
} else {
|
} else {
|
||||||
@ -731,7 +749,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
}
|
}
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
|
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
|
||||||
DealTriger(strMeasurementID);
|
DealTriger(u_short_addr,strMeasurementID);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,12 +764,12 @@ void Uart::DealDataNodeWave(const char *pData, int comand) {
|
|||||||
VecWaveDataY.push_back(*pRecvData);
|
VecWaveDataY.push_back(*pRecvData);
|
||||||
} else if (comand == WAVE_Z) {
|
} else if (comand == WAVE_Z) {
|
||||||
VecWaveDataZ.push_back(*pRecvData);
|
VecWaveDataZ.push_back(*pRecvData);
|
||||||
}else if (comand == WAVE_VOL_X) {
|
}else if (comand == WAVE_LF_X) {
|
||||||
VecWaveDataVolX.push_back(*pRecvData);
|
VecWaveDataLowFreX.push_back(*pRecvData);
|
||||||
}else if (comand == WAVE_VOL_Y) {
|
}else if (comand == WAVE_LF_Y) {
|
||||||
VecWaveDataVolY.push_back(*pRecvData);
|
VecWaveDataLowFreY.push_back(*pRecvData);
|
||||||
}else if (comand == WAVE_VOL_Z) {
|
}else if (comand == WAVE_LF_Z) {
|
||||||
VecWaveDataVolZ.push_back(*pRecvData);
|
VecWaveDataLowFreZ.push_back(*pRecvData);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (comand == WAVE_X) {
|
if (comand == WAVE_X) {
|
||||||
@ -763,15 +781,15 @@ void Uart::DealDataNodeWave(const char *pData, int comand) {
|
|||||||
} else if (comand == WAVE_Z) {
|
} else if (comand == WAVE_Z) {
|
||||||
g_VecWaveDataZ[m_waveCountZ] = *pRecvData;
|
g_VecWaveDataZ[m_waveCountZ] = *pRecvData;
|
||||||
m_waveCountZ++;
|
m_waveCountZ++;
|
||||||
}else if (comand == WAVE_VOL_X) {
|
}else if (comand == WAVE_LF_X) {
|
||||||
g_VecWaveDataVolX[m_waveCountVolX] = *pRecvData;
|
g_VecWaveDataVolX[m_waveCountLowFreX] = *pRecvData;
|
||||||
m_waveCountVolX++;
|
m_waveCountLowFreX++;
|
||||||
}else if (comand == WAVE_VOL_Y) {
|
}else if (comand == WAVE_LF_Y) {
|
||||||
g_VecWaveDataVolY[m_waveCountVolY] = *pRecvData;
|
g_VecWaveDataVolY[m_waveCountLowFreY] = *pRecvData;
|
||||||
m_waveCountVolY++;
|
m_waveCountLowFreY++;
|
||||||
}else if (comand == WAVE_VOL_Z) {
|
}else if (comand == WAVE_LF_Z) {
|
||||||
g_VecWaveDataVolZ[m_waveCountVolZ] = *pRecvData;
|
g_VecWaveDataVolZ[m_waveCountLowFreZ] = *pRecvData;
|
||||||
m_waveCountVolZ++;
|
m_waveCountLowFreZ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -851,12 +869,12 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
compress = g_mapCompress[strShortAddr].compressChannelZ;
|
compress = g_mapCompress[strShortAddr].compressChannelZ;
|
||||||
count = g_mapCompress[strShortAddr].CountZ;
|
count = g_mapCompress[strShortAddr].CountZ;
|
||||||
}
|
}
|
||||||
if (iChannel == WAVE_VOL_X) {
|
if (iChannel == WAVE_LF_X) {
|
||||||
if (VecWaveDataVolX.size() > 0) {
|
if (VecWaveDataLowFreX.size() > 0) {
|
||||||
g_VecWaveDataVolX.assign(VecWaveDataVolX.begin(), VecWaveDataVolX.end());
|
g_VecWaveDataVolX.assign(VecWaveDataLowFreX.begin(), VecWaveDataLowFreX.end());
|
||||||
waveCount = VecWaveDataVolX.size();
|
waveCount = VecWaveDataLowFreX.size();
|
||||||
}
|
}
|
||||||
waveCount = m_waveCountVolX;
|
waveCount = m_waveCountLowFreX;
|
||||||
for (; j < waveCount; j++) {
|
for (; j < waveCount; j++) {
|
||||||
RecvData recvData = g_VecWaveDataVolX[j];
|
RecvData recvData = g_VecWaveDataVolX[j];
|
||||||
memcpy(data + j * 92, recvData.Data, 92);
|
memcpy(data + j * 92, recvData.Data, 92);
|
||||||
@ -867,12 +885,12 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
compress = g_mapCompress[strShortAddr].compressChannelVolX;
|
compress = g_mapCompress[strShortAddr].compressChannelVolX;
|
||||||
count = g_mapCompress[strShortAddr].CountVolX;
|
count = g_mapCompress[strShortAddr].CountVolX;
|
||||||
}
|
}
|
||||||
if (iChannel == WAVE_VOL_Y) {
|
if (iChannel == WAVE_LF_Y) {
|
||||||
if (VecWaveDataVolY.size() > 0) {
|
if (VecWaveDataLowFreY.size() > 0) {
|
||||||
g_VecWaveDataVolY.assign(VecWaveDataVolY.begin(), VecWaveDataVolY.end());
|
g_VecWaveDataVolY.assign(VecWaveDataLowFreY.begin(), VecWaveDataLowFreY.end());
|
||||||
waveCount = VecWaveDataVolY.size();
|
waveCount = VecWaveDataLowFreY.size();
|
||||||
}
|
}
|
||||||
waveCount = m_waveCountVolY;
|
waveCount = m_waveCountLowFreY;
|
||||||
for (; j < waveCount; j++) {
|
for (; j < waveCount; j++) {
|
||||||
RecvData recvData = g_VecWaveDataVolY[j];
|
RecvData recvData = g_VecWaveDataVolY[j];
|
||||||
memcpy(data + j * 92, recvData.Data, 92);
|
memcpy(data + j * 92, recvData.Data, 92);
|
||||||
@ -883,12 +901,12 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
compress = g_mapCompress[strShortAddr].compressChannelVolY;
|
compress = g_mapCompress[strShortAddr].compressChannelVolY;
|
||||||
count = g_mapCompress[strShortAddr].CountVolY;
|
count = g_mapCompress[strShortAddr].CountVolY;
|
||||||
}
|
}
|
||||||
if (iChannel == WAVE_VOL_Z) {
|
if (iChannel == WAVE_LF_Z) {
|
||||||
if (VecWaveDataVolZ.size() > 0) {
|
if (VecWaveDataLowFreZ.size() > 0) {
|
||||||
g_VecWaveDataVolZ.assign(VecWaveDataVolZ.begin(), VecWaveDataVolZ.end());
|
g_VecWaveDataVolZ.assign(VecWaveDataLowFreZ.begin(), VecWaveDataLowFreZ.end());
|
||||||
waveCount = VecWaveDataVolZ.size();
|
waveCount = VecWaveDataLowFreZ.size();
|
||||||
}
|
}
|
||||||
waveCount = m_waveCountVolZ;
|
waveCount = m_waveCountLowFreZ;
|
||||||
for (; j < waveCount; j++) {
|
for (; j < waveCount; j++) {
|
||||||
RecvData recvData = g_VecWaveDataVolZ[j];
|
RecvData recvData = g_VecWaveDataVolZ[j];
|
||||||
memcpy(data + j * 92, recvData.Data, 92);
|
memcpy(data + j * 92, recvData.Data, 92);
|
||||||
@ -899,7 +917,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
compress = g_mapCompress[strShortAddr].compressChannelVolZ;
|
compress = g_mapCompress[strShortAddr].compressChannelVolZ;
|
||||||
count = g_mapCompress[strShortAddr].CountVolZ;
|
count = g_mapCompress[strShortAddr].CountVolZ;
|
||||||
}
|
}
|
||||||
zlog_info(zct, "len = %d,data = %02x,iChannel = %d,compress = %d,count = %d", j, data[0], iChannel, compress, count);
|
zlog_info(zct, "len = %zu,data = %02x,iChannel = %d,compress = %d,count = %zu", j, data[0], iChannel, compress, count);
|
||||||
if (j * 92 < count) return vecData;
|
if (j * 92 < count) return vecData;
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
@ -941,15 +959,15 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
vecData.push_back(fTemp);
|
vecData.push_back(fTemp);
|
||||||
if (strProduct == "01" && version == 1) {
|
if (strProduct == "01" && version == 1) {
|
||||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||||
zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
zlog_info(zct, "%d vecData.size() == %zu,sampleRate * ACCSampleTime = %f", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Y) { //过滤数据包结尾空数据
|
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Y) { //过滤数据包结尾空数据
|
||||||
zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
zlog_info(zct, "%d vecData.size() == %zu,sampleRate * ACCSampleTime = %f", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||||
zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
zlog_info(zct, "%d vecData.size() == %zu,sampleRate * ACCSampleTime = %f", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -973,13 +991,13 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
|||||||
if (vecData.size() == 24000 && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
if (vecData.size() == 24000 && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_X) { //过滤数据包结尾空数据
|
if (vecData.size() == 4096 && iChannel == WAVE_LF_X) { //过滤数据包结尾空数据
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_Y) { //过滤数据包结尾空数据
|
if (vecData.size() == 4096 && iChannel == WAVE_LF_Y) { //过滤数据包结尾空数据
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_Z) { //过滤数据包结尾空数据
|
if (vecData.size() == 4096 && iChannel == WAVE_LF_Z) { //过滤数据包结尾空数据
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1051,7 +1069,7 @@ void Uart::DealWave() {
|
|||||||
version = 1;
|
version = 1;
|
||||||
}
|
}
|
||||||
if (m_waveCountX > 0 || VecWaveDataX.size() > 0) {
|
if (m_waveCountX > 0 || VecWaveDataX.size() > 0) {
|
||||||
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size());
|
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %zu", m_waveCountX, VecWaveDataX.size());
|
||||||
coe = Calcoe(n, WAVE_X, strProduct, range);
|
coe = Calcoe(n, WAVE_X, strProduct, range);
|
||||||
|
|
||||||
vecDataX = DealData(WAVE_X, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
vecDataX = DealData(WAVE_X, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||||
@ -1061,7 +1079,7 @@ void Uart::DealWave() {
|
|||||||
VecWaveDataX.clear();
|
VecWaveDataX.clear();
|
||||||
}
|
}
|
||||||
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
||||||
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size());
|
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %zu", m_waveCountY, VecWaveDataY.size());
|
||||||
coe = Calcoe(n, WAVE_Y, strProduct, range);
|
coe = Calcoe(n, WAVE_Y, strProduct, range);
|
||||||
vecDataY = DealData(WAVE_Y, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
vecDataY = DealData(WAVE_Y, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,accSampleTimeXY,version);
|
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,accSampleTimeXY,version);
|
||||||
@ -1071,7 +1089,7 @@ void Uart::DealWave() {
|
|||||||
}
|
}
|
||||||
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
||||||
//zlog_info(zct, "accSampleTimeXY = %f, accSampleTimeZ = %f,version = %d.softversion = %s", accSampleTimeXY, accSampleTimeZ,version,softVersion.c_str());
|
//zlog_info(zct, "accSampleTimeXY = %f, accSampleTimeZ = %f,version = %d.softversion = %s", accSampleTimeXY, accSampleTimeZ,version,softVersion.c_str());
|
||||||
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size());
|
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %zu", m_waveCountZ, VecWaveDataZ.size());
|
||||||
coe = Calcoe(n, WAVE_Z, strProduct, range);
|
coe = Calcoe(n, WAVE_Z, strProduct, range);
|
||||||
vecDataZ = DealData(WAVE_Z, coe, sampleRate, accSampleTimeZ, strProduct,version);
|
vecDataZ = DealData(WAVE_Z, coe, sampleRate, accSampleTimeZ, strProduct,version);
|
||||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,accSampleTimeZ,version);
|
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,accSampleTimeZ,version);
|
||||||
@ -1079,35 +1097,32 @@ void Uart::DealWave() {
|
|||||||
g_VecWaveDataZ.clear();
|
g_VecWaveDataZ.clear();
|
||||||
VecWaveDataZ.clear();
|
VecWaveDataZ.clear();
|
||||||
}
|
}
|
||||||
zlog_info(zct,"m_waveCountVolX = %d,VecWaveDataVolX = %d", m_waveCountVolX, VecWaveDataVolX.size());
|
zlog_info(zct,"m_waveCountLowFreX = %d,VecWaveDataLowFreX = %zu", m_waveCountLowFreX, VecWaveDataLowFreX.size());
|
||||||
if (m_waveCountVolX > 0 || VecWaveDataVolX.size() > 0) {
|
if (m_waveCountLowFreX > 0 || VecWaveDataLowFreX.size() > 0) {
|
||||||
zlog_info(zct, "m_waveCountVolX = %d,VecWaveDataVolX = %d", m_waveCountVolX, VecWaveDataVolX.size());
|
coe = Calcoe(n, WAVE_LF_X, strProduct, range);
|
||||||
coe = Calcoe(n, WAVE_VOL_X, strProduct, range);
|
vecDataVolX = DealData(WAVE_LF_X, coe, g_mapCompress[strShortAddr].samplerateVolX, volSampleTime, strProduct,version);
|
||||||
vecDataVolX = DealData(WAVE_VOL_X, coe, g_mapCompress[strShortAddr].samplerateVolX, volSampleTime, strProduct,version);
|
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_X, vecDataVolX,strProduct,volSampleTime,version);
|
||||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_X, vecDataVolX,strProduct,volSampleTime,version);
|
m_waveCountLowFreX = 0;
|
||||||
m_waveCountVolX = 0;
|
|
||||||
g_VecWaveDataVolX.clear();
|
g_VecWaveDataVolX.clear();
|
||||||
VecWaveDataVolX.clear();
|
VecWaveDataLowFreX.clear();
|
||||||
}
|
}
|
||||||
zlog_info(zct,"m_waveCountVolY = %d,VecWaveDataVolY = %d", m_waveCountVolY, VecWaveDataVolY.size());
|
zlog_info(zct,"m_waveCountLowFreY = %d,VecWaveDataLowFreY = %zu", m_waveCountLowFreY, VecWaveDataLowFreY.size());
|
||||||
if (m_waveCountVolY > 0 || VecWaveDataVolY.size() > 0) {
|
if (m_waveCountLowFreY > 0 || VecWaveDataLowFreY.size() > 0) {
|
||||||
zlog_info(zct, "m_waveCountVolY = %d,VecWaveDataVolY = %d", m_waveCountVolY, VecWaveDataVolY.size());
|
coe = Calcoe(n, WAVE_LF_Y, strProduct, range);
|
||||||
coe = Calcoe(n, WAVE_VOL_Y, strProduct, range);
|
vecDataVolY = DealData(WAVE_LF_Y, coe, g_mapCompress[strShortAddr].samplerateVolY, volSampleTime, strProduct,version);
|
||||||
vecDataVolY = DealData(WAVE_VOL_Y, coe, g_mapCompress[strShortAddr].samplerateVolY, volSampleTime, strProduct,version);
|
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_Y, vecDataVolY,strProduct,volSampleTime,version);
|
||||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_Y, vecDataVolY,strProduct,volSampleTime,version);
|
m_waveCountLowFreY = 0;
|
||||||
m_waveCountVolY = 0;
|
|
||||||
g_VecWaveDataVolY.clear();
|
g_VecWaveDataVolY.clear();
|
||||||
VecWaveDataVolY.clear();
|
VecWaveDataLowFreY.clear();
|
||||||
}
|
}
|
||||||
zlog_info(zct,"m_waveCountVolZ = %d,VecWaveDataVolZ = %d", m_waveCountVolZ, VecWaveDataVolZ.size());
|
zlog_info(zct,"m_waveCountLowFreZ = %d,VecWaveDataLowFreZ = %zu", m_waveCountLowFreZ, VecWaveDataLowFreZ.size());
|
||||||
if (m_waveCountVolZ > 0 || VecWaveDataVolZ.size() > 0) {
|
if (m_waveCountLowFreZ > 0 || VecWaveDataLowFreZ.size() > 0) {
|
||||||
zlog_info(zct, "m_waveCountVolZ = %d,VecWaveDataVolZ = %d", m_waveCountVolZ, VecWaveDataVolZ.size());
|
coe = Calcoe(n, WAVE_LF_Z, strProduct, range);
|
||||||
coe = Calcoe(n, WAVE_VOL_Z, strProduct, range);
|
vecDataVolZ = DealData(WAVE_LF_Z, coe, g_mapCompress[strShortAddr].samplerateVolZ, volSampleTime, strProduct,version);
|
||||||
vecDataVolZ = DealData(WAVE_VOL_Z, coe, g_mapCompress[strShortAddr].samplerateVolZ, volSampleTime, strProduct,version);
|
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_Z, vecDataVolZ,strProduct,volSampleTime,version);
|
||||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_Z, vecDataVolZ,strProduct,volSampleTime,version);
|
m_waveCountLowFreZ = 0;
|
||||||
m_waveCountVolZ = 0;
|
|
||||||
g_VecWaveDataVolZ.clear();
|
g_VecWaveDataVolZ.clear();
|
||||||
VecWaveDataVolZ.clear();
|
VecWaveDataLowFreZ.clear();
|
||||||
}
|
}
|
||||||
char insertSql[100] = {0x00};
|
char insertSql[100] = {0x00};
|
||||||
memset(whereCon,0,sizeof(whereCon));
|
memset(whereCon,0,sizeof(whereCon));
|
||||||
@ -1128,13 +1143,19 @@ void Uart::DealWave() {
|
|||||||
sprintf(insertSql, "'%s-Z','%02x%02x','%s',%d,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,(char*)timestamp_last.c_str(),g_mapCompress[strShortAddr].CountZ,"");
|
sprintf(insertSql, "'%s-Z','%02x%02x','%s',%d,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,(char*)timestamp_last.c_str(),g_mapCompress[strShortAddr].CountZ,"");
|
||||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||||
}
|
}
|
||||||
zlog_warn(zct,"waveCountX = %d, waveCountY = %d, waveCountZ = %d", vecDataX.size() , vecDataY.size(), vecDataZ.size());
|
zlog_warn(zct,"waveCountX = %zu, waveCountY = %zu, waveCountZ = %zu", vecDataX.size() , vecDataY.size(), vecDataZ.size());
|
||||||
zlog_warn(zct,"CountX = %d, CountY = %d, CountZ = %d", g_mapCompress[strShortAddr].CountX , g_mapCompress[strShortAddr].CountY, g_mapCompress[strShortAddr].CountZ);
|
zlog_warn(zct,"CountX = %d, CountY = %d, CountZ = %d", g_mapCompress[strShortAddr].CountX , g_mapCompress[strShortAddr].CountY, g_mapCompress[strShortAddr].CountZ);
|
||||||
if ((vecDataX.size() <= 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
if ((vecDataX.size() <= 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
||||||
(vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
(vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||||
(vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
(vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||||
{
|
{
|
||||||
int iRet = scheduler::instance().WaveError(wave_shortAddr,z);
|
int iRet = -1;
|
||||||
|
if (vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0)
|
||||||
|
{
|
||||||
|
iRet = scheduler::instance().WaveError(wave_shortAddr,true);
|
||||||
|
}else{
|
||||||
|
iRet = scheduler::instance().WaveError(wave_shortAddr,false);
|
||||||
|
}
|
||||||
if (iRet != 0) {
|
if (iRet != 0) {
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
char updateSql[1024] = { 0 };
|
char updateSql[1024] = { 0 };
|
||||||
@ -1146,7 +1167,11 @@ void Uart::DealWave() {
|
|||||||
(vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
(vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||||
(vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
(vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||||
{
|
{
|
||||||
scheduler::instance().WaveSuccess(wave_shortAddr,z);
|
if(vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0){
|
||||||
|
scheduler::instance().WaveSuccess(wave_shortAddr,true);
|
||||||
|
}else{
|
||||||
|
scheduler::instance().WaveSuccess(wave_shortAddr,false);
|
||||||
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
char updateSql[1024] = { 0 };
|
char updateSql[1024] = { 0 };
|
||||||
sprintf(updateSql, "resend = '%d'", 1);
|
sprintf(updateSql, "resend = '%d'", 1);
|
||||||
@ -1154,9 +1179,9 @@ void Uart::DealWave() {
|
|||||||
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (g_mapCompress[strShortAddr].CountX <= 0 && g_mapCompress[strShortAddr].CountY <= 0 && g_mapCompress[strShortAddr].CountZ <= 0)
|
if (g_mapCompress[strShortAddr].CountX <= 0 && g_mapCompress[strShortAddr].CountY <= 0 && !current_z)
|
||||||
{
|
{
|
||||||
int iRet = scheduler::instance().WaveError(wave_shortAddr,z);
|
int iRet = scheduler::instance().WaveError(wave_shortAddr,false);
|
||||||
if (iRet != 0) {
|
if (iRet != 0) {
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
char updateSql[1024] = { 0 };
|
char updateSql[1024] = { 0 };
|
||||||
@ -1165,6 +1190,18 @@ void Uart::DealWave() {
|
|||||||
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (current_z && g_mapCompress[strShortAddr].CountZ <= 0)
|
||||||
|
{
|
||||||
|
int iRet = scheduler::instance().WaveError(wave_shortAddr,true);
|
||||||
|
if (iRet != 0) {
|
||||||
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
|
char updateSql[1024] = { 0 };
|
||||||
|
sprintf(updateSql, "resend = '%d'", iRet);
|
||||||
|
sprintf(whereCon, "short_addr='%02x%02x' and timestamp = '%s'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,(char*)timestamp_last.c_str());
|
||||||
|
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_mapCompress[strShortAddr].CountX = 0;
|
g_mapCompress[strShortAddr].CountX = 0;
|
||||||
g_mapCompress[strShortAddr].CountY = 0;
|
g_mapCompress[strShortAddr].CountY = 0;
|
||||||
g_mapCompress[strShortAddr].CountZ = 0;
|
g_mapCompress[strShortAddr].CountZ = 0;
|
||||||
@ -1192,8 +1229,8 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
|||||||
if (product == "01") {
|
if (product == "01") {
|
||||||
coe = pow(2, ran) * 8.0f / 32767;
|
coe = pow(2, ran) * 8.0f / 32767;
|
||||||
} else if (product == "02") {
|
} else if (product == "02") {
|
||||||
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_VOL_X ||
|
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_LF_X ||
|
||||||
iChannel == WAVE_VOL_Y || iChannel == WAVE_VOL_Z) {
|
iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) {
|
||||||
coe = 0.00048828125f;
|
coe = 0.00048828125f;
|
||||||
}
|
}
|
||||||
if (iChannel == WAVE_Z ) {
|
if (iChannel == WAVE_Z ) {
|
||||||
@ -1216,44 +1253,44 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
std::string strWaveData = "";
|
std::string strWaveData = "";
|
||||||
WaveChannel wave_channel;
|
WaveChannel wave_channel;
|
||||||
WaveVolChannel wave_vol_channel;
|
WaveVolChannel wave_vol_channel;
|
||||||
|
int wave_type = 0;
|
||||||
memset(mqttData,0,sizeof(mqttData));
|
memset(mqttData,0,sizeof(mqttData));
|
||||||
switch (iChannel) {
|
switch (iChannel) {
|
||||||
case WAVE_X: {
|
case WAVE_X: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-X.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-X.dat";
|
||||||
strChannelID = strMeasurementID + "-X";
|
strChannelID = strMeasurementID + "-X";
|
||||||
|
wave_type = WAVE_X;
|
||||||
} break;
|
} break;
|
||||||
case WAVE_Y: {
|
case WAVE_Y: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-Y.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-Y.dat";
|
||||||
strChannelID = strMeasurementID + "-Y";
|
strChannelID = strMeasurementID + "-Y";
|
||||||
|
wave_type = WAVE_Y;
|
||||||
} break;
|
} break;
|
||||||
case WAVE_Z: {
|
case WAVE_Z: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-Z.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-Z.dat";
|
||||||
strChannelID = strMeasurementID + "-Z";
|
strChannelID = strMeasurementID + "-Z";
|
||||||
|
wave_type = WAVE_Z;
|
||||||
} break;
|
} break;
|
||||||
case WAVE_VOL_X: {
|
case WAVE_LF_X: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-X-VOL.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-X-LF.dat";
|
||||||
strChannelID = strMeasurementID + "-X-VOL";
|
strChannelID = strMeasurementID + "-X";
|
||||||
|
wave_type = WAVE_LF_X;
|
||||||
} break;
|
} break;
|
||||||
case WAVE_VOL_Y: {
|
case WAVE_LF_Y: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-Y-VOL.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-Y-LF.dat";
|
||||||
strChannelID = strMeasurementID + "-Y-VOL";
|
strChannelID = strMeasurementID + "-Y";
|
||||||
|
wave_type = WAVE_LF_Y;
|
||||||
} break;
|
} break;
|
||||||
case WAVE_VOL_Z: {
|
case WAVE_LF_Z: {
|
||||||
strFileName = "/opt/data/" + strMeasurementID + "-Z-VOL.dat";
|
strFileName = "/opt/data/" + strMeasurementID + "-Z-LF.dat";
|
||||||
strChannelID = strMeasurementID + "-Z-VOL";
|
strChannelID = strMeasurementID + "-Z";
|
||||||
|
wave_type = WAVE_LF_Z;
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
FILE *fp = fopen(strFileName.c_str(), "w");
|
FILE *fp = fopen(strFileName.c_str(), "w");
|
||||||
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
|
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
|
||||||
zlog_info(zct, " vecData.size : %d,start ", vecData.size());
|
zlog_info(zct, " vecData.size : %zu,start ", vecData.size());
|
||||||
int id = 0;
|
int id = 0;
|
||||||
for (size_t i = 0; i < vecData.size(); i++) {
|
for (size_t i = 0; i < vecData.size(); i++) {
|
||||||
frTemp = vecData[i] - mean;
|
frTemp = vecData[i] - mean;
|
||||||
@ -1266,11 +1303,11 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
wave_channel.WaveChannelY[i] = frTemp;
|
wave_channel.WaveChannelY[i] = frTemp;
|
||||||
}else if (iChannel == WAVE_Z){
|
}else if (iChannel == WAVE_Z){
|
||||||
wave_channel.WaveChannelZ[i] = frTemp;
|
wave_channel.WaveChannelZ[i] = frTemp;
|
||||||
}else if (iChannel == WAVE_VOL_X){
|
}else if (iChannel == WAVE_LF_X){
|
||||||
wave_vol_channel.WaveChannelVolX[i] = frTemp;
|
wave_vol_channel.WaveChannelVolX[i] = frTemp;
|
||||||
}else if (iChannel == WAVE_VOL_Y){
|
}else if (iChannel == WAVE_LF_Y){
|
||||||
wave_vol_channel.WaveChannelVolY[i] = frTemp;
|
wave_vol_channel.WaveChannelVolY[i] = frTemp;
|
||||||
}else if (iChannel == WAVE_VOL_Z){
|
}else if (iChannel == WAVE_LF_Z){
|
||||||
wave_vol_channel.WaveChannelVolZ[i] = frTemp;
|
wave_vol_channel.WaveChannelVolZ[i] = frTemp;
|
||||||
}
|
}
|
||||||
if (i != vecData.size() -1){
|
if (i != vecData.size() -1){
|
||||||
@ -1285,7 +1322,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 0) ||
|
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 0) ||
|
||||||
(iChannel == WAVE_Z && version == 1) ||
|
(iChannel == WAVE_Z && version == 1) ||
|
||||||
((iChannel == WAVE_VOL_X || iChannel == WAVE_VOL_Y || iChannel == WAVE_VOL_Z) && version == 1)){
|
((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 1)){
|
||||||
sampleRate = 25600;
|
sampleRate = 25600;
|
||||||
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
||||||
size_t outSize = 25600;
|
size_t outSize = 25600;
|
||||||
@ -1308,7 +1345,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
outSize = 2560;
|
outSize = 2560;
|
||||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||||
}
|
}
|
||||||
zlog_info(zct, " outputData_size %d ", outputData.size());
|
zlog_info(zct, " outputData_size %zu ", outputData.size());
|
||||||
float mean = Calculation::mean(outputData);
|
float mean = Calculation::mean(outputData);
|
||||||
memset(mqttData,0,sizeof(mqttData));
|
memset(mqttData,0,sizeof(mqttData));
|
||||||
id = 0;
|
id = 0;
|
||||||
@ -1326,7 +1363,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zlog_info(zct, "fopen file vecData.size : %d end ", vecData.size());
|
zlog_info(zct, "fopen file vecData.size : %zu end ", vecData.size());
|
||||||
wave_channel.wave_timestamp = nowTimetamp;
|
wave_channel.wave_timestamp = nowTimetamp;
|
||||||
g_mapWaveChannel[strMeasurementID] = wave_channel;
|
g_mapWaveChannel[strMeasurementID] = wave_channel;
|
||||||
Json::Value valWaveData;
|
Json::Value valWaveData;
|
||||||
@ -1338,6 +1375,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
valWaveData["timeStamp"] = nowTimetamp;
|
valWaveData["timeStamp"] = nowTimetamp;
|
||||||
valWaveData["waveData"] = mqttData;
|
valWaveData["waveData"] = mqttData;
|
||||||
valWaveData["mean"] = mean;
|
valWaveData["mean"] = mean;
|
||||||
|
valWaveData["waveType"] = wave_type;
|
||||||
Json::FastWriter WaveValue;
|
Json::FastWriter WaveValue;
|
||||||
std::string WaveData = WaveValue.write(valWaveData);
|
std::string WaveData = WaveValue.write(valWaveData);
|
||||||
|
|
||||||
@ -1412,7 +1450,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
|||||||
JsonData jd;
|
JsonData jd;
|
||||||
jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,"send failed");
|
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 = %zu\n", strFileName.c_str(), vecData.size());
|
||||||
}
|
}
|
||||||
char updateSql[1024] = {0x00};
|
char updateSql[1024] = {0x00};
|
||||||
char tmpWhere[128] = {0x00};
|
char tmpWhere[128] = {0x00};
|
||||||
|
|||||||
@ -308,7 +308,7 @@ int Uart::UpdateConfig(uint16_t ushortAdd) {
|
|||||||
sprintf(selCon, "featureInterVal,waveInterVal,range,samplingRate,ACCSampleTime,startBrands,stopBrands,\
|
sprintf(selCon, "featureInterVal,waveInterVal,range,samplingRate,ACCSampleTime,startBrands,stopBrands,\
|
||||||
envelopeBandPass,faultFrequency,timeStamp,viff,ZigbeePower,ZigbeeRetry,MeasurementID,NodeWaveSend");
|
envelopeBandPass,faultFrequency,timeStamp,viff,ZigbeePower,ZigbeeRetry,MeasurementID,NodeWaveSend");
|
||||||
vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selCon, whereCon);
|
vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), selCon, whereCon);
|
||||||
zlog_info(zct, "vecResult size = %d", vecResult.size());
|
zlog_info(zct, "vecResult size = %zu", vecResult.size());
|
||||||
if (vecResult.size() < 1) {
|
if (vecResult.size() < 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -592,7 +592,6 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
|||||||
send_data[18] = y;
|
send_data[18] = y;
|
||||||
send_data[19] = z;
|
send_data[19] = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char tmp = 0x00;
|
unsigned char tmp = 0x00;
|
||||||
for (int k = 0; k < 99; k++) {
|
for (int k = 0; k < 99; k++) {
|
||||||
tmp += send_data[k];
|
tmp += send_data[k];
|
||||||
|
|||||||
@ -347,3 +347,71 @@ std::vector<float> Calculation::fftInterpolate(const std::vector<float>& input,
|
|||||||
|
|
||||||
return output2;
|
return output2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Calculation::freqDomainDecimateFFTW(const std::vector<float>& input,
|
||||||
|
std::vector<float>& output,
|
||||||
|
int factor)
|
||||||
|
{
|
||||||
|
int N = input.size();
|
||||||
|
|
||||||
|
if(N % factor != 0)
|
||||||
|
{
|
||||||
|
std::cout<<"Length not divisible by factor\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int N_out = N / factor;
|
||||||
|
|
||||||
|
// ---------- 分配 ----------
|
||||||
|
double* in_time = (double*)fftw_malloc(sizeof(double)*N);
|
||||||
|
fftw_complex* spectrum =
|
||||||
|
(fftw_complex*)fftw_malloc(sizeof(fftw_complex)*(N/2+1));
|
||||||
|
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
in_time[i] = input[i];
|
||||||
|
|
||||||
|
// ---------- FFT ----------
|
||||||
|
fftw_plan plan_fwd =
|
||||||
|
fftw_plan_dft_r2c_1d(N,in_time,spectrum,FFTW_ESTIMATE);
|
||||||
|
|
||||||
|
fftw_execute(plan_fwd);
|
||||||
|
|
||||||
|
// ---------- 构建新频谱 ----------
|
||||||
|
fftw_complex* new_spec =
|
||||||
|
(fftw_complex*)fftw_malloc(sizeof(fftw_complex)*(N_out/2+1));
|
||||||
|
|
||||||
|
memset(new_spec,0,sizeof(fftw_complex)*(N_out/2+1));
|
||||||
|
|
||||||
|
int half = N_out/2;
|
||||||
|
|
||||||
|
for(int i=0;i<=half;i++)
|
||||||
|
{
|
||||||
|
new_spec[i][0] = spectrum[i][0];
|
||||||
|
new_spec[i][1] = spectrum[i][1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- IFFT ----------
|
||||||
|
double* out_time =
|
||||||
|
(double*)fftw_malloc(sizeof(double)*N_out);
|
||||||
|
|
||||||
|
fftw_plan plan_inv =
|
||||||
|
fftw_plan_dft_c2r_1d(N_out,new_spec,out_time,FFTW_ESTIMATE);
|
||||||
|
|
||||||
|
fftw_execute(plan_inv);
|
||||||
|
|
||||||
|
output.resize(N_out);
|
||||||
|
|
||||||
|
for(int i=0;i<N_out;i++)
|
||||||
|
output[i] = out_time[i] / N_out;
|
||||||
|
|
||||||
|
// ---------- 清理 ----------
|
||||||
|
fftw_destroy_plan(plan_fwd);
|
||||||
|
fftw_destroy_plan(plan_inv);
|
||||||
|
|
||||||
|
fftw_free(in_time);
|
||||||
|
fftw_free(out_time);
|
||||||
|
fftw_free(spectrum);
|
||||||
|
fftw_free(new_spec);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@ -57,6 +57,10 @@ 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);
|
||||||
|
|
||||||
static std::vector<float> fftInterpolate(const std::vector<float>& input, size_t outputSize);
|
static std::vector<float> fftInterpolate(const std::vector<float>& input, size_t outputSize);
|
||||||
|
|
||||||
|
bool freqDomainDecimateFFTW(const std::vector<float>& input,
|
||||||
|
std::vector<float>& output,
|
||||||
|
int factor);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALCULATION_HPP_
|
#endif // CALCULATION_HPP_
|
||||||
|
|||||||
@ -39,7 +39,7 @@ double percentToSignal(double percent, double min, double max) {
|
|||||||
return min + (percent / 100.0) * (max - min);
|
return min + (percent / 100.0) * (max - min);
|
||||||
}
|
}
|
||||||
// 添加或更新设备信息
|
// 添加或更新设备信息
|
||||||
void updateDevice(const std::string& mac, int rssi) {
|
void updateDevice(const std::string& mac, double rssi) {
|
||||||
std::lock_guard<std::mutex> lock(map_mutex);
|
std::lock_guard<std::mutex> lock(map_mutex);
|
||||||
device_map[mac] = {
|
device_map[mac] = {
|
||||||
rssi,
|
rssi,
|
||||||
@ -221,7 +221,7 @@ void ScanBlueteeth::ParseData(unsigned char *data, int len,int8_t rssi){
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
double rssi_percent = signalToPercent((double)rssi, min, max);
|
double rssi_percent = signalToPercent((double)rssi, min, max);
|
||||||
updateDevice(std::string(mac), (int)rssi_percent);
|
updateDevice(std::string(mac), rssi_percent);
|
||||||
removeStaleDevices(1000*300); // 清除超过5分钟未更新的设备
|
removeStaleDevices(1000*300); // 清除超过5分钟未更新的设备
|
||||||
//printf("time %s Bluetooth temp :%f ℃ , NST 1001 temp: %f ℃\n",GetCurrentTime().c_str(),(float)temp*0.01, ((float)temp1*0.0625) - 50.0625);
|
//printf("time %s Bluetooth temp :%f ℃ , NST 1001 temp: %f ℃\n",GetCurrentTime().c_str(),(float)temp*0.01, ((float)temp1*0.0625) - 50.0625);
|
||||||
//printf(" volt : %f v\n", (double)volt * 0.03125 );
|
//printf(" volt : %f v\n", (double)volt * 0.03125 );
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user