移植DG102 代码到DG101
This commit is contained in:
parent
53a94037cf
commit
e21df2cd85
@ -185,15 +185,20 @@ struct Param_32 {
|
||||
|
||||
struct Param_33 {
|
||||
int mMode;
|
||||
std::string mUnit;
|
||||
Param_33() : mMode(0), mUnit(""){};
|
||||
std::string mCmdSerial;
|
||||
std::string mChannelId;
|
||||
std::string mDataNodeNo;
|
||||
int mPackageFlag;
|
||||
Param_33() : mMode(0), mCmdSerial(""), mChannelId(""), mDataNodeNo(""), mPackageFlag(0){};
|
||||
};
|
||||
|
||||
struct Param_34 {
|
||||
int mMode;
|
||||
std::string mBeforeTime;
|
||||
std::string mAfterTime;
|
||||
Param_34() : mMode(0), mBeforeTime(""), mAfterTime(""){};
|
||||
std::string mCmdSerial;
|
||||
std::string mChannelId;
|
||||
std::string mDataNodeNo;
|
||||
int mPackageFlag;
|
||||
Param_34() : mMode(0), mCmdSerial(""), mChannelId(""), mDataNodeNo(""), mPackageFlag(0){};
|
||||
};
|
||||
|
||||
struct Param_35 {
|
||||
@ -307,12 +312,12 @@ struct Param_57 {
|
||||
struct Param_58 {
|
||||
int mMode;
|
||||
int featureInterVal;
|
||||
int featureInterTime;
|
||||
int waveInterVal;
|
||||
int waveInterTime;
|
||||
int maxSensorNum;
|
||||
int sensorCount;
|
||||
Param_58() : mMode(0),featureInterVal(0),featureInterTime(0),waveInterVal(0),waveInterTime(0),maxSensorNum(0),sensorCount(0){};
|
||||
int waveResendNum;
|
||||
int resend;
|
||||
Param_58() : mMode(0),featureInterVal(0),waveInterVal(0),maxSensorNum(0),sensorCount(0),waveResendNum(0),resend(0){};
|
||||
};
|
||||
|
||||
struct Param_59 {
|
||||
@ -322,11 +327,12 @@ struct Param_59 {
|
||||
Param_59() : mMode(0),DataNodeNo(""),straxis(""){};
|
||||
};
|
||||
struct Param_60 {
|
||||
int mMode;
|
||||
std::string fileName;
|
||||
int product;
|
||||
std::string mShortAddr;
|
||||
std::vector<std::string> dataNodeNo;
|
||||
Param_60() : fileName(""),product(0),mShortAddr(""){};
|
||||
Param_60() :mMode(0), fileName(""),product(0),mShortAddr(""){};
|
||||
};
|
||||
struct Param_61 {
|
||||
int mMode;
|
||||
@ -368,4 +374,87 @@ struct Param_65 {
|
||||
std::string timeEnd;
|
||||
Param_65() : mMode(0),mPackageFlag(0),timeStart(""),timeEnd(""){};
|
||||
};
|
||||
struct Param_66 {
|
||||
int mMode;
|
||||
int mSensorLooseEnable;
|
||||
Param_66() : mSensorLooseEnable(0){};
|
||||
};
|
||||
|
||||
struct Param_67 {
|
||||
int mMode;
|
||||
int mPackageFlag;
|
||||
std::vector<std::string> measurementID;
|
||||
Param_67() : mMode(0),mPackageFlag(0){};
|
||||
};
|
||||
|
||||
//0 关闭,1 开启
|
||||
//0 加速度有效值,1 速度有效值
|
||||
struct Param_68_info{
|
||||
std::string measurementID;
|
||||
int status; //0 关闭,1 开启
|
||||
int statisticType; //0 加速度有效值,1 速度有效值
|
||||
float threshold;
|
||||
Param_68_info():measurementID(""),status(0),statisticType(0),threshold(0.0){};
|
||||
};
|
||||
|
||||
struct Param_68 {
|
||||
int mMode;
|
||||
int lowSignal;
|
||||
int signalThreshold;
|
||||
int lowBatteryLevel;
|
||||
int batteryLevelThreshold;
|
||||
int shutdownDetection;
|
||||
std::vector<Param_68_info> vecParam68;
|
||||
Param_68():lowSignal(0),signalThreshold(0),lowBatteryLevel(0),batteryLevelThreshold(0),shutdownDetection(0){};
|
||||
};
|
||||
|
||||
struct Param_69_info{
|
||||
std::string measurementID;
|
||||
int status; //0 关闭,1 开启
|
||||
int trigerType; //0 单次触发,1 多次触发
|
||||
int statisticType; //0 加速度有效值,1 速度有效值
|
||||
float threshold;
|
||||
Param_69_info():measurementID(""),status(0),trigerType(0),statisticType(0),threshold(0.0){};
|
||||
};
|
||||
struct Param_69{
|
||||
int mMode;
|
||||
bool trigerThresholdEnable;
|
||||
std::vector<Param_69_info> vecParam69;
|
||||
Param_69():mMode(0),trigerThresholdEnable(0){};
|
||||
};
|
||||
|
||||
struct Param_70{
|
||||
int mPackageFlag;
|
||||
std::string timeStart;
|
||||
std::string timeEnd;
|
||||
Param_70():mPackageFlag(0),timeStart(""),timeEnd(""){};
|
||||
};
|
||||
|
||||
struct Param_71{
|
||||
int mPackageFlag;
|
||||
std::string timeStart;
|
||||
std::string timeEnd;
|
||||
Param_71():mPackageFlag(0),timeStart(""),timeEnd(""){};
|
||||
};
|
||||
|
||||
// 无线温度传感器(蓝牙)
|
||||
struct Param_100{
|
||||
int mPackageFlag;
|
||||
Param_100() : mPackageFlag(0){};
|
||||
};
|
||||
|
||||
struct Param_101{
|
||||
std::string mac;
|
||||
std::string timeStart;
|
||||
std::string timeEnd;
|
||||
int mPackageFlag;
|
||||
Param_101() : mac(""),timeStart(""),timeEnd(""),mPackageFlag(0){};
|
||||
};
|
||||
|
||||
struct Param_103{
|
||||
std::string mac;
|
||||
std::string name;
|
||||
std::string operate;
|
||||
Param_103() : mac(""),name(""),operate(""){};
|
||||
};
|
||||
#endif // PARAMETER_DEFINATION_HPP_
|
||||
|
||||
@ -17,9 +17,9 @@ const char *T_SENSOR_INFO1[] = {"t_sensor_info", "dataNodeNo", "dataNodeName
|
||||
"zigbeePanId", "zigbeeChannel", "zigbeeShortAddr", "zigbeeLongAddr", "zigbeeDesAddr", "status", "timeStamp", "viff", "RSSI"};
|
||||
|
||||
const char *T_DATA_INFO1[] = {"t_data_info", "dataNodeNo", "channelID", "diagnosisPk", "integratPk", "integratRMS", "rmsValues", "envelopEnergy", "Amp1", "Amp2", "Amp3",
|
||||
"Amp4", "Amp5", "Phase1", "Phase2", "Phase3", "Phase4", "StaticIndex", "timeStamp", "sendMsg", "nodeResend"};
|
||||
"Amp4", "Amp5", "Phase1", "Phase2", "Phase3", "Phase4", "StaticIndex", "timeStamp", "sendMsg", "nodeResend","nodeTimestamp"};
|
||||
|
||||
const char *T_DATASTATIC_INFO1[] = {"t_datastatic_info", "dataNodeNo", "channelID", "temTop", "temBot", "dip", "voltage", "StaticIndex", "timeStamp", "sendMsg", "nodeResend"};
|
||||
const char *T_DATASTATIC_INFO1[] = {"t_datastatic_info", "dataNodeNo", "channelID", "temTop", "temBot", "dip", "voltage", "StaticIndex", "timeStamp", "sendMsg", "nodeResend","nodeTimestamp"};
|
||||
|
||||
const char *T_DATANODE_TIME1[] = {"t_datanode_time", "dataNodeNo", "shortaddr", "staticcycle", "wavecycle", "nodegroup", "nodeindex", "nodewaveindex", "statictime", "staticstarttime"};
|
||||
|
||||
@ -132,7 +132,8 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
|
||||
//创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);",
|
||||
// clang-format off
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s,%s);",
|
||||
T_DATA_INFO(TNAME),
|
||||
T_DATA_INFO(DATANODENO),
|
||||
T_DATA_INFO(CHANNELID),
|
||||
@ -153,17 +154,32 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_DATA_INFO(STATICINDEX),
|
||||
T_DATA_INFO(TIMESTAMP),
|
||||
T_DATA_INFO(SENDMSG),
|
||||
T_DATA_INFO(NODERESEND));
|
||||
T_DATA_INFO(NODERESEND),
|
||||
T_DATA_INFO(NODETIMESTAMP)
|
||||
);
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%nodeResend%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'nodeResend'");
|
||||
}
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%nodeTimeStamp%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'nodeTimeStamp'");
|
||||
}
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%kurtosis%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'kurtosis'");
|
||||
}
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%IntegratRMSMENS%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'IntegratRMSMENS'");
|
||||
}
|
||||
|
||||
//创建传感器静态数据存储表
|
||||
// 创建传感器静态数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);",
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s,%s);",
|
||||
T_DATASTATIC_INFO(TNAME),
|
||||
T_DATASTATIC_INFO(DATANODENO),
|
||||
T_DATASTATIC_INFO(CHANNELID),
|
||||
@ -175,12 +191,18 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_DATASTATIC_INFO(STATICINDEX),
|
||||
T_DATASTATIC_INFO(TIMESTAMP),
|
||||
T_DATASTATIC_INFO(SENDMSG),
|
||||
T_DATASTATIC_INFO(NODERESEND));
|
||||
T_DATASTATIC_INFO(NODERESEND),
|
||||
T_DATASTATIC_INFO(NODETIMESTAMP)
|
||||
);
|
||||
CreateTable(sql_exec);
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_datastatic_info' and sql LIKE '%nodeResend%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'nodeResend'");
|
||||
}
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_datastatic_info' and sql LIKE '%nodeTimeStamp%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'nodeTimeStamp'");
|
||||
}
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
@ -254,15 +276,56 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
execute_sql_file("/opt/configenv/receive_wave_status.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/reboot_record.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/blueteeth_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_sensor_bt_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_system_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_process_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_shutdown_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_wave_triger_info.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/t_debug_info.sql");
|
||||
|
||||
vec_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), "MeasurementID", NULL);
|
||||
for(size_t i = 0; i < vetRes.size() && vetRes.size() > 0; i++){
|
||||
std::string strMeasurementID = boost::algorithm::trim_copy(vetRes[i]);
|
||||
if(strMeasurementID.size() > 0){
|
||||
std::string strTmp = "";
|
||||
char sztableName[100] = {0x00},sql[1024] = {0x00};
|
||||
sprintf(sztableName, "t_dataStatic_%s", strMeasurementID.c_str());
|
||||
strTmp = "name = '" + std::string(sztableName) + "' and sql LIKE '%nodeTimeStamp%' ";
|
||||
iRet = GetTableRows(" sqlite_master ",strTmp.c_str());
|
||||
if(iRet == 0){
|
||||
memset(sql, 0, 1024);
|
||||
sprintf(sql,"ALTER TABLE t_dataStatic_%s ADD COLUMN 'nodeTimeStamp'", strMeasurementID.c_str());
|
||||
CreateTable(sql);
|
||||
}
|
||||
memset(sql, 0, 1024);
|
||||
memset(sztableName, 0, 100);
|
||||
sprintf(sztableName, "t_data_%s", strMeasurementID.c_str());
|
||||
strTmp = "name = '" + std::string(sztableName) + "' and sql LIKE '%nodeTimeStamp%' ";
|
||||
iRet = GetTableRows(" sqlite_master ",strTmp.c_str());
|
||||
if(iRet == 0){
|
||||
memset(sql, 0, 1024);
|
||||
sprintf(sql,"ALTER TABLE t_data_%s ADD COLUMN 'nodeTimeStamp'", strMeasurementID.c_str());
|
||||
CreateTable(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SqliteDB::Createtable(const char *ptableName) {
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);", ptableName, T_DATA_INFO(DATANODENO), T_DATA_INFO(CHANNELID), T_DATA_INFO(DIAGNOSISEAK), T_DATA_INFO(INTEGRATPK), T_DATA_INFO(INTEGRATRMS),
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s,%s,%s,%s);", ptableName, T_DATA_INFO(DATANODENO), T_DATA_INFO(CHANNELID), T_DATA_INFO(DIAGNOSISEAK), T_DATA_INFO(INTEGRATPK), T_DATA_INFO(INTEGRATRMS),
|
||||
T_DATA_INFO(RMSVALUES), T_DATA_INFO(ENVELOPNERGY), T_DATA_INFO(AMP1), T_DATA_INFO(AMP2), T_DATA_INFO(AMP3), T_DATA_INFO(AMP4), T_DATA_INFO(AMP5), T_DATA_INFO(PHASE1), T_DATA_INFO(PHASE2), T_DATA_INFO(PHASE3), T_DATA_INFO(PHASE4), "StaticIndex", T_DATA_INFO(TIMESTAMP),
|
||||
"sendMsg", "nodeResend");
|
||||
"sendMsg", "nodeResend", "nodeTimestamp","kurtosis","IntegratRMSMENS");
|
||||
CreateTable(sql_exec);
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "CREATE INDEX %s_1 ON %s (%s)", ptableName, ptableName, T_DATA_INFO(DATANODENO));
|
||||
@ -298,8 +361,8 @@ void SqliteDB::CreatedataStatictable(const char *ptableName) {
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s,%s integer,%s,%s);", ptableName, T_DATASTATIC_INFO(DATANODENO), T_DATASTATIC_INFO(CHANNELID), T_DATASTATIC_INFO(TEMTOP), T_DATASTATIC_INFO(TEMBOT), T_DATASTATIC_INFO(DIP),
|
||||
T_DATASTATIC_INFO(VOLTAGE), "zigbeeSignal", "StaticIndex", T_DATASTATIC_INFO(TIMESTAMP), "sendMsg", "nodeResend", "zigbeeSignalNode", "statisticType", "timing");
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s,%s integer,%s,%s,%s,%s,%s,%s);", ptableName, T_DATASTATIC_INFO(DATANODENO), T_DATASTATIC_INFO(CHANNELID), T_DATASTATIC_INFO(TEMTOP), T_DATASTATIC_INFO(TEMBOT), T_DATASTATIC_INFO(DIP),
|
||||
T_DATASTATIC_INFO(VOLTAGE), "zigbeeSignal", "StaticIndex", T_DATASTATIC_INFO(TIMESTAMP), "sendMsg", "nodeResend", "zigbeeSignalNode", "statisticType", "timing", "nodeTimestamp","minmumBatteryVoltageType","instantaneousBatteryVoltage","comprehensiveRSSI");
|
||||
CreateTable(sql_exec);
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "CREATE INDEX %s_1 ON %s (%s)", ptableName, ptableName, T_DATA_INFO(DATANODENO));
|
||||
@ -849,7 +912,12 @@ int SqliteDB::CalculateBattery() {
|
||||
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
std::vector<std::string> vParam;
|
||||
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { // 第一次计算
|
||||
std::string total_battery = "" , remain_battery = "";
|
||||
if(vParam.size() > 1){
|
||||
total_battery = vParam[0];
|
||||
remain_battery = vParam[1];
|
||||
}
|
||||
if (vParam.size() <= 0 || vecResSig.size() <= 0 || total_battery == "" || remain_battery == "") { // 第一次计算
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||
@ -965,7 +1033,7 @@ int SqliteDB::CalculateBattery() {
|
||||
if (startCapacity > 0) {
|
||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery);
|
||||
} else {
|
||||
sprintf(updateSql, "batteryPower = '%s,%f' ", vParam[0].c_str(), remainBattery);
|
||||
sprintf(updateSql, "batteryPower = '%s,%f' ", total_battery.c_str(), remainBattery);
|
||||
}
|
||||
|
||||
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
@ -1371,9 +1439,9 @@ int SqliteDB::QueryofflineData() {
|
||||
return res;
|
||||
}
|
||||
int SqliteDB::ClearExpireData(){
|
||||
char whereCon[1024] = {0};
|
||||
char whereCon[128] = {0};
|
||||
char deleteSql[1024] = {0};
|
||||
char selectSql[1024] = {0};
|
||||
char selectSql[128] = {0};
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(deleteSql, 0x00, sizeof(deleteSql));
|
||||
memset(selectSql, 0x00, sizeof(selectSql));
|
||||
@ -1391,6 +1459,164 @@ int SqliteDB::ClearExpireData(){
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void SqliteDB::SaveSystemHardStatus(){
|
||||
Json::Value jsData;
|
||||
std::string sysStatus = GetSysStatus(jsData);
|
||||
char insertSql[1024] = {0};
|
||||
float cpu_use = jsData["cpuUserUse"].asDouble();
|
||||
float mem_use_rate = jsData["memoryUse"].asDouble();
|
||||
int mem_free = jsData["memoryFree"].asInt();
|
||||
int mem_total = jsData["memoryTotal"].asInt();
|
||||
int mem_use = mem_total - mem_free;
|
||||
float disk_free = jsData["hardDiskFree"].asDouble();
|
||||
float disk_total = jsData["hardDiskTotal"].asDouble();
|
||||
float disk_use_rate = jsData["hardDiskUse"].asDouble();
|
||||
int temp = jsData["temperature"].asDouble();
|
||||
zlog_info(zct,"cpu_use = %f,mem_use = %d,mem_free = %d,mem_rate = %f,total = %f,free = %f,rate = %f",cpu_use,mem_use,mem_free,mem_use_rate,disk_total,disk_free,disk_use_rate);
|
||||
|
||||
std::string updateTime = jsData["updateTime"].asString();
|
||||
sprintf(insertSql, " '%f','%d','%d','%f','%f','%f','%f','%d','%s' ",
|
||||
cpu_use,
|
||||
mem_use,mem_free,mem_use_rate,
|
||||
disk_total-disk_free,disk_free,disk_use_rate,
|
||||
temp,
|
||||
updateTime.c_str());
|
||||
sqlite_db_ctrl::instance().InsertData("t_system_info", insertSql);
|
||||
}
|
||||
/* 新电池识别
|
||||
采集计算平均电压:Vc
|
||||
特征值发送瞬时最低电压:Ve
|
||||
波形发送瞬时最低电压:Vw
|
||||
在传感器上线后,第一次波形电压获取到Vw后进行计算,需要同时满足两个条件:
|
||||
1. (Vwp+Vcp+Vep)-(Vwn+Vcn+Ven) > 0.6V
|
||||
2. Vwp>Vw_min
|
||||
Vwn、Vcn、Ven : 网关最后记录24小时Vw、Vcn、Ven平均值
|
||||
Vwp、Vcp、Vep : 当前Vw、Vc、Ve电压值
|
||||
Vw_min : 电池型号相关,如ER34615C=2.8V
|
||||
*/
|
||||
|
||||
void SqliteDB::NewBatteryIdentify(){
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
float capacity = 0.0, startCapacity = 0.0;
|
||||
array_t arrRes;
|
||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
int count = arrRes.size();
|
||||
if (count > 0) {
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
if(atol(localtimestamp) - atol(arrRes[i][38].c_str()) < 90000){ // 每天计算一次,计算前25h内有没有新上线的传感器
|
||||
char tablename[100] = {0},whereCon[150] = {0},updateSql[100] = {0};
|
||||
sprintf(tablename,"t_dataStatic_%s",arrRes[i][44].c_str());
|
||||
sprintf(whereCon, "timeStamp < '%s' ORDER BY timeStamp DESC limit 0,300;", arrRes[i][38].c_str()); // 获取在传感器上线之前的300条电压数据
|
||||
array_t voltage_data = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " voltage,instantaneousBatteryVoltage ", whereCon);
|
||||
if (voltage_data.size() < 1) {
|
||||
continue;
|
||||
}
|
||||
long total_num = 0;
|
||||
for (size_t i = 0; i < voltage_data.size(); i++)
|
||||
{
|
||||
int temp = atoi(voltage_data[i][0].c_str()) + atoi(voltage_data[i][1].c_str());
|
||||
total_num += temp;
|
||||
}
|
||||
int mean_voltage = total_num / (voltage_data.size() * 2);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "minmumBatteryVoltageType = '2' ORDER BY timeStamp DESC limit 0,1;");
|
||||
vec_t voltage_data_new = sqlite_db_ctrl::instance().GetDataSingleLine(tablename, " voltage,instantaneousBatteryVoltage ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "minmumBatteryVoltageType = '1' ORDER BY timeStamp DESC limit 0,1;");
|
||||
std::string voltage = sqlite_db_ctrl::instance().GetData(tablename, " instantaneousBatteryVoltage ", whereCon);
|
||||
|
||||
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;
|
||||
zlog_info(zct,"mean_voltage = %d,voltage = %d,instantaneousBatteryVoltage = %d,instantaneousBatteryVoltage_s = %d diff = %d ",
|
||||
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)){
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), arrRes[i][44].c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo = '%s' ", arrRes[i][44].c_str());
|
||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||
if (Dip == "") {
|
||||
continue;
|
||||
}
|
||||
capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh 电池总量
|
||||
startCapacity = capacity;
|
||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, startCapacity);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
||||
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void SqliteDB::ShutdownCheck(){
|
||||
int checkNumber = readIntValue("config", "shutdownNumber", (char *)GlobalConfig::Config_G.c_str());
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = {0};
|
||||
char tablename[100] = {0};
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
|
||||
if (arrRes.size() > 0) {
|
||||
for (size_t i = 0; i < arrRes.size(); i++){
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(tablename,0,sizeof(tablename));
|
||||
sprintf(tablename,"t_data_%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);
|
||||
if (shutdownCheck.size() < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
array_t arrData;
|
||||
if(shutdownCheck[2] == "1"){
|
||||
if (shutdownCheck[3] == "0")//加速度有效值
|
||||
{
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,%d;",arrRes[i][44].c_str(),checkNumber);
|
||||
arrData = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " rmsValues ", whereCon);
|
||||
}else if(shutdownCheck[3] == "1"){ //速度有效值
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,%d;",arrRes[i][44].c_str(),checkNumber);
|
||||
arrData = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " integratRMS ", whereCon);
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
int shutdownFlag = 0;
|
||||
if (arrData.size() == checkNumber)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (i = 0; i < arrData.size(); i++)
|
||||
{
|
||||
if (atof(arrData[i][0].c_str()) > atof(shutdownCheck[4].c_str()))
|
||||
{
|
||||
break;
|
||||
}else{
|
||||
shutdownFlag = 1;
|
||||
}
|
||||
}
|
||||
if(i < arrData.size() - 1){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
if(shutdownFlag == 1){
|
||||
sprintf(updateSql,"effect = '1'");
|
||||
}else{
|
||||
sprintf(updateSql,"effect = '0'");
|
||||
}
|
||||
sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_shutdown_info", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); }
|
||||
|
||||
int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); }
|
||||
|
||||
@ -69,7 +69,9 @@ public:
|
||||
int InintGateway();
|
||||
int QueryofflineData();
|
||||
int ClearExpireData();
|
||||
int CalculateWaveRate();
|
||||
void SaveSystemHardStatus();
|
||||
void NewBatteryIdentify();
|
||||
void ShutdownCheck();
|
||||
std::string GetNodeConfigureInfor(const char *whereCon);
|
||||
int CloseDB();
|
||||
|
||||
@ -138,7 +140,8 @@ typedef enum {
|
||||
T_DATA_INFO_STATICINDEX,
|
||||
T_DATA_INFO_TIMESTAMP,
|
||||
T_DATA_INFO_SENDMSG,
|
||||
T_DATA_INFO_NODERESEND
|
||||
T_DATA_INFO_NODERESEND,
|
||||
T_DATA_INFO_NODETIMESTAMP
|
||||
} T_DATA_INFO_Index;
|
||||
|
||||
typedef enum {
|
||||
@ -152,7 +155,8 @@ typedef enum {
|
||||
T_DATASTATIC_INFO_STATICINDEX,
|
||||
T_DATASTATIC_INFO_TIMESTAMP,
|
||||
T_DATASTATIC_INFO_SENDMSG,
|
||||
T_DATASTATIC_INFO_NODERESEND
|
||||
T_DATASTATIC_INFO_NODERESEND,
|
||||
T_DATASTATIC_INFO_NODETIMESTAMP
|
||||
} T_DATASTATIC_INFO_Index;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@ -48,10 +48,10 @@ void JsonData::CmtCmd_80(char* send_data,int& send_length)
|
||||
void JsonData::CmtCmd_81(char* recv_body,int& count,char* send_data,int& send_length)
|
||||
{
|
||||
int featureInterVal;
|
||||
int featureInterTime;
|
||||
int waveInterVal;
|
||||
int waveInterTime;
|
||||
int waveResendNum;
|
||||
int maxSensorNum;
|
||||
int sensorCount;
|
||||
array_t arrRes;
|
||||
char whereCon[512]={0};
|
||||
if (recv_body != NULL)
|
||||
@ -158,7 +158,8 @@ void JsonData::CmtCmd_81(char* recv_body,int& count,char* send_data,int& send_le
|
||||
strsql = std::string(sql) + std::string(whereCon);
|
||||
int static_Count = sqlite_db_ctrl::instance().GetTableRows(szTableName,strsql.c_str());
|
||||
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveResendNum,maxSensorNum);
|
||||
zlog_info(zct,"wavex = %d,featureInterVal = %d,waveInterVal = %d",waveX_Count,featureInterVal,waveInterVal);
|
||||
int day_count = 86400 / waveInterVal;
|
||||
|
||||
sensor_info[j].wave_x_reporting_rate = (float( waveX_Count)/(86400/waveInterVal)) * 100;
|
||||
@ -234,7 +235,7 @@ void JsonData::CmtCmd_83(char* recv_body,int& count,char* send_data,int& send_le
|
||||
{
|
||||
array_t arrRes;
|
||||
std::string filename = "";
|
||||
char whereCon[128]={0};
|
||||
char whereCon[512]={0};
|
||||
if (recv_body){
|
||||
printf("count = %d\n",count);
|
||||
char MeasurementID_[256]={0};
|
||||
@ -504,8 +505,10 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
||||
zlog_info(zct,"sum = %x\n",sum % 256);
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
for (int i = 0; i < count; i++)
|
||||
std::vector<UpgradeParameter> param_list;
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
UpgradeParameter upgrade_parameter;
|
||||
char wherecon[100] = {0};
|
||||
char insertSql[200] = {0};
|
||||
char updateSql[100] = {0};
|
||||
@ -515,7 +518,7 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon);
|
||||
if (hw_ver != atoi(vecResult[0].c_str())){
|
||||
zlog_error(zct,"hardVersion error,filename = %s",file_path);
|
||||
upgrade_sensor_res.code = 3;
|
||||
upgrade_sensor_res.code = 2;
|
||||
sprintf(upgrade_sensor_res.message ,"%s","hardVersion error");
|
||||
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
||||
return;
|
||||
@ -531,8 +534,14 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
||||
scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version));
|
||||
upgrade_parameter.short_addr = short_addr;
|
||||
upgrade_parameter.sensor_type = std::string(sensor_type);
|
||||
upgrade_parameter.hw_version = atoi(vecResult[0].c_str());
|
||||
upgrade_parameter.current_sw_version = vecResult[1];
|
||||
upgrade_parameter.upgrade_sw_version = std::string(sf_version);
|
||||
param_list.push_back(upgrade_parameter);
|
||||
}
|
||||
int res = scheduler::instance().UpgradeSensor(param_list);
|
||||
free(buffer);
|
||||
}
|
||||
void JsonData::CmtCmd_87(char* MeasurementID,char* send_data,int& send_length)
|
||||
@ -579,7 +588,7 @@ void JsonData::CmtCmd_88(char* recv_body,int& count,char* send_data,int& send_l
|
||||
{
|
||||
if (recv_body != NULL)
|
||||
{
|
||||
char wherecon[100] = {0};
|
||||
char wherecon[512] = {0};
|
||||
char updateSql[100] = {0};
|
||||
printf("count = %d\n",count);
|
||||
char short_addr_[256]={0};
|
||||
|
||||
@ -41,7 +41,7 @@ public:
|
||||
|
||||
// web command parse2
|
||||
std::string JsonCmd_Cgi_26(Param_26 ¶m);
|
||||
std::string JsonCmd_Cgi_27(Param_27 ¶m);
|
||||
std::string JsonCmd_Cgi_27(std::vector<Param_27> ¶m);
|
||||
std::string JsonCmd_Cgi_28(Param_28 ¶m);
|
||||
std::string JsonCmd_Cgi_29(Param_29 ¶m); //获取原始数据
|
||||
std::string JsonCmd_Cgi_30(Param_30 ¶m); //获取频域数据
|
||||
@ -63,7 +63,7 @@ public:
|
||||
std::string JsonCmd_Cgi_53(std::vector<Param_53> ¶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_57(Param_57 ¶m);
|
||||
std::string JsonCmd_Cgi_58(Param_58 ¶m);
|
||||
@ -74,7 +74,12 @@ public:
|
||||
std::string JsonCmd_Cgi_63(Param_63 ¶m);
|
||||
std::string JsonCmd_Cgi_64(Param_64 ¶m);
|
||||
std::string JsonCmd_Cgi_65(Param_65 ¶m);
|
||||
std::string JsonCmd_Cgi_default();
|
||||
std::string JsonCmd_Cgi_66(Param_66 ¶m);
|
||||
std::string JsonCmd_Cgi_67(Param_67 ¶m);
|
||||
std::string JsonCmd_Cgi_68(Param_68 ¶m);
|
||||
std::string JsonCmd_Cgi_69(Param_69 ¶m);
|
||||
std::string JsonCmd_Cgi_70(Param_70 ¶m);
|
||||
std::string JsonCmd_Cgi_71(Param_71 ¶m);
|
||||
|
||||
//CMT tcp
|
||||
void CmtCmd_80(char* send_data,int& return_length);
|
||||
|
||||
@ -636,19 +636,18 @@ int JsonData::JsonCmd_31(){
|
||||
jsonVal["cmd"] = "31";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
int sensorCount = 0;
|
||||
int featureInterVal = 0;
|
||||
int featureInterTime = 0;
|
||||
int waveInterVal = 0;
|
||||
int waveInterTime = 0;
|
||||
int maxSensorNum = 0;
|
||||
int featureInterVal;
|
||||
int waveInterVal;
|
||||
int waveResendNum;
|
||||
int maxSensorNum;
|
||||
int sensorCount;
|
||||
|
||||
sensorCount = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveResendNum,maxSensorNum);
|
||||
jsBody["featureInterVal"] = featureInterVal;
|
||||
jsBody["featureInterTime"] = featureInterTime;
|
||||
jsBody["featureInterTime"] = 0;
|
||||
jsBody["waveInterVal"] = waveInterVal;
|
||||
jsBody["waveInterTime"] = waveInterTime;
|
||||
jsBody["waveInterTime"] = 0;
|
||||
jsBody["maxSensorNum"] = maxSensorNum;
|
||||
jsBody["sensorCount"] = sensorCount;
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
@ -701,8 +700,8 @@ void JsonData::DataNodeStatusCheck() {
|
||||
std::string strMeasurementID = vetRes[i][44];
|
||||
std::string strChannelId = strMeasurementID + "-X";
|
||||
char whereCon[512] = {0x00}, tablename[128] = {0x00};
|
||||
sprintf(whereCon, "dataNodeNo='%s' and channelID='%s' ORDER BY timeStamp DESC LIMIT 0,1", strDataNodeNo.c_str(), strChannelId.c_str());
|
||||
sprintf(tablename, "t_data_%s", strDataNodeNo.c_str());
|
||||
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", strMeasurementID.c_str());
|
||||
std::string strTimeRes = sqlite_db_ctrl::instance().GetData(tablename, "timeStamp", whereCon);
|
||||
if (strTimeRes.length() > 0) {
|
||||
int llastTime = atoi(strTimeRes.c_str());
|
||||
|
||||
@ -220,6 +220,8 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
jsChannelData["2xPhase"] = atof(arrRes[j][13].c_str());
|
||||
jsChannelData["3xPhase"] = atof(arrRes[j][14].c_str());
|
||||
jsChannelData["4xPhase"] = atof(arrRes[j][15].c_str());
|
||||
jsChannelData["kurtosis"] = atof(arrRes[j][21].c_str());
|
||||
jsChannelData["IntegratRMSMENS"] = atof(arrRes[j][22].c_str());
|
||||
jsChannelData["TimeStamp"] = atof(arrRes[j][17].c_str());
|
||||
jsSensor.append(jsChannelData);
|
||||
}
|
||||
@ -244,11 +246,11 @@ std::string JsonData::JsonCmd_Cgi_09(Param_09 ¶m) {
|
||||
jsStaticData["ChannelType"] = "STATUS";
|
||||
jsStaticData["ChannelId"] = vecRes[1];
|
||||
jsStaticData["TimeStamp"] = vecRes[8];
|
||||
jsStaticData["battery"] = vecRes[13];
|
||||
jsStaticData["battery"] = vecRes[15];
|
||||
jsStaticData["MeasurementID"] = strMeasurementID;
|
||||
jsStaticData["dataNodeNo"] = arrResAll[i][0];
|
||||
jsStaticData["ShortAddr"] = strShortAddr;
|
||||
jsStaticData["status"] = vecRes[11];
|
||||
jsStaticData["status"] = vecRes[13];
|
||||
jsStaticData["loose"] = "0";
|
||||
|
||||
} else {
|
||||
|
||||
@ -19,8 +19,14 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
|
||||
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1;
|
||||
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
char looseValue[10] = {0x00};
|
||||
char whereCon[100] = {0};
|
||||
std::string effect = "" ,rssi = "0",batteryPower = "";
|
||||
readStringValue("config", "loose", looseValue, (char *)GlobalConfig::Config_G.c_str());
|
||||
Json::Value jsArray;
|
||||
array_t arrRes;
|
||||
@ -102,10 +108,42 @@ std::string JsonData::JsonCmd_Cgi_26(Param_26 ¶m) {
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, arrRes[j][40], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamRSSI.size() > 1) {
|
||||
jsSensorData["RSSI"] = arrRes[j][40];
|
||||
jsSensorData["RSSI"] = atof(vParamRSSI[1].c_str()) / 255.0;
|
||||
} else {
|
||||
jsSensorData["RSSI"] = "0," + arrRes[j][40];
|
||||
jsSensorData["RSSI"] = arrRes[j][40];
|
||||
rssi = arrRes[j][40];
|
||||
}
|
||||
batteryPower = arrRes[j][43];
|
||||
std::vector<std::string> vParamBatteryPower;
|
||||
float fBatteryPower = 100.0;
|
||||
if(batteryPower != ""){
|
||||
boost::split(vParamBatteryPower, batteryPower, boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamBatteryPower.size() > 0) {
|
||||
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
|
||||
}
|
||||
}
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon,"shortAddr = '%s' ",arrRes[j][30].c_str());
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon);
|
||||
if (vecResult.size() == 0)
|
||||
{
|
||||
effect = "0";
|
||||
}else{
|
||||
effect = vecResult[5];
|
||||
}
|
||||
|
||||
|
||||
//同时满足时的优先级:低电量>低信号>停机
|
||||
if(effect == "1"){
|
||||
jsSensorData["waveStatus"] = 0; //灰色
|
||||
}
|
||||
if(lowSignal == 1 && atof(rssi.c_str()) < signalThreshold){
|
||||
jsSensorData["waveStatus"] = 1;//红色
|
||||
}
|
||||
if(lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold){
|
||||
jsSensorData["waveStatus"] = 2;//红色
|
||||
}
|
||||
|
||||
jsSensorData["update"] = atoi(arrRes[j][41].c_str());
|
||||
jsSensorData["MeasurementID"] = arrRes[j][44];
|
||||
jsSensorData["battery"] = arrRes[j][43];
|
||||
@ -219,7 +257,7 @@ std::string JsonData::JsonCmd_Cgi_54(Param_54 ¶m) {
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
std::string JsonData::JsonCmd_Cgi_27(std::vector<Param_27> ¶m) {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
|
||||
@ -229,33 +267,41 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
jsonVal["message"] = " ";
|
||||
char whereCon[128] = {0};
|
||||
char localtimestamp[32] = {0};
|
||||
if (param.mDataNodeNo.length() > 0 && param.mType == "DELETE") {
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||||
for (size_t i = 0; i < param.size(); i++)
|
||||
{
|
||||
zlog_info(zct,"type = %s",param[i].mType.c_str());
|
||||
if (param[i].mDataNodeNo.length() > 0 && param[i].mType == "DELETE") {
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param[i].mDataNodeNo.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mMeasurementID.c_str());
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like '%%%s%%'", param.mMeasurementID.c_str());
|
||||
sprintf(whereCon, "MeasurementID = '%s'", param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_debug_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_shutdown_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_triger_info ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like '%%%s%%'", param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_data_waveSend ", whereCon);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param.mMeasurementID.c_str());
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param.mMeasurementID.c_str());
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(param.mShortAddr.c_str(), &end_ptr, 16);
|
||||
short_addr = strtol(param[i].mShortAddr.c_str(), &end_ptr, 16);
|
||||
zlog_warn(zct,"delete short_addr = %02x%02x",UINT16_HIGH(short_addr),UINT16_LOW(short_addr));
|
||||
scheduler::instance().ClearScheduleCfg(short_addr);
|
||||
|
||||
} else if (param.mDataNodeNo.length() > 0 && param.mType == "CORRECT") {
|
||||
} else if (param[i].mDataNodeNo.length() > 0 && param[i].mType == "CORRECT") {
|
||||
char updateSql[1024] = {0};
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param[i].mDataNodeNo.c_str());
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
sprintf(updateSql, "LooseValue = '0,2,");
|
||||
std::string strUpdateSql = std::string(updateSql) + std::string(localtimestamp) + "' ";
|
||||
@ -264,6 +310,7 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
}
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
@ -305,6 +352,81 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
std::string softVersion = res[9];
|
||||
std::string productNo = res[17];
|
||||
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") // DN101所有版本和DN102 2.6以前版本
|
||||
{
|
||||
if (access(filename.c_str(), 0) >= 0 && param.mMode == 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"] = "没有数据文件";
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -352,17 +474,10 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
|
||||
}
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
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["timestamp"] = std::string(localtimestamp);
|
||||
@ -392,6 +507,10 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mDataNodeNo.c_str());
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
std::string softVersion = res[9];
|
||||
std::string productNo = res[17];
|
||||
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") // DN101所有版本和DN102 2.6以前版本
|
||||
{
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
@ -454,7 +573,65 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
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));
|
||||
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
zlog_info(zct,"LF vecWave size %zu,filename = %s",vecWave.size(),filename.c_str());
|
||||
//进行傅立叶变换
|
||||
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"] = "没有数据文件";
|
||||
}
|
||||
}
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
jsBody["package"] = param.mPackageFlag;
|
||||
jsBody["timestamp"] = std::string(localtimestamp);
|
||||
@ -468,7 +645,8 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
zlog_info(zct, "sample_rate=%d", SampleRate);
|
||||
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");
|
||||
if (comper != std::string::npos) {
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
@ -484,6 +662,16 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 ¶m) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(param.mMode == 0 && productNo == "02"){
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos) {
|
||||
resolution = 1 / 1.28;
|
||||
}else{
|
||||
resolution = 1 / 1.6;
|
||||
}
|
||||
}else if(param.mMode == 1 && productNo == "02"){
|
||||
resolution = 1 / 3.2;
|
||||
}
|
||||
|
||||
zlog_info(zct, "the sample rate is %d,the resolution %f", SampleRate, resolution);
|
||||
char buf[32];
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "wifi_5g/wpa_client.h"
|
||||
#include "utility/calculation.hpp"
|
||||
#include "scheduler/schedule.hpp"
|
||||
#include "scheduler/wave_feature_set.hpp"
|
||||
|
||||
extern zlog_category_t *zct;
|
||||
extern const char *JSON_FIELD_CMD;
|
||||
@ -278,10 +279,13 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||
|
||||
std::string softVersion = res[9];
|
||||
std::string productNo = res[17];
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
std::string filename = "";
|
||||
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") {
|
||||
filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
@ -349,10 +353,66 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else{
|
||||
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;
|
||||
std::vector<float> hanningWave;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
resolution = 1 / 3.2 ;
|
||||
|
||||
//积分
|
||||
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = IntegrationWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}
|
||||
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
jsBody["package"] = param.mPackageFlag;
|
||||
zlog_info(zct,"vecWave.size() = %d,sample = %d,second = %f", IntegrationWave.size(), atoi(res[23].c_str()), float(IntegrationWave.size() / atoi(res[23].c_str())));
|
||||
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())));
|
||||
if ((res[17] == "02" && compareVersions(softVersion, "2.6") == -1) || productNo == "01") {
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos && res[17] == "02") {
|
||||
jsBody["second"] = float((float)IntegrationWave.size() / (float)atoi(res[23].c_str()));
|
||||
@ -361,6 +421,9 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
} else {
|
||||
jsBody["second"] = 1;
|
||||
}
|
||||
}else{
|
||||
jsBody["second"] = 3.2;
|
||||
}
|
||||
|
||||
jsBody["Data"] = strWaveData;
|
||||
jsBody["timestamp"] = std::string(localtimestamp);
|
||||
@ -392,9 +455,11 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", whereCon);
|
||||
int SampleRate = 0;
|
||||
double resolution = 0.0;
|
||||
std::string softVersion = res[9];
|
||||
std::string productNo = res[17];
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||
|
||||
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01") {
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
@ -450,7 +515,7 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
|
||||
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;
|
||||
flag = (flag + 1) * sampleRateReference;
|
||||
@ -491,6 +556,61 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else{
|
||||
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;
|
||||
std::vector<float> hanningWave;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
resolution = 1 / 3.2 ;
|
||||
|
||||
//积分
|
||||
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
||||
Calculation::FFTSpec(IntegrationWave, fftWave);
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = fftWave.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", fftWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", fftWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}
|
||||
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
jsBody["package"] = param.mPackageFlag;
|
||||
@ -536,19 +656,18 @@ std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
||||
std::string error_msg = "";
|
||||
if (param.mMode == 1)
|
||||
{
|
||||
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum,error_msg);
|
||||
ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.maxSensorNum,param.waveResendNum,error_msg);
|
||||
}else if (param.mMode == 0)
|
||||
{
|
||||
sensorCount = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
|
||||
ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.waveResendNum,param.maxSensorNum);
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
jsBody["featureInterVal"] = param.featureInterVal;
|
||||
jsBody["featureInterTime"] = param.featureInterTime;
|
||||
jsBody["waveInterVal"] = param.waveInterVal;
|
||||
jsBody["waveInterTime"] = param.waveInterTime;
|
||||
jsBody["maxSensorNum"] = param.maxSensorNum;
|
||||
jsBody["resend"] = param.resend;
|
||||
jsBody["sensorCount"] = sensorCount;
|
||||
}else{
|
||||
jsonVal["success"] = false;
|
||||
@ -567,11 +686,11 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
||||
char table_name[50] ={0};
|
||||
char sql[1024]={0};
|
||||
int featureInterVal = 0;
|
||||
int featureInterTime = 0;
|
||||
int waveInterVal = 0;
|
||||
int waveInterTime = 0;
|
||||
int waveResendNum = 0;
|
||||
int maxSensorNum = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
int sensorCount = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveResendNum,maxSensorNum);
|
||||
|
||||
if (param.mMode == 1)
|
||||
{
|
||||
@ -648,9 +767,14 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "60";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
char wherecon[100] = {0};
|
||||
char insertSql[200] = {0};
|
||||
char updateSql[100] = {0};
|
||||
if(param.mMode == 0){
|
||||
char file_path[64]={0};
|
||||
char cmd[128]={0};
|
||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
||||
zlog_info(zct,"cmd = %s",cmd);
|
||||
system(cmd);
|
||||
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
|
||||
zlog_info(zct,"file_path = %s",file_path);
|
||||
@ -730,11 +854,14 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
zlog_info(zct,"sum = %x\n",sum % 256);
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
std::vector<UpgradeParameter> param_list;
|
||||
|
||||
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
|
||||
{
|
||||
char wherecon[100] = {0};
|
||||
char insertSql[200] = {0};
|
||||
char updateSql[100] = {0};
|
||||
UpgradeParameter upgrade_parameter;
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str());
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon);
|
||||
if (hw_ver != atoi(vecResult[0].c_str()))
|
||||
@ -746,7 +873,7 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
}
|
||||
sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),param.fileName.c_str());
|
||||
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
|
||||
//0 默认状态,1 升级中,2 升级成功,3 升级失败
|
||||
//0 默认状态,1 升级中,2 升级成功,3 升级失败 4,停止升级
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
||||
@ -755,7 +882,14 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
||||
int res = scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version));
|
||||
upgrade_parameter.short_addr = short_addr;
|
||||
upgrade_parameter.sensor_type = std::string(sensor_type);
|
||||
upgrade_parameter.hw_version = atoi(vecResult[0].c_str());
|
||||
upgrade_parameter.current_sw_version = vecResult[1];
|
||||
upgrade_parameter.upgrade_sw_version = std::string(sf_version);
|
||||
param_list.push_back(upgrade_parameter);
|
||||
}
|
||||
int res = scheduler::instance().UpgradeSensor(param_list);
|
||||
if (res != 0)
|
||||
{
|
||||
jsonVal["success"] = false;
|
||||
@ -763,9 +897,32 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
free(buffer);
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
free(buffer);
|
||||
}else if(param.mMode == 1){
|
||||
std::vector<uint16_t> short_addr_list;
|
||||
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
|
||||
{
|
||||
|
||||
UpgradeParameter upgrade_parameter;
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str());
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon);
|
||||
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
||||
short_addr_list.push_back(short_addr);
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
||||
sprintf(updateSql, " upgradeStatus = %d ", 4);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
|
||||
|
||||
}
|
||||
free(buffer);
|
||||
scheduler::instance().CancelUpgradeSensor(short_addr_list);
|
||||
}
|
||||
|
||||
return show_value_.write(jsonVal);
|
||||
|
||||
}
|
||||
@ -1093,19 +1250,20 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "65";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID,RSSI ", NULL);
|
||||
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID,RSSI,batteryPower ", NULL);
|
||||
size_t nSize = vetRes.size();
|
||||
std::string MeasurementID = "";
|
||||
char szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
if (nSize > 0) {
|
||||
|
||||
int interval = atol(param.timeEnd.c_str()) - atol(param.timeStart.c_str());
|
||||
int featureInterVal = 0,waveInterVal = 0,featureInterTime = 0,waveInterTime = 0,maxSensorNum = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
int featureInterVal = 0,waveInterVal = 0,waveRsendNum = 0,maxSensorNum = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,waveRsendNum,maxSensorNum);
|
||||
Json::Value jsBody;
|
||||
char count_sql[1024] = {0};
|
||||
int recive_feature = 0, send_feature = 0,resend_feature = 0;
|
||||
int recive_x = 0, recive_y = 0, recive_z = 0,resend_z = 0;
|
||||
float rssi = 0.0;
|
||||
//int send_x = 0, send_y = 0, send_z = 0;
|
||||
for (size_t i = 0; i < nSize; i++)
|
||||
{
|
||||
@ -1195,16 +1353,30 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
iTem.append(0);
|
||||
iTem.append(0);
|
||||
iTem.append(0);
|
||||
std::vector<std::string> vRssi;
|
||||
boost::split(vRssi, vetRes[i][2], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vRssi.size() > 0 ){
|
||||
iTem.append(atof(vRssi[0].c_str())/float(255));
|
||||
iTem.append(atof(vRssi[1].c_str())/float(255));
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vetRes[i][2], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamRSSI.size() > 1) {
|
||||
iTem.append(atof(vParamRSSI[1].c_str()) / 255.0 );
|
||||
iTem.append(0);
|
||||
rssi = atof(vParamRSSI[1].c_str()) / 255.0 ;
|
||||
} else {
|
||||
iTem.append(atof(vetRes[i][2].c_str()));
|
||||
iTem.append(0);
|
||||
rssi = atof(vetRes[i][2].c_str());
|
||||
}
|
||||
|
||||
iTem.append(resend_feature);
|
||||
iTem.append(resend_z);
|
||||
iTem.append(rssi); //信号
|
||||
iTem.append(vetRes[i][3]); //电池
|
||||
sprintf(whereCon,"timeStamp <> '' order by timeStamp desc limit 0,1 ");
|
||||
memset(szTableName,0,sizeof(szTableName));
|
||||
sprintf(szTableName,"t_dataStatic_%s",vetRes[i][1].c_str());
|
||||
std::string voltage = sqlite_db_ctrl::instance().GetData(szTableName, "voltage", whereCon);
|
||||
iTem.append(voltage); //电压
|
||||
jsBody.append(iTem);
|
||||
|
||||
|
||||
}
|
||||
if (jsBody.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
@ -1218,3 +1390,351 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_66(Param_66 ¶m) {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
Json::Value jsBody;
|
||||
jsonVal[JSON_FIELD_CMD] = "66";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
int looseEnable = -1;
|
||||
if (param.mMode == 1) {
|
||||
looseEnable = writeIntValue("config", "looseEnable", param.mSensorLooseEnable, (char *)GlobalConfig::Config_G.c_str());
|
||||
} else if (param.mMode == 0) {
|
||||
looseEnable = readIntValue("config", "looseEnable", (char *)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
jsBody["looseEnable"] = looseEnable;
|
||||
jsonVal["content"] = jsBody;
|
||||
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal[JSON_FIELD_CMD] = "67";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
char whereCon[512] = {0};
|
||||
char selectCon[128] = {0};
|
||||
char column[128] = {0};
|
||||
char tablename[256] = {0};
|
||||
if(param.mMode == 0){
|
||||
sprintf(selectCon, " t_sensor_info.MeasurementID = t_debug_info.MeasurementID ");
|
||||
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
|
||||
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, column, selectCon);
|
||||
int nSize = arrRes.size();
|
||||
if (nSize > 0) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
jsonVal["package"] = packgeNo;
|
||||
int lastSize = nSize % 10;
|
||||
int index = nSize / 10;
|
||||
if (lastSize > 0 && index > 0) {
|
||||
packgeMax = index + 1;
|
||||
if (packgeNo + 1 == packgeMax) {
|
||||
packgeNum = nSize;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
} else {
|
||||
packgeNum = (packgeNo + 1) * 10;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
} else if (lastSize == 0 && index > 0) {
|
||||
packgeNum = (packgeNo + 1) * 10;
|
||||
packgeMax = index;
|
||||
jsonVal["packageMax"] = index;
|
||||
} else if (lastSize > 0 && index == 0) {
|
||||
packgeNum = lastSize;
|
||||
packgeMax = index + 1;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
Json::Value jsSensor;
|
||||
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
||||
Json::Value jsChannelData;
|
||||
jsChannelData["dataNodeName"] = arrRes[j][10];
|
||||
jsChannelData["zigbeeAddr"] = arrRes[j][1];
|
||||
jsChannelData["MeasurementID"] = arrRes[j][0];
|
||||
jsChannelData["status"] = atoi(arrRes[j][9].c_str());
|
||||
jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str());
|
||||
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
|
||||
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
|
||||
jsChannelData["minimumVoltage"] = atof(arrRes[j][5].c_str());
|
||||
jsChannelData["currentBatteryLevel"] = atof(arrRes[j][6].c_str());
|
||||
jsChannelData["debugStatus"] = atoi(arrRes[j][7].c_str());
|
||||
jsChannelData["TimeStamp"] = arrRes[j][8];
|
||||
jsSensor.append(jsChannelData);
|
||||
}
|
||||
if (jsSensor.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
} else {
|
||||
jsonVal["content"]["dataNodeArray"] = (jsSensor);
|
||||
}
|
||||
}else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
}else if(param.mMode == 1){//启动传感器调试
|
||||
if(param.measurementID.size() > 0){
|
||||
std::vector<uint16_t> short_addr_list;
|
||||
for (size_t i = 0; i < param.measurementID.size(); i++)
|
||||
{
|
||||
char whereCon[512] = {0};
|
||||
char updateSql[256] = {0};
|
||||
sprintf(whereCon, " MeasurementID = '%s' ", param.measurementID[i].c_str());
|
||||
sprintf(updateSql, " status = '%d' ", 1);// 0 未调试,1 调试中,2 调试完成
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
|
||||
short_addr = strtol(vecResult[0].c_str(), &end_ptr, 16);
|
||||
short_addr_list.push_back(short_addr);
|
||||
}
|
||||
scheduler::instance().OpenDebugMode(short_addr_list);
|
||||
}
|
||||
}else if(param.mMode == 2){ // 停止调试
|
||||
char whereCon[512] = {0};
|
||||
char updateSql[256] = {0};
|
||||
sprintf(whereCon, " status = '1' ");
|
||||
sprintf(updateSql, " status = '%d' ", 0);// 0 未调试,1 调试中,2 调试完成
|
||||
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon);
|
||||
scheduler::instance().CloseDebugMode();
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
Json::Value jsonVal;
|
||||
Json::Value dataNodeArray;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal[JSON_FIELD_CMD] = "68";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1,shutdownDetection = -1;
|
||||
char whereCon[512] = {0};
|
||||
char updateSql[256] = {0};
|
||||
if (param.mMode == 1) {
|
||||
lowSignal = writeIntValue("config", "lowSignal", param.lowSignal, (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = writeIntValue("config", "signalThreshold", param.signalThreshold, (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = writeIntValue("config", "lowBatteryLevel", param.lowBatteryLevel, (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = writeIntValue("config", "batteryLevelThreshold", param.batteryLevelThreshold, (char *)GlobalConfig::Config_G.c_str());
|
||||
shutdownDetection = writeIntValue("config", "shutdownDetection", param.shutdownDetection, (char *)GlobalConfig::Config_G.c_str());
|
||||
if(param.vecParam68.size() > 0){
|
||||
for (size_t i = 0; i < param.vecParam68.size(); i++)
|
||||
{
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam68[i].measurementID.c_str());
|
||||
sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f'",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" t_shutdown_info ", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
} else if (param.mMode == 0) {
|
||||
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
shutdownDetection = readIntValue("config", "shutdownDetection", (char *)GlobalConfig::Config_G.c_str());
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_shutdown_info LEFT JOIN t_sensor_info ", " t_shutdown_info.*,t_sensor_info.dataNodeName ", "t_shutdown_info.MeasurementID = t_sensor_info.MeasurementID");
|
||||
if (arrRes.size() > 0) {
|
||||
for (size_t i = 0; i < arrRes.size(); i++)
|
||||
{
|
||||
Json::Value iTem;
|
||||
iTem.append(arrRes[i][0]);
|
||||
iTem.append(atoi(arrRes[i][2].c_str()));
|
||||
iTem.append(atoi(arrRes[i][3].c_str()));
|
||||
iTem.append(atof(arrRes[i][4].c_str()));
|
||||
iTem.append(arrRes[i][6]);
|
||||
dataNodeArray.append(iTem);
|
||||
}
|
||||
}
|
||||
if (dataNodeArray.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
jsonVal["content"]["lowSignal"] = lowSignal;
|
||||
jsonVal["content"]["signalThreshold"] = signalThreshold;
|
||||
jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel;
|
||||
jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold;
|
||||
jsonVal["content"]["shutdownDetection"] = shutdownDetection;
|
||||
}
|
||||
jsonVal["content"]["dataNodeArray"] = dataNodeArray;
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
std::string JsonData::JsonCmd_Cgi_69(Param_69 ¶m){
|
||||
Json::Value jsonVal;
|
||||
Json::Value dataNodeArray;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal[JSON_FIELD_CMD] = "69";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
int trigerThresholdEnable = -1;
|
||||
char whereCon[512] = {0};
|
||||
char updateSql[256] = {0};
|
||||
if (param.mMode == 1) {
|
||||
trigerThresholdEnable = writeIntValue("config", "trigerThresholdEnable", param.trigerThresholdEnable, (char *)GlobalConfig::Config_G.c_str());
|
||||
if(param.vecParam69.size() > 0){
|
||||
for (size_t i = 0; i < param.vecParam69.size(); i++)
|
||||
{
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam69[i].measurementID.c_str());
|
||||
sprintf(updateSql, " status = '%d',trigerType = '%d',statisticType = '%d', threshold = '%f'",param.vecParam69[i].status,param.vecParam69[i].trigerType,param.vecParam69[i].statisticType,param.vecParam69[i].threshold);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" t_waveTriger_info ", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
} else if (param.mMode == 0) {
|
||||
trigerThresholdEnable = readIntValue("config", "trigerThresholdEnable", (char *)GlobalConfig::Config_G.c_str());
|
||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" t_wave_triger_info LEFT JOIN t_sensor_info ", " t_wave_triger_info.*,t_sensor_info.dataNodeName ", "t_wave_triger_info.MeasurementID = t_sensor_info.MeasurementID");
|
||||
if (arrRes.size() > 0) {
|
||||
for (size_t i = 0; i < arrRes.size(); i++)
|
||||
{
|
||||
Json::Value iTem;
|
||||
iTem.append(arrRes[i][0]);
|
||||
iTem.append(atoi(arrRes[i][2].c_str()));
|
||||
iTem.append(atoi(arrRes[i][3].c_str()));
|
||||
iTem.append(atoi(arrRes[i][4].c_str()));
|
||||
iTem.append(atof(arrRes[i][5].c_str()));
|
||||
iTem.append(arrRes[i][7]);
|
||||
dataNodeArray.append(iTem);
|
||||
|
||||
}
|
||||
}
|
||||
if (dataNodeArray.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
}
|
||||
jsonVal["content"]["trigerThresholdEnable"] = trigerThresholdEnable;
|
||||
jsonVal["content"]["dataNodeArray"] = dataNodeArray;
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_70(Param_70 ¶m){
|
||||
Json::Value jsonVal;
|
||||
Json::Value dataNodeArray;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal[JSON_FIELD_CMD] = "70";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
sprintf(szTableName,"t_process_info");
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
jsonVal["package"] = packgeNo;
|
||||
int lastSize = rows % 550;
|
||||
int index = rows / 550;
|
||||
if (lastSize > 0 && index > 0) {
|
||||
packgeMax = index + 1;
|
||||
if (packgeNo + 1 == packgeMax) {
|
||||
packgeNum = rows - lastSize;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
} else {
|
||||
packgeNum = (packgeNo)*550;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
} else if (lastSize == 0 && index > 0) {
|
||||
packgeNum = (packgeNo + 1) * 550;
|
||||
packgeMax = index;
|
||||
jsonVal["packageMax"] = index;
|
||||
} else if (lastSize > 0 && index == 0) {
|
||||
packgeNum = 0;
|
||||
packgeMax = index + 1;
|
||||
jsonVal["packageMax"] = index;
|
||||
}
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
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;
|
||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
||||
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||
if (vecRes.size() > 0) {
|
||||
Json::Value jsStaticData;
|
||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||
Json::Value iTem;
|
||||
iTem.append(vecRes[i][2]);
|
||||
iTem.append(vecRes[i][0]);
|
||||
iTem.append(vecRes[i][1]);
|
||||
jsStaticData.append(iTem);
|
||||
}
|
||||
if (jsStaticData.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
} else {
|
||||
jsonVal["content"] = jsStaticData;
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_71(Param_71 ¶m){
|
||||
Json::Value jsonVal;
|
||||
Json::Value dataNodeArray;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal[JSON_FIELD_CMD] = "71";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
sprintf(szTableName,"t_system_info");
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
jsonVal["package"] = packgeNo;
|
||||
int lastSize = rows % 550;
|
||||
int index = rows / 550;
|
||||
if (lastSize > 0 && index > 0) {
|
||||
packgeMax = index + 1;
|
||||
if (packgeNo + 1 == packgeMax) {
|
||||
packgeNum = rows - lastSize;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
} else {
|
||||
packgeNum = (packgeNo)*550;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
} else if (lastSize == 0 && index > 0) {
|
||||
packgeNum = (packgeNo + 1) * 550;
|
||||
packgeMax = index;
|
||||
jsonVal["packageMax"] = index;
|
||||
} else if (lastSize > 0 && index == 0) {
|
||||
packgeNum = 0;
|
||||
packgeMax = index + 1;
|
||||
jsonVal["packageMax"] = index;
|
||||
}
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
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;
|
||||
vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon);
|
||||
zlog_info(zct, "vecRes = %zu", vecRes.size());
|
||||
if (vecRes.size() > 0) {
|
||||
Json::Value jsStaticData;
|
||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||
Json::Value iTem;
|
||||
iTem.append(vecRes[i][10]);
|
||||
iTem.append(vecRes[i][2]);
|
||||
iTem.append(vecRes[i][5]);
|
||||
iTem.append(vecRes[i][8]);
|
||||
iTem.append(vecRes[i][9]);
|
||||
jsStaticData.append(iTem);
|
||||
}
|
||||
if (jsStaticData.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
} else {
|
||||
jsonVal["content"] = jsStaticData;
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -55,6 +55,12 @@ enum WebCommand {
|
||||
kWaveSend = 63,
|
||||
kFeatureSend = 64,
|
||||
kFeatureWaveCount = 65,
|
||||
KSensorLoose = 66,
|
||||
KDebugSensor = 67, // 调试传感器
|
||||
KWaveRule = 68, // 波形规则配置
|
||||
KTrigerWaveUpload = 69, // 触发波形上传
|
||||
KProcessLog = 70, // 获取应用程序运行日志
|
||||
KSystemLog = 71, // 获取系统日志
|
||||
|
||||
//CMT TCP
|
||||
kGateWayVersion = 80,
|
||||
|
||||
@ -173,11 +173,23 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
return data;
|
||||
} break;
|
||||
case kWebDeleteTransducerInfo: {
|
||||
Param_27 param;
|
||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
||||
param.mMeasurementID = recvBody["MeasurementID"].asString();
|
||||
param.mType = recvBody["type"].asString();
|
||||
std::vector<Param_27> param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
Json::Value recvBodyTemp;
|
||||
Json::Value recvDataNodeNo = recvBody["dataNodeNo"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
for (size_t i = 0; i < recvDataNodeNo.size(); i++) {
|
||||
Param_27 param_27;
|
||||
Json::Value node = recvDataNodeNo[i];
|
||||
param_27.mDataNodeNo = node[0u].asString();
|
||||
param_27.mMeasurementID = node[1u].asString();
|
||||
param_27.mShortAddr = node[2u].asString();
|
||||
param_27.mType = type;
|
||||
|
||||
param.push_back(param_27);
|
||||
}
|
||||
}
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_27(param);
|
||||
return data;
|
||||
@ -193,6 +205,12 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kGetTimeDomainWave: {
|
||||
JsonData jd;
|
||||
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.mPackageFlag = recvBody["package"].asInt();
|
||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||
@ -202,6 +220,12 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kGetFreqDomainWave: {
|
||||
JsonData jd;
|
||||
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.mPackageFlag = recvBody["package"].asInt();
|
||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||
@ -385,10 +409,10 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
param.featureInterVal = recvBody["featureInterVal"].asInt();
|
||||
param.featureInterTime = recvBody["featureInterTime"].asInt();
|
||||
param.waveInterVal = recvBody["waveInterVal"].asInt();
|
||||
param.waveInterTime = recvBody["waveInterTime"].asInt();
|
||||
param.maxSensorNum = recvBody["maxSensorNum"].asInt();
|
||||
param.waveResendNum = recvBody["waveResendNum"].asInt();
|
||||
param.resend = recvBody["resend"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_58(param);
|
||||
return data;
|
||||
}break;
|
||||
@ -404,9 +428,16 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kTransducerUpgrade:{
|
||||
JsonData jd;
|
||||
Param_60 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("UPDATE")) {
|
||||
param.mMode = 0;
|
||||
param.fileName = recvBody["fileName"].asString();
|
||||
param.product = recvBody["product"].asInt();
|
||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
||||
}
|
||||
if (0 == type.compare("STOP")) {
|
||||
param.mMode = 1;
|
||||
}
|
||||
Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
@ -522,6 +553,149 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case KSensorLoose:{
|
||||
JsonData jd;
|
||||
Param_66 param;
|
||||
param.mSensorLooseEnable = recvBody["looseEnable"].asInt();
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 1;
|
||||
}
|
||||
if (0 == type.compare("GET")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_66(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case KDebugSensor:{
|
||||
JsonData jd;
|
||||
Param_67 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 1;
|
||||
Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
for (size_t i = 0; i < recvDataNodeNo.size(); i++) {
|
||||
param.measurementID.push_back(recvDataNodeNo[i].asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 == type.compare("GET")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
if (0 == type.compare("STOP")) {
|
||||
param.mMode = 2;
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_67(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case KWaveRule:{
|
||||
JsonData jd;
|
||||
Param_68 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 1;
|
||||
}else if (0 == type.compare("GET")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
param.lowSignal = recvBody["lowSignal"].asInt();
|
||||
param.signalThreshold = recvBody["signalThreshold"].asInt();
|
||||
param.lowBatteryLevel = recvBody["lowBatteryLevel"].asInt();
|
||||
param.batteryLevelThreshold = recvBody["batteryLevelThreshold"].asInt();
|
||||
param.shutdownDetection = recvBody["shutdownDetection"].asInt();
|
||||
Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < recvDataNodeNo.size(); ++i) {
|
||||
Param_68_info vecParam;
|
||||
Json::Value node = recvDataNodeNo[i];
|
||||
|
||||
vecParam.measurementID = node[0u].asString();
|
||||
vecParam.status = node[1u].asInt();
|
||||
vecParam.statisticType = node[2u].asInt();
|
||||
vecParam.threshold = node[3u].asDouble();
|
||||
param.vecParam68.push_back(vecParam);
|
||||
}
|
||||
}
|
||||
|
||||
std::string data = jd.JsonCmd_Cgi_68(param);
|
||||
return data;
|
||||
}break;
|
||||
case KTrigerWaveUpload:{
|
||||
JsonData jd;
|
||||
Param_69 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 1;
|
||||
}else if (0 == type.compare("GET")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
for (size_t i = 0; i < recvDataNodeNo.size(); i++) {
|
||||
Param_69_info vecParam;
|
||||
Json::Value node = recvDataNodeNo[i];
|
||||
vecParam.measurementID = node[0u].asString();
|
||||
vecParam.status = node[1u].asInt();
|
||||
vecParam.trigerType = node[2u].asInt();
|
||||
vecParam.statisticType = node[3u].asInt();
|
||||
vecParam.threshold = node[4u].asDouble();
|
||||
|
||||
param.vecParam69.push_back(vecParam);
|
||||
}
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_69(param);
|
||||
return data;
|
||||
}break;
|
||||
case KProcessLog:{
|
||||
JsonData jd;
|
||||
Param_70 param;
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_70(param);
|
||||
return data;
|
||||
}break;
|
||||
case KSystemLog:{
|
||||
|
||||
}break;
|
||||
case kGetSensorInfo:{
|
||||
JsonData jd;
|
||||
Param_71 param;
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_71(param);
|
||||
return data;
|
||||
}break;
|
||||
case kGetFeatureSensorInfo:{
|
||||
JsonData jd;
|
||||
Param_101 param;
|
||||
param.mac = recvBody["mac"].asString();
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_101(param);
|
||||
return data;
|
||||
}break;
|
||||
case kScanSenorInfo:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_102();
|
||||
return data;
|
||||
}break;
|
||||
case kOperateSensor:{
|
||||
JsonData jd;
|
||||
Param_103 param;
|
||||
param.mac = recvBody["mac"].asString();
|
||||
param.name = recvBody["name"].asString();
|
||||
param.operate = recvBody["operate"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_103(param);
|
||||
return data;
|
||||
}break;
|
||||
default:
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_default();
|
||||
|
||||
18
main.cpp
18
main.cpp
@ -22,7 +22,9 @@
|
||||
extern std::vector<RecvData> g_VecWaveDataX;
|
||||
extern std::vector<RecvData> g_VecWaveDataY;
|
||||
extern std::vector<RecvData> g_VecWaveDataZ;
|
||||
|
||||
extern std::vector<RecvData> g_VecWaveDataVolX;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolY;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolZ;
|
||||
zlog_category_t *zct = NULL;
|
||||
zlog_category_t *zbt = NULL;
|
||||
|
||||
@ -48,12 +50,21 @@ int main(int argc, char *argv[]) {
|
||||
g_VecWaveDataX.reserve(1000);
|
||||
g_VecWaveDataY.reserve(1000);
|
||||
g_VecWaveDataZ.reserve(1500);
|
||||
g_VecWaveDataVolX.reserve(1000);
|
||||
g_VecWaveDataVolY.reserve(1000);
|
||||
g_VecWaveDataVolZ.reserve(1500);
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_stack_size(1024 * 1024);
|
||||
|
||||
PlatformInit::Init();
|
||||
|
||||
sqlite_db_ctrl::instance().InintGateway();
|
||||
char localtimestamp[32] = { 0 };
|
||||
char insertSql[128] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '3','CIDNSOFT start','%s'",localtimestamp);
|
||||
sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
|
||||
uart_inst::instance().InitZigbeeHW();
|
||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
@ -150,6 +161,11 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
if (count >= 30) {
|
||||
zlog_error(zbt, "===========threadStatus ========failed");
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '1','CheckThread failed','%s'",localtimestamp);
|
||||
sqlite_db_ctrl::instance().InsertData("t_process_info", insertSql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ int GlobalConfig::LinkStatus_G = 0;
|
||||
int GlobalConfig::LinkCount = 0;
|
||||
int GlobalConfig::net0Status = 1;
|
||||
|
||||
std::string GlobalConfig::Version = "5.6";
|
||||
std::string GlobalConfig::Version = "5.8";
|
||||
std::string GlobalConfig::MacAddr_G = "";
|
||||
std::string GlobalConfig::MacAddr_G2 = "";
|
||||
std::string GlobalConfig::IpAddr_G = "";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -4,12 +4,17 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <boost/container/detail/singleton.hpp>
|
||||
#include "upgrade_cfg.hpp"
|
||||
#include "status_mgr.hpp"
|
||||
|
||||
#define SCHEDULE_CONFIG "/opt/configenv/schedule.json"
|
||||
#define DEBUG_SCHEDULE_CONFIG "/opt/configenv/debug_schedule.json"
|
||||
#define UPGRADE_SCHEDULE_CONFIG "/opt/configenv/upgrade_schedule.json"
|
||||
#define TRIGGER_WAVE_CONFIG "/opt/configenv/trigger_wave.json"
|
||||
|
||||
typedef enum {
|
||||
kScheduleResultNone = 0,
|
||||
@ -30,57 +35,54 @@ typedef enum {
|
||||
kUpgradeDoneBefore = 5 // 当前就是这个版本,不需要升级了
|
||||
} FirmFileCheckResult;
|
||||
|
||||
typedef struct {
|
||||
uint16_t short_addr;
|
||||
std::string sensor_type;
|
||||
int hw_version;
|
||||
std::string current_sw_version;
|
||||
std::string upgrade_sw_version;
|
||||
} UpgradeParameter;
|
||||
|
||||
class SensorScheduler {
|
||||
public:
|
||||
SensorScheduler();
|
||||
|
||||
void SetScheduleStatus(ScheduleStatus status);
|
||||
ScheduleStatus GetScheduleStatus();
|
||||
// kScheduleConfigSensor kScheduleUpgrade 等有结果,调我接口通知结果
|
||||
// kScheduleEigenValue kScheduleWaveForm
|
||||
// 上面4个结束,调GetNextDuration()获取休眠时间
|
||||
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
||||
int StartSchedule(int short_addr, int &next_duration, int &next_task_id);
|
||||
int GetNextDuration(int short_addr,int &next_task_id);
|
||||
// int GetNextDuration(int short_addr);
|
||||
|
||||
int WaveError(uint16_t short_addr);
|
||||
int WaveSuccess(uint16_t short_addr);
|
||||
long GetBaseTimestamp(int id);
|
||||
long CalcNextTimestamp(int id, uint16_t short_addr, int& next_task_id);
|
||||
|
||||
// 当有传感器需要更新配置时调用
|
||||
int UpdateSensorConfig(int short_addr);
|
||||
// 当更新结束后,调用此接口,result为0是成功,其它值为失败
|
||||
int UpdateConfigResult(int short_addr, int result);
|
||||
|
||||
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);
|
||||
/**
|
||||
* @brief 当有传感器需要升级时调用
|
||||
* sensor_type: DN101, DN102
|
||||
* hw_version: 3, 4
|
||||
* current_sw_version: 1.1
|
||||
* upgrade_sw_version: 1.2
|
||||
*/
|
||||
int UpgradeSensor(int short_addr, std::string sensor_type, int hw_version,
|
||||
std::string current_sw_version, std::string upgrade_sw_version);
|
||||
/**
|
||||
* @brief 升级后,无线传感器发回来的返回值
|
||||
* @brief
|
||||
*
|
||||
* @param short_addr
|
||||
* @param result 参考:FirmFileCheckResult
|
||||
* 返回值表明操作是否成功,0成功,其它失败
|
||||
* @param z 如果需要触发z轴波形,此参数为1, 否则为0
|
||||
* @param xy 如果需要触发xy轴波形,此参数为1, 否则为0
|
||||
*/
|
||||
int UpgradeResult(int short_addr, int result);
|
||||
int TriggerWave(uint16_t short_addr, uint8_t z, uint8_t xy);
|
||||
|
||||
// z用于说明是z轴波形,还是xy轴波形
|
||||
int WaveError(uint16_t short_addr, bool z);
|
||||
void WaveSuccess(uint16_t short_addr, bool z);
|
||||
// long GetBaseTimestamp(int id);
|
||||
long CalcNextTimestamp(int id, uint16_t short_addr, bool &z, int& next_task_id);
|
||||
|
||||
// 当有传感器需要更新配置时调用
|
||||
int UpdateSensorConfig(uint16_t short_addr);
|
||||
// 当更新结束后,调用此接口,result为0是成功,其它值为失败
|
||||
int UpdateConfigResult(uint16_t short_addr, int result);
|
||||
|
||||
int Config(int eigen_value_send_interval, int wave_form_send_interval,
|
||||
int eigen_value_send_duration, int wave_form_send_duration,
|
||||
int max_sensor_num, std::string &error_msg);
|
||||
int max_sensor_num, int wave_resend_num, std::string &error_msg);
|
||||
|
||||
int CalcAvailableSlice(int eigen_value_send_interval, int wave_form_send_interval,
|
||||
int eigen_value_send_duration, int wave_form_send_duration,
|
||||
int max_sensor_num, int &available_slice, int &free_slice,
|
||||
std::string &error_msg);
|
||||
|
||||
int GetScheduleConfig(int &eigen_value_send_interval, int &wave_form_send_interval,
|
||||
int &eigen_value_send_duration, int &wave_form_send_duration,
|
||||
int GetScheduleConfig(int &eigen_value_send_interval, int &wave_form_send_interval, int &wave_resend_num,
|
||||
int &max_sensor_num);
|
||||
// ======schedule.json操作开始======
|
||||
// 无线网关程序重启时
|
||||
@ -92,20 +94,47 @@ public:
|
||||
void ModifyScheduleTs(int diff_ts);
|
||||
|
||||
// 当接入传感器时,设置为不可修改; 当停用所有传感器后,修改为可修改
|
||||
void AdjustSupportModification(bool support_modification);
|
||||
// void AdjustSupportModification(bool support_modification);
|
||||
// ======schedule.json操作结束======
|
||||
|
||||
void ClearScheduleCfg(int short_addr = 0);
|
||||
void ClearScheduleCfg(uint16_t short_addr = 0);
|
||||
|
||||
long GetLocalTs();
|
||||
long GetLocalWorldTime(std::string &world_time);
|
||||
std::string GetUTCTime(long ts);
|
||||
int GetAvailableId(int short_addr);
|
||||
int GetAvailableId(uint16_t short_addr);
|
||||
|
||||
// 调试模式相关接口
|
||||
// 此接口可多次调用,但是总是以最后一次调用为准
|
||||
int OpenDebugMode(std::vector<uint16_t> short_addr_list);
|
||||
int CloseDebugMode();
|
||||
|
||||
// 升级模式相关接口
|
||||
/**
|
||||
* @brief 当有传感器需要升级时调用, 此接口也会打开升级模式,可重复调用
|
||||
* sensor_type: DN101, DN102
|
||||
* hw_version: 3, 4
|
||||
* current_sw_version: 1.1
|
||||
* upgrade_sw_version: 1.2
|
||||
*/
|
||||
int UpgradeSensor(std::vector<UpgradeParameter> ¶m_list);
|
||||
int CancelUpgradeSensor(std::vector<uint16_t> short_addr_list);
|
||||
int CloseUpgradeMode();
|
||||
/**
|
||||
* @brief 升级后,无线传感器发回来的返回值
|
||||
*
|
||||
* @param short_addr
|
||||
* @param result 参考:FirmFileCheckResult
|
||||
* 返回值表明操作是否成功,0成功,其它失败
|
||||
*/
|
||||
int UpgradeResult(uint16_t short_addr, int result);
|
||||
|
||||
private:
|
||||
void UpdateUpgradeInfo(int id);
|
||||
void CleanIdleOccupiedSet(long ts);
|
||||
void UseDefaultConfig();
|
||||
int GetDebugUpgradeNextDuration(uint16_t short_addr);
|
||||
long GetDebugUpgradeNextTS(uint16_t short_addr);
|
||||
|
||||
// user config
|
||||
int eigen_value_send_interval_;
|
||||
@ -113,6 +142,7 @@ private:
|
||||
int wave_form_send_interval_;
|
||||
int wave_form_send_duration_;
|
||||
int max_sensor_num_;
|
||||
int wave_resend_num_;
|
||||
|
||||
// calc result
|
||||
long start_timestamp_;
|
||||
@ -122,19 +152,23 @@ private:
|
||||
int wave_slice_num_per_eigen_interval_; // 每个特征值窗口中有几个波形发送窗口
|
||||
int seconds_per_wave_slice_; // 波形窗口时长
|
||||
int eigen_value_slice_total_seconds_; // 特征值窗口总时长
|
||||
std::vector<int> slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
||||
|
||||
bool support_modification_;
|
||||
std::map<int, int> sensor_id_nth_slice_; // 传感器编号与第几个波形发送窗口对应关系
|
||||
int *slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
||||
uint8_t *slice_is_z_wave_; // 表明此窗口是z轴波形还是xy的
|
||||
std::unordered_map<int, std::pair<int,int>> sensor_id_nth_slice_; // 传感器编号与z,xy波形发送窗口对应关系
|
||||
std::map<uint16_t, int> short_addr_map_; // base_relation.json
|
||||
|
||||
// 存储当前2小时内失败与成功的传感器
|
||||
std::map<uint16_t, int> failure_map_;
|
||||
std::unordered_set<uint16_t> success_set_;
|
||||
std::unordered_set<uint16_t> patch_set_; // 漏传的补传
|
||||
std::map<uint16_t, int> z_failure_map_;
|
||||
std::map<uint16_t, int> xy_failure_map_;
|
||||
std::unordered_set<uint16_t> z_success_set_;
|
||||
std::unordered_set<uint16_t> xy_success_set_;
|
||||
std::unordered_set<uint16_t> z_patch_set_; // 漏传的补传
|
||||
std::unordered_set<uint16_t> xy_patch_set_; // 漏传的补传
|
||||
void ClearFailureSuccessMap();
|
||||
bool RetransferWave(uint16_t short_addr);
|
||||
bool MissedWave(uint16_t short_addr);
|
||||
bool ZRetransferWave(uint16_t short_addr);
|
||||
bool ZMissedWave(uint16_t short_addr);
|
||||
bool XYRetransferWave(uint16_t short_addr);
|
||||
bool XYMissedWave(uint16_t short_addr);
|
||||
|
||||
// 空闲时间戳被占用
|
||||
std::unordered_set<long> free_slice_ocuppied_;
|
||||
@ -157,6 +191,25 @@ private:
|
||||
int nth_wave_slice_; // 如果ts_in_eigen_slice_是假的话,此值表明是第几个波形窗口
|
||||
|
||||
int current_request_;
|
||||
ScheduleStatus current_schedule_status_;
|
||||
|
||||
|
||||
// debug mode
|
||||
std::map<int, int> debug_sensor_id_nth_slice_; // 调度模式下传感器编号与z波形发送窗口对应关系
|
||||
uint16_t *debug_slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
||||
// std::vector<int> debug_short_addr_list_;
|
||||
std::unordered_set<uint16_t> debug_list_;
|
||||
void GenerateDebugSchedule(std::vector<uint16_t> short_addr_list);
|
||||
|
||||
// upgrade mode
|
||||
std::map<int, int> upgrade_sensor_id_nth_slice_; // 升级模式下传感器编号与升级发送窗口对应关系
|
||||
std::unordered_set<uint16_t> upgrade_list_;
|
||||
uint16_t *upgrade_slice_sensor_id_; // 每个时间窗是哪个传感器使用的
|
||||
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;
|
||||
|
||||
@ -99,6 +99,18 @@ void CheckThread() {
|
||||
JsonData jd;
|
||||
jd.JsonCmd_07();
|
||||
HardStatus = 0;
|
||||
sqlite_db_ctrl::instance().SaveSystemHardStatus();
|
||||
int hour = 0;
|
||||
struct tm *tm_info = get_current_date();
|
||||
hour = tm_info->tm_hour;
|
||||
int statistics = readIntValue( "config", "statistics",(char*)GlobalConfig::Config_G.c_str());
|
||||
if(statistics == 0 && hour > 13 ){
|
||||
writeIntValue("config", "statistics",1,(char*)GlobalConfig::Config_G.c_str());
|
||||
}else if(statistics == 1 && hour < 13){
|
||||
writeIntValue("config", "statistics",0,(char*)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
sqlite_db_ctrl::instance().ShutdownCheck();
|
||||
}
|
||||
}
|
||||
if (mqttresend == 7200) {
|
||||
mqttresend = 0;
|
||||
@ -147,9 +159,15 @@ void CheckThread() {
|
||||
if (3500 == loose_check) {
|
||||
zlog_info(zct, "loosecheck\n");
|
||||
loose_check = 0;
|
||||
int looseEnable = readIntValue("config", "looseEnable", (char *)GlobalConfig::Config_G.c_str());
|
||||
if (looseEnable == 1)
|
||||
{
|
||||
zlog_warn(zct, "loosecheck\n");
|
||||
sqlite_db_ctrl::instance().CalculateDip();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (18000 == commSignal) { // 5h
|
||||
Json::Value jsBody, jsonVal;
|
||||
Json::FastWriter showValue;
|
||||
|
||||
305
uart/uart.cpp
305
uart/uart.cpp
@ -29,6 +29,9 @@ pTestRecvCallBack pTestRecv;
|
||||
extern std::vector<RecvData> g_VecWaveDataX;
|
||||
extern std::vector<RecvData> g_VecWaveDataY;
|
||||
extern std::vector<RecvData> g_VecWaveDataZ;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolX;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolY;
|
||||
extern std::vector<RecvData> g_VecWaveDataVolZ;
|
||||
|
||||
int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
char buff[BUF_LENGTH];
|
||||
@ -119,9 +122,16 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
||||
VecWaveDataX.reserve(1000);
|
||||
VecWaveDataY.reserve(1000);
|
||||
VecWaveDataZ.reserve(1500);
|
||||
m_waveCountLowFreX = 0;
|
||||
m_waveCountLowFreY = 0;
|
||||
m_waveCountLowFreZ = 0;
|
||||
VecWaveDataLowFreX.reserve(1000);
|
||||
VecWaveDataLowFreY.reserve(1000);
|
||||
VecWaveDataLowFreZ.reserve(1500);
|
||||
memset(send_data, 0, sizeof(send_data));
|
||||
last_short_addr = 0;
|
||||
last_time = 0;
|
||||
current_z = false;
|
||||
}
|
||||
|
||||
Uart::~Uart() {
|
||||
@ -341,8 +351,10 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
int next_duration = 0,next_task_id = 0;
|
||||
int taskID;
|
||||
ScheduleTask scheduleTask;
|
||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
|
||||
zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
|
||||
bool z = false;
|
||||
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,current_z = %d", taskID, next_duration, next_task_id,current_z);
|
||||
if (taskID == kScheduleConfigSensor)
|
||||
{
|
||||
scheduleTask.cmd = CONFIG;
|
||||
@ -357,6 +369,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
scheduleTask.cmd = REVIVE_DURATION;
|
||||
scheduleTask.shortAddr = ushortAdd;
|
||||
scheduleTask.duration = next_duration;
|
||||
scheduleTask.z = z;
|
||||
scheduleTask.next_taskID = WAVE_CMD;
|
||||
TaskResp(scheduleTask);
|
||||
}else if (next_task_id == kScheduleEigenValue) {
|
||||
@ -436,8 +449,9 @@ int Uart::DealException(const char* pData){
|
||||
int Uart::DealReviveDuration(uint16_t ushortAdd){
|
||||
ScheduleTask scheduleTask;
|
||||
int next_taskID = 0;
|
||||
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,next_taskID);
|
||||
zlog_info(zct, "next_duration = %d next_taskID = %d", next_duration,next_taskID);
|
||||
bool z = false;
|
||||
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,z,next_taskID);
|
||||
zlog_info(zct, "next_duration = %d next_taskID = %d,z = %d", next_duration,next_taskID,z);
|
||||
scheduleTask.cmd = REVIVE_DURATION;
|
||||
scheduleTask.shortAddr = ushortAdd;
|
||||
scheduleTask.duration = next_duration;
|
||||
@ -456,15 +470,57 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
||||
scheduler::instance().UpdateConfigResult(ushortAdd,0);
|
||||
return 0;
|
||||
}
|
||||
// 判断综合信号强度,低电量,停机状态,任一条件满足都不调度波形
|
||||
int Uart::WaveSendCondition(char* shortAddr){
|
||||
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1;
|
||||
char whereCon[100] = {0};
|
||||
std::string effect = "",rssi = "",batteryPower = "";
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAddr);
|
||||
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
vec_t sensorInfo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME),"RSSI,batteryPower",whereCon);
|
||||
rssi = sensorInfo[0];
|
||||
batteryPower = sensorInfo[1];
|
||||
std::vector<std::string> vParamBatteryPower;
|
||||
float fBatteryPower = 100.0;
|
||||
boost::split(vParamBatteryPower, batteryPower, boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamBatteryPower.size() > 0) {
|
||||
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
|
||||
}
|
||||
memset(whereCon, 0, sizeof(whereCon));
|
||||
sprintf(whereCon,"shortAddr = '%s' ",shortAddr);
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon);
|
||||
effect = vecResult[5];
|
||||
if((lowSignal == 1 && atof(rssi.c_str()) < signalThreshold) || (lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold) || effect == "1"){
|
||||
zlog_warn(zct, "WaveSendCondition not meet condition shortAddr = %s,rssi = %s,batteryPower = %s,effect = %s",shortAddr,rssi.c_str(),batteryPower.c_str(),effect.c_str());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
|
||||
zlog_info(zct, "DealWaveCompress ");
|
||||
wave_shortAddr = ushortAdd;
|
||||
char shortAdd[20] = {0x00},whereCon[100] = {0};
|
||||
char sensor_rssi[10] = {0x00};
|
||||
sprintf(shortAdd, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
|
||||
now_task = WAVE_CMD;
|
||||
WaveResp(ushortAdd);
|
||||
char buf[20] = {0x00};
|
||||
sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
|
||||
std::string strShortAddr = std::string(buf);
|
||||
std::string strShortAddr = std::string(shortAdd);
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",shortAdd);
|
||||
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;
|
||||
if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01"){ // DN101所有版本和DN102 2.6以前版本
|
||||
ScheduleStatus schedule_status = scheduler::instance().GetScheduleStatus();
|
||||
if(schedule_status == kScheduleStatusDebug || schedule_status == kScheduleStatusUpgrade){
|
||||
zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status);
|
||||
scheduler::instance().WaveSuccess(ushortAdd,true);
|
||||
return 1;
|
||||
}
|
||||
WaveResp(ushortAdd);// 响应超时和传感器配值的重试次数有关,重试10次是1s
|
||||
tempchannel.compressChannelX = pData[7];
|
||||
tempchannel.compressChannelY = pData[8];
|
||||
tempchannel.compressChannelZ = pData[9];
|
||||
@ -472,11 +528,48 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
tempchannel.CountX = BUILD_UINT32(pData[13], pData[12],pData[11],pData[10]);
|
||||
tempchannel.CountY = BUILD_UINT32(pData[17], pData[16],pData[15],pData[14]);
|
||||
tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]);
|
||||
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
|
||||
}else{
|
||||
int ret = 0;//= WaveSendCondition(shortAdd);
|
||||
if(ret == 1){
|
||||
zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd);
|
||||
scheduler::instance().WaveSuccess(ushortAdd,true);
|
||||
return 1;
|
||||
}else{
|
||||
ScheduleStatus schedule_status = scheduler::instance().GetScheduleStatus();
|
||||
if(schedule_status == kScheduleStatusUpgrade){
|
||||
zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status);
|
||||
scheduler::instance().WaveSuccess(ushortAdd,true);
|
||||
return 1;
|
||||
}
|
||||
WaveResp(ushortAdd);
|
||||
}
|
||||
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
|
||||
tempchannel.compressChannelX = pData[8];
|
||||
tempchannel.compressChannelY = pData[9];
|
||||
tempchannel.compressChannelZ = pData[10];
|
||||
tempchannel.compressChannelVolX = pData[23];
|
||||
tempchannel.compressChannelVolY = pData[24];
|
||||
tempchannel.compressChannelVolZ = pData[25];
|
||||
|
||||
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
||||
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
||||
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
||||
tempchannel.CountVolX = BUILD_UINT32(pData[29], pData[28],pData[27],pData[26]);
|
||||
tempchannel.CountVolY = BUILD_UINT32(pData[33], pData[32],pData[31],pData[30]);
|
||||
tempchannel.CountVolZ = BUILD_UINT32(pData[37], pData[36],pData[35],pData[34]);
|
||||
|
||||
tempchannel.samplerateX = BUILD_UINT32(pData[41], pData[40],pData[39],pData[38]);
|
||||
tempchannel.samplerateY = BUILD_UINT32(pData[45], pData[44],pData[43],pData[42]);
|
||||
tempchannel.samplerateZ = BUILD_UINT32(pData[49], pData[48],pData[47],pData[46]);
|
||||
tempchannel.samplerateVolX = BUILD_UINT32(pData[53], pData[52],pData[51],pData[50]);
|
||||
tempchannel.samplerateVolY = BUILD_UINT32(pData[57], pData[56],pData[55],pData[54]);
|
||||
tempchannel.samplerateVolZ = BUILD_UINT32(pData[61], pData[60],pData[59],pData[58]);
|
||||
}
|
||||
|
||||
g_mapCompress[strShortAddr] = tempchannel;
|
||||
wave_shortAddr = ushortAdd;
|
||||
char sensor_rssi[10] = {0x00};
|
||||
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
|
||||
|
||||
|
||||
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
|
||||
char errorInfo[100] = {0x00};
|
||||
sprintf(errorInfo, "No RSSI %s", sensor_rssi);
|
||||
@ -496,18 +589,12 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
if (vParamRSSI.size() > 0) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), pData[22] & 0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
||||
zlog_warn(zct, "count X = %d,Y = %d,Z = %d,vol X = %d,vol Y = %d,vol Z = %d short_add = %s", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ,tempchannel.CountVolX,tempchannel.CountVolY,tempchannel.CountVolZ,strShortAddr.c_str());
|
||||
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, "samplerate X = %d,Y = %d,Z = %d ", tempchannel.samplerateX, tempchannel.samplerateY, tempchannel.samplerateZ);
|
||||
zlog_info(zct, "samplerate vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.samplerateVolX, tempchannel.samplerateVolY, tempchannel.samplerateVolZ);
|
||||
return 0;
|
||||
}
|
||||
int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){
|
||||
@ -544,16 +631,6 @@ int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
if (vParamRSSI.size() > 0) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), pData[7] & 0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -592,7 +669,14 @@ int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
DealAskTask(ushortAdd);
|
||||
// char logInfo[100] = {0x00};
|
||||
// std::vector<uint8_t>& data_vec = map_send_data[ushortAdd];
|
||||
// const uint8_t* send_data = data_vec.data();
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
// mssleep(50000);
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
// mssleep(50000);
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
}else {
|
||||
DealAskTask(ushortAdd);
|
||||
DealDataNodeFeature(pData, 0);
|
||||
@ -602,6 +686,7 @@ int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
|
||||
last_time = atol(nowTimetamp.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Uart::DealRecvData(const char *pData) {
|
||||
|
||||
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
|
||||
@ -610,6 +695,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
int next_duration = 0,next_task_id = 0;
|
||||
int taskID = 0;
|
||||
ScheduleTask scheduleTask;
|
||||
bool z = false;
|
||||
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
|
||||
if (command == WAVE_COMPRESS || command == UPGRADE_ASK)
|
||||
{
|
||||
@ -678,7 +764,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
break;
|
||||
case UPGRADE_ASK:
|
||||
mssleep(50000);
|
||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
|
||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
|
||||
taskID = kScheduleUpgrade;
|
||||
if (taskID == kScheduleUpgrade){
|
||||
UpdateWirelessNode(ushortAdd);
|
||||
@ -695,7 +781,36 @@ void Uart::DealRecvData(const char *pData) {
|
||||
}
|
||||
last_short_addr = ushortAdd;
|
||||
}
|
||||
|
||||
void Uart::DelRepeatData(char *pShortAdd,const char* dataNodeNo,const char* measurementID){
|
||||
char whereCon[64] = {0};
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), dataNodeNo);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), measurementID);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID = '%s'", measurementID);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_debug_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_shutdown_info ", whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_wave_triger_info ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like'%s'", measurementID);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_data_waveSend ", whereCon);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", measurementID);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", measurementID);
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(pShortAdd, &end_ptr, 16);
|
||||
scheduler::instance().ClearScheduleCfg(short_addr);
|
||||
}
|
||||
void Uart::DealDataNodeName(const char *pData) {
|
||||
zlog_info(zct, "DealDataNodeName ");
|
||||
std::string strTime = GetLocalTimeWithMs();
|
||||
@ -705,14 +820,14 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
sprintf(szShortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF);
|
||||
memcpy(NodeName, &pData[7], 64);
|
||||
memcpy(shortAdd, &pData[3], 2);
|
||||
char whereCon[64] = {0};
|
||||
char uplCon[200] = {0x00};
|
||||
char whereCon[512] = {0};
|
||||
char uplCon[512] = {0x00};
|
||||
char nodeWaveSend[10] = {0x00};
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
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]);
|
||||
|
||||
|
||||
@ -723,30 +838,8 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
||||
if (vecRes.size() > 1) {
|
||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
||||
if (vecRes[i][1] != "") {
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), vecRes[i][0].c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_INFO(TNAME), whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), vecRes[i][1].c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATA_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_DATASTATIC_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like'%s'", vecRes[i][1].c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_data_waveSend ", whereCon);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", vecRes[i][1].c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", vecRes[i][1].c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(szShortAdd, &end_ptr, 16);
|
||||
scheduler::instance().ClearScheduleCfg(short_addr);
|
||||
|
||||
if (vecRes[i][1] != "") {//删除短地址重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
||||
DelRepeatData(szShortAdd,vecRes[i][0].c_str(),vecRes[i][1].c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -758,6 +851,17 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
memcpy(MeasurementID, vecRes[0][0].c_str(), sizeof(MeasurementID));
|
||||
}
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID='%s'", MeasurementID);
|
||||
array_t vecRes2 = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
|
||||
zlog_info(zct, "vecRes2 = %zu", vecRes2.size());
|
||||
if (vecRes2.size() > 1) {
|
||||
for (size_t i = 0; i < vecRes2.size(); i++) {
|
||||
if (vecRes2[i][1] != "") {//删除通道ID重复的传感器,新增的传感器,通道编码此时为空,将不会删除。
|
||||
DelRepeatData(szShortAdd,vecRes2[i][0].c_str(),vecRes2[i][1].c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
|
||||
std::string strNodeName(NodeName);
|
||||
zlog_info(zct, "strNodeName = %s", strNodeName.c_str());
|
||||
@ -771,7 +875,7 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
std::string strData = sqlite_db_ctrl::instance().GetNodeConfigureInfor(whereCon);
|
||||
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);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon,"type='table' and name = '%s'",szTableName);
|
||||
@ -789,6 +893,19 @@ void Uart::DealDataNodeName(const char *pData) {
|
||||
if (ret == 0){
|
||||
sqlite_db_ctrl::instance().CreatedataStatictable(szTableName);
|
||||
}
|
||||
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, " '%s','%s','','','','','','0',''",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_debug_info", insertSql);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '%s','%s','0','0','0','0'",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_shutdown_info", insertSql);
|
||||
memset(insertSql,0,sizeof(insertSql));
|
||||
sprintf(insertSql, " '%s','%s','0','0','0','0','0'",
|
||||
MeasurementID, szShortAdd);
|
||||
sqlite_db_ctrl::instance().InsertData("t_wave_triger_info", insertSql);
|
||||
}
|
||||
|
||||
void Uart::DealDataNodeInfo(const char *pData) {
|
||||
@ -1205,16 +1322,20 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
g_VecWaveDataZ.clear();
|
||||
break;
|
||||
}
|
||||
if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) && now_task == WAVE_CMD) {
|
||||
if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && \
|
||||
(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) {
|
||||
mPackgeIndex = UartRecvBuf[i + 6] & 0xFF;
|
||||
} else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) && now_task == WAVE_CMD) {
|
||||
} 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_LF_X || command == WAVE_LF_Y|| command == WAVE_LF_Z) && \
|
||||
now_task == WAVE_CMD) {
|
||||
zlog_warn(zct, "mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str());
|
||||
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) && 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_warn(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str());
|
||||
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_error(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str());
|
||||
|
||||
char tmp[10] = {0x00};
|
||||
char tmp2[10] = {0x00};
|
||||
@ -1222,7 +1343,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||
strcat(tmp2, tmp);
|
||||
}
|
||||
zlog_warn(zct, "error str = %s", tmp2);
|
||||
zlog_error(zct, "error str = %s", tmp2);
|
||||
char insertSql[100] = {0x00};
|
||||
char whereCon[50] = {0x00};
|
||||
std::string error_msg = "";
|
||||
@ -1254,9 +1375,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now_task == WAVE_CMD && (command == WAVE_X || command == WAVE_Y || command == WAVE_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)) {
|
||||
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 tmp2[10] = {0x00};
|
||||
for (int j = 0; j < 100; j++) {
|
||||
@ -1311,7 +1432,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 8);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1319,7 +1440,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 9);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1327,18 +1448,34 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||
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 tmp2[10] = {0x00};
|
||||
for (int j = 0; j < 100; j++) {
|
||||
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
|
||||
strcat(tmp2, tmp);
|
||||
}
|
||||
zlog_error(zct, " crc error str = %s", tmp2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DealRecvData(RecvBuf);
|
||||
|
||||
}else if( command == WAVE_COMPRESS && now_task != WAVE_CMD) {
|
||||
if (bytesRead > 30)
|
||||
{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||
if (!CheckCrc(RecvBuf, 99)) {
|
||||
zlog_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
||||
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;
|
||||
}
|
||||
}
|
||||
// char tmp[23] = {0x00};
|
||||
// char tmp2[23] = {0x00};
|
||||
// for (int j = 0; j < 23; j++) {
|
||||
@ -1365,14 +1502,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char *)vecDataNodeNo[0].c_str(), strTimetamp.c_str());
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParamRSSI.size() > 0) {
|
||||
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), UartRecvBuf[i + 14] & 0xFF);
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1445,18 +1574,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
} else {
|
||||
jsBody["looseStatus"] = "0";
|
||||
}
|
||||
std::vector<std::string> vParamRSSI;
|
||||
boost::split(vParamRSSI, vecDataNodeNo[2], boost::is_any_of(","), boost::token_compress_on);
|
||||
memset(updateSql,0,sizeof(updateSql));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
if (vParamRSSI.size() == 1) {
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[0].c_str());
|
||||
|
||||
} else if (vParamRSSI.size() == 2) {
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ", UartRecvBuf[i + 6] & 0xFF, vParamRSSI[1].c_str());
|
||||
}
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
|
||||
jsonVal["cmd"] = "52";
|
||||
jsBody["timeStamp"] = strTimetamp;
|
||||
|
||||
@ -31,7 +31,10 @@ enum InteractiveCommand {
|
||||
WAVE_COMPRESS = 15, // 波形数据压缩
|
||||
UPGRADE_FIRMWARE = 16, //固件升级内容
|
||||
UPGRADE_ASK = 17, //固件升级请求
|
||||
WAVE_RESP = 18 // 波形数据回复
|
||||
WAVE_RESP = 18, // 波形数据回复
|
||||
WAVE_LF_X = 19,
|
||||
WAVE_LF_Y = 20,
|
||||
WAVE_LF_Z = 21
|
||||
};
|
||||
|
||||
// 无线传感器请求任务
|
||||
@ -123,6 +126,7 @@ typedef struct ScheduleTask_{
|
||||
uint16_t millisecond;
|
||||
uint8_t next_taskID;
|
||||
uint8_t acc_z;
|
||||
bool z; // true: z波形 false: xy波形
|
||||
ScheduleTask_(){
|
||||
cmd = 0;
|
||||
shortAddr = 0;
|
||||
@ -131,6 +135,7 @@ typedef struct ScheduleTask_{
|
||||
millisecond = 0;
|
||||
next_taskID = 0;
|
||||
acc_z = 0;
|
||||
z = false;
|
||||
}
|
||||
} ScheduleTask;
|
||||
|
||||
@ -167,6 +172,7 @@ public:
|
||||
|
||||
void UpdateZigbeeInfo(const char* pData);
|
||||
void DealRecvData(const char* pData);
|
||||
void DelRepeatData(char *pShortAdd,const char* dataNodeNo,const char* measurementID);
|
||||
void DealDataNodeInfo(const char* pData);
|
||||
void DealDataNodeName(const char* pData);
|
||||
void ZigbeeParameterConfig();
|
||||
@ -184,16 +190,18 @@ public:
|
||||
int DealSensorRSSI(const char *pData,uint16_t ushortAdd);
|
||||
int DealUpgrade(uint16_t ushortAdd,int status);
|
||||
void GetLocalZigbeeRSSI(uint16_t ushortAdd);
|
||||
int WaveSendCondition(char* shortAddr);
|
||||
|
||||
// feature parse
|
||||
int DealDataNodeFeature(const char* pData, int flag);
|
||||
void DealTriger(uint16_t ushortAdd,std::string & measurementID);
|
||||
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
||||
void DealDataNodeWave(const char* pData, int comand);
|
||||
void DealWaveThread();
|
||||
void DealWave();
|
||||
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
|
||||
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, float ACCSampleTime, std::string strProduct,int version);
|
||||
float Calcoe(int ran, int iChannel, std::string& product, int range);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product,int ACCSampleTime);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product,float ACCSampleTime,int version);
|
||||
float ScaleConvert(int highbit);
|
||||
void DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n);
|
||||
|
||||
@ -247,6 +255,7 @@ private:
|
||||
std::string m_strDestShortAddr;
|
||||
uint16_t wave_shortAddr;
|
||||
int now_task;
|
||||
struct timespec wave_recv_start,wave_recv_end;
|
||||
|
||||
int waittime;
|
||||
enum { BUF_LENGTH = 40960 };
|
||||
@ -261,13 +270,20 @@ private:
|
||||
int m_waveCountX;
|
||||
int m_waveCountY;
|
||||
int m_waveCountZ;
|
||||
int m_waveCountLowFreX;
|
||||
int m_waveCountLowFreY;
|
||||
int m_waveCountLowFreZ;
|
||||
std::vector<RecvData> VecWaveDataX;
|
||||
std::vector<RecvData> VecWaveDataY;
|
||||
std::vector<RecvData> VecWaveDataZ;
|
||||
std::vector<RecvData> VecWaveDataLowFreX;
|
||||
std::vector<RecvData> VecWaveDataLowFreY;
|
||||
std::vector<RecvData> VecWaveDataLowFreZ;
|
||||
|
||||
uint8_t send_data[100];
|
||||
uint16_t last_short_addr;
|
||||
long last_time;
|
||||
bool current_z;
|
||||
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
||||
};
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "mqttclient/mqtt_client.h"
|
||||
#include "minilzo/minilzo.h"
|
||||
#include "jsonparse/communication_cmd.hpp"
|
||||
#include "utility/calculation.hpp"
|
||||
#include "scheduler/schedule.hpp"
|
||||
|
||||
extern zlog_category_t *zct;
|
||||
@ -19,6 +20,9 @@ extern zlog_category_t *zbt;
|
||||
std::vector<RecvData> g_VecWaveDataX;
|
||||
std::vector<RecvData> g_VecWaveDataY;
|
||||
std::vector<RecvData> g_VecWaveDataZ;
|
||||
std::vector<RecvData> g_VecWaveDataVolX;
|
||||
std::vector<RecvData> g_VecWaveDataVolY;
|
||||
std::vector<RecvData> g_VecWaveDataVolZ;
|
||||
std::map<std::string, compressWaveChannel> g_mapCompress;
|
||||
std::map<std::string, WaveChannel> g_mapWaveChannel;
|
||||
|
||||
@ -31,8 +35,103 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%d','%f','%f','%f','%d','','','%s'", strLongAddr.c_str(), dataStatic.Dip, dataStatic.TemBot, dataStatic.nodeWorkTime, dataStatic.nodeSendTime, dataStatic.Voltage, nowTimetamp.c_str());
|
||||
sqlite_db_ctrl::instance().InsertData(T_BATTERY_INFO(TNAME), insertSql);
|
||||
}
|
||||
|
||||
//计算综合信号强度
|
||||
char tableName[64] = {0};
|
||||
char whereCon[128] = {0};
|
||||
sprintf(tableName,"t_dataStatic_%s",(char*)strLongAddr.c_str());
|
||||
sprintf(whereCon, "dataNodeNo='%s' and zigbeeSignal <> '' and zigbeeSignalNode <> '' and comprehensiveRSSI = '' order by timeStamp desc limit 1", strLongAddr.c_str());
|
||||
vec_t res_static = sqlite_db_ctrl::instance().GetDataSingleLine(tableName, " * ", whereCon);
|
||||
if(res_static.size() < 1){
|
||||
zlog_info(zct, "No static data found for dataNodeNo='%s' to calculate comprehensiveRSSI", strLongAddr.c_str());
|
||||
return;
|
||||
}
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"data_nodeno like '%%%s%%' and timeStamp = '%s'", strLongAddr.c_str(), res_static[8].c_str());
|
||||
vec_t package_length = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(" receive_wave_status ", " package_length ", whereCon);
|
||||
int wave_dataLen = 0;
|
||||
if (package_length.size() < 1)
|
||||
{
|
||||
zlog_info(zct, "No wave package_length found for dataNodeNo='%s' and timeStamp = '%s'", strLongAddr.c_str(), res_static[8].c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < package_length.size(); i++){
|
||||
wave_dataLen += atoi(package_length[i].c_str());
|
||||
}
|
||||
//信号质量计算:[传感器信号强度+网关信号强度]x[实际速率/标准速率(5kB/s)]
|
||||
if (res_static.size() > 0){
|
||||
int zigbeeSignal = atoi(res_static[6].c_str());
|
||||
int zigbeeSignalNode = atoi(res_static[11].c_str());
|
||||
float standardRate = 5000.0f; //5kB/s
|
||||
float actualRate = 0.0f;
|
||||
if (dataStatic.nodeSendTime > 0){
|
||||
actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位:KB/s
|
||||
}
|
||||
float comprehensiveRSSI = (zigbeeSignal + zigbeeSignalNode) * (actualRate / standardRate);
|
||||
if (comprehensiveRSSI > 1.0f) {
|
||||
comprehensiveRSSI = 1.0f; //综合信号强度最大为1
|
||||
}
|
||||
|
||||
zlog_info(zct, "dataNodeNo='%s',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f", strLongAddr.c_str(), wave_dataLen, dataStatic.nodeSendTime, actualRate);
|
||||
//更新综合信号强度到数据库
|
||||
char updateSql[256] = {0};
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", strLongAddr.c_str(), res_static[8].c_str());
|
||||
sprintf(updateSql, "comprehensiveRSSI = '%f'", comprehensiveRSSI);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(updateSql,0x00,sizeof(updateSql));
|
||||
sprintf(whereCon,"MeasurementID = '%s'", strLongAddr.c_str());
|
||||
sprintf(updateSql,"RSSI = '%f'", comprehensiveRSSI);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI);
|
||||
}
|
||||
}
|
||||
void Uart::DealTriger(uint16_t ushortAdd,std::string & measurementID){
|
||||
vec_t vecTrigger;
|
||||
char whereCon[256] = {0},tablename[128] = {0};
|
||||
sprintf(whereCon, "MeasurementID='%s' and status ='1' ", measurementID.c_str());
|
||||
sprintf(tablename,"t_data_%s",measurementID.c_str());
|
||||
vecTrigger = sqlite_db_ctrl::instance().GetDataSingleLine(" t_wave_triger_info ", " * ", whereCon);
|
||||
if (vecTrigger.size() > 0){// 加速度有效值
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,3;",measurementID.c_str());
|
||||
if(vecTrigger[3] == "0"){
|
||||
array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,rmsValues ", whereCon);
|
||||
if(arrValue.size()){
|
||||
for (size_t i = 0; i < arrValue.size(); i++)
|
||||
{
|
||||
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"){// 速度有效值
|
||||
array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,integratRMS ", whereCon);
|
||||
if(arrValue.size()){
|
||||
for (size_t i = 0; i < arrValue.size(); i++)
|
||||
{
|
||||
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) {
|
||||
char buf[20] = {0};
|
||||
sprintf(buf, "%02x%02x", p->Data[id+1], p->Data[id]);
|
||||
@ -75,6 +174,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
std::string strLongAddr = vecResult[1];
|
||||
std::string strMeasurementID = vecResult[2];
|
||||
std::string strProductNo = vecResult[3];
|
||||
std::string softVersion = vecResult[0];
|
||||
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
@ -86,10 +186,13 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
|
||||
return -2;
|
||||
}
|
||||
long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
||||
long nodetimestamp_ = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
||||
|
||||
char localtimestamp[32] = {0};
|
||||
sprintf(localtimestamp,"%ld",nodetimestamp);
|
||||
char nodetimestamp[32] = {0};
|
||||
sprintf(nodetimestamp,"%ld",nodetimestamp_);
|
||||
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
std::string nowTimetamp = std::string(localtimestamp);
|
||||
strTimetamp = nowTimetamp;
|
||||
|
||||
@ -136,37 +239,60 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
DataExtract(pRecvData, 32, lowbit, n);
|
||||
dataStatic.nodeSendTime = lowbit * n;
|
||||
dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime;
|
||||
|
||||
zlog_info(zct, "nodeWorkTime = %f,nodeSendTime = %f", dataStatic.nodeWorkTime, dataStatic.nodeSendTime);
|
||||
RecordBattery(strMeasurementID, dataStatic, nowTimetamp);
|
||||
|
||||
if (compareVersions(softVersion, "2.4"))
|
||||
{
|
||||
char chTemp = pRecvData->Data[80]; //设备状态标志 1 byte
|
||||
DataNodeInfo dataNodeInfo;
|
||||
dataNodeInfo.EquipSta = GET_BIT(chTemp, 2);
|
||||
dataNodeInfo.TemTopFlag = GET_BIT(chTemp, 3);
|
||||
dataNodeInfo.TemBotFlag = GET_BIT(chTemp, 4);
|
||||
dataNodeInfo.ZigbeeFlag = GET_BIT(chTemp, 5);
|
||||
dataNodeInfo.AccFlag = GET_BIT(chTemp, 6);
|
||||
dataNodeInfo.InitFlag = GET_BIT(chTemp, 7);
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(updateSql, " initFlag = '%d',accFlag = '%d',zigbeeFlag = '%d',temTopFlag = '%d',temBotFlag = '%d',equipSta = '%d'",
|
||||
dataNodeInfo.InitFlag, dataNodeInfo.AccFlag, dataNodeInfo.ZigbeeFlag, dataNodeInfo.TemTopFlag, dataNodeInfo.TemBotFlag, dataNodeInfo.EquipSta);
|
||||
sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, "%02x", pRecvData->Data[81]);
|
||||
iTemp = (int)strtol(buf, NULL, 8);
|
||||
dataStatic.minmumBatteryVoltageType = iTemp;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", pRecvData->Data[83], pRecvData->Data[82]);
|
||||
iTemp = (int)strtol(buf, NULL, 16);
|
||||
dataStatic.instantaneousBatteryVoltage = iTemp;
|
||||
|
||||
char szTableName[50] = {0x00}, szTableNameStatic[50] = {0x00}, szTableNameData[50] = {0x00};
|
||||
sprintf(szTableName, "t_dataStatic_%s", strMeasurementID.c_str());
|
||||
memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic));
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
|
||||
//时间戳判断,是否重包
|
||||
sprintf(whereCon, "timeStamp = '%s'", localtimestamp);
|
||||
int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
||||
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
||||
// sprintf(whereCon, "timeStamp = '%s'", localtimestamp);
|
||||
// int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
||||
// sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
||||
|
||||
int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
|
||||
if (count > 0 || count2 > 0) {
|
||||
char logInfo[100] = {0x00};
|
||||
sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2);
|
||||
zlog_info(zct, logInfo);
|
||||
std::vector<uint8_t>& data_vec = map_send_data[u_short_addr];
|
||||
|
||||
const uint8_t* send_data = data_vec.data();
|
||||
if (send_data == nullptr || data_vec.size() < 100) {
|
||||
zlog_error(zct, "send_data is null or size is less than 100");
|
||||
return -3;
|
||||
}
|
||||
WriteToUart((const char*)send_data, 100);
|
||||
mssleep(50000);
|
||||
WriteToUart((const char*)send_data, 100);
|
||||
mssleep(50000);
|
||||
WriteToUart((const char*)send_data, 100);
|
||||
}
|
||||
// int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
|
||||
// if (count > 0 || count2 > 0) {
|
||||
// char logInfo[100] = {0x00};
|
||||
// sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2);
|
||||
// zlog_info(zct, logInfo);
|
||||
// std::vector<uint8_t>& data_vec = map_send_data[u_short_addr];
|
||||
// const uint8_t* send_data = data_vec.data();
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
// mssleep(50000);
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
// mssleep(50000);
|
||||
// WriteToUart((const char*)send_data, 100);
|
||||
// }
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
||||
///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0
|
||||
@ -232,24 +358,24 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
|
||||
zlog_info(zct, "dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage);
|
||||
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '%d',timing = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend, flag, timing);
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '%d',timing = '%d',nodeTimestamp = '%s',minmumBatteryVoltageType = '%d',instantaneousBatteryVoltage = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend, flag, timing, nodetimestamp, dataStatic.minmumBatteryVoltageType, dataStatic.instantaneousBatteryVoltage);
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
zlog_info(zct, "insert static data to sql");
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d,'','%d','%d'", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend, flag,
|
||||
timing);
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d,'','%d','%d','%s','%d','%d',''", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend, flag,
|
||||
timing,nodetimestamp, dataStatic.minmumBatteryVoltageType, dataStatic.instantaneousBatteryVoltage);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect
|
||||
char insertSql[1024] = {0};
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
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().CalculateBattery();
|
||||
} else {
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld,nodeTimestamp = '%s' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex,nodetimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
} else {
|
||||
@ -260,7 +386,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
|
||||
memset(updateSql, 0x00, sizeof(updateSql));
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex);
|
||||
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld,nodeTimestamp = '%s' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(), staticIndex,nodetimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATASTATIC_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
@ -295,6 +421,9 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
DataExtract(pRecvData, 24, lowbit, n);
|
||||
dataDymX.Amp5 = lowbit * n;
|
||||
|
||||
DataExtract(pRecvData, 84, lowbit, n);
|
||||
dataDymX.kurtosis = lowbit * n;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
dataDymX.EnvelopEnergy = 0;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
@ -313,14 +442,14 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
|
||||
memset(updateSql, 0, 1024);
|
||||
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d ",
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d, nodeTimestamp = '%s',kurtosis = '%f'",
|
||||
dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend);
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend,nodetimestamp,dataDymX.kurtosis);
|
||||
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0 || nodeResend != 0) { // 1 week
|
||||
char insertSql[1024] = {0};
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
|
||||
dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d,'%s','%f',0", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues,
|
||||
dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend,nodetimestamp,dataDymX.kurtosis);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
@ -329,15 +458,15 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0", (strMeasurementID + "-X").c_str(), strTime.c_str());
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-X").c_str(), strTime.c_str(),nodetimestamp);
|
||||
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
zlog_info(zct, "x:%s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk,
|
||||
dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str());
|
||||
zlog_info(zct, "x:%s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s,nodeTimestamp=%s", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk,
|
||||
dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str(),nodetimestamp);
|
||||
|
||||
Json::Value valNodeData;
|
||||
Json::Value valNodeFeature;
|
||||
@ -357,7 +486,8 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
valNodeFeature["Phase2"] = dataDymX.Phase2;
|
||||
valNodeFeature["Phase3"] = dataDymX.Phase3;
|
||||
valNodeFeature["Phase4"] = dataDymX.Phase4;
|
||||
valNodeFeature["timeStamp"] = nowTimetamp;
|
||||
valNodeFeature["kurtosis"] = dataDymX.kurtosis;
|
||||
valNodeFeature["timeStamp"] = localtimestamp;
|
||||
if (Feature_x)
|
||||
{
|
||||
valNodeData.append(valNodeFeature);
|
||||
@ -391,6 +521,9 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
DataExtract(pRecvData, 50, lowbit, n);
|
||||
dataDymY.Amp5 = lowbit * n;
|
||||
|
||||
DataExtract(pRecvData, 86, lowbit, n);
|
||||
dataDymY.kurtosis = lowbit * n;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
dataDymY.EnvelopEnergy = 0;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
@ -406,14 +539,14 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
|
||||
memset(updateSql, 0, 1024);
|
||||
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d ",
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d, nodeTimestamp = '%s',kurtosis = '%f' ",
|
||||
dataDymY.DiagnosisPk, dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend);
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend,nodetimestamp,dataDymY.kurtosis);
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0 ) {
|
||||
char insertSql[1024] = {0};
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk, dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues,
|
||||
dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d,%s,%f,0", strMeasurementID.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk, dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues,
|
||||
dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend,nodetimestamp,dataDymY.kurtosis);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
@ -422,14 +555,14 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0", (strMeasurementID + "-Y").c_str(), strTime.c_str());
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-Y").c_str(), strTime.c_str(),nodetimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
zlog_info(zct, "y: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strMeasurementID.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk,
|
||||
dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, nowTimetamp.c_str());
|
||||
zlog_info(zct, "y: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s,,kurtosis = %f", strMeasurementID.c_str(), (strMeasurementID + "-Y").c_str(), dataDymY.DiagnosisPk,
|
||||
dataDymY.IntegratPk, dataDymY.IntegratRMS, dataDymY.RmsValues, dataDymY.EnvelopEnergy, dataDymY.Amp1, dataDymY.Amp2, dataDymY.Amp3, dataDymY.Amp4, dataDymY.Amp5, dataDymY.Phase1, dataDymY.Phase2, dataDymY.Phase3, dataDymY.Phase4, nowTimetamp.c_str(),dataDymY.kurtosis);
|
||||
|
||||
valNodeFeature["dataNodeNo"] = strMeasurementID;
|
||||
valNodeFeature["ChannelId"] = strMeasurementID + "-Y";
|
||||
@ -447,7 +580,8 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
valNodeFeature["Phase2"] = dataDymY.Phase2;
|
||||
valNodeFeature["Phase3"] = dataDymY.Phase3;
|
||||
valNodeFeature["Phase4"] = dataDymY.Phase4;
|
||||
valNodeFeature["timeStamp"] = nowTimetamp;
|
||||
valNodeFeature["kurtosis"] = dataDymY.kurtosis;
|
||||
valNodeFeature["timeStamp"] = localtimestamp;
|
||||
if (Feature_y)
|
||||
{
|
||||
valNodeData.append(valNodeFeature);
|
||||
@ -496,19 +630,26 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
DataExtract(pRecvData, 78, lowbit, n);
|
||||
dataDymZ.Phase4 = lowbit * n;
|
||||
|
||||
DataExtract(pRecvData, 88, lowbit, n);
|
||||
dataDymZ.kurtosis = lowbit * n;
|
||||
|
||||
DataExtract(pRecvData, 90, lowbit, n);
|
||||
dataDymZ.IntegratRMSMENS = lowbit * n;
|
||||
|
||||
|
||||
memset(whereCon, 0, 1024);
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
|
||||
memset(updateSql, 0, 1024);
|
||||
|
||||
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d ",
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %ld,nodeResend = %d, nodeTimestamp = '%s',kurtosis = '%f',integratRMSMENS = '%f' ",
|
||||
dataDymZ.DiagnosisPk, dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4,
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend);
|
||||
nowTimetamp.c_str(), staticIndex, nodeResend,nodetimestamp,dataDymZ.kurtosis,dataDymZ.IntegratRMSMENS);
|
||||
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0 ) {
|
||||
char insertSql[1024] = {0};
|
||||
memset(insertSql, 0x00, sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk, dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues,
|
||||
dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend);
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d,'%s','%f','%f'", strMeasurementID.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk, dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues,
|
||||
dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend,nodetimestamp,dataDymZ.kurtosis,dataDymZ.IntegratRMSMENS);
|
||||
sqlite_db_ctrl::instance().InsertData(szTableName, insertSql);
|
||||
|
||||
if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATA_INFO(TNAME), whereCon))
|
||||
@ -517,14 +658,14 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
} else {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0", (strMeasurementID + "-Z").c_str(), strTime.c_str());
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-Z").c_str(), strTime.c_str(),nodetimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
zlog_info(zct, "Z: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s", strMeasurementID.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk,
|
||||
dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, nowTimetamp.c_str());
|
||||
zlog_info(zct, "Z: %s,%s,diagnosisPk=%f,integratPk=%f,integratRMS=%f,rmsValues=%f,envelopEnergy=%f,Amp1=%f,Amp2=%f,Amp3=%f,Amp4=%f,Amp5=%f,Phase1=%f,Phase2=%f,Phase3=%f,Phase4=%f,timeStamp=%s,kurtosis = %f,integratRMSMENS = %f", strMeasurementID.c_str(), (strMeasurementID + "-Z").c_str(), dataDymZ.DiagnosisPk,
|
||||
dataDymZ.IntegratPk, dataDymZ.IntegratRMS, dataDymZ.RmsValues, dataDymZ.EnvelopEnergy, dataDymZ.Amp1, dataDymZ.Amp2, dataDymZ.Amp3, dataDymZ.Amp4, dataDymZ.Amp5, dataDymZ.Phase1, dataDymZ.Phase2, dataDymZ.Phase3, dataDymZ.Phase4, nowTimetamp.c_str(),dataDymZ.kurtosis,dataDymZ.IntegratRMSMENS);
|
||||
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID='%s'", strMeasurementID.c_str());
|
||||
@ -547,7 +688,8 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
valNodeFeature["Phase2"] = dataDymZ.Phase2;
|
||||
valNodeFeature["Phase3"] = dataDymZ.Phase3;
|
||||
valNodeFeature["Phase4"] = dataDymZ.Phase4;
|
||||
valNodeFeature["timeStamp"] = nowTimetamp;
|
||||
valNodeFeature["kurtosis"] = dataDymZ.kurtosis;
|
||||
valNodeFeature["timeStamp"] = localtimestamp;
|
||||
if (Feature_z)
|
||||
{
|
||||
valNodeData.append(valNodeFeature);
|
||||
@ -575,14 +717,18 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
valdatastatic["Voltage"] = dataStatic.Voltage;
|
||||
valdatastatic["ChannelType"] = "STATUS";
|
||||
valdatastatic["ChannelId"] = strMeasurementID + "-S";
|
||||
valdatastatic["TimeStamp"] = nowTimetamp;
|
||||
valdatastatic["TimeStamp"] = localtimestamp;
|
||||
if(vBattery[1] == "" || vBattery[0] == ""){
|
||||
valdatastatic["bateryProportion"] = 0.9;
|
||||
}else{
|
||||
valdatastatic["bateryProportion"] = atof(vBattery[1].c_str()) / atof(vBattery[0].c_str());
|
||||
}
|
||||
valdatastatic["batteryRemainDay"] = atof(vBattery[1].c_str());
|
||||
valdatastatic["dataNodeNo"] = strMeasurementID;
|
||||
valNodeData.append(valdatastatic);
|
||||
|
||||
root["data"] = valNodeData;
|
||||
root["TimeStamp"] = nowTimetamp;
|
||||
root["TimeStamp"] = localtimestamp;
|
||||
root["dataNodeNo"] = strMeasurementID;
|
||||
root["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
Json::FastWriter featureValue;
|
||||
@ -624,6 +770,12 @@ void Uart::DealDataNodeWave(const char *pData, int comand) {
|
||||
VecWaveDataY.push_back(*pRecvData);
|
||||
} else if (comand == WAVE_Z) {
|
||||
VecWaveDataZ.push_back(*pRecvData);
|
||||
}else if (comand == WAVE_LF_X) {
|
||||
VecWaveDataLowFreX.push_back(*pRecvData);
|
||||
}else if (comand == WAVE_LF_Y) {
|
||||
VecWaveDataLowFreY.push_back(*pRecvData);
|
||||
}else if (comand == WAVE_LF_Z) {
|
||||
VecWaveDataLowFreZ.push_back(*pRecvData);
|
||||
}
|
||||
} else {
|
||||
if (comand == WAVE_X) {
|
||||
@ -635,6 +787,15 @@ void Uart::DealDataNodeWave(const char *pData, int comand) {
|
||||
} else if (comand == WAVE_Z) {
|
||||
g_VecWaveDataZ[m_waveCountZ] = *pRecvData;
|
||||
m_waveCountZ++;
|
||||
}else if (comand == WAVE_LF_X) {
|
||||
g_VecWaveDataVolX[m_waveCountLowFreX] = *pRecvData;
|
||||
m_waveCountLowFreX++;
|
||||
}else if (comand == WAVE_LF_Y) {
|
||||
g_VecWaveDataVolY[m_waveCountLowFreY] = *pRecvData;
|
||||
m_waveCountLowFreY++;
|
||||
}else if (comand == WAVE_LF_Z) {
|
||||
g_VecWaveDataVolZ[m_waveCountLowFreZ] = *pRecvData;
|
||||
m_waveCountLowFreZ++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -650,7 +811,7 @@ void Uart::DealWaveThread() {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct) {
|
||||
std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRate, float ACCSampleTime, std::string strProduct,int version) {
|
||||
|
||||
memset(data,0,sizeof(data));
|
||||
memset(dealdata,0,sizeof(dealdata));
|
||||
@ -712,7 +873,55 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
compress = g_mapCompress[strShortAddr].compressChannelZ;
|
||||
count = g_mapCompress[strShortAddr].CountZ;
|
||||
}
|
||||
zlog_info(zct, "len = %d,data = %02x,iChannel = %d,compress = %d,count = %d", j, data[0], iChannel, compress, count);
|
||||
if (iChannel == WAVE_LF_X) {
|
||||
if (VecWaveDataLowFreX.size() > 0) {
|
||||
g_VecWaveDataVolX.assign(VecWaveDataLowFreX.begin(), VecWaveDataLowFreX.end());
|
||||
waveCount = VecWaveDataLowFreX.size();
|
||||
}
|
||||
waveCount = m_waveCountLowFreX;
|
||||
for (; j < waveCount; j++) {
|
||||
RecvData recvData = g_VecWaveDataVolX[j];
|
||||
memcpy(data + j * 92, recvData.Data, 92);
|
||||
}
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", g_VecWaveDataVolX[0].ShortAddr[0], g_VecWaveDataVolX[0].ShortAddr[1]);
|
||||
strShortAddr = std::string(buf);
|
||||
compress = g_mapCompress[strShortAddr].compressChannelVolX;
|
||||
count = g_mapCompress[strShortAddr].CountVolX;
|
||||
}
|
||||
if (iChannel == WAVE_LF_Y) {
|
||||
if (VecWaveDataLowFreY.size() > 0) {
|
||||
g_VecWaveDataVolY.assign(VecWaveDataLowFreY.begin(), VecWaveDataLowFreY.end());
|
||||
waveCount = VecWaveDataLowFreY.size();
|
||||
}
|
||||
waveCount = m_waveCountLowFreY;
|
||||
for (; j < waveCount; j++) {
|
||||
RecvData recvData = g_VecWaveDataVolY[j];
|
||||
memcpy(data + j * 92, recvData.Data, 92);
|
||||
}
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", g_VecWaveDataVolY[0].ShortAddr[0], g_VecWaveDataVolY[0].ShortAddr[1]);
|
||||
strShortAddr = std::string(buf);
|
||||
compress = g_mapCompress[strShortAddr].compressChannelVolY;
|
||||
count = g_mapCompress[strShortAddr].CountVolY;
|
||||
}
|
||||
if (iChannel == WAVE_LF_Z) {
|
||||
if (VecWaveDataLowFreZ.size() > 0) {
|
||||
g_VecWaveDataVolZ.assign(VecWaveDataLowFreZ.begin(), VecWaveDataLowFreZ.end());
|
||||
waveCount = VecWaveDataLowFreZ.size();
|
||||
}
|
||||
waveCount = m_waveCountLowFreZ;
|
||||
for (; j < waveCount; j++) {
|
||||
RecvData recvData = g_VecWaveDataVolZ[j];
|
||||
memcpy(data + j * 92, recvData.Data, 92);
|
||||
}
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", g_VecWaveDataVolZ[0].ShortAddr[0], g_VecWaveDataVolZ[0].ShortAddr[1]);
|
||||
strShortAddr = std::string(buf);
|
||||
compress = g_mapCompress[strShortAddr].compressChannelVolZ;
|
||||
count = g_mapCompress[strShortAddr].CountVolZ;
|
||||
}
|
||||
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 (compress) {
|
||||
@ -742,7 +951,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
fTemp = (((~iTemp) & 0xffff) + 1) * -coe * 9.8f; // convert to m/s2
|
||||
}
|
||||
vecData.push_back(fTemp);
|
||||
if (strProduct == "01") {
|
||||
if (strProduct == "01" && version == 1) {
|
||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||
break;
|
||||
@ -756,7 +965,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (strProduct == "02") {
|
||||
} else if (strProduct == "02" && version == 1) {
|
||||
if (vecData.size() == 8192 && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
@ -766,6 +975,25 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
}else if( version == 0){
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_Y) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 30720 && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_Y) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 13108 && iChannel == WAVE_LF_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return vecData;
|
||||
@ -778,9 +1006,13 @@ void Uart::DealWave() {
|
||||
std::string strMeasurementID = "";
|
||||
std::string strFileName = "";
|
||||
std::string strProduct = "";
|
||||
std::vector<float> vecDataX, vecDataY, vecDataZ;
|
||||
std::string softVersion = "";
|
||||
int version = 0;// 0 新版本 1 旧版本
|
||||
std::vector<float> vecDataX, vecDataY, vecDataZ,vecDataVolX, vecDataVolY, vecDataVolZ;
|
||||
bool z = false;
|
||||
if (wave_trans_) { //对每个传感器的每个通道进行遍历然后处理数据,例如:传感器1x轴的数据处理完后,再去处理y轴的。传感器1的所有数据处理完后,再处理传感器2的
|
||||
char getzigbeeShortAddr[32] = {0};
|
||||
|
||||
char getzigbeeShortAddr[32] = {0}, tableName[64] = {0}, whereCon[128] = {0};
|
||||
sprintf(getzigbeeShortAddr, "zigbeeShortAddr='%02x%02x'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF);
|
||||
vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", getzigbeeShortAddr);
|
||||
if (res.size() < 0)
|
||||
@ -796,13 +1028,18 @@ void Uart::DealWave() {
|
||||
wave_trans_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(tableName, "t_dataStatic_%s", (char *)res[44].c_str());
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s' order by timeStamp desc limit 1", strMeasurementID.c_str());
|
||||
std::string timestamp_last = sqlite_db_ctrl::instance().GetData(tableName, " timeStamp ", whereCon);
|
||||
|
||||
std::string ran = "";
|
||||
int n = 0;
|
||||
int range = 0;
|
||||
float coe = 0;
|
||||
int sampleRate = 0, ACCSampleTime = 0;
|
||||
float accSampleTimeXY = 1.6 , accSampleTimeZ = 1.28;
|
||||
float volSampleTime = 3.2 ;
|
||||
char getrange[32] = {0};
|
||||
std::string str = "range";
|
||||
sprintf(getrange, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
@ -810,14 +1047,36 @@ void Uart::DealWave() {
|
||||
sampleRate = atoi(res[23].c_str());
|
||||
ACCSampleTime = atoi(res[36].c_str());
|
||||
strProduct = res[17];
|
||||
softVersion = res[9];
|
||||
memset(getrange, 0, 32);
|
||||
sprintf(getrange, "%s", ran.c_str());
|
||||
n = (int)strtol(getrange, NULL, 32);
|
||||
if (compareVersions(softVersion, "2.6") == -1 && strProduct == "02") {
|
||||
accSampleTimeXY = (float)8192;
|
||||
accSampleTimeZ = (float)ACCSampleTime;
|
||||
version = 1;
|
||||
}
|
||||
if (m_waveCountX > 0 || VecWaveDataX.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size());
|
||||
coe = Calcoe(n, WAVE_X, strProduct, range);
|
||||
vecDataX = DealData(WAVE_X, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecDataX,strProduct,ACCSampleTime);
|
||||
|
||||
vecDataX = DealData(WAVE_X, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||
if(vecDataX.size() > 0 && g_mapCompress[strShortAddr].CountX > 0){
|
||||
scheduler::instance().WaveSuccess(wave_shortAddr,false);
|
||||
zlog_info(zct, "WaveSuccess shortAddr = %02x%02x,channel = %d", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,WAVE_X);
|
||||
}else{
|
||||
int iRet = scheduler::instance().WaveError(wave_shortAddr,false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
zlog_info(zct,"DealReviveDuration start shortAddr = %02x%02x,channel = %d", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,WAVE_X);
|
||||
DealReviveDuration(wave_shortAddr);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecDataX,strProduct,accSampleTimeXY,version);
|
||||
m_waveCountX = 0;
|
||||
g_VecWaveDataX.clear();
|
||||
VecWaveDataX.clear();
|
||||
@ -825,8 +1084,8 @@ void Uart::DealWave() {
|
||||
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size());
|
||||
coe = Calcoe(n, WAVE_Y, strProduct, range);
|
||||
vecDataY = DealData(WAVE_Y, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,ACCSampleTime);
|
||||
vecDataY = DealData(WAVE_Y, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,accSampleTimeXY,version);
|
||||
m_waveCountY = 0;
|
||||
g_VecWaveDataY.clear();
|
||||
VecWaveDataY.clear();
|
||||
@ -834,72 +1093,130 @@ void Uart::DealWave() {
|
||||
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size());
|
||||
coe = Calcoe(n, WAVE_Z, strProduct, range);
|
||||
vecDataZ = DealData(WAVE_Z, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,ACCSampleTime);
|
||||
vecDataZ = DealData(WAVE_Z, coe, sampleRate, accSampleTimeZ, strProduct,version);
|
||||
if(vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0){
|
||||
scheduler::instance().WaveSuccess(wave_shortAddr,true);
|
||||
}else{
|
||||
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);
|
||||
}
|
||||
}
|
||||
zlog_info(zct,"DealReviveDuration start shortAddr = %02x%02x,channel = %d", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,WAVE_X);
|
||||
DealReviveDuration(wave_shortAddr);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,accSampleTimeZ,version);
|
||||
m_waveCountZ = 0;
|
||||
g_VecWaveDataZ.clear();
|
||||
VecWaveDataZ.clear();
|
||||
}
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
zlog_info(zct,"m_waveCountLowFreX = %d,VecWaveDataLowFreX = %zu", m_waveCountLowFreX, VecWaveDataLowFreX.size());
|
||||
if (m_waveCountLowFreX > 0 || VecWaveDataLowFreX.size() > 0) {
|
||||
coe = Calcoe(n, WAVE_LF_X, strProduct, range);
|
||||
vecDataVolX = DealData(WAVE_LF_X, coe, g_mapCompress[strShortAddr].samplerateVolX, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_X, vecDataVolX,strProduct,volSampleTime,version);
|
||||
m_waveCountLowFreX = 0;
|
||||
g_VecWaveDataVolX.clear();
|
||||
VecWaveDataLowFreX.clear();
|
||||
}
|
||||
zlog_info(zct,"m_waveCountLowFreY = %d,VecWaveDataLowFreY = %zu", m_waveCountLowFreY, VecWaveDataLowFreY.size());
|
||||
if (m_waveCountLowFreY > 0 || VecWaveDataLowFreY.size() > 0) {
|
||||
coe = Calcoe(n, WAVE_LF_Y, strProduct, range);
|
||||
vecDataVolY = DealData(WAVE_LF_Y, coe, g_mapCompress[strShortAddr].samplerateVolY, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_Y, vecDataVolY,strProduct,volSampleTime,version);
|
||||
m_waveCountLowFreY = 0;
|
||||
g_VecWaveDataVolY.clear();
|
||||
VecWaveDataLowFreY.clear();
|
||||
}
|
||||
zlog_info(zct,"m_waveCountLowFreZ = %d,VecWaveDataLowFreZ = %zu", m_waveCountLowFreZ, VecWaveDataLowFreZ.size());
|
||||
if (m_waveCountLowFreZ > 0 || VecWaveDataLowFreZ.size() > 0) {
|
||||
coe = Calcoe(n, WAVE_LF_Z, strProduct, range);
|
||||
vecDataVolZ = DealData(WAVE_LF_Z, coe, g_mapCompress[strShortAddr].samplerateVolZ, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_LF_Z, vecDataVolZ,strProduct,volSampleTime,version);
|
||||
m_waveCountLowFreZ = 0;
|
||||
g_VecWaveDataVolZ.clear();
|
||||
VecWaveDataLowFreZ.clear();
|
||||
}
|
||||
char insertSql[100] = {0x00};
|
||||
char whereCon[50] = {0x00};
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str());
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
if (vecDataX.size() > 0)
|
||||
{
|
||||
sprintf(insertSql, "'%s-X','%02x%02x','%s',0,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
|
||||
sprintf(insertSql, "'%s-X','%02x%02x','%s',%d,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,(char*)timestamp_last.c_str(),g_mapCompress[strShortAddr].CountX,"");
|
||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||
}
|
||||
if (vecDataY.size() > 0)
|
||||
{
|
||||
sprintf(insertSql, "'%s-Y','%02x%02x','%s',0,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
|
||||
sprintf(insertSql, "'%s-Y','%02x%02x','%s',%d,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,(char*)timestamp_last.c_str(),g_mapCompress[strShortAddr].CountY,"");
|
||||
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
|
||||
}
|
||||
if (vecDataZ.size() > 0)
|
||||
{
|
||||
sprintf(insertSql, "'%s-Z','%02x%02x','%s',0,'1','%s','' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
|
||||
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);
|
||||
}
|
||||
zlog_warn(zct,"waveCountX = %d, waveCountY = %d, waveCountZ = %d", 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);
|
||||
if ((vecDataX.size() <= 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
||||
(vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||
(vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||
{
|
||||
int iRet = scheduler::instance().WaveError(wave_shortAddr);
|
||||
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,localtimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||
}
|
||||
}else if ((vecDataX.size() > 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
||||
(vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||
(vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||
{
|
||||
int iRet = scheduler::instance().WaveSuccess(wave_shortAddr);
|
||||
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,localtimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
zlog_warn(zct,"waveCountX = %zu, waveCountY = %zu, waveCountZ = %zu", vecDataX.size() , vecDataY.size(), vecDataZ.size());
|
||||
zlog_warn(zct,"CountX = %d, CountY = %d, CountZ = %d,strShortAddr = %s", g_mapCompress[strShortAddr].CountX , g_mapCompress[strShortAddr].CountY, g_mapCompress[strShortAddr].CountZ,strShortAddr.c_str());
|
||||
// if ((vecDataX.size() <= 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
||||
// (vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||
// (vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||
// {
|
||||
// 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) {
|
||||
// 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);
|
||||
// }
|
||||
// }else if ((vecDataX.size() > 0 && g_mapCompress[strShortAddr].CountX > 0) ||
|
||||
// (vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) ||
|
||||
// (vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0))
|
||||
// {
|
||||
// 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));
|
||||
// char updateSql[1024] = { 0 };
|
||||
// sprintf(updateSql, "resend = '%d'", 1);
|
||||
// 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);
|
||||
|
||||
if (g_mapCompress[strShortAddr].CountX <= 0 && g_mapCompress[strShortAddr].CountY <= 0 && g_mapCompress[strShortAddr].CountZ <= 0)
|
||||
{
|
||||
int iRet = scheduler::instance().WaveError(wave_shortAddr);
|
||||
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,localtimestamp);
|
||||
sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
// }
|
||||
// if (g_mapCompress[strShortAddr].CountX <= 0 && g_mapCompress[strShortAddr].CountY <= 0 && !current_z)
|
||||
// {
|
||||
// int iRet = scheduler::instance().WaveError(wave_shortAddr,false);
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// 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].CountY = 0;
|
||||
@ -907,47 +1224,41 @@ void Uart::DealWave() {
|
||||
g_mapCompress[strShortAddr].compressChannelX = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelY = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelZ = 0;
|
||||
g_mapCompress[strShortAddr].CountVolX = 0;
|
||||
g_mapCompress[strShortAddr].CountVolY = 0;
|
||||
g_mapCompress[strShortAddr].CountVolZ = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolX = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolY = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolZ = 0;
|
||||
std::vector<float>().swap(vecDataX);
|
||||
std::vector<float>().swap(vecDataY);
|
||||
std::vector<float>().swap(vecDataZ);
|
||||
std::vector<float>().swap(vecDataVolX);
|
||||
std::vector<float>().swap(vecDataVolY);
|
||||
std::vector<float>().swap(vecDataVolZ);
|
||||
wave_trans_ = false;
|
||||
zlog_warn(zct,"DealWave end, wave_shortAddr = %02x%02x", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF);
|
||||
//DealReviveDuration(wave_shortAddr);
|
||||
}
|
||||
}
|
||||
|
||||
float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
||||
float coe = 0.0f;
|
||||
if (product == "01") {
|
||||
switch (ran) {
|
||||
case 0: {
|
||||
range = 8;
|
||||
coe = 8 * 1.0f / 32767;
|
||||
} break;
|
||||
case 1: {
|
||||
range = 16;
|
||||
coe = 16 * 1.0f / 32767;
|
||||
} break;
|
||||
case 2: {
|
||||
range = 32;
|
||||
coe = 32 * 1.0f / 32767;
|
||||
} break;
|
||||
case 3: {
|
||||
range = 64;
|
||||
coe = 64 * 1.0f / 32767;
|
||||
} break;
|
||||
}
|
||||
|
||||
coe = pow(2, ran) * 8.0f / 32767;
|
||||
} else if (product == "02") {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y) {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_LF_X ||
|
||||
iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) {
|
||||
coe = 0.00048828125f;
|
||||
}
|
||||
if (iChannel == WAVE_Z) {
|
||||
if (iChannel == WAVE_Z ) {
|
||||
coe = 0.00172607421875f;
|
||||
}
|
||||
}
|
||||
return coe;
|
||||
}
|
||||
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product,int ACCSampleTime) {
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product,float ACCSampleTime,int version) {
|
||||
if (vecData.size() <= 0) return;
|
||||
std::string strFileName = "";
|
||||
char localtimestamp[32] = {0};
|
||||
@ -959,23 +1270,39 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
char buf[33] = {0x00};
|
||||
std::string strWaveData = "";
|
||||
WaveChannel wave_channel;
|
||||
|
||||
WaveVolChannel wave_vol_channel;
|
||||
int wave_type = 0;
|
||||
memset(mqttData,0,sizeof(mqttData));
|
||||
switch (iChannel) {
|
||||
case WAVE_X: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-X.dat";
|
||||
strChannelID = strMeasurementID + "-X";
|
||||
|
||||
wave_type = WAVE_X;
|
||||
} break;
|
||||
case WAVE_Y: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Y.dat";
|
||||
strChannelID = strMeasurementID + "-Y";
|
||||
|
||||
wave_type = WAVE_Y;
|
||||
} break;
|
||||
case WAVE_Z: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Z.dat";
|
||||
strChannelID = strMeasurementID + "-Z";
|
||||
|
||||
wave_type = WAVE_Z;
|
||||
} break;
|
||||
case WAVE_LF_X: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-X-LF.dat";
|
||||
strChannelID = strMeasurementID + "-X";
|
||||
wave_type = WAVE_LF_X;
|
||||
} break;
|
||||
case WAVE_LF_Y: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Y-LF.dat";
|
||||
strChannelID = strMeasurementID + "-Y";
|
||||
wave_type = WAVE_LF_Y;
|
||||
} break;
|
||||
case WAVE_LF_Z: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Z-LF.dat";
|
||||
strChannelID = strMeasurementID + "-Z";
|
||||
wave_type = WAVE_LF_Z;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
@ -994,6 +1321,12 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
wave_channel.WaveChannelY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_Z){
|
||||
wave_channel.WaveChannelZ[i] = frTemp;
|
||||
}else if (iChannel == WAVE_LF_X){
|
||||
wave_vol_channel.WaveChannelVolX[i] = frTemp;
|
||||
}else if (iChannel == WAVE_LF_Y){
|
||||
wave_vol_channel.WaveChannelVolY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_LF_Z){
|
||||
wave_vol_channel.WaveChannelVolZ[i] = frTemp;
|
||||
}
|
||||
if (i != vecData.size() -1){
|
||||
strncpy(mqttData + id ,buf,strlen(buf));
|
||||
@ -1005,14 +1338,20 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (product == "02" && sampleRate == 24000 && iChannel == WAVE_Z){
|
||||
zlog_info(zct, " vecData.size : %zu,start ", vecData.size());
|
||||
|
||||
zlog_info(zct, " product = %s,version = %d ,iChannel = %d", product.c_str(),version,iChannel);
|
||||
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 1) ||
|
||||
(iChannel == WAVE_Z && version == 0) ||
|
||||
((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 0)){
|
||||
sampleRate = 25600;
|
||||
zlog_info(zct, " sampleRate = %d,product = %s ", sampleRate,product.c_str());
|
||||
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
||||
size_t outSize = 25600;
|
||||
std::vector<float> outputData,outputData2;
|
||||
if (ACCSampleTime == 1){
|
||||
float epsilon = 1e-6f;
|
||||
if (std::fabs(ACCSampleTime - 1) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(ACCSampleTime == 2){
|
||||
}else if(std::fabs(ACCSampleTime - 2) < epsilon){
|
||||
std::vector<float> first_wave = std::vector<float>(vecData.begin(), vecData.begin() + vecData.size()/2);
|
||||
std::vector<float> second_wave = std::vector<float>(vecData.begin() + vecData.size()/2, vecData.end());
|
||||
outputData = Calculation::fftInterpolate(first_wave, outSize);
|
||||
@ -1021,6 +1360,13 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
{
|
||||
outputData.push_back(outputData2[i]);
|
||||
}
|
||||
}else if(std::fabs(ACCSampleTime - 1.28) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime);
|
||||
}else if(std::fabs(ACCSampleTime - 3.2) < epsilon){
|
||||
outSize = 8192;
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime);
|
||||
}
|
||||
zlog_info(zct, " outputData_size %d ", outputData.size());
|
||||
float mean = Calculation::mean(outputData);
|
||||
@ -1052,6 +1398,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
valWaveData["timeStamp"] = nowTimetamp;
|
||||
valWaveData["waveData"] = mqttData;
|
||||
valWaveData["mean"] = mean;
|
||||
valWaveData["waveType"] = wave_type;
|
||||
Json::FastWriter WaveValue;
|
||||
std::string WaveData = WaveValue.write(valWaveData);
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "common/common_func.hpp"
|
||||
#include "minilzo/minilzo.h"
|
||||
#include "scheduler/wave_feature_set.hpp"
|
||||
|
||||
#include "scheduler/schedule.hpp"
|
||||
|
||||
extern zlog_category_t* zct;
|
||||
extern zlog_category_t* zbt;
|
||||
@ -51,12 +51,12 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
char insertSql[100] = {0};
|
||||
char wherecon[100] = {0};
|
||||
char wherecon[512] = {0};
|
||||
sprintf(wherecon," short_Addr = '%02x%02x' and status = 3 and start_timestamp > ( SELECT MAX(submit_timestamp) FROM firmware_upgrade ) order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon);
|
||||
if (atoi(spend_count.c_str()) >= 10){
|
||||
//if (atoi(spend_count.c_str()) >= 12)
|
||||
{
|
||||
zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
return ;
|
||||
}
|
||||
if (spend_count == "")spend_count = "0";
|
||||
|
||||
@ -66,6 +66,9 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
memset(wherecon,0,sizeof(wherecon));
|
||||
sprintf(wherecon," zigbeeShortAddr = '%02x%02x' ",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,upgradeStatus ", wherecon);
|
||||
if(vecResult.size() < 1){
|
||||
return ;
|
||||
}
|
||||
if (vecResult[3] == "2"){
|
||||
zlog_warn(zbt, "UpdateWirelessNode already ,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
return;
|
||||
@ -141,7 +144,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
// zlog_warn(zct,"This block contains incompressible data.out_len = %lu,thisSize = %lu",out_len,thisSize);
|
||||
// memcpy(fw_senddata,buffer,thisSize);
|
||||
// }
|
||||
memcpy(fw_senddata,buffer,thisSize);
|
||||
//memcpy(fw_senddata,buffer,thisSize);
|
||||
unsigned char Data[100] = {0x00};
|
||||
unsigned char size[4] = {0x00};
|
||||
zlog_info(zct, "thisSize = %d", (int)thisSize);
|
||||
@ -196,7 +199,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
UpdateData[4]=UINT16_LOW(shortAdd);
|
||||
UpdateData[5]=0x10;
|
||||
UpdateData[6]=0xff & j;
|
||||
memcpy(&UpdateData[7],fw_senddata + 92 * j,92);
|
||||
memcpy(&UpdateData[7],buffer + 92 * j,92);
|
||||
tmp = 0x00;
|
||||
for(int k = 0; k < 99;k++){
|
||||
tmp +=UpdateData[k];
|
||||
@ -216,6 +219,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
if(time >= 150){
|
||||
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x,index = %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),j);
|
||||
zlog_warn(zct, "gpio_read failed \n");
|
||||
scheduler::instance().UpgradeResult(shortAdd,kRecvDataLenError);
|
||||
bUpdate = false;
|
||||
upgrade_status = 3;
|
||||
goto endUpdate;
|
||||
@ -236,7 +240,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
UpdateData[4] = UINT16_LOW(shortAdd);
|
||||
UpdateData[5] = 0x10;
|
||||
UpdateData[6] = 0xff & Count;
|
||||
memcpy(&UpdateData[7], fw_senddata + 92 * Count, lastSize);
|
||||
memcpy(&UpdateData[7], buffer + 92 * Count, lastSize);
|
||||
tmp = 0x00;
|
||||
for (int k = 0; k < 99; k++) {
|
||||
tmp += UpdateData[k];
|
||||
@ -261,6 +265,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
if (time >= 150) {
|
||||
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
zlog_warn(zct, "gpio_read failed \n");
|
||||
scheduler::instance().UpgradeResult(shortAdd,kRecvDataLenError);
|
||||
bUpdate = false;
|
||||
upgrade_status = 3;
|
||||
goto endUpdate;
|
||||
@ -561,6 +566,11 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
||||
char localtimestamp[32] = {0x00};
|
||||
int millisecond = 0;
|
||||
std::string rtcTime = GetRTC(localtimestamp, millisecond);
|
||||
if (rtcTime == "")
|
||||
{
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
}
|
||||
|
||||
scheduleTask.timeStamp = atoi(localtimestamp);
|
||||
zlog_info(zct,"next taskID = %d\n",scheduleTask.next_taskID);
|
||||
|
||||
@ -577,12 +587,17 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
|
||||
|
||||
if (scheduleTask.next_taskID == WAVE_CMD)
|
||||
{
|
||||
uint8_t x,y,z;
|
||||
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
|
||||
uint8_t x = 0,y = 0,z = 1;
|
||||
if (scheduleTask.z)
|
||||
{
|
||||
x = 1;
|
||||
y = 1;
|
||||
z = 0;
|
||||
}
|
||||
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
|
||||
send_data[17] = (x^1) & 0xFF;
|
||||
send_data[18] = (y^1) & 0xFF;
|
||||
send_data[19] = (z^1) & 0xFF;
|
||||
send_data[17] = x;
|
||||
send_data[18] = y;
|
||||
send_data[19] = z;
|
||||
}
|
||||
unsigned char tmp = 0x00;
|
||||
for (int k = 0; k < 99; k++) {
|
||||
|
||||
@ -345,3 +345,71 @@ std::vector<float> Calculation::fftInterpolate(const std::vector<float>& input,
|
||||
|
||||
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 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_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user