移植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,40 +267,49 @@ 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());
|
||||
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());
|
||||
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());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_data_waveSend ", whereCon);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param.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());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
short_addr = strtol(param.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);
|
||||
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[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, "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[i].mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
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[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") {
|
||||
char updateSql[1024] = {0};
|
||||
sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), param.mDataNodeNo.c_str());
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
sprintf(updateSql, "LooseValue = '0,2,");
|
||||
std::string strUpdateSql = std::string(updateSql) + std::string(localtimestamp) + "' ";
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon);
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
} else if (param[i].mDataNodeNo.length() > 0 && param[i].mType == "CORRECT") {
|
||||
char updateSql[1024] = {0};
|
||||
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) + "' ";
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), strUpdateSql.c_str(), whereCon);
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有传感器号";
|
||||
}
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -305,64 +352,132 @@ std::string JsonData::JsonCmd_Cgi_29(Param_29 ¶m) {
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), 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;
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = vecWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
jsBody["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,69 +507,131 @@ 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);
|
||||
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;
|
||||
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) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = "false";
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos && res[17] == "02") {
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
//进行傅立叶变换
|
||||
Calculation::FFTSpec(vecWave, fftWave);
|
||||
sampleRateReference = 1000;
|
||||
|
||||
} else {
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
//进行傅立叶变换
|
||||
Calculation::FFTSpec(vecWave, fftWave);
|
||||
sampleRateReference = 1024;
|
||||
}
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * sampleRateReference;
|
||||
int number = fftWave.size();
|
||||
int start = param.mPackageFlag * sampleRateReference;
|
||||
if (number < sampleRateReference) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.6f", fftWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.6f", fftWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
|
||||
int max = number / sampleRateReference;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else {
|
||||
if (param.mMode == 1 && productNo == "02") // DN102 有高频和低频
|
||||
{
|
||||
filename = "/opt/data/" + param.mChannelId + "-LF.dat";
|
||||
}
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = "false";
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos && res[17] == "02") {
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
//进行傅立叶变换
|
||||
Calculation::FFTSpec(vecWave, fftWave);
|
||||
sampleRateReference = 1000;
|
||||
|
||||
} else {
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) { // 取8K进行计算
|
||||
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 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;
|
||||
|
||||
int max = number / sampleRateReference;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
} 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;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
} 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];
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
param.fileName = recvBody["fileName"].asString();
|
||||
param.product = recvBody["product"].asInt();
|
||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
||||
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,7 +159,13 @@ void CheckThread() {
|
||||
if (3500 == loose_check) {
|
||||
zlog_info(zct, "loosecheck\n");
|
||||
loose_check = 0;
|
||||
sqlite_db_ctrl::instance().CalculateDip();
|
||||
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
|
||||
|
||||
323
uart/uart.cpp
323
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,27 +470,106 @@ 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;
|
||||
tempchannel.compressChannelX = pData[7];
|
||||
tempchannel.compressChannelY = pData[8];
|
||||
tempchannel.compressChannelZ = pData[9];
|
||||
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];
|
||||
|
||||
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]);
|
||||
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,17 +1448,33 @@ 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) {
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
||||
if (!CheckCrc(RecvBuf, 23)) {
|
||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
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_error(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// char tmp[23] = {0x00};
|
||||
// char tmp2[23] = {0x00};
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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