add x,y,z switch

This commit is contained in:
zhangsheng 2025-01-04 15:10:54 +08:00
parent b820734282
commit 59864c8461
18 changed files with 1742 additions and 1102 deletions

View File

@ -18,7 +18,7 @@ enum enumZigBeeTransmitStatus {
//#define NR5G_MODULE
//#define Q4G_MODULE
#define Q4G_MODULE
//#define WIFI_MODULE
//#define NR5G_MEIGE

View File

@ -2,6 +2,7 @@
#define PARAMETER_DEFINATION_HPP_
#include <string>
#include "scheduler/wave_feature_set.hpp"
struct Param_01 {
int mMode; // 0:登陆 1:更改密码
@ -343,5 +344,18 @@ struct Param_62 {
int mPackageFlag;
Param_62() : MeasurementID(""),timeStart(""),timeEnd(""),mPackageFlag(0){};
};
struct Param_63 {
int mMode;
bool partial;
std::vector<FeatureEntryUploadCfg> cfg;
Param_63() : mMode(0),partial(false){};
};
struct Param_64 {
int mMode;
bool partial;
std::vector<FeatureEntryUploadCfg> cfg;
Param_64() : mMode(0),partial(false){};
};
#endif // PARAMETER_DEFINATION_HPP_

View File

@ -71,6 +71,8 @@ public:
std::string JsonCmd_Cgi_60(Param_60 &param);
std::string JsonCmd_Cgi_61(Param_61 &param);
std::string JsonCmd_Cgi_62(Param_62 &param);
std::string JsonCmd_Cgi_63(Param_63 &param);
std::string JsonCmd_Cgi_64(Param_64 &param);
std::string JsonCmd_Cgi_default();
private:

View File

@ -955,3 +955,96 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 &param){
}
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_63(Param_63 &param)
{
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "63";
jsonVal["success"] = true;
jsonVal["message"] = "";
if (param.mMode == 0)
{
std::vector<FeatureEntryUploadCfg> cfg;
wave_feature_set_inst::instance().GetAllFeatureCfg(cfg);
if (cfg.size() > 0)
{
for (size_t i = 0; i < cfg.size(); i++)
{
Json::Value xyz_status;
xyz_status.append(cfg[i].x);
xyz_status.append(cfg[i].y);
xyz_status.append(cfg[i].z);
if (cfg[i].short_addr == 0)
{
jsBody["global"] = xyz_status;
}else{
char buf[8] = {0};
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(cfg[i].short_addr), UINT16_LOW(cfg[i].short_addr));
jsBody[buf] = xyz_status;
}
}
}else{
jsonVal["success"] = false;
jsonVal["message"] = "";
}
}else if(param.mMode == 1){
if (param.partial)
{
zlog_info(zct, "63 short_addr = %d,x = %d,y = %d,z = %d", param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
wave_feature_set_inst::instance().SetFeatureCfg(param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
}else{
wave_feature_set_inst::instance().SetAllFeatureCfg(param.cfg);
}
}
jsonVal["cmdBody"] = jsBody;
return show_value_.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_64(Param_64 &param)
{
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "64";
jsonVal["success"] = true;
jsonVal["message"] = "";
if (param.mMode == 0)
{
std::vector<FeatureEntryUploadCfg> cfg;
wave_feature_set_inst::instance().GetAllWaveCfg(cfg);
zlog_info(zct,"cfg size = %d",cfg.size());
if (cfg.size() > 0)
{
for (size_t i = 0; i < cfg.size(); i++)
{
Json::Value xyz_status;
xyz_status.append(cfg[i].x);
xyz_status.append(cfg[i].y);
xyz_status.append(cfg[i].z);
if (cfg[i].short_addr == 0)
{
jsBody["global"] = xyz_status;
}else{
char buf[8] = {0};
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(cfg[i].short_addr), UINT16_LOW(cfg[i].short_addr));
jsBody[buf] = xyz_status;
}
}
}else{
jsonVal["success"] = false;
jsonVal["message"] = "";
}
}else if(param.mMode == 1){
if (param.partial)
{
zlog_info(zct, "64 short_addr = %d,x = %d,y = %d,z = %d", param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
wave_feature_set_inst::instance().SetWaveCfg(param.cfg[0].short_addr, param.cfg[0].x, param.cfg[0].y, param.cfg[0].z);
}else{
wave_feature_set_inst::instance().SetAllWaveCfg(param.cfg);
}
}
jsonVal["cmdBody"] = jsBody;
return show_value_.write(jsonVal);
}

View File

@ -51,7 +51,9 @@ enum WebCommand {
kLostRecords = 59,
kTransducerUpgrade = 60,
kWaveRecords = 61,
kWaveReceive = 62
kWaveReceive = 62,
kWaveSend = 63,
kFeatureSend = 64
};
class LocalServer {

View File

@ -438,6 +438,78 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
std::string data = jd.JsonCmd_Cgi_62(param);
return data;
}break;
case kWaveSend:{
JsonData jd;
Param_63 param;
param.mMode = recvBody["sub_cmd"].asInt();
param.partial = recvBody["partial"].asBool();
if (param.mMode == 1)
{
for (const auto &key : recvBody.getMemberNames())
{
if (key != "sub_cmd" && key != "partial")
{
FeatureEntryUploadCfg tmpCfg;
char *end_ptr;
if (key == "global")
{
tmpCfg.short_addr = 0;
}else{
tmpCfg.short_addr = strtol(key.c_str(), &end_ptr, 16);
}
Json::Value xyz_status = recvBody[key];
for (size_t i = 0; i < xyz_status.size(); ++i) {
if (i == 0) {
tmpCfg.x = xyz_status[i].asInt();
} else if (i == 1) {
tmpCfg.y = xyz_status[i].asInt();
} else if (i == 2) {
tmpCfg.z = xyz_status[i].asInt();
}
}
param.cfg.push_back(tmpCfg);
}
}
}
std::string data = jd.JsonCmd_Cgi_63(param);
return data;
}break;
case kFeatureSend:{
JsonData jd;
Param_64 param;
param.mMode = recvBody["sub_cmd"].asInt();
param.partial = recvBody["partial"].asBool();
if (param.mMode == 1)
{
for (const auto &key : recvBody.getMemberNames())
{
if (key != "sub_cmd" && key != "partial")
{
FeatureEntryUploadCfg tmpCfg;
char *end_ptr;
if (key == "global")
{
tmpCfg.short_addr = 0;
}else{
tmpCfg.short_addr = strtol(key.c_str(), &end_ptr, 16);
}
Json::Value xyz_status = recvBody[key];
for (size_t i = 0; i < xyz_status.size(); ++i) {
if (i == 0) {
tmpCfg.x = xyz_status[i].asInt();
} else if (i == 1) {
tmpCfg.y = xyz_status[i].asInt();
} else if (i == 2) {
tmpCfg.z = xyz_status[i].asInt();
}
}
param.cfg.push_back(tmpCfg);
}
}
}
std::string data = jd.JsonCmd_Cgi_64(param);
return data;
}break;
default:
JsonData jd;
std::string data = jd.JsonCmd_Cgi_default();

File diff suppressed because it is too large Load Diff

View File

@ -1,152 +1,152 @@
#ifndef SCHEDULE_HPP_
#define SCHEDULE_HPP_
#include <iostream>
#include <map>
#include <unordered_set>
#include <vector>
#include <stdint.h>
#include <boost/container/detail/singleton.hpp>
#include "upgrade_cfg.hpp"
#define SCHEDULE_CONFIG "/opt/configenv/schedule.json"
typedef enum {
kScheduleResultNone = 0,
kScheduleUnknownSensor = 1,
kScheduleConfigSensor = 2,
kScheduleEigenValue = 3,
kScheduleWaveForm = 4,
kScheduleUpgrade = 5,
kScheduleWrongTime = 6
} ScheduleResult;
typedef enum {
kUpgradeSuccess = 0, // 成功
kProductTypeMismatch = 1, // 包有问题,不再重试
kZigbeeHWMismatch = 2, // 包有问题,不再重试
kTransmitFileCrcError = 3, // 此返回值时,要重试
kRecvDataLenError = 4, // 此返回值时,要重试
kUpgradeDoneBefore = 5 // 当前就是这个版本,不需要升级了
} FirmFileCheckResult;
class SensorScheduler {
public:
SensorScheduler();
// kScheduleConfigSensor kScheduleUpgrade 等有结果,调我接口通知结果
// kScheduleEigenValue kScheduleWaveForm
// 上面4个结束调GetNextDuration()获取休眠时间
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
int StartSchedule(int short_addr, int &next_duration);
int GetNextDuration(int short_addr);
long GetBaseTimestamp(int id);
long CalcNextTimestamp(int id, uint16_t short_addr);
// 当有传感器需要更新配置时调用
int UpdateSensorConfig(int short_addr);
// 当更新结束后调用此接口result为0是成功其它值为失败
int UpdateConfigResult(int short_addr, int result);
/**
* @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 线
*
* @param short_addr
* @param result FirmFileCheckResult
* 0
*/
int UpgradeResult(int 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 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 &max_sensor_num);
// ======schedule.json操作开始======
// 无线网关程序重启时
// void ReadScheduleCfg();
// 配置完成后
int WriteScheduleCfg(long &ts, std::string &world_time);
// 当系统进行校时时,输入参数为新的时间戳与以前时间戳的差值
void ModifyScheduleTs(int diff_ts);
// 当接入传感器时,设置为不可修改; 当停用所有传感器后,修改为可修改
void AdjustSupportModification(bool support_modification);
// ======schedule.json操作结束======
void ClearScheduleCfg(int short_addr = 0);
long GetLocalTs();
long GetLocalWorldTime(std::string &world_time);
std::string GetUTCTime(long ts);
int GetAvailableId(int short_addr);
private:
void UpdateUpgradeInfo(int id);
void CleanIdleOccupiedSet(long ts);
// user config
int eigen_value_send_interval_;
int eigen_value_send_duration_;
int wave_form_send_interval_;
int wave_form_send_duration_;
int max_sensor_num_;
// calc result
long start_timestamp_;
std::string start_ts_str_;
int available_slice_;
int free_slice_;
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_; // 传感器编号与第几个波形发送窗口对应关系
std::map<uint16_t, int> short_addr_map_; // base_relation.json
// 空闲时间戳被占用
std::unordered_set<long> free_slice_ocuppied_;
// sensor config update
std::unordered_set<int> update_;
// sensor upgrade
std::map<int, UpgradeInfo> upgrade_;
// temp variables
long current_ts_; // 当前时间戳
long current_wave_start_ts_; // 当前所在的波形发送间隔的开始时间戳
long nth_wave_start_slice_; // 第几个波形发送窗口
long seconds_in_current_wave_slice_; // 时间戳相对波形开始时间戳的秒数
int nth_eigen_value_slice_; // 第几个特征值发送窗口
int seconds_in_current_eigen_slice_; // 相对特征值发送间隔的秒数
bool ts_in_eigen_slice_; // 时间位于特征值发送窗口中
int nth_eigen_slice_; // 如果ts_in_eigen_slice_是真的话此值表明是第几个特征值窗口
bool nth_wave_slice_; // 如果ts_in_eigen_slice_是假的话此值表明是第几个波形窗口
int current_request_;
};
typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler;
#ifndef SCHEDULE_HPP_
#define SCHEDULE_HPP_
#include <iostream>
#include <map>
#include <unordered_set>
#include <vector>
#include <stdint.h>
#include <boost/container/detail/singleton.hpp>
#include "upgrade_cfg.hpp"
#define SCHEDULE_CONFIG "/opt/configenv/schedule.json"
typedef enum {
kScheduleResultNone = 0,
kScheduleUnknownSensor = 1,
kScheduleConfigSensor = 2,
kScheduleEigenValue = 3,
kScheduleWaveForm = 4,
kScheduleUpgrade = 5,
kScheduleWrongTime = 6
} ScheduleResult;
typedef enum {
kUpgradeSuccess = 0, // 成功
kProductTypeMismatch = 1, // 包有问题,不再重试
kZigbeeHWMismatch = 2, // 包有问题,不再重试
kTransmitFileCrcError = 3, // 此返回值时,要重试
kRecvDataLenError = 4, // 此返回值时,要重试
kUpgradeDoneBefore = 5 // 当前就是这个版本,不需要升级了
} FirmFileCheckResult;
class SensorScheduler {
public:
SensorScheduler();
// kScheduleConfigSensor kScheduleUpgrade 等有结果,调我接口通知结果
// kScheduleEigenValue kScheduleWaveForm
// 上面4个结束调GetNextDuration()获取休眠时间
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
int StartSchedule(int short_addr, int &next_duration);
int GetNextDuration(int short_addr);
long GetBaseTimestamp(int id);
long CalcNextTimestamp(int id, uint16_t short_addr);
// 当有传感器需要更新配置时调用
int UpdateSensorConfig(int short_addr);
// 当更新结束后调用此接口result为0是成功其它值为失败
int UpdateConfigResult(int short_addr, int result);
/**
* @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 线
*
* @param short_addr
* @param result FirmFileCheckResult
* 0
*/
int UpgradeResult(int 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 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 &max_sensor_num);
// ======schedule.json操作开始======
// 无线网关程序重启时
// void ReadScheduleCfg();
// 配置完成后
int WriteScheduleCfg(long &ts, std::string &world_time);
// 当系统进行校时时,输入参数为新的时间戳与以前时间戳的差值
void ModifyScheduleTs(int diff_ts);
// 当接入传感器时,设置为不可修改; 当停用所有传感器后,修改为可修改
void AdjustSupportModification(bool support_modification);
// ======schedule.json操作结束======
void ClearScheduleCfg(int short_addr = 0);
long GetLocalTs();
long GetLocalWorldTime(std::string &world_time);
std::string GetUTCTime(long ts);
int GetAvailableId(int short_addr);
private:
void UpdateUpgradeInfo(int id);
void CleanIdleOccupiedSet(long ts);
// user config
int eigen_value_send_interval_;
int eigen_value_send_duration_;
int wave_form_send_interval_;
int wave_form_send_duration_;
int max_sensor_num_;
// calc result
long start_timestamp_;
std::string start_ts_str_;
int available_slice_;
int free_slice_;
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_; // 传感器编号与第几个波形发送窗口对应关系
std::map<uint16_t, int> short_addr_map_; // base_relation.json
// 空闲时间戳被占用
std::unordered_set<long> free_slice_ocuppied_;
// sensor config update
std::unordered_set<int> update_;
// sensor upgrade
std::map<int, UpgradeInfo> upgrade_;
// temp variables
long current_ts_; // 当前时间戳
long current_wave_start_ts_; // 当前所在的波形发送间隔的开始时间戳
long nth_wave_start_slice_; // 第几个波形发送窗口
long seconds_in_current_wave_slice_; // 时间戳相对波形开始时间戳的秒数
int nth_eigen_value_slice_; // 第几个特征值发送窗口
int seconds_in_current_eigen_slice_; // 相对特征值发送间隔的秒数
bool ts_in_eigen_slice_; // 时间位于特征值发送窗口中
int nth_eigen_slice_; // 如果ts_in_eigen_slice_是真的话此值表明是第几个特征值窗口
bool nth_wave_slice_; // 如果ts_in_eigen_slice_是假的话此值表明是第几个波形窗口
int current_request_;
};
typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler;
#endif // SCHEDULE_HPP_

View File

@ -1,68 +1,68 @@
#include "short_addr_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
#include "common/common_func.hpp"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int ShortAddrCfg::ReadCfg(std::map<uint16_t, int>& short_addr_map) {
std::ifstream base_relation_file(BASE_RELATION);
if (!base_relation_file.good()) {
zlog_info(zbt, "[ShortAddrCfg] no file %s", BASE_RELATION);
return 0;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(base_relation_file, root, false)) {
zlog_error(zbt, "[ShortAddrCfg] invalid format, fail to parse %s", BASE_RELATION);
base_relation_file.close();
return 1;
}
base_relation_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[ShortAddrCfg] invalid format, not an array: %s", BASE_RELATION);
return 2;
}
if (root.size() == 0) {
zlog_info(zbt, "[ShortAddrCfg] no element in %s", BASE_RELATION);
return 0;
}
uint16_t short_addr;
int index = 0;
std::string short_addr_str;
char *end_ptr;
for (const auto &item : root) {
short_addr_str = item["short_addr"].asString();
short_addr = strtol(short_addr_str.c_str(), &end_ptr, 16);
index = item["id"].asInt();
zlog_info(zbt, "[ShortAddrCfg] index:%d, short addr:%02x", index, short_addr);
short_addr_map[short_addr] = index;
}
return 0;
}
int ShortAddrCfg::WriteCfg(std::map<uint16_t, int> &short_addr_map) {
Json::Value root;
char buf[8] = {0};
for (auto it = short_addr_map.begin(); it != short_addr_map.end(); ++it) {
Json::Value item;
item["id"] = it->second;
memset(buf, 0, 8);
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(it->first),UINT16_LOW(it->first));
item["short_addr"] = buf;
root.append(item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(BASE_RELATION);
streamWriter.write(out_file, root);
return 0;
}
void ShortAddrCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(BASE_RELATION);
system(clear_cmd.c_str());
}
#include "short_addr_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
#include "common/common_func.hpp"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int ShortAddrCfg::ReadCfg(std::map<uint16_t, int>& short_addr_map) {
std::ifstream base_relation_file(BASE_RELATION);
if (!base_relation_file.good()) {
zlog_info(zbt, "[ShortAddrCfg] no file %s", BASE_RELATION);
return 0;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(base_relation_file, root, false)) {
zlog_error(zbt, "[ShortAddrCfg] invalid format, fail to parse %s", BASE_RELATION);
base_relation_file.close();
return 1;
}
base_relation_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[ShortAddrCfg] invalid format, not an array: %s", BASE_RELATION);
return 2;
}
if (root.size() == 0) {
zlog_info(zbt, "[ShortAddrCfg] no element in %s", BASE_RELATION);
return 0;
}
uint16_t short_addr;
int index = 0;
std::string short_addr_str;
char *end_ptr;
for (const auto &item : root) {
short_addr_str = item["short_addr"].asString();
short_addr = strtol(short_addr_str.c_str(), &end_ptr, 16);
index = item["id"].asInt();
zlog_info(zbt, "[ShortAddrCfg] index:%d, short addr:%02x", index, short_addr);
short_addr_map[short_addr] = index;
}
return 0;
}
int ShortAddrCfg::WriteCfg(std::map<uint16_t, int> &short_addr_map) {
Json::Value root;
char buf[8] = {0};
for (auto it = short_addr_map.begin(); it != short_addr_map.end(); ++it) {
Json::Value item;
item["id"] = it->second;
memset(buf, 0, 8);
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(it->first),UINT16_LOW(it->first));
item["short_addr"] = buf;
root.append(item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(BASE_RELATION);
streamWriter.write(out_file, root);
return 0;
}
void ShortAddrCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(BASE_RELATION);
system(clear_cmd.c_str());
}

