优化消息代码
This commit is contained in:
@@ -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,451 @@
|
||||
#ifndef UDEVICE_SECDISTSTATE_H
|
||||
#define UDEVICE_SECDISTSTATE_H
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
#include "../driver.h"
|
||||
#include "../loguru.hpp"
|
||||
|
||||
class uDevice_secdistStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uDevice_secdistStateMsg(){};
|
||||
~uDevice_secdistStateMsg(){};
|
||||
std::string key_fb = "uDevice_secdistState_st";
|
||||
std::string key_cmd = "uPower_secdistState_cmd";
|
||||
|
||||
struct DeviceSecdistState
|
||||
{
|
||||
// UNIT1
|
||||
u_int8_t bowCover1;
|
||||
u_int8_t bowCover2;
|
||||
u_int8_t bowCover3;
|
||||
u_int8_t bowCover4;
|
||||
u_int8_t bowCover5;
|
||||
u_int8_t bowCover6;
|
||||
u_int8_t singleBeamSonar1;
|
||||
u_int8_t singleBeamSonar2;
|
||||
u_int8_t singleBeamSonar3;
|
||||
u_int8_t singleBeamSonar4;
|
||||
u_int8_t singleBeamSonar5;
|
||||
u_int8_t singleBeamSonar6;
|
||||
u_int8_t forwardSonar;
|
||||
u_int8_t depth3;
|
||||
u_int8_t soundVeloc;
|
||||
u_int8_t bowRudderServo;
|
||||
u_int8_t bowRudderDeploy;
|
||||
u_int8_t ctd1;
|
||||
u_int8_t waterInject;
|
||||
|
||||
// UNIT2
|
||||
u_int8_t sideSonar;
|
||||
u_int8_t bowWaterInet1;
|
||||
u_int8_t bowWaterInet2;
|
||||
u_int8_t bowWaterInet3;
|
||||
u_int8_t bowWaterInet4;
|
||||
u_int8_t bowWaterInet5;
|
||||
u_int8_t bowWaterInet6;
|
||||
u_int8_t bowWaterInet7;
|
||||
u_int8_t bowWaterInet8;
|
||||
u_int8_t launchControler;
|
||||
u_int8_t electSensor;
|
||||
u_int8_t lowFreqSonar;
|
||||
|
||||
// UNIT3
|
||||
u_int8_t buoyancyAdjust1;
|
||||
u_int8_t buoyancyAdjust2;
|
||||
u_int8_t buoyancyAdjust3;
|
||||
u_int8_t USBL;
|
||||
u_int8_t depth1;
|
||||
u_int8_t commDev;
|
||||
u_int8_t mastLiftingServo;
|
||||
u_int8_t DVL;
|
||||
u_int8_t ADCP;
|
||||
u_int8_t inOutLetWater1;
|
||||
u_int8_t inOutLetWater2;
|
||||
|
||||
// UNIT4
|
||||
u_int8_t singleBeamSonar7;
|
||||
u_int8_t singleBeamSonar8;
|
||||
u_int8_t buoyage;
|
||||
u_int8_t bowThrow;
|
||||
u_int8_t depth2;
|
||||
u_int8_t thruster;
|
||||
u_int8_t dragSonar;
|
||||
u_int8_t haulingMachine;
|
||||
u_int8_t buoyancyAdjust4;
|
||||
u_int8_t buoyancyAdjust5;
|
||||
u_int8_t sternRudderServo1;
|
||||
u_int8_t sternRudderServo2;
|
||||
u_int8_t sternRudderServo3;
|
||||
u_int8_t sternRudderServo4;
|
||||
u_int8_t ctd2;
|
||||
u_int8_t commDevStern;
|
||||
u_int8_t inOutLetWater3;
|
||||
|
||||
// UNIT5
|
||||
u_int8_t secINS;
|
||||
u_int8_t photoSensor;
|
||||
u_int8_t sternThrow;
|
||||
u_int8_t mainINS;
|
||||
} deviceSecdistState;
|
||||
|
||||
|
||||
|
||||
bool parseSecdistStateFromJson(DeviceSecdistState &state, const std::string &strJson){
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder readerBuilder;
|
||||
std::unique_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
||||
std::string errors;
|
||||
|
||||
if(!reader->parse(strJson.c_str(), strJson.c_str() + strJson.length(), &root, &errors)){
|
||||
LOG_F(ERROR, "Failed to parse JSON: %s", errors.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto checkField = [&root](const std::string& field) -> bool {
|
||||
if(!root.isMember(field) || !root[field].isUInt()) {
|
||||
// std::cerr << "Missing or invalid field: " << field << std::endl;
|
||||
LOG_F(ERROR, "Missing or invalid field: %s", field.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
bool ok = true;
|
||||
|
||||
// UNIT1
|
||||
if(!checkField("bowCover1_uint8")) ok=false; state.bowCover1 = root["bowCover1_uint8"].asUInt();
|
||||
if(!checkField("bowCover2_uint8")) ok=false; state.bowCover2 = root["bowCover2_uint8"].asUInt();
|
||||
if(!checkField("bowCover3_uint8")) ok=false; state.bowCover3 = root["bowCover3_uint8"].asUInt();
|
||||
if(!checkField("bowCover4_uint8")) ok=false; state.bowCover4 = root["bowCover4_uint8"].asUInt();
|
||||
if(!checkField("bowCover5_uint8")) ok=false; state.bowCover5 = root["bowCover5_uint8"].asUInt();
|
||||
if(!checkField("bowCover6_uint8")) ok=false; state.bowCover6 = root["bowCover6_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar1_uint8")) ok=false; state.singleBeamSonar1 = root["singleBeamSonar1_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar2_uint8")) ok=false; state.singleBeamSonar2 = root["singleBeamSonar2_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar3_uint8")) ok=false; state.singleBeamSonar3 = root["singleBeamSonar3_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar4_uint8")) ok=false; state.singleBeamSonar4 = root["singleBeamSonar4_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar5_uint8")) ok=false; state.singleBeamSonar5 = root["singleBeamSonar5_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar6_uint8")) ok=false; state.singleBeamSonar6 = root["singleBeamSonar6_uint8"].asUInt();
|
||||
if(!checkField("forwardSonar_uint8")) ok=false; state.forwardSonar = root["forwardSonar_uint8"].asUInt();
|
||||
if(!checkField("depth3_uint8")) ok=false; state.depth3 = root["depth3_uint8"].asUInt();
|
||||
if(!checkField("soundVeloc_uint8")) ok=false; state.soundVeloc = root["soundVeloc_uint8"].asUInt();
|
||||
if(!checkField("bowRudderServo_uint8")) ok=false; state.bowRudderServo = root["bowRudderServo_uint8"].asUInt();
|
||||
if(!checkField("bowRudderDeploy_uint8")) ok=false; state.bowRudderDeploy = root["bowRudderDeploy_uint8"].asUInt();
|
||||
if(!checkField("ctd1_uint8")) ok=false; state.ctd1 = root["ctd1_uint8"].asUInt();
|
||||
if(!checkField("waterInject_uint8")) ok=false; state.waterInject = root["waterInject_uint8"].asUInt();
|
||||
|
||||
// UNIT2
|
||||
if(!checkField("sideSonar_uint8")) ok=false; state.sideSonar = root["sideSonar_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet1_uint8")) ok=false; state.bowWaterInet1 = root["bowWaterInet1_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet2_uint8")) ok=false; state.bowWaterInet2 = root["bowWaterInet2_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet3_uint8")) ok=false; state.bowWaterInet3 = root["bowWaterInet3_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet4_uint8")) ok=false; state.bowWaterInet4 = root["bowWaterInet4_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet5_uint8")) ok=false; state.bowWaterInet5 = root["bowWaterInet5_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet6_uint8")) ok=false; state.bowWaterInet6 = root["bowWaterInet6_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet7_uint8")) ok=false; state.bowWaterInet7 = root["bowWaterInet7_uint8"].asUInt();
|
||||
if(!checkField("bowWaterInet8_uint8")) ok=false; state.bowWaterInet8 = root["bowWaterInet8_uint8"].asUInt();
|
||||
if(!checkField("launchControler_uint8")) ok=false; state.launchControler = root["launchControler_uint8"].asUInt();
|
||||
if(!checkField("electSensor_uint8")) ok=false; state.electSensor = root["electSensor_uint8"].asUInt();
|
||||
if(!checkField("lowFreqSonar_uint8")) ok=false; state.lowFreqSonar = root["lowFreqSonar_uint8"].asUInt();
|
||||
|
||||
// UNIT3
|
||||
if(!checkField("buoyancyAdjust1_uint8")) ok=false; state.buoyancyAdjust1 = root["buoyancyAdjust1_uint8"].asUInt();
|
||||
if(!checkField("buoyancyAdjust2_uint8")) ok=false; state.buoyancyAdjust2 = root["buoyancyAdjust2_uint8"].asUInt();
|
||||
if(!checkField("buoyancyAdjust3_uint8")) ok=false; state.buoyancyAdjust3 = root["buoyancyAdjust3_uint8"].asUInt();
|
||||
if(!checkField("USBL_uint8")) ok=false; state.USBL = root["USBL_uint8"].asUInt();
|
||||
if(!checkField("depth1_uint8")) ok=false; state.depth1 = root["depth1_uint8"].asUInt();
|
||||
if(!checkField("commDev_uint8")) ok=false; state.commDev = root["commDev_uint8"].asUInt();
|
||||
if(!checkField("mastLiftingServo_uint8")) ok=false; state.mastLiftingServo = root["mastLiftingServo_uint8"].asUInt();
|
||||
if(!checkField("DVL_uint8")) ok=false; state.DVL = root["DVL_uint8"].asUInt();
|
||||
if(!checkField("ADCP_uint8")) ok=false; state.ADCP = root["ADCP_uint8"].asUInt();
|
||||
if(!checkField("inOutLetWater1_uint8")) ok=false; state.inOutLetWater1 = root["inOutLetWater1_uint8"].asUInt();
|
||||
if(!checkField("inOutLetWater2_uint8")) ok=false; state.inOutLetWater2 = root["inOutLetWater2_uint8"].asUInt();
|
||||
|
||||
// UNIT4
|
||||
if(!checkField("singleBeamSonar7_uint8")) ok=false; state.singleBeamSonar7 = root["singleBeamSonar7_uint8"].asUInt();
|
||||
if(!checkField("singleBeamSonar8_uint8")) ok=false; state.singleBeamSonar8 = root["singleBeamSonar8_uint8"].asUInt();
|
||||
if(!checkField("buoyage_uint8")) ok=false; state.buoyage = root["buoyage_uint8"].asUInt();
|
||||
if(!checkField("bowThrow_uint8")) ok=false; state.bowThrow = root["bowThrow_uint8"].asUInt();
|
||||
if(!checkField("depth2_uint8")) ok=false; state.depth2 = root["depth2_uint8"].asUInt();
|
||||
if(!checkField("thruster_uint8")) ok=false; state.thruster = root["thruster_uint8"].asUInt();
|
||||
if(!checkField("dragSonar_uint8")) ok=false; state.dragSonar = root["dragSonar_uint8"].asUInt();
|
||||
if(!checkField("haulingMachine_uint8")) ok=false; state.haulingMachine = root["haulingMachine_uint8"].asUInt();
|
||||
if(!checkField("buoyancyAdjust4_uint8")) ok=false; state.buoyancyAdjust4 = root["buoyancyAdjust4_uint8"].asUInt();
|
||||
if(!checkField("buoyancyAdjust5_uint8")) ok=false; state.buoyancyAdjust5 = root["buoyancyAdjust5_uint8"].asUInt();
|
||||
if(!checkField("sternRudderServo1_uint8")) ok=false; state.sternRudderServo1 = root["sternRudderServo1_uint8"].asUInt();
|
||||
if(!checkField("sternRudderServo2_uint8")) ok=false; state.sternRudderServo2 = root["sternRudderServo2_uint8"].asUInt();
|
||||
if(!checkField("sternRudderServo3_uint8")) ok=false; state.sternRudderServo3 = root["sternRudderServo3_uint8"].asUInt();
|
||||
if(!checkField("sternRudderServo4_uint8")) ok=false; state.sternRudderServo4 = root["sternRudderServo4_uint8"].asUInt();
|
||||
if(!checkField("ctd2_uint8")) ok=false; state.ctd2 = root["ctd2_uint8"].asUInt();
|
||||
if(!checkField("commDevStern_uint8")) ok=false; state.commDevStern = root["commDevStern_uint8"].asUInt();
|
||||
if(!checkField("inOutLetWater3_uint8")) ok=false; state.inOutLetWater3 = root["inOutLetWater3_uint8"].asUInt();
|
||||
|
||||
// UNIT5
|
||||
if(!checkField("secINS_uint8")) ok=false; state.secINS = root["secINS_uint8"].asUInt();
|
||||
if(!checkField("photoSensor_uint8")) ok=false; state.photoSensor = root["photoSensor_uint8"].asUInt();
|
||||
if(!checkField("sternThrow_uint8")) ok=false; state.sternThrow = root["sternThrow_uint8"].asUInt();
|
||||
if(!checkField("mainINS_uint8")) ok=false; state.mainINS = root["mainINS_uint8"].asUInt();
|
||||
|
||||
return ok;
|
||||
};
|
||||
std::string buildSecdistStateToJson(DeviceSecdistState &state){
|
||||
Json::Value root;
|
||||
|
||||
// UNIT1
|
||||
root["bowCover1_uint8"] = state.bowCover1;
|
||||
root["bowCover2_uint8"] = state.bowCover2;
|
||||
root["bowCover3_uint8"] = state.bowCover3;
|
||||
root["bowCover4_uint8"] = state.bowCover4;
|
||||
root["bowCover5_uint8"] = state.bowCover5;
|
||||
root["bowCover6_uint8"] = state.bowCover6;
|
||||
root["singleBeamSonar1_uint8"] = state.singleBeamSonar1;
|
||||
root["singleBeamSonar2_uint8"] = state.singleBeamSonar2;
|
||||
root["singleBeamSonar3_uint8"] = state.singleBeamSonar3;
|
||||
root["singleBeamSonar4_uint8"] = state.singleBeamSonar4;
|
||||
root["singleBeamSonar5_uint8"] = state.singleBeamSonar5;
|
||||
root["singleBeamSonar6_uint8"] = state.singleBeamSonar6;
|
||||
root["forwardSonar_uint8"] = state.forwardSonar;
|
||||
root["depth3_uint8"] = state.depth3;
|
||||
root["soundVeloc_uint8"] = state.soundVeloc;
|
||||
root["bowRudderServo_uint8"] = state.bowRudderServo;
|
||||
root["bowRudderDeploy_uint8"] = state.bowRudderDeploy;
|
||||
root["ctd1_uint8"] = state.ctd1;
|
||||
root["waterInject_uint8"] = state.waterInject;
|
||||
|
||||
// UNIT2
|
||||
root["sideSonar_uint8"] = state.sideSonar;
|
||||
root["bowWaterInet1_uint8"] = state.bowWaterInet1;
|
||||
root["bowWaterInet2_uint8"] = state.bowWaterInet2;
|
||||
root["bowWaterInet3_uint8"] = state.bowWaterInet3;
|
||||
root["bowWaterInet4_uint8"] = state.bowWaterInet4;
|
||||
root["bowWaterInet5_uint8"] = state.bowWaterInet5;
|
||||
root["bowWaterInet6_uint8"] = state.bowWaterInet6;
|
||||
root["bowWaterInet7_uint8"] = state.bowWaterInet7;
|
||||
root["bowWaterInet8_uint8"] = state.bowWaterInet8;
|
||||
root["launchControler_uint8"] = state.launchControler;
|
||||
root["electSensor_uint8"] = state.electSensor;
|
||||
root["lowFreqSonar_uint8"] = state.lowFreqSonar;
|
||||
|
||||
// UNIT3
|
||||
root["buoyancyAdjust1_uint8"] = state.buoyancyAdjust1;
|
||||
root["buoyancyAdjust2_uint8"] = state.buoyancyAdjust2;
|
||||
root["buoyancyAdjust3_uint8"] = state.buoyancyAdjust3;
|
||||
root["USBL_uint8"] = state.USBL;
|
||||
root["depth1_uint8"] = state.depth1;
|
||||
root["commDev_uint8"] = state.commDev;
|
||||
root["mastLiftingServo_uint8"] = state.mastLiftingServo;
|
||||
root["DVL_uint8"] = state.DVL;
|
||||
root["ADCP_uint8"] = state.ADCP;
|
||||
root["inOutLetWater1_uint8"] = state.inOutLetWater1;
|
||||
root["inOutLetWater2_uint8"] = state.inOutLetWater2;
|
||||
|
||||
// UNIT4
|
||||
root["singleBeamSonar7_uint8"] = state.singleBeamSonar7;
|
||||
root["singleBeamSonar8_uint8"] = state.singleBeamSonar8;
|
||||
root["buoyage_uint8"] = state.buoyage;
|
||||
root["bowThrow_uint8"] = state.bowThrow;
|
||||
root["depth2_uint8"] = state.depth2;
|
||||
root["thruster_uint8"] = state.thruster;
|
||||
root["dragSonar_uint8"] = state.dragSonar;
|
||||
root["haulingMachine_uint8"] = state.haulingMachine;
|
||||
root["buoyancyAdjust4_uint8"] = state.buoyancyAdjust4;
|
||||
root["buoyancyAdjust5_uint8"] = state.buoyancyAdjust5;
|
||||
root["sternRudderServo1_uint8"] = state.sternRudderServo1;
|
||||
root["sternRudderServo2_uint8"] = state.sternRudderServo2;
|
||||
root["sternRudderServo3_uint8"] = state.sternRudderServo3;
|
||||
root["sternRudderServo4_uint8"] = state.sternRudderServo4;
|
||||
root["ctd2_uint8"] = state.ctd2;
|
||||
root["commDevStern_uint8"] = state.commDevStern;
|
||||
root["inOutLetWater3_uint8"] = state.inOutLetWater3;
|
||||
|
||||
// UNIT5
|
||||
root["secINS_uint8"] = state.secINS;
|
||||
root["photoSensor_uint8"] = state.photoSensor;
|
||||
root["sternThrow_uint8"] = state.sternThrow;
|
||||
root["mainINS_uint8"] = state.mainINS;
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = ""; // 紧凑格式,无缩进
|
||||
return Json::writeString(writerBuilder, root);
|
||||
};
|
||||
|
||||
bool converFromDriverTable(DeviceSecdistState &state,const DriverTable &driver){
|
||||
// UNIT1
|
||||
state.bowCover1 = driver.bowCover1;
|
||||
state.bowCover2 = driver.bowCover2;
|
||||
state.bowCover3 = driver.bowCover3;
|
||||
state.bowCover4 = driver.bowCover4;
|
||||
state.bowCover5 = driver.bowCover5;
|
||||
state.bowCover6 = driver.bowCover6;
|
||||
state.singleBeamSonar1 = driver.singleBeamSonar1;
|
||||
state.singleBeamSonar2 = driver.singleBeamSonar2;
|
||||
state.singleBeamSonar3 = driver.singleBeamSonar3;
|
||||
state.singleBeamSonar4 = driver.singleBeamSonar4;
|
||||
state.singleBeamSonar5 = driver.singleBeamSonar5;
|
||||
state.singleBeamSonar6 = driver.singleBeamSonar6;
|
||||
state.forwardSonar = driver.forwardSonar;
|
||||
state.depth3 = driver.depth3;
|
||||
state.soundVeloc = driver.soundVeloc;
|
||||
state.bowRudderServo = driver.bowRudderServo1 | driver.bowRudderServo2;
|
||||
state.bowRudderDeploy = driver.bowRudderDeploy;
|
||||
state.ctd1 = driver.ctd1;
|
||||
state.waterInject = driver.waterInject;
|
||||
|
||||
// UNIT2
|
||||
state.sideSonar = driver.sideSonar;
|
||||
state.bowWaterInet1 = driver.bowWaterlnet1;
|
||||
state.bowWaterInet2 = driver.bowWaterlnet2;
|
||||
state.bowWaterInet3 = driver.bowWaterlnet3;
|
||||
state.bowWaterInet4 = driver.bowWaterlnet4;
|
||||
state.bowWaterInet5 = driver.bowWaterlnet5;
|
||||
state.bowWaterInet6 = driver.bowWaterlnet6;
|
||||
state.bowWaterInet7 = driver.bowWaterlnet7;
|
||||
state.bowWaterInet8 = driver.bowWaterlnet8;
|
||||
state.launchControler = driver.launchControler;
|
||||
state.electSensor = driver.electSensor;
|
||||
state.lowFreqSonar = driver.lowFreqSonar;
|
||||
|
||||
// UNIT3
|
||||
state.buoyancyAdjust1 = driver.buoyancyAdjust1;
|
||||
state.buoyancyAdjust2 = driver.buoyancyAdjust2;
|
||||
state.buoyancyAdjust3 = driver.buoyancyAdjust3;
|
||||
state.USBL = driver.USBL;
|
||||
state.depth1 = driver.depth1;
|
||||
state.commDev = driver.commMast;
|
||||
state.mastLiftingServo = driver.mastLiftingServo;
|
||||
state.DVL = driver.DVL;
|
||||
state.ADCP = driver.DVL; // Assuming ADCP is same as DVL
|
||||
state.inOutLetWater1 = driver.inputWaterSensor1;
|
||||
state.inOutLetWater2 = driver.inputWaterSensor2;
|
||||
|
||||
// UNIT4
|
||||
state.singleBeamSonar7 = driver.singleBeamSonar7;
|
||||
state.singleBeamSonar8 = driver.singleBeamSonar8;
|
||||
state.buoyage = driver.buoyage;
|
||||
state.bowThrow = driver.bowThrow;
|
||||
state.depth2 = driver.depth2;
|
||||
state.thruster = driver.thruster;
|
||||
state.haulingMachine = 0; // No corresponding field in DriverTable
|
||||
state.buoyancyAdjust4 = driver.buoyancyAdjust4;
|
||||
state.buoyancyAdjust5 = driver.buoyancyAdjust5;
|
||||
state.sternRudderServo1 = driver.sternRudderServo1;
|
||||
state.sternRudderServo2 = driver.sternRudderServo2;
|
||||
state.sternRudderServo3 = driver.sternRudderServo3;
|
||||
state.sternRudderServo4 = driver.sternRudderServo4;
|
||||
state.ctd2 = driver.ctd2;
|
||||
state.commDevStern = 0; // No corresponding field in DriverTable
|
||||
state.inOutLetWater3 = driver.inputWaterSensor3;
|
||||
|
||||
// UNIT5
|
||||
state.secINS = driver.ins;
|
||||
state.photoSensor = driver.photoSensor;
|
||||
state.sternThrow = driver.sternThrow;
|
||||
state.mainINS = driver.ins;
|
||||
|
||||
// 未映射字段
|
||||
// driver.overDeep1
|
||||
// driver.overDeep2
|
||||
// driver.ntp
|
||||
state.dragSonar = 0; // Assuming dragSonar is same as lowFreqSonar
|
||||
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bool converToDriverTable(const DeviceSecdistState &state, DriverTable &driver){
|
||||
// UNIT1
|
||||
driver.bowCover1 = state.bowCover1;
|
||||
driver.bowCover2 = state.bowCover2;
|
||||
driver.bowCover3 = state.bowCover3;
|
||||
driver.bowCover4 = state.bowCover4;
|
||||
driver.bowCover5 = state.bowCover5;
|
||||
driver.bowCover6 = state.bowCover6;
|
||||
driver.singleBeamSonar1 = state.singleBeamSonar1;
|
||||
driver.singleBeamSonar2 = state.singleBeamSonar2;
|
||||
driver.singleBeamSonar3 = state.singleBeamSonar3;
|
||||
driver.singleBeamSonar4 = state.singleBeamSonar4;
|
||||
driver.singleBeamSonar5 = state.singleBeamSonar5;
|
||||
driver.singleBeamSonar6 = state.singleBeamSonar6;
|
||||
driver.forwardSonar = state.forwardSonar;
|
||||
driver.depth3 = state.depth3;
|
||||
driver.soundVeloc = state.soundVeloc;
|
||||
driver.bowRudderServo1 = state.bowRudderServo;
|
||||
driver.bowRudderServo2 = state.bowRudderServo;
|
||||
driver.bowRudderDeploy = state.bowRudderDeploy;
|
||||
driver.ctd1 = state.ctd1;
|
||||
driver.waterInject = state.waterInject;
|
||||
|
||||
// UNIT2
|
||||
driver.sideSonar = state.sideSonar;
|
||||
driver.bowWaterlnet1 = state.bowWaterInet1;
|
||||
driver.bowWaterlnet2 = state.bowWaterInet2;
|
||||
driver.bowWaterlnet3 = state.bowWaterInet3;
|
||||
driver.bowWaterlnet4 = state.bowWaterInet4;
|
||||
driver.bowWaterlnet5 = state.bowWaterInet5;
|
||||
driver.bowWaterlnet6 = state.bowWaterInet6;
|
||||
driver.bowWaterlnet7 = state.bowWaterInet7;
|
||||
driver.bowWaterlnet8 = state.bowWaterInet8;
|
||||
driver.launchControler = state.launchControler;
|
||||
driver.electSensor = state.electSensor;
|
||||
driver.lowFreqSonar = state.lowFreqSonar;
|
||||
|
||||
// UNIT3
|
||||
driver.buoyancyAdjust1 = state.buoyancyAdjust1;
|
||||
driver.buoyancyAdjust2 = state.buoyancyAdjust2;
|
||||
driver.buoyancyAdjust3 = state.buoyancyAdjust3;
|
||||
driver.USBL = state.USBL;
|
||||
driver.depth1 = state.depth1;
|
||||
driver.commMast = state.commDev;
|
||||
driver.ntp = 1;
|
||||
driver.mastLiftingServo = state.mastLiftingServo;
|
||||
driver.DVL = state.DVL;
|
||||
driver.inputWaterSensor1 = state.inOutLetWater1;
|
||||
driver.inputWaterSensor2 = state.inOutLetWater2;
|
||||
driver.overDeep1 = (state.depth1 == 1) ? 1 : 0;
|
||||
driver.overDeep2 = (state.depth2 == 1 || state.depth3 == 1) ? 1 : 0;
|
||||
|
||||
// UNIT4
|
||||
driver.singleBeamSonar7 = state.singleBeamSonar7;
|
||||
driver.singleBeamSonar8 = state.singleBeamSonar8;
|
||||
driver.buoyage = state.buoyage;
|
||||
driver.bowThrow = state.bowThrow;
|
||||
driver.depth2 = state.depth2;
|
||||
driver.thruster = state.thruster;
|
||||
driver.buoyancyAdjust4 = state.buoyancyAdjust4;
|
||||
driver.buoyancyAdjust5 = state.buoyancyAdjust5;
|
||||
driver.sternRudderServo1 = state.sternRudderServo1;
|
||||
driver.sternRudderServo2 = state.sternRudderServo2;
|
||||
driver.sternRudderServo3 = state.sternRudderServo3;
|
||||
driver.sternRudderServo4 = state.sternRudderServo4;
|
||||
driver.ctd2 = state.ctd2;
|
||||
driver.inputWaterSensor3 = state.inOutLetWater3;
|
||||
|
||||
// UNIT5
|
||||
driver.ins = state.secINS | state.mainINS;
|
||||
driver.photoSensor = state.photoSensor;
|
||||
driver.sternThrow = state.sternThrow;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string buildMsg(DriverTable &driver){
|
||||
DeviceSecdistState s;
|
||||
converFromDriverTable(s,driver);
|
||||
return buildSecdistStateToJson(s);
|
||||
};
|
||||
|
||||
bool parseMsg(const std::string &strJson,DriverTable &driver){
|
||||
DeviceSecdistState s;
|
||||
if(!parseSecdistStateFromJson(s,strJson)){
|
||||
LOG_F(WARNING, "parseSecdistStateFromJson failed");
|
||||
return false;
|
||||
}
|
||||
converToDriverTable(s,driver);
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#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,81 @@
|
||||
#ifndef U_POWER_CURRENTSTATE_ST_H
|
||||
#define U_POWER_CURRENTSTATE_ST_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
|
||||
class uPower_currentStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_currentStateMsg() {
|
||||
memset(&state, 0, sizeof(state));
|
||||
};
|
||||
~uPower_currentStateMsg() {};
|
||||
std::string key = "uPower_currentState_st";
|
||||
|
||||
pmState state;
|
||||
std::string buildMsg(pmState state)
|
||||
{
|
||||
// 状态赋值
|
||||
Json::Value currentBusState;
|
||||
currentBusState["HVBpowerBusVol_uint16"] = state.bus1State.powerBusVoltage;
|
||||
currentBusState["HVBdcDc5Cur_uint16"] = state.bus1State.dcDc5ModuleCurrent;
|
||||
currentBusState["HVBpowerBusCur_uint16"] = state.bus1State.powerBusCurrent;
|
||||
currentBusState["HVBbusAVol_uint16"] = state.bus1State.busbarAVoltage;
|
||||
currentBusState["HVBmotorCur_uint16"] = state.bus1State.propulsionMotorControlBoxCurrent;
|
||||
currentBusState["HVBbusACur_uint16"] = state.bus1State.busbarACurrent;
|
||||
currentBusState["HVBbatGroupCur_uint16"] = state.bus1State.lithiumBatteryGroupMeterCurrent;
|
||||
currentBusState["HVBbowHVolDisBoxCur_uint16"] = state.bus1State.bowHighVoltageDistributionBoxCurrent;
|
||||
currentBusState["HVBFTDev45Cur_uint16"] = state.bus1State.sternFTDevice45Current;
|
||||
currentBusState["HVBtyzCur_uint16"] = state.bus1State.tyzReservedSwitchCurrent;
|
||||
currentBusState["HVBsternRud1Cur_uint16"] = state.bus1State.sternRudderSwitch1Current;
|
||||
currentBusState["HVBreservedCur1_uint16"] = state.bus1State.reservedCurrent1;
|
||||
currentBusState["HVBsternRud2Cur_uint16"] = state.bus1State.sternRudderSwitch2Current;
|
||||
currentBusState["HVBreservedCur2_uint16"] = state.bus1State.reservedCurrent2;
|
||||
currentBusState["HVBfbCur_uint16"] = state.bus1State.fbReservedSwitchCurrent;
|
||||
currentBusState["HVBreservedCur3_uint16"] = state.bus1State.reservedCurrent3;
|
||||
|
||||
currentBusState["HVABbusBVol_uint16"] = state.bus2State.busbarBVoltage;
|
||||
currentBusState["HVABbusBCur_uint16"] = state.bus2State.busbarBCurrent;
|
||||
currentBusState["HVABFTDev123Cur_uint16"] = state.bus2State.bowFTDevice123Current;
|
||||
currentBusState["HVABactCur_uint16"] = state.bus2State.actuatorCurrent;
|
||||
currentBusState["HVABmastSteGeaCur_uint16"] = state.bus2State.mastSteeringGearControlBoxCurrent;
|
||||
currentBusState["HVABxczCur_uint16"] = state.bus2State.xczCurrent;
|
||||
currentBusState["HVABbowRudCur_uint16"] = state.bus2State.bowRudderControlBoxCurrent;
|
||||
currentBusState["HVABopenWaterCur_uint16"] = state.bus2State.openWaterCoverStartCylinderCurrent;
|
||||
|
||||
currentBusState["HVBBinsBusVol_uint16"] = state.bus3State.instrumentBusbarVoltage;
|
||||
currentBusState["HVBBbowLowVolDisBoxCur_uint16"] = state.bus3State.bowLowVoltageDistributionBoxCurrent;
|
||||
currentBusState["HVBBdcC1InsCur_uint16"] = state.bus3State.dcC1InstrumentDC48VCurrent;
|
||||
currentBusState["HVBBreservedCur1_uint16"] = state.bus3State.reservedCurrent1;
|
||||
currentBusState["HVBBemerBatCur_uint16"] = state.bus3State.emergencyLithiumBatteryGroup2Current;
|
||||
currentBusState["HVBBbatInsCur_uint16"] = state.bus3State.lithiumBatteryGroupInstrumentCurrent;
|
||||
currentBusState["HVBBunit4Cur_uint16"] = state.bus3State.unit4InstrumentDC48VCurrent;
|
||||
currentBusState["HVBBreservedCur2_uint16"] = state.bus3State.reservedCurrent2;
|
||||
currentBusState["HVBBemer2BusVol_uint16"] = state.bus3State.emergency2BusbarVoltage;
|
||||
currentBusState["HVBBCCUCur_uint16"] = state.bus3State.compositeEnergyManagementSystemEmergencyDC48VCurrent;
|
||||
currentBusState["HVBBFCSSecurSysCur_uint16"] = state.bus3State.fuelCellSecuritySystemEmergencyDC48VCurrent;
|
||||
currentBusState["HVBBplcCur_uint16"] = state.bus3State.plcControlPowerCurrent;
|
||||
|
||||
currentBusState["LVBinsBusVol_uint16"] = state.bus4State.instrumentBusbarVoltage;
|
||||
currentBusState["LVBBinsBusCur_uint16"] = state.bus4State.instrumentBusbarCurrent;
|
||||
currentBusState["LVBBunit1Cur_uint16"] = state.bus4State.unit1Current;
|
||||
currentBusState["LVBBunit2Cur_uint16"] = state.bus4State.unit2Current;
|
||||
currentBusState["LVBBunit3Cur_uint16"] = state.bus4State.unit3Current;
|
||||
currentBusState["LVBBunit5Cur_uint16"] = state.bus4State.unit5Current;
|
||||
currentBusState["LVBBbowPZDevCur_uint16"] = state.bus4State.bowPZDeviceCurrent;
|
||||
currentBusState["LVBBemerBatCur_uint16"] = state.bus4State.emergencyLithiumBatteryGroup1Current;
|
||||
currentBusState["LVBBemerBusVol_uint16"] = state.bus4State.emergency1BusbarVoltage;
|
||||
|
||||
// 转化为json格式
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
return Json::writeString(writerBuilder, currentBusState);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef U_POWER_DISSYSSTATE_ST_H
|
||||
#define U_POWER_DISSYSSTATE_ST_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
#include "../pmSysvariable.h"
|
||||
|
||||
class uPower_disSysStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_disSysStateMsg() {
|
||||
};
|
||||
~uPower_disSysStateMsg() {};
|
||||
std::string key = "uPower_disSysState_st";
|
||||
|
||||
disSysBreakerList currentDisBreakerState;
|
||||
|
||||
std::string buildMsg(disSysBreakerList currentDisBreakerState)
|
||||
{
|
||||
//构建配电系统状态报告
|
||||
Json::Value dis;
|
||||
disBus1Breaker* pdis1=new disBus1Breaker;
|
||||
disBus2Breaker* pdis2=new disBus2Breaker;
|
||||
disBus3Breaker* pdis3=new disBus3Breaker;
|
||||
disBus4Breaker* pdis4=new disBus4Breaker;
|
||||
|
||||
*pdis1 = currentDisBreakerState.bus1Breaker;
|
||||
*pdis2 = currentDisBreakerState.bus2Breaker;
|
||||
*pdis3 = currentDisBreakerState.bus3Breaker;
|
||||
*pdis4 = currentDisBreakerState.bus4Breaker;
|
||||
|
||||
dis["HVolBusBreaker_uint16"] = *(unsigned short*)pdis1;
|
||||
dis["HVolABusBreaker_unit16"] = *(unsigned short*)pdis2;
|
||||
dis["HVolBBusBreaker_unit16"] = *(unsigned short*)pdis3;
|
||||
dis["LVolBusBreaker_uint16"] = *(unsigned short*)pdis4;
|
||||
|
||||
//TODO: 构建配电系统故障码
|
||||
// Json::Value faultCodeDis_array;
|
||||
// for(auto val : m_pm->faultCode)
|
||||
// {
|
||||
// faultCodeDis_array.append(val);
|
||||
// }
|
||||
// dis[VAR_TO_STR(faultCode_array)] = faultCodeDis_array;
|
||||
// 转化为json格式
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
return Json::writeString(writerBuilder, dis);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,220 @@
|
||||
#ifndef U_POWER_EQUINSSTATE_H
|
||||
#define U_POWER_EQUINSSTATE_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
class uPower_equInsStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_equInsStateMsg() {
|
||||
// 初始化成员变量
|
||||
//state全部初始化为0
|
||||
memset(&state, 0, sizeof(state));
|
||||
}; // 添加默认构造函数实现
|
||||
~uPower_equInsStateMsg() {}; // 添加析构函数实现
|
||||
std::string key = "uPower_equInsState_fb";
|
||||
|
||||
struct SensorState
|
||||
{
|
||||
unsigned int singleBeamSonar1 : 1; // 单波束声呐1
|
||||
unsigned int singleBeamSonar2 : 1; // 单波束声呐2
|
||||
unsigned int singleBeamSonar3 : 1; // 单波束声呐3
|
||||
unsigned int singleBeamSonar4 : 1; // 单波束声呐4
|
||||
unsigned int singleBeamSonar5 : 1; // 单波束声呐5
|
||||
unsigned int singleBeamSonar6 : 1; // 单波束声呐6
|
||||
unsigned int singleBeamSonar7 : 1; // 单波束声呐7
|
||||
unsigned int singleBeamSonar8 : 1; // 单波束声呐8
|
||||
unsigned int forwardSonar : 1; // 前视声呐
|
||||
unsigned int ctd1 : 1; // CTD1
|
||||
unsigned int ctd2 : 1; // CTD2
|
||||
unsigned int soundVelocityMeter : 1; // 声速仪
|
||||
unsigned int ntp : 1; // 深度计
|
||||
unsigned int depthMeter1 : 1; // 深度计1
|
||||
unsigned int depthMeter2 : 1; // 深度计2
|
||||
unsigned int depthMeter3 : 1; // 深度计3
|
||||
};
|
||||
struct ActuatorState
|
||||
{
|
||||
unsigned int openCloseMechanism1 : 1; // bit 0 启闭机构1
|
||||
unsigned int openCloseMechanism2 : 1; // bit 1 启闭机构2
|
||||
unsigned int openCloseMechanism3 : 1; // bit 2 启闭机构3
|
||||
unsigned int openCloseMechanism4 : 1; // bit 3 启闭机构4
|
||||
unsigned int openCloseMechanism5 : 1; // bit 4 启闭机构5
|
||||
unsigned int openCloseMechanism6 : 1; // bit 5 启闭机构6
|
||||
unsigned int reserved1 : 2; // bit 6-7 保留
|
||||
unsigned int openWaterMechanism1 : 1; // bit 8 敞水机构1
|
||||
unsigned int openWaterMechanism2 : 1; // bit 9 敞水机构2
|
||||
unsigned int openWaterMechanism3 : 1; // bit 10 敞水机构3
|
||||
unsigned int openWaterMechanism4 : 1; // bit 11 敞水机构4
|
||||
unsigned int openWaterMechanism5 : 1; // bit 12 敞水机构5
|
||||
unsigned int openWaterMechanism6 : 1; // bit 13 敞水机构6
|
||||
unsigned int openWaterMechanism7 : 1; // bit 14 敞水机构7
|
||||
unsigned int openWaterMechanism8 : 1; // bit 15 敞水机构8
|
||||
};
|
||||
|
||||
struct MotionState
|
||||
{
|
||||
unsigned int sternRudder1 : 1; // bit 0 艉部舵机1
|
||||
unsigned int sternRudder2 : 1; // bit 1 艉部舵机2
|
||||
unsigned int sternRudder3 : 1; // bit 2 艉部舵机3
|
||||
unsigned int sternRudder4 : 1; // bit 3 艉部舵机4
|
||||
unsigned int bowRudder : 1; // bit 4 艏舵电缸
|
||||
unsigned int waterInjection : 1; // bit 5 注水机构
|
||||
unsigned int propulsionMotor : 1; // bit 6 推进电机
|
||||
unsigned int buoyancyAdjust1 : 1; // bit 7 浮调机构(艏部)1
|
||||
unsigned int buoyancyAdjust2 : 1; // bit 8 浮调机构(艏部)2
|
||||
unsigned int buoyancyAdjust3 : 1; // bit 9 浮调机构(艏部)3
|
||||
unsigned int buoyancyAdjust4 : 1; // bit 10 浮调机构(艉部)4
|
||||
unsigned int buoyancyAdjust5 : 1; // bit 11 浮调机构(艉部)5
|
||||
unsigned int DVL : 1; // bit 12 DVL
|
||||
unsigned int INS : 1; // bit 13 惯导系统
|
||||
unsigned int bowRudderLeft : 1; // bit 14 艏舵左舵机
|
||||
unsigned int bowRudderRight : 1; // bit 15 艏右舵舵机
|
||||
};
|
||||
struct LoadcommState
|
||||
{
|
||||
unsigned int payloadControl : 1; // bit 0 载荷发控
|
||||
unsigned int optMast : 1; // bit 1 光电桅杆
|
||||
unsigned int emMast : 1; // bit 2 电磁桅杆
|
||||
unsigned int reserved1 : 1; // bit 3 保留
|
||||
unsigned int sideSonar : 1; // bit 4 舷侧声纳
|
||||
unsigned int towedSonar : 1; // bit 5 拖曳声纳
|
||||
unsigned int reserved2 : 2; // bit 6-7 保留
|
||||
unsigned int commMast : 1; // bit 8 通信桅杆
|
||||
unsigned int midLowFreqSonar : 1; // bit 9 中低频声呐
|
||||
unsigned int highFreqComm : 1; // bit 10 高频声通机
|
||||
unsigned int buoySystem : 1; // bit 11 浮标系统
|
||||
unsigned int commMastRudder : 1; // bit 12 通信桅杆舵机
|
||||
unsigned int optMastRudder : 1; // bit 13 光电桅杆舵机
|
||||
unsigned int emMastRudder : 1; // bit 14 电磁桅杆舵机
|
||||
unsigned int reserved3 : 1; // bit 15 保留
|
||||
};
|
||||
struct ThrowPowerState
|
||||
{
|
||||
unsigned int bowThrow : 1; // bit 0 艏部抛载
|
||||
unsigned int reserved1 : 7; // bit 1-7 保留
|
||||
unsigned int fuelCellController : 1; // bit 8 燃料电池控制器
|
||||
unsigned int instrumentPanel : 1; // bit 9 仪表配电板
|
||||
unsigned int powerPanel : 1; // bit 10 动力配电板
|
||||
unsigned int instrumentBattery : 1; // bit 11 仪表锂电池
|
||||
unsigned int powerBattery : 1; // bit 12 动力锂电
|
||||
unsigned int sternThrow : 1; // bit 13 艉部抛载
|
||||
unsigned int reserved2 : 2; // bit 14-15 保留
|
||||
};
|
||||
struct uPower_equInsState
|
||||
{
|
||||
SensorState sensorState;
|
||||
ActuatorState actuatorState;
|
||||
MotionState motionState;
|
||||
LoadcommState loadcommState;
|
||||
ThrowPowerState throwPowerState;
|
||||
} state;
|
||||
std::string buildMsg(DriverTable s)
|
||||
{
|
||||
// 按照协议格式填充数据
|
||||
|
||||
// 传感器状态赋值
|
||||
state.sensorState.singleBeamSonar1 = s.singleBeamSonar1;
|
||||
state.sensorState.singleBeamSonar2 = s.singleBeamSonar2;
|
||||
state.sensorState.singleBeamSonar3 = s.singleBeamSonar3;
|
||||
state.sensorState.singleBeamSonar4 = s.singleBeamSonar4;
|
||||
state.sensorState.singleBeamSonar5 = s.singleBeamSonar5;
|
||||
state.sensorState.singleBeamSonar6 = s.singleBeamSonar6;
|
||||
state.sensorState.singleBeamSonar7 = s.singleBeamSonar7;
|
||||
state.sensorState.singleBeamSonar8 = s.singleBeamSonar8;
|
||||
state.sensorState.forwardSonar = s.forwardSonar;
|
||||
state.sensorState.ctd1 = s.ctd1;
|
||||
state.sensorState.ctd2 = s.ctd2;
|
||||
state.sensorState.soundVelocityMeter = s.soundVeloc;
|
||||
state.sensorState.ntp = s.ntp;
|
||||
state.sensorState.depthMeter1 = s.depth1;
|
||||
state.sensorState.depthMeter2 = s.depth2;
|
||||
state.sensorState.depthMeter3 = s.depth3;
|
||||
|
||||
// 执行机构状态赋值
|
||||
state.actuatorState.openCloseMechanism1 = s.bowCover1;
|
||||
state.actuatorState.openCloseMechanism2 = s.bowCover2;
|
||||
state.actuatorState.openCloseMechanism3 = s.bowCover3;
|
||||
state.actuatorState.openCloseMechanism4 = s.bowCover4;
|
||||
state.actuatorState.openCloseMechanism5 = s.bowCover5;
|
||||
state.actuatorState.openCloseMechanism6 = s.bowCover6;
|
||||
state.actuatorState.openWaterMechanism1 = s.bowWaterlnet1;
|
||||
state.actuatorState.openWaterMechanism2 = s.bowWaterlnet2;
|
||||
state.actuatorState.openWaterMechanism3 = s.bowWaterlnet3;
|
||||
state.actuatorState.openWaterMechanism4 = s.bowWaterlnet4;
|
||||
state.actuatorState.openWaterMechanism5 = s.bowWaterlnet5;
|
||||
state.actuatorState.openWaterMechanism6 = s.bowWaterlnet6;
|
||||
state.actuatorState.openWaterMechanism7 = s.bowWaterlnet7;
|
||||
state.actuatorState.openWaterMechanism8 = s.bowWaterlnet8;
|
||||
|
||||
// 运动状态赋值
|
||||
state.motionState.sternRudder1 = s.sternRudderServo1;
|
||||
state.motionState.sternRudder2 = s.sternRudderServo2;
|
||||
state.motionState.sternRudder3 = s.sternRudderServo3;
|
||||
state.motionState.sternRudder4 = s.sternRudderServo4;
|
||||
|
||||
state.motionState.bowRudder = s.bowRudderDeploy;
|
||||
|
||||
state.motionState.waterInjection = s.waterInject;
|
||||
|
||||
state.motionState.propulsionMotor = s.thruster;
|
||||
state.motionState.buoyancyAdjust1 = s.buoyancyAdjust1;
|
||||
state.motionState.buoyancyAdjust2 = s.buoyancyAdjust2;
|
||||
state.motionState.buoyancyAdjust3 = s.buoyancyAdjust3;
|
||||
state.motionState.buoyancyAdjust4 = s.buoyancyAdjust4;
|
||||
state.motionState.buoyancyAdjust5 = s.buoyancyAdjust5;
|
||||
state.motionState.DVL = s.DVL;
|
||||
state.motionState.INS = s.ins;
|
||||
|
||||
state.motionState.bowRudderLeft = s.bowRudderServo1;
|
||||
state.motionState.bowRudderRight = s.bowRudderServo2;
|
||||
|
||||
// 负载通信状态赋值
|
||||
state.loadcommState.payloadControl = s.launchControler;
|
||||
state.loadcommState.sideSonar = s.sideSonar;
|
||||
state.loadcommState.optMast = s.photoSensor;
|
||||
state.loadcommState.emMast = s.electSensor;
|
||||
state.loadcommState.buoySystem = s.buoyage;
|
||||
state.loadcommState.commMastRudder = s.mastLiftingServo;
|
||||
state.loadcommState.optMastRudder = s.mastLiftingServo;
|
||||
state.loadcommState.emMastRudder = s.mastLiftingServo;
|
||||
state.loadcommState.highFreqComm = s.USBL;
|
||||
state.loadcommState.midLowFreqSonar = s.lowFreqSonar;
|
||||
state.loadcommState.commMast = s.commMast;
|
||||
state.loadcommState.towedSonar = 0; //拖曳声纳未安装,默认为0
|
||||
|
||||
// 抛载和电源状态赋值
|
||||
state.throwPowerState.bowThrow = s.bowThrow; // 艏部抛载
|
||||
state.throwPowerState.sternThrow = s.sternThrow; // 艉部抛载
|
||||
state.throwPowerState.fuelCellController = 1; // 燃料电池控制器 默认开启
|
||||
state.throwPowerState.instrumentPanel = 1; // 仪表配电板 默认开启
|
||||
state.throwPowerState.powerPanel = 1; // 动力配电板 默认开启
|
||||
state.throwPowerState.instrumentBattery = 1; // 仪表锂电池 默认开启
|
||||
state.throwPowerState.powerBattery = 1; // 动力锂电 默认开启
|
||||
|
||||
// 转化为json格式
|
||||
Json::Value root;
|
||||
root["sensor_int16"] = *reinterpret_cast<uint16_t*>(&state.sensorState);
|
||||
root["actuator_int16"] = *reinterpret_cast<uint16_t*>(&state.actuatorState);
|
||||
root["motion_int16"] = *reinterpret_cast<uint16_t*>(&state.motionState);
|
||||
root["loadcomm_int16"] = *reinterpret_cast<uint16_t*>(&state.loadcommState);
|
||||
root["throwpower_int16"] = *reinterpret_cast<uint16_t*>(&state.throwPowerState);
|
||||
|
||||
//以二进制形式打印
|
||||
// std::cout << "sensor_int16: " << std::bitset<16>(*reinterpret_cast<uint16_t*>(&state.sensorState)) << std::endl;
|
||||
// std::cout << "actuator_int16: " << std::bitset<16>(*reinterpret_cast<uint16_t*>(&state.actuatorState)) << std::endl;
|
||||
// std::cout << "motion_int16: " << std::bitset<16>(*reinterpret_cast<uint16_t*>(&state.motionState)) << std::endl;
|
||||
// std::cout << "loadcomm_int16: " << std::bitset<16>(*reinterpret_cast<uint16_t*>(&state.loadcommState)) << std::endl;
|
||||
// std::cout << "throwpower_int16: " << std::bitset<16>(*reinterpret_cast<uint16_t*>(&state.throwPowerState)) << std::endl;
|
||||
|
||||
// 返回json字符串
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = ""; // 紧凑格式,无缩进
|
||||
return Json::writeString(writerBuilder, root);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef U_POWER_EQUSTATE_FB_H
|
||||
#define U_POWER_EQUSTATE_FB_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
|
||||
class uPower_equStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_equStateMsg() {
|
||||
};
|
||||
~uPower_equStateMsg() {};
|
||||
std::string key = "uPower_equState_fb";
|
||||
|
||||
Driver driver;
|
||||
|
||||
std::string buildMsg(DriverTable s)
|
||||
{
|
||||
return driver.saveDriverTableToJson(&s);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
//控制消息
|
||||
#define DB_TO_PM_EQUIPMENTCMD "uPower_equState_cmd"
|
||||
@@ -0,0 +1,133 @@
|
||||
#ifndef U_POWER_FCSSTATE_ST_H
|
||||
#define U_POWER_FCSSTATE_ST_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
|
||||
class uPower_fcsStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_fcsStateMsg() {
|
||||
memset(&state, 0, sizeof(state));
|
||||
};
|
||||
~uPower_fcsStateMsg() {};
|
||||
std::string key = "uPower_fcsState_st";
|
||||
|
||||
struct uPower_fcsState
|
||||
{
|
||||
unsigned int fcsStatus : 4; // 燃料电池状态
|
||||
unsigned int outputPower : 12; // 输出功率 (0-4095)
|
||||
unsigned int temperature : 8; // 温度 (0-255)
|
||||
unsigned int errorCode : 8; // 错误代码
|
||||
} state;
|
||||
|
||||
std::string buildMsg(ccuState ccustate)
|
||||
{
|
||||
//TODO:根据最新协议修改
|
||||
Json::Value fcs;
|
||||
// suffix = getTypeName(typeid(ccustate.fcuState).name());
|
||||
// fcs["fcuState"] = ccustate.fcuState;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuFaultLeve).name());
|
||||
// fcs["fcuFaultLeve"] = ccustate.fcuFaultLeve;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.powerLimit).name());
|
||||
// fcs[VAR_TO_STR(powLimit)+suffix] = ccustate.powerLimit;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.totalPowerGeneration).name());
|
||||
// fcs[VAR_TO_STR(powerGen)+suffix] = ccustate.totalPowerGeneration;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.ch4o).name());
|
||||
// fcs[VAR_TO_STR(ch4o)+suffix] = ccustate.ch4o;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.o2).name());
|
||||
// fcs[VAR_TO_STR(o2)+suffix] = ccustate.o2;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuVoltage).name());
|
||||
// fcs[VAR_TO_STR(fcuVol)+suffix] = ccustate.fcuVoltage;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuCurrent).name());
|
||||
// fcs[VAR_TO_STR(fcuCur)+suffix] = ccustate.fcuCurrent;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.o2Level).name());
|
||||
// fcs[VAR_TO_STR(o2Level)+suffix] = ccustate.o2Level;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.exchangerTemperature).name());
|
||||
// fcs[VAR_TO_STR(excTemp)+suffix] = ccustate.exchangerTemperature;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuOutPower).name());
|
||||
// fcs[VAR_TO_STR(fcuOutPower)+suffix] = ccustate.fcuOutPower;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuOutIns).name());
|
||||
// fcs[VAR_TO_STR(fcuOutIns)+suffix] = ccustate.fcuOutIns;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuVoltageIns).name());
|
||||
// fcs[VAR_TO_STR(fcuVolIns)+suffix] = ccustate.fcuVoltageIns;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuVoltagePower).name());
|
||||
// fcs[VAR_TO_STR(fcuVolPower)+suffix] = ccustate.fcuVoltagePower;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuCurrentIns).name());
|
||||
// fcs[VAR_TO_STR(fcuCurIns)+suffix] = ccustate.fcuCurrentIns;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.fcuCurrentPower).name());
|
||||
// fcs[VAR_TO_STR(fcuCurPower)+suffix] = ccustate.fcuCurrentPower;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.h2Concentration1).name());
|
||||
// fcs[VAR_TO_STR(h2Concent1)+suffix] = ccustate.h2Concentration1;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.h2Concentration2).name());
|
||||
// fcs[VAR_TO_STR(h2Concent2)+suffix] = ccustate.h2Concentration2;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.o2Concentration1).name());
|
||||
// fcs[VAR_TO_STR(o2Concent1)+suffix] = ccustate.o2Concentration1;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.o2Concentration2).name());
|
||||
// fcs[VAR_TO_STR(o2Concent2)+suffix] = ccustate.o2Concentration2;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.ch4oConcentration1).name());
|
||||
// fcs[VAR_TO_STR(ch4oConcent1)+suffix] = ccustate.ch4oConcentration1;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.ch4oConcentration2).name());
|
||||
// fcs[VAR_TO_STR(ch4oConcent2)+suffix] = ccustate.ch4oConcentration2;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.backpressure1).name());
|
||||
// fcs[VAR_TO_STR(backpressure1)+suffix] = ccustate.backpressure1;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.backpressure2).name());
|
||||
// fcs[VAR_TO_STR(backpressure2)+suffix] = ccustate.backpressure2;
|
||||
|
||||
// suffix = getTypeName(typeid(ccustate.flameDetection).name());
|
||||
// fcs[VAR_TO_STR(flameDet)+suffix] = ccustate.flameDetection;
|
||||
|
||||
// unsigned short faultCode1;
|
||||
// unsigned short faultCode2;
|
||||
// unsigned short faultCode3;
|
||||
// faultCode1 = (ccustate.fcuGZ_1H << 8) | ccustate.fcuGZ_1L;
|
||||
// faultCode2 = (ccustate.fcuGZ_2H << 8) | ccustate.fcuGZ_2L;
|
||||
// faultCode3 = (ccustate.fcuGZ_3H << 8) | ccustate.fcuGZ_3L;
|
||||
|
||||
// suffix = getTypeName(typeid(faultCode1).name());
|
||||
// fcs[VAR_TO_STR(faultCode1)+suffix] = faultCode1;
|
||||
// suffix = getTypeName(typeid(faultCode2).name());
|
||||
// fcs[VAR_TO_STR(faultCode2)+suffix] = faultCode2;
|
||||
// suffix = getTypeName(typeid(faultCode3).name());
|
||||
// fcs[VAR_TO_STR(faultCode3)+suffix] = faultCode3;
|
||||
|
||||
// // 转化为json格式
|
||||
// Json::Value root;
|
||||
// root["fcsStatus"] = state.fcsStatus;
|
||||
// root["outputPower"] = state.outputPower;
|
||||
// root["temperature"] = state.temperature;
|
||||
// root["errorCode"] = state.errorCode;
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
return Json::writeString(writerBuilder, fcs);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,137 @@
|
||||
#ifndef U_POWER_LIBATSTATE_ST_H
|
||||
#define U_POWER_LIBATSTATE_ST_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
|
||||
class uPower_liBatStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_liBatStateMsg() {
|
||||
};
|
||||
~uPower_liBatStateMsg() {};
|
||||
std::string key = "uPower_liBatState_st";
|
||||
|
||||
|
||||
std::string buildMsg(ccuState ccustate)
|
||||
{
|
||||
//TODO:根据最新协议修改
|
||||
Json::Value lbs;
|
||||
//构建动力锂电池状态报告
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPosRelayState).name());
|
||||
// lbs[VAR_TO_STR(insPosRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.insPosRelayState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insNegRelayState).name());
|
||||
// lbs[VAR_TO_STR(insNegRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.insNegRelayState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPosRelayState).name());
|
||||
// lbs[VAR_TO_STR(powPosRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPosRelayState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerNegRelayState).name());
|
||||
// lbs[VAR_TO_STR(powNegRelayState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerNegRelayState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatLimit).name());
|
||||
// lbs[VAR_TO_STR(insBatLimit)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatLimit;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatLimit).name());
|
||||
// lbs[VAR_TO_STR(powerBatLimit)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatLimit;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatSoc).name());
|
||||
// lbs[VAR_TO_STR(insBatSoc)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatSoc;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatSoc).name());
|
||||
// lbs[VAR_TO_STR(powBatSoc)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatSoc;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatTotalElectricity).name());
|
||||
// lbs[VAR_TO_STR(insBatTotalElect)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatTotalElectricity;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatTotalElectricity).name());
|
||||
// lbs[VAR_TO_STR(powBatTotalElect)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatTotalElectricity;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insBatCurrentElectricity).name());
|
||||
// lbs[VAR_TO_STR(insBatCurElect)+suffix] = m_pm->m_pmCurrentState.ccustate.insBatCurrentElectricity;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerBatCurrentElectricity).name());
|
||||
// lbs[VAR_TO_STR(powBatCurElect)+suffix] = m_pm->m_pmCurrentState.ccustate.powerBatCurrentElectricity;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insChargeState).name());
|
||||
// lbs[VAR_TO_STR(insChargeState)+suffix] = m_pm->m_pmCurrentState.ccustate.insChargeState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerChargeState).name());
|
||||
// lbs[VAR_TO_STR(powChargeState)+suffix] = m_pm->m_pmCurrentState.ccustate.powerChargeState;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insLinkVoltage).name());
|
||||
// lbs[VAR_TO_STR(insLinkVol)+suffix] = m_pm->m_pmCurrentState.ccustate.insLinkVoltage;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPackVoltage).name());
|
||||
// lbs[VAR_TO_STR(insPackVol)+suffix] = m_pm->m_pmCurrentState.ccustate.insPackVoltage;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrent).name());
|
||||
// lbs[VAR_TO_STR(insCurrent)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrent;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insPosInsulationResistance).name());
|
||||
// lbs[VAR_TO_STR(insPosRes)+suffix] = m_pm->m_pmCurrentState.ccustate.insPosInsulationResistance;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insNegInsulationResistance).name());
|
||||
// lbs[VAR_TO_STR(insNegRes)+suffix] = m_pm->m_pmCurrentState.ccustate.insNegInsulationResistance;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerLinkVoltage).name());
|
||||
// lbs[VAR_TO_STR(powLinkVol)+suffix] = m_pm->m_pmCurrentState.ccustate.powerLinkVoltage;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPackVoltage).name());
|
||||
// lbs[VAR_TO_STR(powerPackVol)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPackVoltage;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrent).name());
|
||||
// lbs[VAR_TO_STR(powCur)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrent;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerPosInsulationResistance).name());
|
||||
// lbs[VAR_TO_STR(powPosRes)+suffix] = m_pm->m_pmCurrentState.ccustate.powerPosInsulationResistance;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerNegInsulationResistance).name());
|
||||
// lbs[VAR_TO_STR(powNegRes)+suffix] = m_pm->m_pmCurrentState.ccustate.powerNegInsulationResistance;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold1).name());
|
||||
// lbs[VAR_TO_STR(insCurSocHold1)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold1;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold2).name());
|
||||
// lbs[VAR_TO_STR(insCurSocHold2)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold2;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insCurrentSocHold3).name());
|
||||
// lbs[VAR_TO_STR(insCurSocHold3)+suffix] = m_pm->m_pmCurrentState.ccustate.insCurrentSocHold3;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentToInsLimit1).name());
|
||||
// lbs[VAR_TO_STR(fcuCurToInsLimit1)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentToInsLimit1;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.fcuCurrentToinsLimit2).name());
|
||||
// lbs[VAR_TO_STR(fcuCurToinsLimit2)+suffix] = m_pm->m_pmCurrentState.ccustate.fcuCurrentToinsLimit2;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold1).name());
|
||||
// lbs[VAR_TO_STR(powCurSocHold1)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold1;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold2).name());
|
||||
// lbs[VAR_TO_STR(powCurSocHold2)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold2;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold3).name());
|
||||
// lbs[VAR_TO_STR(powCurSocHold3)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentSocHold3;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentToInsLimit1).name());
|
||||
// lbs[VAR_TO_STR(powCurToInsLimit1)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentToInsLimit1;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerCurrentToinsLimit2).name());
|
||||
// lbs[VAR_TO_STR(powCurToinsLimit2)+suffix] = m_pm->m_pmCurrentState.ccustate.powerCurrentToinsLimit2;
|
||||
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.insAlarmIdentificationWord).name());
|
||||
// lbs[VAR_TO_STR(insfaultCode)+suffix] = m_pm->m_pmCurrentState.ccustate.insAlarmIdentificationWord;
|
||||
// suffix = getTypeName(typeid(m_pm->m_pmCurrentState.ccustate.powerAlarmIdentificationWord).name());
|
||||
// lbs[VAR_TO_STR(powfaultCode)+suffix] = m_pm->m_pmCurrentState.ccustate.powerAlarmIdentificationWord;
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
return Json::writeString(writerBuilder, lbs);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef U_POWER_PMSTATE_FB_H
|
||||
#define U_POWER_PMSTATE_FB_H
|
||||
#include "../driver.h"
|
||||
#include "string"
|
||||
#include "json/json.h"
|
||||
#include <bitset>
|
||||
|
||||
class uPower_pmStateMsg
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uPower_pmStateMsg() {
|
||||
memset(&state, 0, sizeof(state));
|
||||
};
|
||||
~uPower_pmStateMsg() {};
|
||||
std::string key = "uPower_pmState_fb";
|
||||
|
||||
struct uPower_pmState
|
||||
{
|
||||
unsigned char workCondition;
|
||||
unsigned char currentMod;
|
||||
unsigned char powerState;
|
||||
unsigned char faultLevel;
|
||||
vector<unsigned int> faultCode;
|
||||
unsigned int soc;
|
||||
unsigned int sustainableTime;
|
||||
unsigned int m_faultNum;
|
||||
unsigned char m_leakage;
|
||||
} state;
|
||||
|
||||
std::string buildMsg()
|
||||
{
|
||||
// 状态赋值
|
||||
//1.构建系统状态报告
|
||||
Json::Value pms;
|
||||
|
||||
pms["workCondition_uint"] = state.workCondition;
|
||||
pms["currentMod_uint8"] = state.currentMod;
|
||||
pms["powerState_uint8"] = state.powerState;
|
||||
pms["faultLevel_uint8"] = state.faultLevel;
|
||||
|
||||
Json::Value faultCode_array;
|
||||
for(auto val : state.faultCode)
|
||||
{
|
||||
faultCode_array.append(val);
|
||||
}
|
||||
pms["faultCode_array"] = faultCode_array;
|
||||
|
||||
pms["soc_uint16"] = state.soc;
|
||||
|
||||
pms["sustainableTime_int64"] = state.sustainableTime;
|
||||
|
||||
pms["leakage_uint8"] = state.m_leakage;
|
||||
|
||||
// 转化为json格式
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
return Json::writeString(writerBuilder, pms);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
//控制消息
|
||||
#define DB_TO_PM_MSCMD "uPower_sysState_cmd"
|
||||
Reference in New Issue
Block a user