重构了与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
+9 -9
View File
@@ -9,6 +9,7 @@
#include "MBUtils.h"
#include "ACTable.h"
#include "PowerManger.h"
#include "loguru.hpp"
#include <memory>
using namespace std;
@@ -83,7 +84,7 @@ bool PowerManger::OnNewMail(MOOSMSG_LIST &NewMail)
//处理上位机发送的控制指令
if(!m_upperCommManager->processUpperMsg(key,strJson))
{
cout << "processUpperMsg failed" << endl;
LOG_F(ERROR, "上位机消息处理错误: %s", key.c_str());
}
#if 0 // Keep these around just for template
@@ -96,8 +97,8 @@ bool PowerManger::OnNewMail(MOOSMSG_LIST &NewMail)
bool mstr = msg.IsString();
#endif
if(key == "FOO")
cout << "great!";
if(key == "FOO")
LOG_F(INFO, "Received FOO message");
else if(key != "APPCAST_REQ") // handled by AppCastingMOOSApp
reportRunWarning("Unhandled Mail: " + key);
@@ -193,6 +194,8 @@ void PowerManger::registerVariables()
Register(DB_TO_PM_MSCMD, 0);
Register(DB_TO_PM_EQUIPMENTCMD, 0);
Register(DB_TO_PM_SUBDISSTATE, 0);
Register(DB_TO_PM_MISSION,0);
Register(DB_TO_PM_DEEPTH,0);
}
@@ -266,14 +269,11 @@ int PowerManger::checkError()
}
void PowerManger::printState(const std::string& stateName, const std::string& desp){
cout << MOOS::ConsoleColours::Yellow() << "STATE " << stateName << " " << MOOS::ConsoleColours::reset();
cout << MOOS::ConsoleColours::Blue() << " -> " << MOOS::ConsoleColours::reset();
// 检查desp是否有“故障”
if (desp.find("故障") != string::npos) {
cout << MOOS::ConsoleColours::Red() << desp << MOOS::ConsoleColours::reset() << endl;
return;
LOG_F(ERROR, "STATE %s -> %s", stateName.c_str(), desp.c_str());
} else {
LOG_F(INFO, "STATE %s -> %s", stateName.c_str(), desp.c_str());
}
cout << MOOS::ConsoleColours::Green() << desp << MOOS::ConsoleColours::reset() << endl;
}