为数据库插入增加保护
This commit is contained in:
@@ -40,7 +40,7 @@ public:
|
||||
std::unique_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
||||
Json::Value j;
|
||||
std::string errors;
|
||||
|
||||
LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
bool parsingSuccessful = reader->parse(jsonString.c_str(), jsonString.c_str() + jsonString.length(), &j, &errors);
|
||||
if (!parsingSuccessful) {
|
||||
LOG_F(ERROR, "Failed to parse JSON: %s", errors.c_str());
|
||||
@@ -50,9 +50,6 @@ public:
|
||||
if (j.isMember("xcLowVoltageAdd_int32") && j.isMember("xcHighVoltageAdd_int32")) {
|
||||
xcLowVoltageAdd_int32 = j["xcLowVoltageAdd_int32"].asInt();
|
||||
xcHighVoltageAdd_int32 = j["xcHighVoltageAdd_int32"].asInt();
|
||||
LOG_F(INFO, "xcLowVoltageAdd_int32: %d", xcLowVoltageAdd_int32);
|
||||
LOG_F(INFO, "xcHighVoltageAdd_int32: %d", xcHighVoltageAdd_int32);
|
||||
LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
return true;
|
||||
}
|
||||
LOG_F(ERROR, "JSON does not contain required fields");
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
std::unique_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
||||
Json::Value j;
|
||||
std::string errors;
|
||||
|
||||
LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
bool parsingSuccessful = reader->parse(jsonString.c_str(), jsonString.c_str() + jsonString.length(), &j, &errors);
|
||||
if (!parsingSuccessful) {
|
||||
LOG_F(ERROR, "Failed to parse JSON: %s", errors.c_str());
|
||||
@@ -46,8 +46,6 @@ public:
|
||||
|
||||
if (j.isMember("zdpVoltageAdd_int32")) {
|
||||
zdpVoltageAdd_int32 = j["zdpVoltageAdd_int32"].asInt();
|
||||
LOG_F(INFO, "zdpVoltageAdd_int32: %d", zdpVoltageAdd_int32);
|
||||
LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
return true;
|
||||
}
|
||||
LOG_F(ERROR, "JSON does not contain required fields");
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
{
|
||||
"rpm int16": "xxx", // 实际转速,类型:int16_t
|
||||
"voltage_uint16": "xxx", // 电压,类型:uint16_t,单位 V
|
||||
"current_uint16": "xxx", // 电流,类型:uint16_t,单位 A
|
||||
"ctrlTemp_uint16": "xxx", // 控制器温度,类型:uint16_t,单位 °C
|
||||
"motorTemp_uint16": "xxx", // 电机温度,类型:uint16_t,单位 °C
|
||||
"motorTorque_uint16": "xxx", // 电机扭矩,类型:uint16_t,单位 N・m
|
||||
"maxTorque_uint16": "xxx", // 电机最大扭矩,类型:uint16_t,单位 N・m,电机使能时该字段非零,无使能地址报警,含使能整标标识字,00 无故障,按位常量零
|
||||
"error_int64": "xxx" // 见表 [1],类型:int64_t
|
||||
}
|
||||
*/
|
||||
#ifndef UDEVICE_THRUSTER_ST_H
|
||||
#define UDEVICE_THRUSTER_ST_H
|
||||
|
||||
#include "../logc/loguru.hpp"
|
||||
#include "json/json.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
class uDevice_thruster_st
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uDevice_thruster_st(){};
|
||||
~uDevice_thruster_st(){};
|
||||
|
||||
int16_t rpm_int16;
|
||||
uint16_t voltage_uint16;
|
||||
uint16_t current_uint16;
|
||||
uint16_t ctrlTemp_uint16;
|
||||
uint16_t motorTemp_uint16;
|
||||
uint16_t motorTorque_uint16;
|
||||
uint16_t maxTorque_uint16;
|
||||
int64_t error_int64;
|
||||
|
||||
static std::string key;
|
||||
|
||||
std::string toJsonString()
|
||||
{
|
||||
Json::Value j;
|
||||
j["rpm_int16"] = rpm_int16;
|
||||
j["voltage_uint16"] = voltage_uint16;
|
||||
j["current_uint16"] = current_uint16;
|
||||
j["ctrlTemp_uint16"] = ctrlTemp_uint16;
|
||||
j["motorTemp_uint16"] = motorTemp_uint16;
|
||||
j["motorTorque_uint16"] = motorTorque_uint16;
|
||||
j["maxTorque_uint16"] = maxTorque_uint16;
|
||||
j["error_int64"] = static_cast<Json::Int64>(error_int64);
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder.settings_["indentation"] = "";
|
||||
return Json::writeString(builder, j);
|
||||
}
|
||||
|
||||
bool fromJsonString(std::string jsonString)
|
||||
{
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
JSONCPP_STRING errs;
|
||||
|
||||
// 解析JSON字符串
|
||||
std::istringstream stream(jsonString);
|
||||
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
|
||||
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取rpm_int16
|
||||
if (root.isMember("rpm_int16") && root["rpm_int16"].isInt()) {
|
||||
rpm_int16 = root["rpm_int16"].asInt();
|
||||
// LOG_F(INFO, "rpm_int16: %d", rpm_int16);
|
||||
}
|
||||
|
||||
// 提取voltage_uint16
|
||||
if (root.isMember("voltage_uint16") && root["voltage_uint16"].isUInt()) {
|
||||
voltage_uint16 = root["voltage_uint16"].asUInt();
|
||||
// LOG_F(INFO, "voltage_uint16: %u", voltage_uint16);
|
||||
}
|
||||
|
||||
// 提取current_uint16
|
||||
if (root.isMember("current_uint16") && root["current_uint16"].isUInt()) {
|
||||
current_uint16 = root["current_uint16"].asUInt();
|
||||
// LOG_F(INFO, "current_uint16: %u", current_uint16);
|
||||
}
|
||||
|
||||
// 提取ctrlTemp_uint16
|
||||
if (root.isMember("ctrlTemp_uint16") && root["ctrlTemp_uint16"].isUInt()) {
|
||||
ctrlTemp_uint16 = root["ctrlTemp_uint16"].asUInt();
|
||||
// LOG_F(INFO, "ctrlTemp_uint16: %u", ctrlTemp_uint16);
|
||||
}
|
||||
|
||||
// 提取motorTemp_uint16
|
||||
if (root.isMember("motorTemp_uint16") && root["motorTemp_uint16"].isUInt()) {
|
||||
motorTemp_uint16 = root["motorTemp_uint16"].asUInt();
|
||||
// LOG_F(INFO, "motorTemp_uint16: %u", motorTemp_uint16);
|
||||
}
|
||||
|
||||
// 提取motorTorque_uint16
|
||||
if (root.isMember("motorTorque_uint16") && root["motorTorque_uint16"].isUInt()) {
|
||||
motorTorque_uint16 = root["motorTorque_uint16"].asUInt();
|
||||
// LOG_F(INFO, "motorTorque_uint16: %u", motorTorque_uint16);
|
||||
}
|
||||
|
||||
// 提取maxTorque_uint16
|
||||
if (root.isMember("maxTorque_uint16") && root["maxTorque_uint16"].isUInt()) {
|
||||
maxTorque_uint16 = root["maxTorque_uint16"].asUInt();
|
||||
// LOG_F(INFO, "maxTorque_uint16: %u", maxTorque_uint16);
|
||||
}
|
||||
|
||||
// 提取error_int64
|
||||
if (root.isMember("error_int64") && root["error_int64"].isInt64()) {
|
||||
error_int64 = root["error_int64"].asInt64();
|
||||
// LOG_F(INFO, "error_int64: %lld", error_int64);
|
||||
}
|
||||
|
||||
// LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
{
|
||||
"rpm_int16": "xx", // 期望转速;单位:rpm;类型 int16_t
|
||||
"enable_int16": "xx" // 使能指令,1 - 使能,0 - 去使能。类型 int16_t
|
||||
}
|
||||
*/
|
||||
#ifndef UEXTERNCOMM_SETTHRUSTSPEED_CMD_H
|
||||
#define UEXTERNCOMM_SETTHRUSTSPEED_CMD_H
|
||||
|
||||
#include "../logc/loguru.hpp"
|
||||
#include "json/json.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
class uExternComm_setThrustSpeed_cmd
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
uExternComm_setThrustSpeed_cmd(){};
|
||||
~uExternComm_setThrustSpeed_cmd(){};
|
||||
|
||||
int16_t rpm_int16;
|
||||
int16_t enable_int16;
|
||||
|
||||
static std::string key;
|
||||
|
||||
std::string toJsonString()
|
||||
{
|
||||
Json::Value j;
|
||||
j["rpm_int16"] = rpm_int16;
|
||||
j["enable_int16"] = enable_int16;
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder.settings_["indentation"] = "";
|
||||
return Json::writeString(builder, j);
|
||||
}
|
||||
|
||||
bool fromJsonString(std::string jsonString)
|
||||
{
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
JSONCPP_STRING errs;
|
||||
|
||||
// 解析JSON字符串
|
||||
std::istringstream stream(jsonString);
|
||||
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
|
||||
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取rpm_int16
|
||||
if (root.isMember("rpm_int16") && root["rpm_int16"].isInt()) {
|
||||
rpm_int16 = root["rpm_int16"].asInt();
|
||||
// LOG_F(INFO, "rpm_int16: %d", rpm_int16);
|
||||
}
|
||||
|
||||
// 提取enable_int16
|
||||
if (root.isMember("enable_int16") && root["enable_int16"].isInt()) {
|
||||
enable_int16 = root["enable_int16"].asInt();
|
||||
// LOG_F(INFO, "enable_int16: %d", enable_int16);
|
||||
}
|
||||
|
||||
// LOG_F(INFO, "jsonString: %s", jsonString.c_str());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
m_state_of_bus_lv_a.set_reserved_breaker_1((data.instrument_bus_status.reservedCircuitBreaker1 == 1));
|
||||
m_state_of_bus_lv_a.set_reserved_breaker_2((data.instrument_bus_status.reservedCircuitBreaker2 == 1));
|
||||
m_state_of_bus_lv_a.set_emergency_lithium_battery_group_1_breaker((data.instrument_bus_status.emergencyLithiumBatteryGroup1CircuitBreaker == 1));
|
||||
dis["LVolBusBreaker_uint16"] = m_state_of_bus_lv.relay_states.to_ulong();
|
||||
dis["LVolBusBreaker_uint16"] = m_state_of_bus_lv_a.relay_states.to_ulong();
|
||||
|
||||
//构建配电系统故障码
|
||||
Json::Value faultCodeDis_array = Json::Value(Json::arrayValue);
|
||||
|
||||
@@ -129,7 +129,8 @@ public:
|
||||
state.sensorState.ctd1 = s.ctd1;
|
||||
state.sensorState.ctd2 = s.ctd2;
|
||||
state.sensorState.soundVelocityMeter = s.soundVeloc;
|
||||
state.sensorState.ntp = s.ntp;
|
||||
// state.sensorState.ntp = s.ntp;
|
||||
state.sensorState.ntp = 0;
|
||||
state.sensorState.depthMeter1 = s.depth1;
|
||||
state.sensorState.depthMeter2 = s.depth2;
|
||||
state.sensorState.depthMeter3 = s.depth3;
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
{
|
||||
//TODO:根据最新协议修改
|
||||
Json::Value lbs;
|
||||
//构建动力锂电池状态报告
|
||||
//构建锂电池状态报告
|
||||
lbs["insBatCurElect_uint16"] = data.ins_current;
|
||||
lbs["insBatLimit_uint16"] = data.ins_power_limit1;
|
||||
lbs[ "insBatSoc_uint8"] = data.ins_soc;
|
||||
@@ -61,6 +61,17 @@ public:
|
||||
//TODO:默认屏蔽故障码
|
||||
lbs["insCommState_uint8"] = 0;
|
||||
lbs["powCommState_uint8"] = 0;
|
||||
|
||||
//应急电池
|
||||
// 增加应急锂电池状态
|
||||
lbs["emergencyBattery1Voltage_int16"] = data.emergency_battery1_voltage;
|
||||
lbs["emergencyBattery1Current_int16"] = data.emergency_battery1_current;
|
||||
lbs["emergencyBattery1MaxTemp_int16"] = data.emergency_battery1_max_temp;
|
||||
lbs["emergencyBattery1FaultWord_uint16"] = data.emergency_battery1_fault_word;
|
||||
lbs["emergencyBattery2Voltage_int16"] = data.emergency_battery2_voltage;
|
||||
lbs["emergencyBattery2Current_int16"] = data.emergency_battery2_current;
|
||||
lbs["emergencyBattery2MaxTemp_int16"] = data.emergency_battery2_max_temp;
|
||||
lbs["emergencyBattery2FaultWord_uint16"] = data.emergency_battery2_fault_word;
|
||||
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
writerBuilder.settings_["indentation"] = "";
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "uDetect_zdpVoltage_cmd.h"
|
||||
#include "uDetect_xcVoltage_cmd.h"
|
||||
#include "uDevice_thruster_st.h"
|
||||
#include "uExternComm_setThrustSpeed_cmd.h"
|
||||
|
||||
// 定义静态成员变量
|
||||
std::string uDetect_zdpVoltage_cmd::key = "uDetect_zdpVoltage_cmd";
|
||||
std::string uDetect_xcVoltage_cmd::key = "uDetect_xcVoltage_cmd";
|
||||
std::string uDevice_thruster_st::key = "uDevice_thruster_st";
|
||||
std::string uExternComm_setThrustSpeed_cmd::key = "uExternComm_setThrustSpeed_cmd";
|
||||
|
||||
Reference in New Issue
Block a user