add codes for update and upgrade.
This commit is contained in:
parent
d1b714be78
commit
202da28673
@ -314,6 +314,64 @@ long SensorScheduler::CalcNextTimestamp(int id) {
|
|||||||
return available_ts;
|
return available_ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SensorScheduler::UpdateSensorConfig(int short_addr) {
|
||||||
|
int id = 0;
|
||||||
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
|
if (iter == short_addr_map_.end()) {
|
||||||
|
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
id = iter->second;
|
||||||
|
}
|
||||||
|
if (update_.count(id) > 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
update_.insert(id);
|
||||||
|
UpdateConfigFile();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SensorScheduler::UpdateConfigResult(int short_addr, int result) {
|
||||||
|
int id = 0;
|
||||||
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
|
if (iter == short_addr_map_.end()) {
|
||||||
|
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
id = iter->second;
|
||||||
|
}
|
||||||
|
if (result != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
update_.erase(id);
|
||||||
|
UpdateConfigFile();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SensorScheduler::UpgradeSensor(int short_addr, std::string sensor_type, int hw_version,
|
||||||
|
std::string current_sw_version, std::string upgrade_sw_version) {
|
||||||
|
int id = 0;
|
||||||
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
|
if (iter == short_addr_map_.end()) {
|
||||||
|
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
id = iter->second;
|
||||||
|
}
|
||||||
|
UpgradeInfo info;
|
||||||
|
info.try_times = 0;
|
||||||
|
info.sensor_type = sensor_type;
|
||||||
|
info.hw_version = hw_version;
|
||||||
|
info.current_sw_version = current_sw_version;
|
||||||
|
info.upgrade_sw_version = upgrade_sw_version;
|
||||||
|
long ts = GetLocalTs();
|
||||||
|
info.submit_time = GetUTCTime(ts);
|
||||||
|
upgrade_[id] = info;
|
||||||
|
UpdateUpgradeFile();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int SensorScheduler::GetAvailableId(int short_addr) {
|
int SensorScheduler::GetAvailableId(int short_addr) {
|
||||||
int max_support_sensor[128] = {0};
|
int max_support_sensor[128] = {0};
|
||||||
for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) {
|
for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) {
|
||||||
@ -463,9 +521,27 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SensorScheduler::Config(int eigen_value_send_interval, int wave_form_send_interval,
|
int SensorScheduler::UpgradeResult(int short_addr, int result) {
|
||||||
int eigen_value_send_duration, int wave_form_send_duration,
|
int id = 0;
|
||||||
int max_sensor_num) {
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
|
if (iter == short_addr_map_.end()) {
|
||||||
|
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
id = iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == kUpgradeSuccess ||
|
||||||
|
result == kProductTypeMismatch ||
|
||||||
|
result == kZigbeeHWMismatch ||
|
||||||
|
result == kUpgradeDoneBefore) {
|
||||||
|
upgrade_.erase(id);
|
||||||
|
UpdateUpgradeFile();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SensorScheduler::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) {
|
||||||
if (!support_modification_) {
|
if (!support_modification_) {
|
||||||
zlog_warn(zct, "not support modification");
|
zlog_warn(zct, "not support modification");
|
||||||
return 1;
|
return 1;
|
||||||
@ -580,3 +656,38 @@ std::string SensorScheduler::GetUTCTime(long ts) {
|
|||||||
std::string world_time = str;
|
std::string world_time = str;
|
||||||
return world_time;
|
return world_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorScheduler::UpdateConfigFile() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorScheduler::UpdateUpgradeFile() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@ -24,6 +24,15 @@ typedef enum {
|
|||||||
kScheduleWrongTime = 6
|
kScheduleWrongTime = 6
|
||||||
} ScheduleResult;
|
} ScheduleResult;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kUpgradeSuccess = 0, // 成功
|
||||||
|
kProductTypeMismatch = 1, // 包有问题,不再重试
|
||||||
|
kZigbeeHWMismatch = 2, // 包有问题,不再重试
|
||||||
|
kTransmitFileCrcError = 3, // 此返回值时,要重试
|
||||||
|
kRecvDataLenError = 4, // 此返回值时,要重试
|
||||||
|
kUpgradeDoneBefore = 5 // 当前就是这个版本,不需要升级了
|
||||||
|
} FirmFileCheckResult;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int try_times;
|
int try_times;
|
||||||
std::string sensor_type;
|
std::string sensor_type;
|
||||||
@ -49,6 +58,29 @@ public:
|
|||||||
long GetBaseTimestamp(int id);
|
long GetBaseTimestamp(int id);
|
||||||
long CalcNextTimestamp(int id);
|
long CalcNextTimestamp(int id);
|
||||||
|
|
||||||
|
// 当有传感器需要更新配置时调用
|
||||||
|
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 Config(int eigen_value_send_interval, int wave_form_send_interval,
|
||||||
int eigen_value_send_duration, int wave_form_send_duration,
|
int eigen_value_send_duration, int wave_form_send_duration,
|
||||||
int max_sensor_num);
|
int max_sensor_num);
|
||||||
@ -76,6 +108,8 @@ public:
|
|||||||
int GetAvailableId(int short_addr);
|
int GetAvailableId(int short_addr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void UpdateUpgradeFile();
|
||||||
|
void UpdateConfigFile();
|
||||||
|
|
||||||
// user config
|
// user config
|
||||||
int eigen_value_send_interval_;
|
int eigen_value_send_interval_;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user