View File

@ -1,15 +1,15 @@
#ifndef SHORT_ADDR_CFG_HPP_
#define SHORT_ADDR_CFG_HPP_
#include <stdint.h>
#include <map>
#define BASE_RELATION "/opt/configenv/base_relation.json"
class ShortAddrCfg {
public:
static int ReadCfg(std::map<uint16_t, int> &short_addr_map);
static int WriteCfg(std::map<uint16_t, int> &short_addr_map);
static void ClearCfg();
};
#ifndef SHORT_ADDR_CFG_HPP_
#define SHORT_ADDR_CFG_HPP_
#include <stdint.h>
#include <map>
#define BASE_RELATION "/opt/configenv/base_relation.json"
class ShortAddrCfg {
public:
static int ReadCfg(std::map<uint16_t, int> &short_addr_map);
static int WriteCfg(std::map<uint16_t, int> &short_addr_map);
static void ClearCfg();
};
#endif // SHORT_ADDR_CFG_HPP_

View File

@ -1,54 +1,54 @@
#include "update_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int UpdateCfg::ReadCfg(std::unordered_set<int>& update) {
std::ifstream config_update_file(CONFIG_UPDATE);
if (!config_update_file.good()) {
zlog_info(zbt, "[UpdateCfg] no file");
return 0;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(config_update_file, root, false)) {
zlog_error(zbt, "[UpdateCfg] invalid format, fail to parse %s", CONFIG_UPDATE);
config_update_file.close();
return 1;
}
config_update_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[UpdateCfg] invalid format, not an array: %s", CONFIG_UPDATE);
return 2;
}
if (root.size() > 0) {
zlog_info(zbt, "[UpdateCfg] element in %s", CONFIG_UPDATE);
for (const auto &item : root) {
update.insert(item.asInt());
zlog_info(zbt, "[UpdateCfg] sensor id:%d need to update", item.asInt());
}
}
return 0;
}
int UpdateCfg::WriteCfg(std::unordered_set<int> &update) {
Json::Value root;
for (auto item : update) {
root.append(item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(CONFIG_UPDATE);
streamWriter.write(out_file, root);
out_file.close();
return 0;
}
void UpdateCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(CONFIG_UPDATE);
system(clear_cmd.c_str());
}
#include "update_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int UpdateCfg::ReadCfg(std::unordered_set<int>& update) {
std::ifstream config_update_file(CONFIG_UPDATE);
if (!config_update_file.good()) {
zlog_info(zbt, "[UpdateCfg] no file");
return 0;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(config_update_file, root, false)) {
zlog_error(zbt, "[UpdateCfg] invalid format, fail to parse %s", CONFIG_UPDATE);
config_update_file.close();
return 1;
}
config_update_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[UpdateCfg] invalid format, not an array: %s", CONFIG_UPDATE);
return 2;
}
if (root.size() > 0) {
zlog_info(zbt, "[UpdateCfg] element in %s", CONFIG_UPDATE);
for (const auto &item : root) {
update.insert(item.asInt());
zlog_info(zbt, "[UpdateCfg] sensor id:%d need to update", item.asInt());
}
}
return 0;
}
int UpdateCfg::WriteCfg(std::unordered_set<int> &update) {
Json::Value root;
for (auto item : update) {
root.append(item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(CONFIG_UPDATE);
streamWriter.write(out_file, root);
out_file.close();
return 0;
}
void UpdateCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(CONFIG_UPDATE);
system(clear_cmd.c_str());
}

View File

@ -1,15 +1,15 @@
#ifndef UPDATE_CFG_HPP_
#define UPDATE_CFG_HPP_
#include <unordered_set>
#define CONFIG_UPDATE "/opt/configenv/config_update.json"
class UpdateCfg {
public:
static int ReadCfg(std::unordered_set<int> &update);
static int WriteCfg(std::unordered_set<int> &update);
static void ClearCfg();
};
#ifndef UPDATE_CFG_HPP_
#define UPDATE_CFG_HPP_
#include <unordered_set>
#define CONFIG_UPDATE "/opt/configenv/config_update.json"
class UpdateCfg {
public:
static int ReadCfg(std::unordered_set<int> &update);
static int WriteCfg(std::unordered_set<int> &update);
static void ClearCfg();
};
#endif // UPDATE_CFG_HPP_

View File

@ -1,94 +1,82 @@
#include "upgrade_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int UpgradeCfg::ReadCfg(std::map<int, UpgradeInfo> &upgrade) {
std::ifstream upgrade_file(UPGRADE_CONFIG);
if (!upgrade_file.good()) {
zlog_info(zbt, "[UpgradeCfg] no such file");
return 0;
}
upgrade_file.seekg(0, std::ios::end);
std::streampos file_size = upgrade_file.tellg();
if (file_size > 256000) {
zlog_error(zct, "upgrade file exception, will remove it");
ClearCfg();
return 1;
}
upgrade_file.seekg(0, std::ios::beg);
Json::Reader reader;
Json::Value root;
if (!reader.parse(upgrade_file, root, false)) {
zlog_error(zbt, "[UpgradeCfg] invalid format, fail to parse %s", UPGRADE_CONFIG);
upgrade_file.close();
return 1;
}
upgrade_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[UpgradeCfg] invalid format, not an array: %s", UPGRADE_CONFIG);
return 2;
}
if (root.size() == 0) {
zlog_info(zbt, "[UpgradeCfg] no element");
return 0;
}
UpgradeInfo info;
for (const auto &item : root) {
info.try_times = item["try_times"].asInt();
info.sensor_type = item["type"].asString();
info.hw_version = item["hw_version"].asInt();
info.current_sw_version = item["current_sw_version"].asString();
info.upgrade_sw_version = item["upgrade_sw_version"].asString();
info.submit_time = item["submit_time"].asString();
for (const auto &time_item : item["try_world_time"]) {
info.try_world_time1.push_back(time_item.asString());
}
upgrade[item["id"].asInt()] = info;
zlog_info(zbt, "[UpgradeCfg] id:%d need to upgrade from:%s to %s", item["id"].asInt(),
info.current_sw_version.c_str(), info.upgrade_sw_version.c_str());
}
return 0;
}
int UpgradeCfg::WriteCfg(std::map<int, UpgradeInfo> &upgrade) {
if (upgrade.size() == 0) {
ClearCfg();
return 0;
}
Json::Value root;
for (auto item : upgrade) {
Json::Value upgrade_item;
upgrade_item["id"] = item.first;
upgrade_item["try_times"] = item.second.try_times;
upgrade_item["type"] = item.second.sensor_type;
upgrade_item["hw_version"] = item.second.hw_version;
upgrade_item["current_sw_version"] = item.second.current_sw_version;
upgrade_item["upgrade_sw_version"] = item.second.upgrade_sw_version;
upgrade_item["submit_time"] = item.second.submit_time;
Json::Value try_world_time;
for (auto entry : item.second.try_world_time1) {
try_world_time.append(entry);
}
upgrade_item["try_world_time"] = try_world_time;
root.append(upgrade_item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(UPGRADE_CONFIG);
streamWriter.write(out_file, root);
out_file.close();
return 0;
}
void UpgradeCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(UPGRADE_CONFIG);
system(clear_cmd.c_str());
}
#include "upgrade_cfg.hpp"
#include <fstream>
#include <json/json.h>
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
int UpgradeCfg::ReadCfg(std::map<int, UpgradeInfo> &upgrade) {
std::ifstream upgrade_file(UPGRADE_CONFIG);
if (!upgrade_file.good()) {
zlog_info(zbt, "[UpgradeCfg] no such file");
return 0;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(upgrade_file, root, false)) {
zlog_error(zbt, "[UpgradeCfg] invalid format, fail to parse %s", UPGRADE_CONFIG);
upgrade_file.close();
return 1;
}
upgrade_file.close();
if (!root.isArray()) {
zlog_error(zbt, "[UpgradeCfg] invalid format, not an array: %s", UPGRADE_CONFIG);
return 2;
}
if (root.size() == 0) {
zlog_info(zbt, "[UpgradeCfg] no element");
return 0;
}
UpgradeInfo info;
for (const auto &item : root) {
info.try_times = item["try_times"].asInt();
info.sensor_type = item["type"].asString();
info.hw_version = item["hw_version"].asInt();
info.current_sw_version = item["current_sw_version"].asString();
info.upgrade_sw_version = item["upgrade_sw_version"].asString();
info.submit_time = item["submit_time"].asString();
for (const auto &time_item : item["try_world_time"]) {
info.try_world_time1.push_back(time_item.asString());
}
upgrade[item["id"].asInt()] = info;
zlog_info(zbt, "[UpgradeCfg] id:%d need to upgrade from:%s to %s", item["id"].asInt(),
info.current_sw_version.c_str(), info.upgrade_sw_version.c_str());
}
return 0;
}
int UpgradeCfg::WriteCfg(std::map<int, UpgradeInfo> &upgrade) {
Json::Value root;
for (auto item : upgrade) {
Json::Value upgrade_item;
upgrade_item["id"] = item.first;
upgrade_item["try_times"] = item.second.try_times;
upgrade_item["type"] = item.second.sensor_type;
upgrade_item["hw_version"] = item.second.hw_version;
upgrade_item["current_sw_version"] = item.second.current_sw_version;
upgrade_item["upgrade_sw_version"] = item.second.upgrade_sw_version;
upgrade_item["submit_time"] = item.second.submit_time;
Json::Value try_world_time;
for (auto entry : item.second.try_world_time1) {
try_world_time.append(entry);
}
upgrade_item["try_world_time"] = try_world_time;
root.append(upgrade_item);
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(UPGRADE_CONFIG);
streamWriter.write(out_file, root);
out_file.close();
return 0;
}
void UpgradeCfg::ClearCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(UPGRADE_CONFIG);
system(clear_cmd.c_str());
}

View File

@ -1,26 +1,26 @@
#ifndef UPGRADE_CFG_HPP_
#define UPGRADE_CFG_HPP_
#include <string>
#include <vector>
#include <map>
#define UPGRADE_CONFIG "/opt/configenv/upgrade.json"
typedef struct {
int try_times;
std::string sensor_type;
int hw_version;
std::string current_sw_version;
std::string upgrade_sw_version;
std::string submit_time;
std::vector<std::string> try_world_time1;
} UpgradeInfo;
class UpgradeCfg {
public:
static int ReadCfg(std::map<int, UpgradeInfo> &upgrade);
static int WriteCfg(std::map<int, UpgradeInfo> &upgrade);
static void ClearCfg();
};
#ifndef UPGRADE_CFG_HPP_
#define UPGRADE_CFG_HPP_
#include <string>
#include <vector>
#include <map>
#define UPGRADE_CONFIG "/opt/configenv/upgrade.json"
typedef struct {
int try_times;
std::string sensor_type;
int hw_version;
std::string current_sw_version;
std::string upgrade_sw_version;
std::string submit_time;
std::vector<std::string> try_world_time1;
} UpgradeInfo;
class UpgradeCfg {
public:
static int ReadCfg(std::map<int, UpgradeInfo> &upgrade);
static int WriteCfg(std::map<int, UpgradeInfo> &upgrade);
static void ClearCfg();
};
#endif // UPGRADE_CFG_HPP_

View File

@ -0,0 +1,370 @@
#include "wave_feature_set.hpp"
#include <fstream>
#include "common/common_func.hpp"
#include <zlog.h>
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
WaveFeatureSetting::WaveFeatureSetting() {
std::ifstream feature_filter_file(FEATURE_FILTER_CFG);
if (!feature_filter_file.good()) {
zlog_info(zbt, "[WaveFeatureSetting] no file %s", FEATURE_FILTER_CFG);
global_feature_.short_addr = 0;
global_feature_.x = 1;
global_feature_.y = 1;
global_feature_.z = 1;
} else {
Json::Reader reader;
Json::Value root;
if (!reader.parse(feature_filter_file, root, false)) {
zlog_error(zbt, "[WaveFeatureSetting] invalid format, fail to parse %s", FEATURE_FILTER_CFG);
feature_filter_file.close();
global_feature_.short_addr = 0;
global_feature_.x = 1;
global_feature_.y = 1;
global_feature_.z = 1;
} else {
uint16_t short_addr;
char *end_ptr;
for (const auto &key : root.getMemberNames()) {
if (key == "global") {
Json::Value v = root[key];
global_feature_.short_addr = 0;
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0) {
global_feature_.x = v[i].asInt();
} else if (i == 1) {
global_feature_.y = v[i].asInt();
} else if (i == 2) {
global_feature_.z = v[i].asInt();
}
}
} else {
short_addr = strtol(key.c_str(), &end_ptr, 16);
Json::Value v = root[key];
FeatureEntryPrivateCfg item;
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0) {
item.x = v[i].asInt();
} else if (i == 1) {
item.y = v[i].asInt();
} else if (i == 2) {
item.z = v[i].asInt();
}
}
eigen_map_[short_addr] = item;
}
}
}
}
std::ifstream wave_filter_file(WAVE_FILTER_CFG);
if (!wave_filter_file.good()) {
zlog_info(zbt, "[WaveFeatureSetting] no file %s", WAVE_FILTER_CFG);
global_wave_.short_addr = 0;
global_wave_.x = 1;
global_wave_.y = 1;
global_wave_.z = 1;
} else {
Json::Reader reader;
Json::Value root;
if (!reader.parse(wave_filter_file, root, false)) {
zlog_error(zbt, "[WaveFeatureSetting] invalid format, fail to parse %s", WAVE_FILTER_CFG);
wave_filter_file.close();
global_wave_.short_addr = 0;
global_wave_.x = 1;
global_wave_.y = 1;
global_wave_.z = 1;
} else {
uint16_t short_addr;
char *end_ptr;
for (const auto &key : root.getMemberNames()) {
if (key == "global") {
Json::Value v = root[key];
global_wave_.short_addr = 0;
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0) {
global_wave_.x = v[i].asInt();
} else if (i == 1) {
global_wave_.y = v[i].asInt();
} else if (i == 2) {
global_wave_.z = v[i].asInt();
}
}
} else {
short_addr = strtol(key.c_str(), &end_ptr, 16);
Json::Value v = root[key];
FeatureEntryPrivateCfg item;
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0) {
item.x = v[i].asInt();
} else if (i == 1) {
item.y = v[i].asInt();
} else if (i == 2) {
item.z = v[i].asInt();
}
}
wave_map_[short_addr] = item;
}
}
}
}
}
int WaveFeatureSetting::GetFeatureCfg(uint16_t short_addr, uint8_t &x, uint8_t &y, uint8_t &z) {
if (short_addr == 0) {
x = global_feature_.x;
y = global_feature_.y;
z = global_feature_.z;
return 0;
}
auto iter = eigen_map_.find(short_addr);
if (iter == eigen_map_.end()) {
x = global_feature_.x;
y = global_feature_.y;
z = global_feature_.z;
return 0;
}
x = iter->second.x;
y = iter->second.y;
z = iter->second.z;
return 0;
}
void WaveFeatureSetting::SetFeatureCfg(uint16_t short_addr, uint8_t x, uint8_t y, uint8_t z) {
bool need_submit = false;
if (short_addr == 0) {
if (global_feature_.x == x && global_feature_.y == y && global_feature_.z == z) {
return;
}
need_submit = true;
global_feature_.x = x;
global_feature_.y = y;
global_feature_.z = z;
} else {
auto iter = eigen_map_.find(short_addr);
if (iter == eigen_map_.end()) {
FeatureEntryPrivateCfg cfg;
cfg.x = x;
cfg.y = y;
cfg.z = z;
eigen_map_[short_addr] = cfg;
need_submit = true;
} else {
if (iter->second.x == x && iter->second.y == y && iter->second.z == z) {
return;
}
iter->second.x = x;
iter->second.y = y;
iter->second.z = z;
need_submit = true;
}
}
if (need_submit) {
WriteFeatureCfgFile();
}
}
void WaveFeatureSetting::SetAllFeatureCfg(std::vector<FeatureEntryUploadCfg> cfg) {
eigen_map_.clear();
for (auto item : cfg) {
if (item.short_addr == 0) {
global_feature_.short_addr = 0;
global_feature_.x = item.x;
global_feature_.y = item.y;
global_feature_.z = item.z;
} else {
FeatureEntryPrivateCfg entry;
entry.x = item.x;
entry.y = item.y;
entry.z = item.z;
eigen_map_[item.short_addr] = entry;
}
}
WriteFeatureCfgFile();
}
int WaveFeatureSetting::GetAllFeatureCfg(std::vector<FeatureEntryUploadCfg> &cfg) {
cfg.clear();
cfg.push_back(global_feature_);
for (auto item : eigen_map_) {
FeatureEntryUploadCfg current;
current.short_addr = item.first;
current.x = item.second.x;
current.y = item.second.y;
current.z = item.second.z;
cfg.push_back(current);
}
return 0;
}
void WaveFeatureSetting::RemoveFeatureCfg(uint16_t short_addr) {
auto iter = eigen_map_.find(short_addr);
if (iter == eigen_map_.end()) {
return;
}
eigen_map_.erase(short_addr);
WriteFeatureCfgFile();
}
void WaveFeatureSetting::RemoveAllFeatureCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(FEATURE_FILTER_CFG);
system(clear_cmd.c_str());
}
void WaveFeatureSetting::WriteFeatureCfgFile() {
Json::Value root;
Json::Value global_arr;
global_arr.append(global_feature_.x);
global_arr.append(global_feature_.y);
global_arr.append(global_feature_.z);
root["global"] = global_arr;
char buf[8] = {0};
for (auto item : eigen_map_) {
memset(buf, 0, 8);
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(item.first), UINT16_LOW(item.first));
Json::Value arr;
arr.append(item.second.x);
arr.append(item.second.y);
arr.append(item.second.z);
root[buf] = arr;
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(FEATURE_FILTER_CFG);
streamWriter.write(out_file, root);
}
void WaveFeatureSetting::WriteWaveCfgFile() {
Json::Value root;
Json::Value global_arr;
global_arr.append(global_wave_.x);
global_arr.append(global_wave_.y);
global_arr.append(global_wave_.z);
root["global"] = global_arr;
char buf[8] = {0};
for (auto item : wave_map_) {
memset(buf, 0, 8);
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(item.first), UINT16_LOW(item.first));
Json::Value arr;
arr.append(item.second.x);
arr.append(item.second.y);
arr.append(item.second.z);
root[buf] = arr;
}
Json::StyledStreamWriter streamWriter;
std::ofstream out_file(WAVE_FILTER_CFG);
streamWriter.write(out_file, root);
}
int WaveFeatureSetting::GetWaveCfg(uint16_t short_addr, uint8_t &x, uint8_t &y, uint8_t &z) {
if (short_addr == 0) {
x = global_wave_.x;
y = global_wave_.y;
z = global_wave_.z;
return 0;
}
auto iter = wave_map_.find(short_addr);
if (iter == wave_map_.end()) {
x = global_wave_.x;
y = global_wave_.y;
z = global_wave_.z;
return 0;
}
x = iter->second.x;
y = iter->second.y;
z = iter->second.z;
return 0;
}
void WaveFeatureSetting::SetWaveCfg(uint16_t short_addr, uint8_t x, uint8_t y, uint8_t z) {
bool need_submit = false;
if (short_addr == 0) {
if (global_wave_.x == x && global_wave_.y == y && global_wave_.z == z) {
return;
}
need_submit = true;
global_wave_.x = x;
global_wave_.y = y;
global_wave_.z = z;
} else {
auto iter = wave_map_.find(short_addr);
if (iter == wave_map_.end()) {
FeatureEntryPrivateCfg cfg;
cfg.x = x;
cfg.y = y;
cfg.z = z;
wave_map_[short_addr] = cfg;
need_submit = true;
} else {
if (iter->second.x == x && iter->second.y == y && iter->second.z == z) {
return;
}
iter->second.x = x;
iter->second.y = y;
iter->second.z = z;
need_submit = true;
}
}
if (need_submit) {
WriteWaveCfgFile();
}
}
void WaveFeatureSetting::SetAllWaveCfg(std::vector<FeatureEntryUploadCfg> cfg) {
eigen_map_.clear();
for (auto item : cfg) {
if (item.short_addr == 0) {
global_wave_.short_addr = 0;
global_wave_.x = item.x;
global_wave_.y = item.y;
global_wave_.z = item.z;
} else {
FeatureEntryPrivateCfg entry;
entry.x = item.x;
entry.y = item.y;
entry.z = item.z;
wave_map_[item.short_addr] = entry;
}
}
WriteWaveCfgFile();
}
int WaveFeatureSetting::GetAllWaveCfg(std::vector<FeatureEntryUploadCfg> &cfg) {
cfg.clear();
cfg.push_back(global_wave_);
for (auto item : wave_map_) {
FeatureEntryUploadCfg current;
current.short_addr = item.first;
current.x = item.second.x;
current.y = item.second.y;
current.z = item.second.z;
cfg.push_back(current);
}
return 0;
}
void WaveFeatureSetting::RemoveWaveCfg(uint16_t short_addr) {
auto iter = wave_map_.find(short_addr);
if (iter == wave_map_.end()) {
return;
}
wave_map_.erase(short_addr);
WriteWaveCfgFile();
}
void WaveFeatureSetting::RemoveAllWaveCfg() {
std::string clear_cmd = "rm -rf ";
clear_cmd.append(WAVE_FILTER_CFG);
system(clear_cmd.c_str());
}

