重构了与DB的交互逻辑,以及与任务\上位机指令的消息,使用新的loguru库进行日志管理

This commit is contained in:
zjk
2025-04-20 22:42:28 +08:00
parent c5e28cee54
commit 06226b6704
35 changed files with 5430 additions and 175 deletions
+44
View File
@@ -1,12 +1,16 @@
#include "UpperCommManager.h"
#include "PowerManger.h"
#include "driver.h"
#include "PowerManagerFsm.hpp"
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {}
bool UpperCommManager::processUpperMsg(const string& key, const string& strJson) {
if(key == DB_TO_PM_MSCMD) {
m_pm->m_msCmd = getMasterControlCmd(key, strJson);
cout << "m_msCmd: " << endl;
MasterCommandEvent event;
PowerManagerFsm::dispatch(event);
return true;
}
else if(key == DB_TO_PM_EQUIPMENTCMD) {
@@ -21,6 +25,10 @@ bool UpperCommManager::processUpperMsg(const string& key, const string& strJson)
m_pm->m_depth = getDeepth(key, strJson);
return true;
}
else if(key == DB_TO_PM_MISSION) {
m_pm->m_missionState = getMission(key, strJson);
return true;
}
std::cout << "Unknown key: " << key << std::endl;
return false;
}
@@ -89,6 +97,42 @@ const int UpperCommManager::getDeepth(const std::string& key, const std::string&
return deepth;
}
MissionState UpperCommManager::getMission(const std::string& key, const std::string& msg) {
MissionState mission;
Json::Value root;
Json::CharReaderBuilder builder;
JSONCPP_STRING errs;
// 解析JSON字符串
std::istringstream stream(msg);
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
std::cerr << "JSON解析失败: " << errs << std::endl;
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
return mission;
}
// 提取taskType_str
if (root.isMember("taskType_str") && root["taskType_str"].isString()) {
mission.type = TaskType::fromString(root["taskType_str"].asString());
LOG_F(INFO, "taskType: %d", mission.type, root["taskType_str"].asString());
}
// 提取balanceEnabled_bool
if (root.isMember("balanceEnabled_bool") && root["balanceEnabled_bool"].isBool()) {
mission.enableBuoyancyAdjustment = root["balanceEnabled_bool"].asBool();
LOG_F(INFO, "balanceEnabled_bool: %d", mission.enableBuoyancyAdjustment);
}
// 提取bowRudderUnfold_bool
if (root.isMember("bowRudderUnfold_bool") && root["bowRudderUnfold_bool"].isBool()) {
mission.enableBowRudder = root["bowRudderUnfold_bool"].asBool();
LOG_F(INFO, "bowRudderUnfold_bool: %d", mission.enableBowRudder);
}
return mission;
}
const std::string UpperCommManager::getCurrentEquState(DriverTable& driver)
{
return m_pm->m_driver.saveDriverTableToJson(&driver);