diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index 3199502..bbc99d0 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -909,7 +909,7 @@ int SensorScheduler::WriteScheduleCfg(long &ts, std::string &world_time) { 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 available_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秒 // 一次特征值发送时长为2秒,波形发送时长为60秒,所有特征值在特征值发送间隔的第1分钟中的第3秒至第57秒全部完成 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) { - if (max_sensor_num <= 0) { - error_msg = "max_sensor_num:" + std::to_string(max_sensor_num) + " must bigger than 0"; - zlog_error(zbt, "%s", error_msg.c_str()); - return 1; - } + // if (max_sensor_num <= 0) { + // error_msg = "max_sensor_num:" + std::to_string(max_sensor_num) + " must bigger than 0"; + // zlog_error(zbt, "%s", error_msg.c_str()); + // return 1; + // } if (2 > eigen_value_send_interval) { 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; } - if (max_sensor_num * 60 * 2 > wave_form_send_interval) { // xy, z分开发送 - 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); - zlog_error(zbt, "%s", error_msg.c_str()); - return 3; - } + // if (max_sensor_num * 60 * 2 > wave_form_send_interval) { // xy, z分开发送 + // 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); + // zlog_error(zbt, "%s", error_msg.c_str()); + // return 3; + // } 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) + @@ -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 slice_per_eigen_value_interval = rest_duration / 60; available_slice = wave_form_send_interval / eigen_value_send_interval * slice_per_eigen_value_interval; - free_slice = available_slice - max_sensor_num * 2; - if (free_slice < 0) { - error_msg = "invalid config, available slice:" + std::to_string(available_slice) + ", required slice:" + std::to_string(max_sensor_num); + // free_slice = available_slice - max_sensor_num * 2; + max_sensor_num = available_slice / 2; + // 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()); return 5; } diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index e38792b..f1280c2 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -76,10 +76,10 @@ public: int UpdateConfigResult(uint16_t short_addr, int result); 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 max_sensor_num, int &available_slice, int &free_slice, + 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 &wave_resend_num, diff --git a/scheduler/status_mgr.cpp b/scheduler/status_mgr.cpp index 3d897be..830c242 100644 --- a/scheduler/status_mgr.cpp +++ b/scheduler/status_mgr.cpp @@ -1,118 +1,118 @@ -#include "status_mgr.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -extern zlog_category_t *zbt; - -ScheduleStatus get_schedule_status() { - std::ifstream status_file("/opt/configenv/status.json"); - if (!status_file.good()) { - zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json"); - return kScheduleStatusNormal; - } - Json::Value json_data; - Json::Reader reader; - - if (reader.parse(status_file, json_data, false)) { - std::string status = json_data["status"].asString(); - - if (status == "debug") { - status_file.close(); - return kScheduleStatusDebug; - } else if (status == "normal") { - status_file.close(); - return kScheduleStatusNormal; - } else if (status == "upgrade") { - status_file.close(); - return kScheduleStatusUpgrade; - } - } - status_file.close(); - return kScheduleStatusNormal; -} - -void set_schedule_status(ScheduleStatus status) { - std::string status_str; - switch (status) { - case kScheduleStatusNormal: - status_str = "normal"; - break; - case kScheduleStatusDebug: - status_str = "debug"; - break; - case kScheduleStatusUpgrade: - status_str = "upgrade"; - break; - } - - // Write to status.json - Json::Value json_data; - json_data["status"] = status_str; - - std::ofstream status_file("/opt/configenv/status.json"); - if (status_file.is_open()) { - status_file << json_data; - status_file.close(); - } else { - std::cerr << "Unable to open status.json for writing" << std::endl; - } - - // Append to status_history.json - Json::Value history_data; - std::ifstream history_file("/opt/configenv/status_history.json"); - if (history_file.good()) { - Json::Reader reader; - reader.parse(history_file, history_data, false); - history_file.close(); - } - - // Get the current time - auto now = std::chrono::system_clock::now(); - auto now_c = std::chrono::system_clock::to_time_t(now); - std::tm* now_tm = std::localtime(&now_c); - - // Format time as "YYYY-MM-DD HH:MM:SS" - char time_buffer[20]; - std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", now_tm); - - // Add the new status and time to history - Json::Value new_entry; - new_entry["status"] = status_str; - new_entry["time"] = time_buffer; - history_data.append(new_entry); - - // Write back to status_history.json - std::ofstream history_file_out("/opt/configenv/status_history.json"); - if (history_file_out.is_open()) { - history_file_out << history_data; - history_file_out.close(); - } else { - std::cerr << "Unable to open status_history.json for writing" << std::endl; - } -} - -std::string get_status_desc(ScheduleStatus status) { - std::string status_str; - switch (status) { - case kScheduleStatusNormal: - status_str = "normal"; - break; - case kScheduleStatusDebug: - status_str = "debug"; - break; - case kScheduleStatusUpgrade: - status_str = "upgrade"; - break; - default: - status_str = "normal"; - zlog_error(zbt, "fail to get status desc:%d", status); - break; - } - return status_str; -} +#include "status_mgr.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +extern zlog_category_t *zbt; + +ScheduleStatus get_schedule_status() { + std::ifstream status_file("/opt/configenv/status.json"); + if (!status_file.good()) { + zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json"); + return kScheduleStatusNormal; + } + Json::Value json_data; + Json::Reader reader; + + if (reader.parse(status_file, json_data, false)) { + std::string status = json_data["status"].asString(); + + if (status == "debug") { + status_file.close(); + return kScheduleStatusDebug; + } else if (status == "normal") { + status_file.close(); + return kScheduleStatusNormal; + } else if (status == "upgrade") { + status_file.close(); + return kScheduleStatusUpgrade; + } + } + status_file.close(); + return kScheduleStatusNormal; +} + +void set_schedule_status(ScheduleStatus status) { + std::string status_str; + switch (status) { + case kScheduleStatusNormal: + status_str = "normal"; + break; + case kScheduleStatusDebug: + status_str = "debug"; + break; + case kScheduleStatusUpgrade: + status_str = "upgrade"; + break; + } + + // Write to status.json + Json::Value json_data; + json_data["status"] = status_str; + + std::ofstream status_file("/opt/configenv/status.json"); + if (status_file.is_open()) { + status_file << json_data; + status_file.close(); + } else { + std::cerr << "Unable to open status.json for writing" << std::endl; + } + + // Append to status_history.json + Json::Value history_data; + std::ifstream history_file("/opt/configenv/status_history.json"); + if (history_file.good()) { + Json::Reader reader; + reader.parse(history_file, history_data, false); + history_file.close(); + } + + // Get the current time + auto now = std::chrono::system_clock::now(); + auto now_c = std::chrono::system_clock::to_time_t(now); + std::tm* now_tm = std::localtime(&now_c); + + // Format time as "YYYY-MM-DD HH:MM:SS" + char time_buffer[20]; + std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", now_tm); + + // Add the new status and time to history + Json::Value new_entry; + new_entry["status"] = status_str; + new_entry["time"] = time_buffer; + history_data.append(new_entry); + + // Write back to status_history.json + std::ofstream history_file_out("/opt/configenv/status_history.json"); + if (history_file_out.is_open()) { + history_file_out << history_data; + history_file_out.close(); + } else { + std::cerr << "Unable to open status_history.json for writing" << std::endl; + } +} + +std::string get_status_desc(ScheduleStatus status) { + std::string status_str; + switch (status) { + case kScheduleStatusNormal: + status_str = "normal"; + break; + case kScheduleStatusDebug: + status_str = "debug"; + break; + case kScheduleStatusUpgrade: + status_str = "upgrade"; + break; + default: + status_str = "normal"; + zlog_error(zbt, "fail to get status desc:%d", status); + break; + } + return status_str; +} diff --git a/scheduler/status_mgr.hpp b/scheduler/status_mgr.hpp index 0fe99c3..141a81c 100644 --- a/scheduler/status_mgr.hpp +++ b/scheduler/status_mgr.hpp @@ -1,23 +1,23 @@ -#ifndef STATUS_MGR_HPP_ -#define STATUS_MGR_HPP_ -#include -/** - * @brief 对调度状态切换进行管理,并对调度切换时历史进行记录 - * - * @version 0.1 - * @author pandx (dxpan2002@163.com) - * @date 2026-01-21 - * @copyright Copyright (c) 2026 - */ - -typedef enum { - kScheduleStatusNormal = 1, - kScheduleStatusDebug = 2, - kScheduleStatusUpgrade = 3 -} ScheduleStatus; - -ScheduleStatus get_schedule_status(); -void set_schedule_status(ScheduleStatus status); -std::string get_status_desc(ScheduleStatus status); - +#ifndef STATUS_MGR_HPP_ +#define STATUS_MGR_HPP_ +#include +/** + * @brief 对调度状态切换进行管理,并对调度切换时历史进行记录 + * + * @version 0.1 + * @author pandx (dxpan2002@163.com) + * @date 2026-01-21 + * @copyright Copyright (c) 2026 + */ + +typedef enum { + kScheduleStatusNormal = 1, + kScheduleStatusDebug = 2, + kScheduleStatusUpgrade = 3 +} ScheduleStatus; + +ScheduleStatus get_schedule_status(); +void set_schedule_status(ScheduleStatus status); +std::string get_status_desc(ScheduleStatus status); + #endif \ No newline at end of file diff --git a/uart/uart.cpp b/uart/uart.cpp index 2e4f0a1..f97e521 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -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]); sprintf(sensor_rssi, "%02d", pData[22] & 0xFF); }else{ - int ret = 0;//= WaveSendCondition(shortAdd); + int ret = WaveSendCondition(shortAdd); if(ret == 1){ zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd); scheduler::instance().WaveSuccess(ushortAdd,true); diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 6864f77..3fc5d3e 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -63,7 +63,7 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s if (res_static.size() > 0){ int zigbeeSignal = atoi(res_static[6].c_str()); int zigbeeSignalNode = atoi(res_static[11].c_str()); - float standardRate = 5000.0f; //5kB/s + float standardRate = 5.0f; //5kB/s float actualRate = 0.0f; if (dataStatic.nodeSendTime > 0){ actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位:KB/s