优化消息代码
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#ifndef UEXTERCOMM_SETOPCONDITION_CMD_H
|
||||
#define UEXTERCOMM_SETOPCONDITION_CMD_H
|
||||
#include <string>
|
||||
#include "../loguru.hpp"
|
||||
#include "json/json.h"
|
||||
//外部通信消息
|
||||
#define DB_TO_PM_SETOPCONDITION "uExternComm_setOpCondition_cmd"
|
||||
|
||||
class uExternComm_setOpConditionMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
std::string key = "uExternComm_setOpCondition_cmd";
|
||||
uExternComm_setOpConditionMsg(/* args */){};
|
||||
~uExternComm_setOpConditionMsg(){};
|
||||
|
||||
int getSetOpCondition(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)) {
|
||||
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 检查并读取操作条件
|
||||
if (root.isMember("state_uint8") && root["state_uint8"].isUInt()) {
|
||||
return root["state_uint8"].asUInt();
|
||||
LOG_F(INFO, "上位机指令:opCondition: %d", root["state_uint8"].asUInt());
|
||||
} else {
|
||||
LOG_F(WARNING, "缺少或类型不匹配: opCondition");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user