已完成上位机通信代码结构优化

This commit is contained in:
zjk
2025-05-14 21:01:57 +08:00
parent 18f00d70d4
commit b7a624334e
24 changed files with 647 additions and 309 deletions
@@ -0,0 +1,39 @@
#ifndef UEXTERNCONM_SETPMSYS_H
#define UEXTERNCONM_SETPMSYS_H
#include <string>
#include "../loguru.hpp"
#define DB_TO_PM_SETPMSYS "uExternComm_setPowerSystem_cmd"
class uExternComm_setPowerSystemMsg
{
private:
public:
std::string key = "uExternComm_setPowerSystem_cmd";
uExternComm_setPowerSystemMsg(/* args */){};
~uExternComm_setPowerSystemMsg(){};
int getSetPMSys(const std::string& key, const std::string& msg)
{
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;
return -1;
}
// 检查并读取电源系统设置
if (root.isMember("powerCmd_uint8") && root["powerCmd_uint8"].isUInt()) {
return root["powerCmd_uint8"].asUInt();
} else {
LOG_F(WARNING, "缺少或类型不匹配: powerCmd_uint8");
return -1;
}
}
};
#endif