View File

@ -0,0 +1,56 @@
#ifndef WAVE_FEATURE_SET_HPP_
#define WAVE_FEATURE_SET_HPP_
#include <iostream>
#include <map>
#include <unordered_set>
#include <vector>
#include <stdint.h>
#include <boost/container/detail/singleton.hpp>
#include <json/json.h>
#define FEATURE_FILTER_CFG "/opt/configenv/feature_filter.json"
#define WAVE_FILTER_CFG "/opt/configenv/wave_filter.json"
typedef struct {
uint16_t short_addr; // 全局配置的短地址写0
uint8_t x, y, z;
} FeatureEntryUploadCfg;
typedef struct {
uint8_t x, y, z;
} FeatureEntryPrivateCfg;
class WaveFeatureSetting {
public:
WaveFeatureSetting();
// Feature set
int GetFeatureCfg(uint16_t short_addr, uint8_t &x, uint8_t &y, uint8_t &z); // 获取单个
void SetFeatureCfg(uint16_t short_addr, uint8_t x, uint8_t y, uint8_t z); // 设置单个传感器
void SetAllFeatureCfg(std::vector<FeatureEntryUploadCfg> cfg); // 设置所有的
int GetAllFeatureCfg(std::vector<FeatureEntryUploadCfg> &cfg); // 获取所有的
void RemoveFeatureCfg(uint16_t short_addr);
void RemoveAllFeatureCfg();
// Wave set
int GetWaveCfg(uint16_t short_addr, uint8_t &x, uint8_t &y, uint8_t &z); // 获取单个
void SetWaveCfg(uint16_t short_addr, uint8_t x, uint8_t y, uint8_t z); // 设置单个传感器
void SetAllWaveCfg(std::vector<FeatureEntryUploadCfg> cfg); // 设置所有的
int GetAllWaveCfg(std::vector<FeatureEntryUploadCfg> &cfg); // 获取所有的
void RemoveWaveCfg(uint16_t short_addr);
void RemoveAllWaveCfg();
private:
void WriteFeatureCfgFile();
FeatureEntryUploadCfg global_feature_;
std::map<uint16_t, FeatureEntryPrivateCfg> eigen_map_;
void WriteWaveCfgFile();
FeatureEntryUploadCfg global_wave_;
std::map<uint16_t, FeatureEntryPrivateCfg> wave_map_;
};
typedef boost::container::dtl::singleton_default<WaveFeatureSetting> wave_feature_set_inst;
#endif // WAVE_FEATURE_SET_HPP_

