modify bugs

This commit is contained in:
zhangsheng 2026-03-09 13:58:17 +08:00
parent c0d609b51a
commit 44f506de9b
6 changed files with 166 additions and 160 deletions

View File

@ -909,7 +909,7 @@ int SensorScheduler::WriteScheduleCfg(long &ts, std::string &world_time) {
return 0; return 0;
} }
int SensorScheduler::Config(int eigen_value_send_interval, int wave_form_send_interval, int max_sensor_num, int SensorScheduler::Config(int eigen_value_send_interval, int wave_form_send_interval, int &max_sensor_num,
int wave_resend_num, std::string &error_msg) { int wave_resend_num, std::string &error_msg) {
int available_slice = 0; int available_slice = 0;
int free_slice = 0; int free_slice = 0;
@ -952,13 +952,13 @@ int SensorScheduler::Config(int eigen_value_send_interval, int wave_form_send_in
// 特征值发送间隔300秒波形发送间隔为7200秒 // 特征值发送间隔300秒波形发送间隔为7200秒
// 一次特征值发送时长为2秒波形发送时长为60秒所有特征值在特征值发送间隔的第1分钟中的第3秒至第57秒全部完成 // 一次特征值发送时长为2秒波形发送时长为60秒所有特征值在特征值发送间隔的第1分钟中的第3秒至第57秒全部完成
int SensorScheduler::CalcAvailableSlice(int eigen_value_send_interval, int wave_form_send_interval, int SensorScheduler::CalcAvailableSlice(int eigen_value_send_interval, int wave_form_send_interval,
int max_sensor_num, int &available_slice, int &free_slice, int &max_sensor_num, int &available_slice, int &free_slice,
std::string &error_msg) { std::string &error_msg) {
if (max_sensor_num <= 0) { // if (max_sensor_num <= 0) {
error_msg = "max_sensor_num:" + std::to_string(max_sensor_num) + " must bigger than 0"; // error_msg = "max_sensor_num:" + std::to_string(max_sensor_num) + " must bigger than 0";
zlog_error(zbt, "%s", error_msg.c_str()); // zlog_error(zbt, "%s", error_msg.c_str());
return 1; // return 1;
} // }
if (2 > eigen_value_send_interval) { if (2 > eigen_value_send_interval) {
error_msg = "invalid max_sensor_num:" + std::to_string(max_sensor_num) + error_msg = "invalid max_sensor_num:" + std::to_string(max_sensor_num) +
@ -967,12 +967,12 @@ int SensorScheduler::CalcAvailableSlice(int eigen_value_send_interval, int wave_
return 2; return 2;
} }
if (max_sensor_num * 60 * 2 > wave_form_send_interval) { // xy, z分开发送 // if (max_sensor_num * 60 * 2 > wave_form_send_interval) { // xy, z分开发送
error_msg = "invalid wave_form_send_duration:" + std::to_string(60) + // error_msg = "invalid wave_form_send_duration:" + std::to_string(60) +
"* 2 * max_sensor_num:" + std::to_string(max_sensor_num) + " > wave_form_send_interval:" + std::to_string(wave_form_send_interval); // "* 2 * max_sensor_num:" + std::to_string(max_sensor_num) + " > wave_form_send_interval:" + std::to_string(wave_form_send_interval);
zlog_error(zbt, "%s", error_msg.c_str()); // zlog_error(zbt, "%s", error_msg.c_str());
return 3; // return 3;
} // }
if (wave_form_send_interval % eigen_value_send_interval != 0) { if (wave_form_send_interval % eigen_value_send_interval != 0) {
error_msg = "wave_form_send_interval:" + std::to_string(wave_form_send_interval) + " %% eigen_value_send_interval:" + std::to_string(eigen_value_send_interval) + error_msg = "wave_form_send_interval:" + std::to_string(wave_form_send_interval) + " %% eigen_value_send_interval:" + std::to_string(eigen_value_send_interval) +
@ -985,9 +985,15 @@ int SensorScheduler::CalcAvailableSlice(int eigen_value_send_interval, int wave_
int rest_duration = eigen_value_send_interval - total_eigen_value_send_duration; int rest_duration = eigen_value_send_interval - total_eigen_value_send_duration;
int slice_per_eigen_value_interval = rest_duration / 60; int slice_per_eigen_value_interval = rest_duration / 60;
available_slice = wave_form_send_interval / eigen_value_send_interval * slice_per_eigen_value_interval; available_slice = wave_form_send_interval / eigen_value_send_interval * slice_per_eigen_value_interval;
free_slice = available_slice - max_sensor_num * 2; // free_slice = available_slice - max_sensor_num * 2;
if (free_slice < 0) { max_sensor_num = available_slice / 2;
error_msg = "invalid config, available slice:" + std::to_string(available_slice) + ", required slice:" + std::to_string(max_sensor_num); // if (free_slice < 0) {
// error_msg = "invalid config, available slice:" + std::to_string(available_slice) + ", required slice:" + std::to_string(max_sensor_num*2);
// zlog_error(zbt, "%s", error_msg.c_str());
// return 5;
// }
if (available_slice <= 0) {
error_msg = "invalid config, available slice:" + std::to_string(available_slice) + ", required slice:" + std::to_string(max_sensor_num*2);
zlog_error(zbt, "%s", error_msg.c_str()); zlog_error(zbt, "%s", error_msg.c_str());
return 5; return 5;
} }

View File

@ -76,10 +76,10 @@ public:
int UpdateConfigResult(uint16_t short_addr, int result); int UpdateConfigResult(uint16_t 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 max_sensor_num, int wave_resend_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 CalcAvailableSlice(int eigen_value_send_interval, int wave_form_send_interval,
int max_sensor_num, int &available_slice, int &free_slice, int &max_sensor_num, int &available_slice, int &free_slice,
std::string &error_msg); std::string &error_msg);
int GetScheduleConfig(int &eigen_value_send_interval, int &wave_form_send_interval, int &wave_resend_num, int GetScheduleConfig(int &eigen_value_send_interval, int &wave_form_send_interval, int &wave_resend_num,

View File

@ -1,118 +1,118 @@
#include "status_mgr.hpp" #include "status_mgr.hpp"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <json/json.h> #include <json/json.h>
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <zlog.h> #include <zlog.h>
extern zlog_category_t *zbt; extern zlog_category_t *zbt;
ScheduleStatus get_schedule_status() { ScheduleStatus get_schedule_status() {
std::ifstream status_file("/opt/configenv/status.json"); std::ifstream status_file("/opt/configenv/status.json");
if (!status_file.good()) { if (!status_file.good()) {
zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json"); zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json");
return kScheduleStatusNormal; return kScheduleStatusNormal;
} }
Json::Value json_data; Json::Value json_data;
Json::Reader reader; Json::Reader reader;
if (reader.parse(status_file, json_data, false)) { if (reader.parse(status_file, json_data, false)) {
std::string status = json_data["status"].asString(); std::string status = json_data["status"].asString();
if (status == "debug") { if (status == "debug") {
status_file.close(); status_file.close();
return kScheduleStatusDebug; return kScheduleStatusDebug;
} else if (status == "normal") { } else if (status == "normal") {
status_file.close(); status_file.close();
return kScheduleStatusNormal; return kScheduleStatusNormal;
} else if (status == "upgrade") { } else if (status == "upgrade") {
status_file.close(); status_file.close();
return kScheduleStatusUpgrade; return kScheduleStatusUpgrade;
} }
} }
status_file.close(); status_file.close();
return kScheduleStatusNormal; return kScheduleStatusNormal;
} }
void set_schedule_status(ScheduleStatus status) { void set_schedule_status(ScheduleStatus status) {
std::string status_str; std::string status_str;
switch (status) { switch (status) {
case kScheduleStatusNormal: case kScheduleStatusNormal:
status_str = "normal"; status_str = "normal";
break; break;
case kScheduleStatusDebug: case kScheduleStatusDebug:
status_str = "debug"; status_str = "debug";
break; break;
case kScheduleStatusUpgrade: case kScheduleStatusUpgrade:
status_str = "upgrade"; status_str = "upgrade";
break; break;
} }
// Write to status.json // Write to status.json
Json::Value json_data; Json::Value json_data;
json_data["status"] = status_str; json_data["status"] = status_str;
std::ofstream status_file("/opt/configenv/status.json"); std::ofstream status_file("/opt/configenv/status.json");
if (status_file.is_open()) { if (status_file.is_open()) {
status_file << json_data; status_file << json_data;
status_file.close(); status_file.close();
} else { } else {
std::cerr << "Unable to open status.json for writing" << std::endl; std::cerr << "Unable to open status.json for writing" << std::endl;
} }
// Append to status_history.json // Append to status_history.json
Json::Value history_data; Json::Value history_data;
std::ifstream history_file("/opt/configenv/status_history.json"); std::ifstream history_file("/opt/configenv/status_history.json");
if (history_file.good()) { if (history_file.good()) {
Json::Reader reader; Json::Reader reader;
reader.parse(history_file, history_data, false); reader.parse(history_file, history_data, false);
history_file.close(); history_file.close();
} }
// Get the current time // Get the current time
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto now_c = std::chrono::system_clock::to_time_t(now); auto now_c = std::chrono::system_clock::to_time_t(now);
std::tm* now_tm = std::localtime(&now_c); std::tm* now_tm = std::localtime(&now_c);
// Format time as "YYYY-MM-DD HH:MM:SS" // Format time as "YYYY-MM-DD HH:MM:SS"
char time_buffer[20]; char time_buffer[20];
std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", now_tm); std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", now_tm);
// Add the new status and time to history // Add the new status and time to history
Json::Value new_entry; Json::Value new_entry;
new_entry["status"] = status_str; new_entry["status"] = status_str;
new_entry["time"] = time_buffer; new_entry["time"] = time_buffer;
history_data.append(new_entry); history_data.append(new_entry);
// Write back to status_history.json // Write back to status_history.json
std::ofstream history_file_out("/opt/configenv/status_history.json"); std::ofstream history_file_out("/opt/configenv/status_history.json");
if (history_file_out.is_open()) { if (history_file_out.is_open()) {
history_file_out << history_data; history_file_out << history_data;
history_file_out.close(); history_file_out.close();
} else { } else {
std::cerr << "Unable to open status_history.json for writing" << std::endl; std::cerr << "Unable to open status_history.json for writing" << std::endl;
} }
} }
std::string get_status_desc(ScheduleStatus status) { std::string get_status_desc(ScheduleStatus status) {
std::string status_str; std::string status_str;
switch (status) { switch (status) {
case kScheduleStatusNormal: case kScheduleStatusNormal:
status_str = "normal"; status_str = "normal";
break; break;
case kScheduleStatusDebug: case kScheduleStatusDebug:
status_str = "debug"; status_str = "debug";
break; break;
case kScheduleStatusUpgrade: case kScheduleStatusUpgrade:
status_str = "upgrade"; status_str = "upgrade";
break; break;
default: default:
status_str = "normal"; status_str = "normal";
zlog_error(zbt, "fail to get status desc:%d", status); zlog_error(zbt, "fail to get status desc:%d", status);
break; break;
} }
return status_str; return status_str;
} }

View File

@ -1,23 +1,23 @@
#ifndef STATUS_MGR_HPP_ #ifndef STATUS_MGR_HPP_
#define STATUS_MGR_HPP_ #define STATUS_MGR_HPP_
#include <string> #include <string>
/** /**
* @brief * @brief
* *
* @version 0.1 * @version 0.1
* @author pandx (dxpan2002@163.com) * @author pandx (dxpan2002@163.com)
* @date 2026-01-21 * @date 2026-01-21
* @copyright Copyright (c) 2026 * @copyright Copyright (c) 2026
*/ */
typedef enum { typedef enum {
kScheduleStatusNormal = 1, kScheduleStatusNormal = 1,
kScheduleStatusDebug = 2, kScheduleStatusDebug = 2,
kScheduleStatusUpgrade = 3 kScheduleStatusUpgrade = 3
} ScheduleStatus; } ScheduleStatus;
ScheduleStatus get_schedule_status(); ScheduleStatus get_schedule_status();
void set_schedule_status(ScheduleStatus status); void set_schedule_status(ScheduleStatus status);
std::string get_status_desc(ScheduleStatus status); std::string get_status_desc(ScheduleStatus status);
#endif #endif

View File

@ -505,7 +505,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]); tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]);
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF); sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
}else{ }else{
int ret = 0;//= WaveSendCondition(shortAdd); int ret = WaveSendCondition(shortAdd);
if(ret == 1){ if(ret == 1){
zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd); zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd);
scheduler::instance().WaveSuccess(ushortAdd,true); scheduler::instance().WaveSuccess(ushortAdd,true);

View File

@ -63,7 +63,7 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
if (res_static.size() > 0){ if (res_static.size() > 0){
int zigbeeSignal = atoi(res_static[6].c_str()); int zigbeeSignal = atoi(res_static[6].c_str());
int zigbeeSignalNode = atoi(res_static[11].c_str()); int zigbeeSignalNode = atoi(res_static[11].c_str());
float standardRate = 5000.0f; //5kB/s float standardRate = 5.0f; //5kB/s
float actualRate = 0.0f; float actualRate = 0.0f;
if (dataStatic.nodeSendTime > 0){ if (dataStatic.nodeSendTime > 0){
actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位KB/s actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位KB/s