增加了解析上位机指令的功能
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
{
|
||||
"backpressure1_fp32": 10.0,
|
||||
"backpressure2_fp32": 6.0,
|
||||
"ch4oConcent1_fp32": 67.0,
|
||||
"ch4oConcent2_fp32": 64.0,
|
||||
"backpressure1_fp32": 8.0,
|
||||
"backpressure2_fp32": 9.0,
|
||||
"ch4oConcent1_fp32": 53.0,
|
||||
"ch4oConcent2_fp32": 81.0,
|
||||
"ch4o_fp32": 0.0,
|
||||
"excTemp_fp32": 44.0,
|
||||
"excTemp_fp32": 84.0,
|
||||
"faultCode1_uint16": 0,
|
||||
"faultCode2_uint16": 0,
|
||||
"faultCode3_uint16": 0,
|
||||
"fcuCurIns_fp32": 0.0,
|
||||
"fcuCurPower_fp32": 0.0,
|
||||
"fcuCur_fp32": 98.0,
|
||||
"fcuCur_fp32": 14.0,
|
||||
"fcuFaultLeve_uint8": 0,
|
||||
"fcuOutIns_fp32": 90.0,
|
||||
"fcuOutPower_fp32": 514.0,
|
||||
"fcuOutIns_fp32": 56.0,
|
||||
"fcuOutPower_fp32": 386.0,
|
||||
"fcuState_uint8": 0,
|
||||
"fcuVolIns_fp32": 0.0,
|
||||
"fcuVolPower_fp32": 0.0,
|
||||
"fcuVol_fp32": 380.0,
|
||||
"flameDet_uint8": 0,
|
||||
"h2Concent1_fp32": 20.0,
|
||||
"h2Concent2_fp32": 25.0,
|
||||
"o2Concent1_fp32": 63.0,
|
||||
"o2Concent2_fp32": 19.0,
|
||||
"fcuVol_fp32": 382.0,
|
||||
"flameDet_uint8": 1,
|
||||
"h2Concent1_fp32": 5.0,
|
||||
"h2Concent2_fp32": 3.0,
|
||||
"o2Concent1_fp32": 80.0,
|
||||
"o2Concent2_fp32": 82.0,
|
||||
"o2Level_fp32": 0.0,
|
||||
"o2_fp32": 0.0,
|
||||
"powLimit_fp32": 95.0,
|
||||
"powerGen_fp32": 834.0
|
||||
"powLimit_fp32": 10.0,
|
||||
"powerGen_fp32": 390.0
|
||||
}
|
||||
@@ -2,37 +2,37 @@
|
||||
"fcuCurToInsLimit1_uint8": 0,
|
||||
"fcuCurToinsLimit2_uint8": 0,
|
||||
"insBatCurElect_uint16": 0,
|
||||
"insBatLimit_uint16": 2,
|
||||
"insBatSoc_uint8": 23,
|
||||
"insBatTotalElect_uint16": 783,
|
||||
"insBatLimit_uint16": 89,
|
||||
"insBatSoc_uint8": 57,
|
||||
"insBatTotalElect_uint16": 829,
|
||||
"insChargeState_uint8": 0,
|
||||
"insCurSocHold1_uint8": 0,
|
||||
"insCurSocHold2_uint8": 0,
|
||||
"insCurSocHold3_uint8": 0,
|
||||
"insCurrent_uint16": 55,
|
||||
"insCurrent_uint16": 77,
|
||||
"insLinkVol_uint16": 0,
|
||||
"insNegRelayState_uint8": 0,
|
||||
"insNegRelayState_uint8": 1,
|
||||
"insNegRes_uint16": 0,
|
||||
"insPackVol_uint16": 0,
|
||||
"insPosRelayState_uint8": 0,
|
||||
"insPosRes_uint16": 0,
|
||||
"insfaultCode_uint8": 0,
|
||||
"powBatCurElect_uint16": 0,
|
||||
"powBatSoc_uint8": 85,
|
||||
"powBatTotalElect_uint16": 513,
|
||||
"powBatSoc_uint8": 55,
|
||||
"powBatTotalElect_uint16": 924,
|
||||
"powChargeState_uint8": 0,
|
||||
"powCurSocHold1_uint8": 0,
|
||||
"powCurSocHold2_uint8": 0,
|
||||
"powCurSocHold3_uint8": 0,
|
||||
"powCurToInsLimit1_uint8": 0,
|
||||
"powCurToinsLimit2_uint8": 0,
|
||||
"powCur_uint16": 14,
|
||||
"powCur_uint16": 74,
|
||||
"powLinkVol_uint16": 0,
|
||||
"powNegRelayState_uint8": 0,
|
||||
"powNegRes_uint16": 0,
|
||||
"powPosRelayState_uint8": 1,
|
||||
"powPosRelayState_uint8": 0,
|
||||
"powPosRes_uint16": 0,
|
||||
"powerBatLimit_uint16": 43,
|
||||
"powerBatLimit_uint16": 53,
|
||||
"powerPackVol_uint16": 0,
|
||||
"powfaultCode_uint8": 0
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"powerCMD":0,
|
||||
"modCMD":0,
|
||||
"workCMD":0
|
||||
}
|
||||
@@ -10,10 +10,14 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "../pPowerManger/SQLiteDB.h"
|
||||
#include "../pPowerManger/pmSysvariable.h"
|
||||
#include <MOOS/libMOOS/Comms/MOOSAsyncCommClient.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// 定义一个全局变量,用于存储状态信息
|
||||
ccuState ccustate;
|
||||
|
||||
// 读取 HTML 文件内容
|
||||
string read_file(const string& path) {
|
||||
ifstream file(path);
|
||||
|
||||
@@ -88,10 +88,25 @@ bool PowerManger::OnNewMail(MOOSMSG_LIST &NewMail)
|
||||
AppCastingMOOSApp::OnNewMail(NewMail);
|
||||
|
||||
MOOSMSG_LIST::iterator p;
|
||||
for(p=NewMail.begin(); p!=NewMail.end(); p++) {
|
||||
for(p=NewMail.begin(); p!=NewMail.end(); p++)
|
||||
{
|
||||
CMOOSMsg &msg = *p;
|
||||
string key = msg.GetKey();
|
||||
|
||||
//处理上位机发送的控制指令
|
||||
if(key == PM_MS_CMD_VAR)
|
||||
{
|
||||
string strJson = msg.GetString();
|
||||
if(getMsCmdFromJson(m_msCmd,strJson))
|
||||
{
|
||||
cout << "get ms cmd:" << strJson << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "get ms cmd error:" << strJson << endl;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // Keep these around just for template
|
||||
string comm = msg.GetCommunity();
|
||||
double dval = msg.GetDouble();
|
||||
@@ -223,7 +238,7 @@ bool PowerManger::OnStartUp()
|
||||
void PowerManger::registerVariables()
|
||||
{
|
||||
AppCastingMOOSApp::RegisterVariables();
|
||||
// Register("FOOBAR", 0);
|
||||
Register(PM_MS_CMD_VAR, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -663,6 +678,11 @@ void PowerManger::initControlCmd()
|
||||
m_CcuColCmd.powerBatEfficiency = 230; //默认为最大
|
||||
m_CcuColCmd.heartbeat = 0;
|
||||
m_CcuColCmd.masterState = 0xAA;//主站状态,运行中
|
||||
|
||||
//================初始化上位机指令=========================
|
||||
m_msCmd.modCMD = 0;
|
||||
m_msCmd.powerCMD = 0;
|
||||
m_msCmd.workCMD = 0;
|
||||
}
|
||||
|
||||
char PowerManger::getBreakerOption(char cmd)
|
||||
@@ -675,6 +695,53 @@ char PowerManger::getBreakerOption(char cmd)
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool PowerManger::getMsCmdFromJson(MSControlCmd &cmd, const std::string &strJson)
|
||||
{
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::Value root;
|
||||
std::string errs;
|
||||
|
||||
// 解析JSON字符串
|
||||
std::istringstream s(strJson);
|
||||
if (!Json::parseFromStream(builder, s, &root, &errs))
|
||||
{
|
||||
std::cerr << "JSON解析失败: " << errs << std::endl;
|
||||
return false; // 解析失败
|
||||
}
|
||||
if (root.isMember("powerCMD") && root["powerCMD"].isUInt())
|
||||
{
|
||||
cmd.powerCMD = root["powerCMD"].asUInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "缺少或类型不匹配: powerCMD" << std::endl;
|
||||
return false; // 缺少或类型不匹配
|
||||
}
|
||||
|
||||
if (root.isMember("modCMD") && root["modCMD"].isUInt())
|
||||
{
|
||||
cmd.modCMD = root["modCMD"].asUInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "缺少或类型不匹配: modCMD" << std::endl;
|
||||
return false; // 缺少或类型不匹配
|
||||
}
|
||||
|
||||
if (root.isMember("workCMD") && root["workCMD"].isUInt())
|
||||
{
|
||||
cmd.workCMD = root["workCMD"].asUInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "缺少或类型不匹配: workCMD" << std::endl;
|
||||
return false; // 缺少或类型不匹配
|
||||
}
|
||||
return true; // 成功
|
||||
}
|
||||
|
||||
string PowerManger::getTypeName(const string typeName)
|
||||
{
|
||||
// 映射类型名称到指定的字符串
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef PowerManger_HEADER
|
||||
#define PowerManger_HEADER
|
||||
#define UNIX
|
||||
#define JSON_USE_EXCEPTION 1
|
||||
|
||||
#include <queue>
|
||||
#include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h"
|
||||
@@ -41,12 +42,18 @@
|
||||
#define MAX_UDP_PKT_SIZE 65535
|
||||
#define SKEW_TOLERANCE 5
|
||||
|
||||
//能源管理反馈的消息
|
||||
#define PM_STATE_VAR "uPower_pmState_st"
|
||||
#define PM_CURRENTSTATE_VAR "uPower_currentState_st"
|
||||
#define PM_DISSTATE_VAR "uPower_disSysState_st"
|
||||
#define PM_LIBATSTATE_VAR "uPower_liBatState_st"
|
||||
#define PM_FCSSTATE_VAR "uPower_fcsState_st"
|
||||
|
||||
//控制消息
|
||||
#define PM_MS_CMD_VAR "uPower_sysState_cmd"
|
||||
#define PM_SUBDIS_CMD_VAR "uPower_secdistState_cmd"
|
||||
#define PM_SUBDIS_STATE_VAR "uDevice_ secdistState _st"
|
||||
#define PM_EQUIPMENT_STATE_VAR "uPower_equState_fb"
|
||||
#define PM_EQUIPMENT_CMD_VAR "uPower_equState_cmd"
|
||||
|
||||
class PowerManger : public AppCastingMOOSApp
|
||||
{
|
||||
@@ -118,7 +125,9 @@ class PowerManger : public AppCastingMOOSApp
|
||||
void initControlCmd();
|
||||
|
||||
//上位机操作函数
|
||||
MSControlCmd m_msCmd;
|
||||
bool buildPowerSysReport();
|
||||
bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson);
|
||||
|
||||
private:
|
||||
udpComm m_udpComm;
|
||||
|
||||
@@ -121,6 +121,7 @@ public:
|
||||
void getDJ_MODEable(DriverTable* driverTable);
|
||||
|
||||
std::string saveDriverTableToJson(const DriverTable* driverTable);
|
||||
|
||||
std::string getDriverTableJson();
|
||||
|
||||
private:
|
||||
|
||||
@@ -353,5 +353,12 @@ typedef struct pmState
|
||||
disBus4Breaker bus4Breaker;
|
||||
} disSysBreaker;
|
||||
|
||||
typedef struct MSControlCmd
|
||||
{
|
||||
unsigned int powerCMD;
|
||||
unsigned int modCMD;
|
||||
unsigned int workCMD;
|
||||
}MSControlCmd;
|
||||
|
||||
|
||||
#endif
|
||||
+10
-10
@@ -4,7 +4,7 @@ project(SQLiteDBTest)
|
||||
# 设置 C++ 标准
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
#############################################SQLiteDBTest####################################################################
|
||||
# 查找 SQLiteDB 项目库
|
||||
find_library(SQLiteDB_LIB NAMES SQLiteDB PATHS /home/zjk/project/H100/H100PowerManger/lib)
|
||||
if(NOT SQLiteDB_LIB)
|
||||
@@ -16,9 +16,15 @@ find_package(Catch2 REQUIRED)
|
||||
|
||||
# 添加测试可执行文件
|
||||
add_executable(SQLiteDBTest SQLiteDBTest.cpp)
|
||||
# 链接库文件(注意顺序:先项目库后系统库)
|
||||
target_link_libraries(SQLiteDBTest
|
||||
${SQLiteDB_LIB} # 项目SQLiteDB库
|
||||
Catch2::Catch2WithMain # 测试框架
|
||||
sqlite3
|
||||
jsoncpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
################################################udpCommTest####################################################################
|
||||
# 查找 udpComm 项目库
|
||||
find_library(UDPCOMM_LIB NAMES UDPComm PATHS /home/zjk/project/H100/H100PowerManger/lib)
|
||||
if(NOT UDPCOMM_LIB)
|
||||
@@ -35,10 +41,4 @@ target_link_libraries(udpCommTest
|
||||
Catch2::Catch2WithMain # 测试框架
|
||||
)
|
||||
|
||||
# 链接库文件(注意顺序:先项目库后系统库)
|
||||
target_link_libraries(SQLiteDBTest
|
||||
${SQLiteDB_LIB} # 项目SQLiteDB库
|
||||
Catch2::Catch2WithMain # 测试框架
|
||||
sqlite3
|
||||
jsoncpp
|
||||
)
|
||||
################################################PowerMangerTest####################################################################
|
||||
|
||||
Reference in New Issue
Block a user