优化消息代码
This commit is contained in:
Binary file not shown.
@@ -165,7 +165,9 @@ bool LowerCommManager::updatePoweSystemStates(){
|
||||
m_pm->m_pmCurrentState.ccustate = m_CcuCurrentState.data;
|
||||
// m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库
|
||||
//DEBUG
|
||||
coutMsg(m_CcuCurrentState);
|
||||
//写入文件
|
||||
std::ofstream outFile("ccuState.txt", std::ios::app);
|
||||
coutMsg(m_CcuCurrentState, outFile);
|
||||
msg_CcuStateFbMsg_Update_time = time;
|
||||
}
|
||||
if(!m_udpComm->m_qReceiveDisHighVolBusBuffer.empty())
|
||||
@@ -420,11 +422,11 @@ void LowerCommManager::coutMsg(const msg_CcuStateFbMsg& p, std::ostream& os){
|
||||
os << "仪表SOC (ins_soc): " << static_cast<int>(p.data.ins_soc) << "%\n";
|
||||
os << "动力SOC (dyn_soc): " << static_cast<int>(p.data.dyn_soc) << "%\n";
|
||||
|
||||
os << "仪表电池总能量 (ins_total_energy): " << p.data.ins_total_energy << " kWh\n";
|
||||
os << "动力电池总能量 (dyn_total_energy): " << p.data.dyn_total_energy << " kWh\n";
|
||||
os << "仪表电池总能量 (ins_total_energy): " << p.data.ins_total_energy * 0.1 << " kWh\n";
|
||||
os << "动力电池总能量 (dyn_total_energy): " << p.data.dyn_total_energy * 0.1 << " kWh\n";
|
||||
|
||||
os << "仪表输入功率 (ins_power_input): " << p.data.ins_power_input << " kW\n";
|
||||
os << "动力输入功率 (dyn_power_input): " << p.data.dyn_power_input << " kW\n";
|
||||
os << "仪表输入功率 (ins_power_input): " << p.data.ins_power_input * 0.1 << " kW\n";
|
||||
os << "动力输入功率 (dyn_power_input): " << p.data.dyn_power_input * 0.1 << " kW\n";
|
||||
|
||||
os << "仪表充电状态 (ins_charge_status): 0x" << std::hex << static_cast<int>(p.data.ins_charge_status) << "\n";
|
||||
os << "动力充电状态 (dyn_charge_status): 0x" << static_cast<int>(p.data.dyn_charge_status) << "\n";
|
||||
|
||||
@@ -47,6 +47,15 @@ PowerManger::PowerManger()
|
||||
//初始化控制指令
|
||||
initControlCmd();
|
||||
|
||||
//初始化UDP通信
|
||||
m_lowerCommManager = new LowerCommManager(this,IPORT,CCUPORT,CCUHOST);
|
||||
m_lowerCommManager->initUdpComm();
|
||||
m_lowerCommManager->startListenThread();
|
||||
|
||||
//初始化上位机通信
|
||||
m_upperCommManager = new UpperCommManager(this);
|
||||
//
|
||||
|
||||
//初始化数据库
|
||||
// string dbPath = "/home/zjk/project/H100/H100PowerManger/data/power_data.db";
|
||||
// m_db = new SQLiteDB(dbPath);
|
||||
@@ -129,6 +138,8 @@ bool PowerManger::Iterate()
|
||||
CycleTriggeredEvent cycleEvent;
|
||||
PowerManagerFsm::dispatch(cycleEvent);
|
||||
faultLevel = getFaultLevel();
|
||||
//打印信息大小
|
||||
cout << sizeof(m_CcuColCmd) << endl;
|
||||
if (m_ticker++ % 5 == 0)
|
||||
{
|
||||
m_CcuColCmd.heartbeat++;
|
||||
@@ -173,13 +184,7 @@ bool PowerManger::OnStartUp()
|
||||
}
|
||||
|
||||
registerVariables();
|
||||
//初始化UDP通信
|
||||
m_lowerCommManager = new LowerCommManager(this,IPORT,CCUPORT,CCUHOST);
|
||||
m_lowerCommManager->initUdpComm();
|
||||
m_lowerCommManager->startListenThread();
|
||||
|
||||
//初始化上位机通信
|
||||
m_upperCommManager = new UpperCommManager(this);
|
||||
|
||||
// 初始化状态机
|
||||
PowerManagerFsm::init(this);
|
||||
@@ -195,9 +200,11 @@ bool PowerManger::OnStartUp()
|
||||
void PowerManger::registerVariables()
|
||||
{
|
||||
AppCastingMOOSApp::RegisterVariables();
|
||||
// Register(DB_TO_PM_SUBDISSTATE, 0);
|
||||
|
||||
Register(DB_TO_PM_MSCMD, 0);
|
||||
Register(DB_TO_PM_EQUIPMENTCMD, 0);
|
||||
Register(DB_TO_PM_SUBDISSTATE, 0);
|
||||
Register(m_upperCommManager->m_secdistStateMsg.key_fb,0);
|
||||
Register(DB_TO_PM_MISSION,0);
|
||||
Register(DB_TO_PM_DEEPTH,0);
|
||||
Register(DB_TO_PM_SETOPCONDITION,0);
|
||||
|
||||
@@ -3,7 +3,24 @@
|
||||
#include "driver.h"
|
||||
#include "fsm/PowerManagerFsm.hpp"
|
||||
|
||||
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {};
|
||||
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {
|
||||
// 初始化消息结构体
|
||||
// uPower_equInsStateMsg m_equInsStateMsg;
|
||||
// uDevice_secdistStateMsg m_secdistStateMsg;
|
||||
// uPower_equStateMsg m_equStateMsg;
|
||||
// uPower_disSysStateMsg m_disSysStateMsg;
|
||||
// uPower_currentStateMsg m_currentStateMsg;
|
||||
// uPower_pmStateMsg m_pmStateMsg;
|
||||
// uPower_fcsStateMsg m_fcsStateMsg;
|
||||
// uPower_liBatStateMsg m_liBatStateMsg;
|
||||
|
||||
// //上位机订阅消息
|
||||
// uDevice_depthMsg m_depthMsg;
|
||||
// uExternComm_setOpConditionMsg m_setOpConditionMsg;
|
||||
m_secdistStateMsg = uDevice_secdistStateMsg();
|
||||
m_setOpConditionMsg = uExternComm_setOpConditionMsg();
|
||||
|
||||
};
|
||||
|
||||
bool UpperCommManager::processUpperMsg(const string& key, const string& strJson) {
|
||||
if(key == DB_TO_PM_MSCMD) {
|
||||
@@ -39,8 +56,13 @@ bool UpperCommManager::processUpperMsg(const string& key, const string& strJson)
|
||||
//m_pm->m_subDisSysState = m_pm->m_deviceState;
|
||||
return true;
|
||||
}
|
||||
else if(key == DB_TO_PM_DEEPTH) {
|
||||
m_pm->m_depth = getDeepth(key, strJson);
|
||||
// else if(key == DB_TO_PM_DEEPTH) {
|
||||
// m_pm->m_depth = getDeepth(key, strJson);
|
||||
// return true;
|
||||
// }
|
||||
else if(key == m_depthMsg.key)
|
||||
{
|
||||
m_pm->m_depth = m_depthMsg.getDepth(key, strJson);
|
||||
return true;
|
||||
}
|
||||
else if(key == DB_TO_PM_MISSION) {
|
||||
@@ -56,11 +78,15 @@ bool UpperCommManager::processUpperMsg(const string& key, const string& strJson)
|
||||
MasterCommandEvent event;
|
||||
PowerManagerFsm::dispatch(event);
|
||||
return true;
|
||||
} else if(key == DB_TO_PM_SETOPMODE) {
|
||||
m_pm->m_msCmd.modCMD = getSetOpMode(key, strJson);
|
||||
// } else if(key == DB_TO_PM_SETOPMODE) {
|
||||
// m_pm->m_msCmd.modCMD = getSetOpMode(key, strJson);
|
||||
// MasterCommandEvent event;
|
||||
// PowerManagerFsm::dispatch(event);
|
||||
// return true;
|
||||
} else if(key == m_setOpConditionMsg.key) {
|
||||
m_pm->m_msCmd.workCMD = m_setOpConditionMsg.getSetOpCondition(key, strJson);
|
||||
MasterCommandEvent event;
|
||||
PowerManagerFsm::dispatch(event);
|
||||
return true;
|
||||
} else if(key == DB_TO_PM_SETPMSYS) {
|
||||
m_pm->m_msCmd.powerCMD = getSetPMSys(key, strJson);
|
||||
MasterCommandEvent event;
|
||||
@@ -130,37 +156,37 @@ const DriverTable UpperCommManager::getSubDisState(const std::string& key, const
|
||||
}
|
||||
}
|
||||
|
||||
const int UpperCommManager::getDeepth(const std::string& key, const std::string& msg){
|
||||
int deepth;
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
JSONCPP_STRING errs;
|
||||
// const int UpperCommManager::getDeepth(const std::string& key, const std::string& msg){
|
||||
// int deepth;
|
||||
// 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 -1;
|
||||
}
|
||||
// // 解析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 -1;
|
||||
// }
|
||||
|
||||
// 检查并读取深度数组
|
||||
if (root.isMember("value_array_int32") && root["value_array_int32"].isArray()) {
|
||||
const Json::Value& array = root["value_array_int32"];
|
||||
if (array.size() >= 3) {
|
||||
// 计算三个深度值的平均值
|
||||
deepth = (array[0].asInt() + array[1].asInt() + array[2].asInt()) / 3;
|
||||
} else {
|
||||
LOG_F(WARNING, "深度数组元素不足3个");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
LOG_F(WARNING, "缺少或类型不匹配: value_array_int32");
|
||||
return -1;
|
||||
}
|
||||
// // 检查并读取深度数组
|
||||
// if (root.isMember("value_array_int32") && root["value_array_int32"].isArray()) {
|
||||
// const Json::Value& array = root["value_array_int32"];
|
||||
// if (array.size() >= 3) {
|
||||
// // 计算三个深度值的平均值
|
||||
// deepth = (array[0].asInt() + array[1].asInt() + array[2].asInt()) / 3;
|
||||
// } else {
|
||||
// LOG_F(WARNING, "深度数组元素不足3个");
|
||||
// return -1;
|
||||
// }
|
||||
// } else {
|
||||
// LOG_F(WARNING, "缺少或类型不匹配: value_array_int32");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
return deepth;
|
||||
}
|
||||
// return deepth;
|
||||
// }
|
||||
|
||||
MissionState UpperCommManager::getMission(const std::string& key, const std::string& msg) {
|
||||
MissionState mission;
|
||||
|
||||
@@ -8,29 +8,21 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "msg/uPower_equInsState.h"
|
||||
#include "msg/uDevice_secdistState.h"
|
||||
#include "msg/uPower_equState.h"
|
||||
#include "msg/uPower_disSysState.h"
|
||||
#include "msg/uPower_currentState_st.h"
|
||||
#include "msg/uPower_pmState.h"
|
||||
#include "msg/uPower_fcsState.h"
|
||||
#include "msg/uPower_liBatState.h"
|
||||
#include "upmsg/uPower_equInsState.h"
|
||||
#include "upmsg/uDevice_secdistState.h"
|
||||
#include "upmsg/uPower_equState.h"
|
||||
#include "upmsg/uPower_disSysState.h"
|
||||
#include "upmsg/uPower_currentState_st.h"
|
||||
#include "upmsg/uPower_pmState.h"
|
||||
#include "upmsg/uPower_fcsState.h"
|
||||
#include "upmsg/uPower_liBatState.h"
|
||||
#include "upmsg/uDevice_depth.h"
|
||||
#include "upmsg/uExternComm_setOpCondition.h"
|
||||
using namespace std;
|
||||
#define VAR_TO_STR(var) #var
|
||||
//能源管理反馈的消息
|
||||
#define PM_TO_DB_STATE "uPower_pmState_fb"
|
||||
#define PM_TO_DB_CURRENTSTATE "uPower_currentState_st"
|
||||
#define PM_TO_DB_DISSTATE "uPower_disSysState_st"
|
||||
#define PM_TO_DB_LIBATSTATE "uPower_liBatState_st"
|
||||
#define PM_TO_DB_FCSSTATE "uPower_fcsState_st"
|
||||
|
||||
#define PM_TO_DB_SUBDISCMD "uPower_secdistState_cmd"
|
||||
|
||||
//控制消息
|
||||
#define DB_TO_PM_MSCMD "uPower_sysState_cmd"
|
||||
#define DB_TO_PM_EQUIPMENTCMD "uPower_equState_cmd"
|
||||
#define DB_TO_PM_SUBDISSTATE "uDevice_secdistState_st"
|
||||
|
||||
//决策消息
|
||||
#define DB_TO_PM_DEEPTH "uDevice_depth_st"
|
||||
@@ -63,7 +55,7 @@ public:
|
||||
const MSControlCmd getMasterControlCmd(const std::string& key, const std::string& msg);
|
||||
const DriverTable getEquipmentCmd(const std::string& key, const std::string& msg);
|
||||
const DriverTable getSubDisState(const std::string& key, const std::string& msg);
|
||||
const int getDeepth(const std::string& key, const std::string& msg);
|
||||
// const int getDeepth(const std::string& key, const std::string& msg);
|
||||
MissionState getMission(const std::string& key, const std::string& msg);
|
||||
bool getTaskStop(const std::string& key, const std::string& msg);
|
||||
// 处理外部通信消息
|
||||
@@ -76,10 +68,7 @@ public:
|
||||
// 其他公共函数
|
||||
bool saveStringToJsonFile(const string &strJson, const string &filePath);
|
||||
|
||||
private:
|
||||
PowerManger* m_pm;
|
||||
MSControlCmd m_msCmd;
|
||||
Driver m_driver;
|
||||
public:
|
||||
//定义上位机消息
|
||||
uPower_equInsStateMsg m_equInsStateMsg;
|
||||
uDevice_secdistStateMsg m_secdistStateMsg;
|
||||
@@ -90,6 +79,14 @@ private:
|
||||
uPower_fcsStateMsg m_fcsStateMsg;
|
||||
uPower_liBatStateMsg m_liBatStateMsg;
|
||||
|
||||
//上位机订阅消息
|
||||
uDevice_depthMsg m_depthMsg;
|
||||
uExternComm_setOpConditionMsg m_setOpConditionMsg;
|
||||
|
||||
private:
|
||||
PowerManger* m_pm;
|
||||
MSControlCmd m_msCmd;
|
||||
Driver m_driver;
|
||||
|
||||
bool parseControlCmdFromJson(MSControlCmd &cmd, const std::string &strJson);
|
||||
};
|
||||
|
||||
@@ -800,13 +800,9 @@ vector<DriverCommand> Driver::loadDriverIdFromJson(const std::string &strJson) {
|
||||
{"launchControler", 37}, {"sideSonar", 35}, {"buoyage", 56}
|
||||
};
|
||||
|
||||
// 检查每个字段,如果存在且值发生变化,则添加到返回向量中
|
||||
for (const auto& [field, id] : fieldToId) {
|
||||
if (root.isMember(field)) {
|
||||
unsigned char newValue = root[field].asUInt();
|
||||
// unsigned char& currentValue = *((unsigned char*)&table + offsetof(DriverTable, depth1) +
|
||||
// (fieldToId.at(field) - 18) * sizeof(unsigned char));
|
||||
|
||||
DriverCommand cmd;
|
||||
cmd.id = id;
|
||||
cmd.cmd = newValue;
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
void StandbyState::entry() {
|
||||
PowerManagerFsm::entry();
|
||||
pm->m_driver.getSTANDBYTable(&pm->m_subDisSysCmd);
|
||||
pm->m_CcuColCmd.fcuCmd = FcuCommand::Stop;
|
||||
// pm->m_CcuColCmd.fcuCmd = FcuCommand::Stop;
|
||||
// pm->m_CcuColCmd.powerBatCmd = BatteryCommand::Stop;
|
||||
// 启动流程 仪表电一直设置为启动
|
||||
pm->m_CcuColCmd.powerBatCmd = BatteryCommand::Start;
|
||||
pm->workCondition = WorkCondition::STANDBY;
|
||||
|
||||
// 依次启动仪表电设备
|
||||
|
||||
//
|
||||
LOG_F(INFO, "WorkCondition %d", pm->workCondition);
|
||||
}
|
||||
void StandbyState::react(StandbyEvent const &) {
|
||||
|
||||
@@ -52,6 +52,7 @@ typedef struct ccuState
|
||||
uint16_t ch3oh_concentration2; // 舱室甲醇气体浓度2,单位:0.01% LEL
|
||||
|
||||
uint16_t reserved1[18]; // 保留字段,地址范围35~52,共18个uint16_t,协议预留
|
||||
uint8_t reserved2[1]; // 保留字段,地址范围54~55,共2个uint8_t,协议预留
|
||||
|
||||
uint8_t dyn_alarm_flag[6]; // 动力锂电池报警标志字数组,共6字节,按位表示各类报警
|
||||
uint8_t ins_alarm_flag[6]; // 仪表锂电池报警标志字数组,共6字节,按位表示各类报警
|
||||
@@ -91,7 +92,7 @@ typedef struct ccuState
|
||||
uint8_t ins_emergency_status; // 仪表电池紧急状态字,按位表示异常或告警状态
|
||||
uint8_t dyn_emergency_status; // 动力电池紧急状态字,按位表示异常或告警状态
|
||||
|
||||
uint8_t reserved2[2]; // 保留字节,协议预留
|
||||
uint8_t reserved3[2]; // 保留字节,协议预留
|
||||
|
||||
uint8_t ins_soc_threshold1; // 仪表电池1 SOC门限,范围:0~100
|
||||
uint8_t ins_soc_threshold2; // 仪表电池2 SOC门限,范围:0~100
|
||||
@@ -108,7 +109,7 @@ typedef struct ccuState
|
||||
uint32_t device_online_flag1; // 设备在线状态标志1,byte0:低压配电板在线标志位 byte1:复合管控主机在线标志位 byte2:复合管控备机在线标志位
|
||||
uint32_t device_online_flag2; // 设备在线状态标志2,byte0:仪表锂电在线标志位 byte1:动力锂电在线标志位 byte2:燃电锂电在线标志位 byte3:高压配电板在线标志位
|
||||
|
||||
uint32_t reserved3; // 保留字段,协议预留
|
||||
uint32_t reserved4; // 保留字段,协议预留
|
||||
uint32_t heartbeat; // 主机心跳计数器或标志值
|
||||
} ccuState;
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ bool udpComm::getMsgId(char *m,unsigned short &id)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
sError.push_back("Msg Header errar");
|
||||
// sError.push_back("Msg Header errar");
|
||||
// LOG_F(ERROR, "Msg Header errar start1: %d, start2: %d", h.start1, h.start2);
|
||||
return false;
|
||||
}
|
||||
bool udpComm::getMsgFromBuff(char *m, msg_CcuStateFbMsg &s) {
|
||||
@@ -144,7 +145,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
{
|
||||
if(m==NULL)
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,Msg is NULL");
|
||||
// sError.push_back("pushMsgToQueue faile,Msg is NULL");
|
||||
LOG_F(ERROR, "pushMsgToQueue faile,Msg is NULL m: %p", m);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,7 +157,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
memcpy(header,Buff,sizeof(m_header));
|
||||
if(!getMsgId(header,id))
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,Msg ID error");
|
||||
// sError.push_back("pushMsgToQueue faile,Msg ID error");
|
||||
// LOG_F(INFO, "pushMsgToQueue faile,Msg ID error header: %p", header);
|
||||
return false;
|
||||
}
|
||||
delete []header;
|
||||
@@ -174,7 +177,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,CcuState buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,CcuState buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,CcuState buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +200,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,CcuSetParm buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,CcuSetParm buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,CcuSetParm buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -218,7 +223,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVBus buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,DisSysHVBus buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,DisSysHVBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -240,7 +246,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVABus buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,DisSysHVABus buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,DisSysHVABus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -262,7 +269,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysHVBBus buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,DisSysHVBBus buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,DisSysHVBBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -284,7 +292,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
}
|
||||
else
|
||||
{
|
||||
sError.push_back("pushMsgToQueue faile,DisSysLVBus buffer is full");
|
||||
// sError.push_back("pushMsgToQueue faile,DisSysLVBus buffer is full");
|
||||
LOG_F(INFO, "pushMsgToQueue faile,DisSysLVBus buffer is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <utility> // for std::pair
|
||||
|
||||
#include <utility>
|
||||
#include "loguru.hpp"
|
||||
using namespace std;
|
||||
#define QUENUE_SIZE 100
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
//决策消息
|
||||
#ifndef UDEVICE_DEPTH_ST_H
|
||||
#define UDEVICE_DEPTH_ST_H
|
||||
#include <string>
|
||||
#include "../loguru.hpp"
|
||||
#define DB_TO_PM_DEEPTH "uDevice_depth_st"
|
||||
class uDevice_depthMsg
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
std::string key = "uDevice_depth_st";
|
||||
uDevice_depthMsg(/* args */){};
|
||||
~uDevice_depthMsg(){};
|
||||
int getDepth(const std::string& msgkey, const std::string& msg){
|
||||
if (msgkey != DB_TO_PM_DEEPTH)
|
||||
{
|
||||
LOG_F(WARNING, "消息类型错误 %s", msgkey.c_str());
|
||||
return 0;
|
||||
}
|
||||
int deepth;
|
||||
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 -1;
|
||||
}
|
||||
// 检查并读取深度数组
|
||||
if (root.isMember("value_array_int32") && root["value_array_int32"].isArray()) {
|
||||
const Json::Value& array = root["value_array_int32"];
|
||||
if (array.size() >= 3) {
|
||||
// 计算三个深度值的平均值
|
||||
deepth = (array[0].asInt() + array[1].asInt() + array[2].asInt()) / 3;
|
||||
} else {
|
||||
LOG_F(WARNING, "深度数组元素不足3个");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
LOG_F(WARNING, "缺少或类型不匹配: value_array_int32");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return deepth;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef UEXTERNCOMM_SETDEVICESWITCH_CMD_H
|
||||
#define UEXTERNCOMM_SETDEVICESWITCH_CMD_H
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
//外部通信消息
|
||||
#define DB_TO_PM_SETOPMODE "uExternComm_setOpMode_cmd"
|
||||
@@ -0,0 +1,2 @@
|
||||
//外部通信消息
|
||||
#define DB_TO_PM_SETPMSYS "uExternComm_setPowerSystem_cmd"
|
||||
@@ -0,0 +1,2 @@
|
||||
//决策消息
|
||||
#define DB_TO_PM_TASKSTOP "uPlan_planStop_cmd"
|
||||
@@ -0,0 +1,2 @@
|
||||
//决策消息
|
||||
#define DB_TO_PM_MISSION "uPlan_taskStart_cmd"
|
||||
@@ -0,0 +1,2 @@
|
||||
//控制消息
|
||||
#define DB_TO_PM_EQUIPMENTCMD "uPower_equState_cmd"
|
||||
@@ -0,0 +1,2 @@
|
||||
//控制消息
|
||||
#define DB_TO_PM_MSCMD "uPower_sysState_cmd"
|
||||
Reference in New Issue
Block a user