View File

@ -52,11 +52,12 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (flag == 1) {
zlog_info(zct, "DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag);
}
if (bSendTimeStamp) //波形处理中
return;
uint8_t Feature_x,Feature_y,Feature_z;
char *end_ptr;
uint16_t u_short_addr = strtol(buf, &end_ptr, 16);
wave_feature_set_inst::instance().GetFeatureCfg(u_short_addr,Feature_x,Feature_y,Feature_z);
std::string strShortAddr = std::string(buf);
zlog_info(zct, "zigbeeShortAddr='%s'", strShortAddr.c_str());
zlog_info(zct, "zigbeeShortAddr='%s',Feature_x = %d,Feature_y = %d,Feature_z = %d", strShortAddr.c_str(),Feature_x,Feature_y,Feature_z);
char getLongAddr_sql[32] = {0};
//根据数据包中的传感器的短地址获取数据库中长地址MAC在下面判断该传感器是否存在如果不存在则把数据包丢弃
sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", strShortAddr.c_str());
@ -343,7 +344,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
valNodeFeature["Phase3"] = dataDymX.Phase3;
valNodeFeature["Phase4"] = dataDymX.Phase4;
valNodeFeature["timeStamp"] = nowTimetamp;
valNodeData.append(valNodeFeature);
if (Feature_x)
{
valNodeData.append(valNodeFeature);
}
DataRecvDym dataDymY;
DataExtract(pRecvData, 34, lowbit, n);
@ -430,7 +434,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
valNodeFeature["Phase3"] = dataDymY.Phase3;
valNodeFeature["Phase4"] = dataDymY.Phase4;
valNodeFeature["timeStamp"] = nowTimetamp;
valNodeData.append(valNodeFeature);
if (Feature_y)
{
valNodeData.append(valNodeFeature);
}
DataRecvDym dataDymZ;
DataExtract(pRecvData, 52, lowbit, n);
@ -527,7 +534,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
valNodeFeature["Phase3"] = dataDymZ.Phase3;
valNodeFeature["Phase4"] = dataDymZ.Phase4;
valNodeFeature["timeStamp"] = nowTimetamp;
valNodeData.append(valNodeFeature);
if (Feature_z)
{
valNodeData.append(valNodeFeature);
}
memset(whereCon, 0, 1024);
sprintf(whereCon, "MeasurementID='%s'", strMeasurementID.c_str());

View File

@ -9,6 +9,8 @@
#include <zlog.h>
#include "common/common_func.hpp"
#include "minilzo/minilzo.h"
#include "scheduler/wave_feature_set.hpp"
extern zlog_category_t* zct;
extern zlog_category_t* zbt;
@ -560,13 +562,20 @@ int Uart::TaskResp(ScheduleTask scheduleTask){
{
UpdateData[7] = UINT16_LOW(scheduleTask.duration);
UpdateData[8] = UINT16_HIGH(scheduleTask.duration);
}
if (scheduleTask.cmd == MEAS_EVAL)
}else if (scheduleTask.cmd == MEAS_EVAL)
{
UpdateData[9] = UINT32_LOW_2(scheduleTask.timeStamp);
UpdateData[10] = UINT32_LOW_1(scheduleTask.timeStamp);
UpdateData[11] = UINT32_HIGH_2(scheduleTask.timeStamp);
UpdateData[12] = UINT32_HIGH_1(scheduleTask.timeStamp);
}else if (scheduleTask.cmd == WAVE_CMD)
{
uint8_t x,y,z;
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
UpdateData[17] = (x^1) & 0xFF;
UpdateData[18] = (y^1) & 0xFF;
UpdateData[19] = (z^1) & 0xFF;
}
unsigned char tmp = 0x00;
for (int k = 0; k < 99; k++) {