优化结构
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
@startuml PowerManagerFsm状态图
|
||||||
|
[*] --> InitState
|
||||||
|
|
||||||
|
state InitState {
|
||||||
|
[*] --> 等待复合管控消息
|
||||||
|
等待复合管控消息 --> 等待关键断路器闭合: 连接成功
|
||||||
|
等待复合管控消息 --> FaultState: 超时(10秒)
|
||||||
|
等待关键断路器闭合 --> StandbyState: 关键断路器闭合
|
||||||
|
等待关键断路器闭合 --> FaultState: 系统错误
|
||||||
|
}
|
||||||
|
|
||||||
|
state StandbyState {
|
||||||
|
[*] --> 待机
|
||||||
|
待机 --> FaultState: 检测到错误
|
||||||
|
待机 --> 处理电源命令: 收到命令
|
||||||
|
处理电源命令 --> 待机: 完成处理
|
||||||
|
}
|
||||||
|
|
||||||
|
state FaultState {
|
||||||
|
[*] --> 故障处理
|
||||||
|
}
|
||||||
|
|
||||||
|
InitState --> FaultState : FaultEvent(faultCode=1/2)
|
||||||
|
StandbyState --> FaultState : FaultEvent(faultCode)
|
||||||
|
InitState --> StandbyState : StandbyEvent
|
||||||
|
@enduml
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
# PowerManager系统架构优化设计方案
|
||||||
|
|
||||||
|
## 1. 总体架构
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class PowerManagerCore {
|
||||||
|
+startup()
|
||||||
|
+shutdown()
|
||||||
|
+getSystemState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class StateMachineService {
|
||||||
|
+triggerEvent()
|
||||||
|
+getCurrentState()
|
||||||
|
+addStateListener()
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommunicationMediator {
|
||||||
|
+registerHandler()
|
||||||
|
+sendMessage()
|
||||||
|
+addMessageListener()
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerManagerCore --> StateMachineService
|
||||||
|
PowerManagerCore --> CommunicationMediator
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. 状态机重构方案
|
||||||
|
|
||||||
|
### 2.1 状态设计模式
|
||||||
|
```cpp
|
||||||
|
class IPowerState {
|
||||||
|
public:
|
||||||
|
virtual void onEntry(PowerContext&) = 0;
|
||||||
|
virtual void handleEvent(PowerContext&, const Event&) = 0;
|
||||||
|
virtual void onExit(PowerContext&) = 0;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 状态转换规则
|
||||||
|
```yaml
|
||||||
|
# states_config.yaml
|
||||||
|
transitions:
|
||||||
|
- from: STANDBY
|
||||||
|
event: START_CMD
|
||||||
|
to: OPERATING
|
||||||
|
- from: OPERATING
|
||||||
|
event: STOP_CMD
|
||||||
|
to: STANDBY
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. 通信中介者设计
|
||||||
|
|
||||||
|
### 3.1 核心架构
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant Upper as 上位机
|
||||||
|
participant Mediator as 通信中介者
|
||||||
|
participant Lower as 下位机
|
||||||
|
|
||||||
|
Upper->>Mediator: 控制命令(JSON)
|
||||||
|
Mediator->>Lower: 设备指令(ProtocolBuffer)
|
||||||
|
Lower->>Mediator: 状态更新
|
||||||
|
Mediator->>Upper: 系统报告
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 关键实现
|
||||||
|
```cpp
|
||||||
|
class CommunicationMediator {
|
||||||
|
// 线程安全消息队列
|
||||||
|
moodycamel::ConcurrentQueue<Message> queue;
|
||||||
|
|
||||||
|
// 消息处理线程
|
||||||
|
void processMessages() {
|
||||||
|
while (running) {
|
||||||
|
Message msg;
|
||||||
|
if (queue.try_dequeue(msg)) {
|
||||||
|
handlers[msg.type]->handle(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. 数据库服务设计
|
||||||
|
|
||||||
|
### 4.1 日志策略模式
|
||||||
|
```cpp
|
||||||
|
class ILogStrategy {
|
||||||
|
public:
|
||||||
|
virtual bool log(const SystemLog& log) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SQLiteLogStrategy : public ILogStrategy {
|
||||||
|
// SQLite实现...
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileLogStrategy : public ILogStrategy {
|
||||||
|
// 文件系统实现...
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. 实施计划
|
||||||
|
|
||||||
|
### 5.1 阶段划分
|
||||||
|
```mermaid
|
||||||
|
gantt
|
||||||
|
title 重构实施甘特图
|
||||||
|
section 核心框架
|
||||||
|
接口定义 :2025-04-08, 3d
|
||||||
|
基础实现 :2025-04-11, 5d
|
||||||
|
|
||||||
|
section 模块重构
|
||||||
|
状态机 :2025-04-16, 5d
|
||||||
|
通信模块 :2025-04-21, 5d
|
||||||
|
|
||||||
|
section 测试验证
|
||||||
|
单元测试 :2025-04-26, 3d
|
||||||
|
集成测试 :2025-04-29, 5d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6. 性能指标
|
||||||
|
|
||||||
|
| 模块 | 当前QPS | 目标QPS | 优化手段 |
|
||||||
|
|----------------|---------|---------|-----------------------|
|
||||||
|
| 状态机处理 | 100 | 500 | 无锁状态转换 |
|
||||||
|
| 消息处理 | 200 | 1000 | 批量处理+线程池 |
|
||||||
|
| 数据库写入 | 50 | 300 | 异步写入+批量提交 |
|
||||||
@@ -26,6 +26,7 @@ SET(SRC
|
|||||||
main.cpp
|
main.cpp
|
||||||
SQLiteDB.cpp
|
SQLiteDB.cpp
|
||||||
driver.cpp
|
driver.cpp
|
||||||
|
LowerCommManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE(pPowerManger ${SRC})
|
ADD_EXECUTABLE(pPowerManger ${SRC})
|
||||||
@@ -56,17 +57,18 @@ SET(FSMLIB_SRC
|
|||||||
SET(DRIVER_SRC
|
SET(DRIVER_SRC
|
||||||
driver.cpp)
|
driver.cpp)
|
||||||
|
|
||||||
SET(POWERMANGE_SRC
|
# SET(POWERMANGE_SRC
|
||||||
PowerManger.cpp
|
# PowerManger.cpp
|
||||||
PowerManger_Info.cpp
|
# PowerManger_Info.cpp
|
||||||
udpComm.cpp
|
# udpComm.cpp
|
||||||
SQLiteDB.cpp
|
# SQLiteDB.cpp
|
||||||
driver.cpp
|
# driver.cpp
|
||||||
PowerManagerFsm.cpp)
|
# PowerManagerFsm.cpp)
|
||||||
|
|
||||||
ADD_LIBRARY(SQLiteDB STATIC ${SQLITEDB_SRC})
|
ADD_LIBRARY(SQLiteDB STATIC ${SQLITEDB_SRC})
|
||||||
ADD_LIBRARY(UDPComm STATIC ${UDPCOMM_SRC})
|
ADD_LIBRARY(UDPComm STATIC ${UDPCOMM_SRC})
|
||||||
ADD_LIBRARY(FSMLib STATIC ${FSMLIB_SRC})
|
ADD_LIBRARY(FSMLib STATIC ${FSMLIB_SRC})
|
||||||
ADD_LIBRARY(Driver STATIC ${DRIVER_SRC})
|
ADD_LIBRARY(Driver STATIC ${DRIVER_SRC})
|
||||||
ADD_LIBRARY(PowerMange STATIC ${POWERMANGE_SRC})
|
# ADD_LIBRARY(PowerMange STATIC ${POWERMANGE_SRC})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,219 @@
|
|||||||
|
#include "LowerCommManager.h"
|
||||||
|
#include "PowerManger.h"
|
||||||
|
#include "driver.h"
|
||||||
|
#include "udpComm.h"
|
||||||
|
|
||||||
|
bool _ListenCB(void * pParam)
|
||||||
|
{
|
||||||
|
LowerCommManager* pMe = (LowerCommManager* )pParam;
|
||||||
|
return pMe->listenThreadFunc();
|
||||||
|
}
|
||||||
|
|
||||||
|
LowerCommManager::LowerCommManager(PowerManger* pm, long myPort, long ccuPort, const std::string& cccHost){
|
||||||
|
m_pm = pm;
|
||||||
|
m_udpComm = new udpComm();
|
||||||
|
m_port = myPort;
|
||||||
|
m_udpComm->ccuHost = cccHost;
|
||||||
|
if(ccuPort < 0 || ccuPort > 65535) {
|
||||||
|
throw std::invalid_argument("Invalid CCU port: " + std::to_string(ccuPort));
|
||||||
|
}
|
||||||
|
m_udpComm->ccuPort = static_cast<unsigned short>(ccuPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
LowerCommManager::~LowerCommManager(){
|
||||||
|
try {
|
||||||
|
stopListenThread();
|
||||||
|
if (m_udpComm) {
|
||||||
|
delete m_udpComm;
|
||||||
|
m_udpComm = nullptr;
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
cerr << "Error during cleanup" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool LowerCommManager::initUdpComm(){
|
||||||
|
//设置UDP监听端口
|
||||||
|
XPCUdpSocket* m_udpSocket = new XPCUdpSocket(m_port);
|
||||||
|
if(m_udpSocket)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_udpSocket->vBindSocket();
|
||||||
|
m_udpComm->ccuHost = m_ccuHost;
|
||||||
|
m_udpComm->ccuPort = m_ccuPort;
|
||||||
|
cout<<MOOS::ConsoleColours::green()<< "UDP set succeed!"<< MOOS::ConsoleColours::reset() << endl;
|
||||||
|
m_udpComm->udpScoket = m_udpSocket;
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << '\n';
|
||||||
|
cout<<MOOS::ConsoleColours::red()<< "UDP set Fild!"<< MOOS::ConsoleColours::reset() << endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<MOOS::ConsoleColours::red()<< "UDP set Fild!"<< MOOS::ConsoleColours::reset() << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void LowerCommManager::processPeriodicTasks() {
|
||||||
|
// sendCcuCommand(m_pm->m_CcuColCmd);
|
||||||
|
// sendDisSysCommand(m_pm->m_targetDisBreakerState);
|
||||||
|
int msg = 10;
|
||||||
|
m_udpComm->udpScoket->iSendMessageTo((void*) msg, 6, m_udpComm->ccuPort, "127.0.0.1");
|
||||||
|
m_udpComm->clearMsgQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LowerCommManager::sendCcuCommand(const ccuColCmd cmd){
|
||||||
|
// m_pm->m_db->insertCcuSysCmd(cmd);
|
||||||
|
if(!m_udpComm->sendCcuColCmd(cmd))
|
||||||
|
cout << "send ccu command failed!" << endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LowerCommManager::sendDisSysCommand(const disSysBreakerList& cmd){
|
||||||
|
//根据目标状态进行断路器操作
|
||||||
|
//a. 高压母线的断路器
|
||||||
|
disHighVolBusCmd a;
|
||||||
|
a.fuelCellCircuitBreaker = getBreakerOption(cmd.bus1Breaker.fuelCellCircuitBreaker);
|
||||||
|
a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(cmd.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||||
|
a.dcDc5ModuleCircuitBreaker = getBreakerOption(cmd.bus1Breaker.dcDc5ModuleCircuitBreaker);
|
||||||
|
a.powerLithiumBatteryCircuitBreaker = getBreakerOption(cmd.bus1Breaker.powerLithiumBatteryCircuitBreaker);
|
||||||
|
a.propulsionMotorCircuitBreaker = getBreakerOption(cmd.bus1Breaker.propulsionMotorCircuitBreaker);
|
||||||
|
a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(cmd.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker);
|
||||||
|
a.tyzReservedCircuitBreaker = getBreakerOption(cmd.bus1Breaker.tyzReservedCircuitBreaker);
|
||||||
|
a.sternFTDevice45CircuitBreaker = getBreakerOption(cmd.bus1Breaker.sternFTDevice45CircuitBreaker);
|
||||||
|
a.sternRudderSwitch1CircuitBreaker = getBreakerOption(cmd.bus1Breaker.sternRudderSwitch1CircuitBreaker);
|
||||||
|
a.sternRudderSwitch2CircuitBreaker = getBreakerOption(cmd.bus1Breaker.sternRudderSwitch2CircuitBreaker);
|
||||||
|
a.reservedCircuitBreaker = getBreakerOption(cmd.bus1Breaker.reservedCircuitBreaker);
|
||||||
|
a.fbReservedCircuitBreaker = getBreakerOption(cmd.bus1Breaker.fbReservedCircuitBreaker);
|
||||||
|
m_udpComm->sendDisSysCmd(a);
|
||||||
|
//b. 高压汇流排A断路器
|
||||||
|
disHighAVolBusCmd b;
|
||||||
|
b.bowFTDevice123CircuitBreaker = getBreakerOption(cmd.bus2Breaker.bowFTDevice123CircuitBreaker);
|
||||||
|
b.actuatorCircuitBreaker = getBreakerOption(cmd.bus2Breaker.actuatorCircuitBreaker);
|
||||||
|
b.mastSteeringGearControlBoxCircuitBreaker = getBreakerOption(cmd.bus2Breaker.mastSteeringGearControlBoxCircuitBreaker);
|
||||||
|
b.xczCircuitBreaker = getBreakerOption(cmd.bus2Breaker.xczCircuitBreaker);
|
||||||
|
b.bowRudderControlBoxCircuitBreaker = getBreakerOption(cmd.bus2Breaker.bowRudderControlBoxCircuitBreaker);
|
||||||
|
b.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(cmd.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker);
|
||||||
|
m_udpComm->sendDisSysCmd(b);
|
||||||
|
//c. 高压汇流排B断路器
|
||||||
|
disHighBVolBusCmd c;
|
||||||
|
c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(cmd.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||||
|
c.bowLowVoltageDistributionBoxCircuitBreaker = getBreakerOption(cmd.bus3Breaker.bowLowVoltageDistributionBoxCircuitBreaker);
|
||||||
|
c.unit4InstrumentDC48VCircuitBreaker = getBreakerOption(cmd.bus3Breaker.unit4InstrumentDC48VCircuitBreaker);
|
||||||
|
c.dcC1DCDistributionPanelCircuitBreaker = getBreakerOption(cmd.bus3Breaker.dcC1DCDistributionPanelCircuitBreaker);
|
||||||
|
c.reservedCircuitBreaker1 = getBreakerOption(cmd.bus3Breaker.reservedCircuitBreaker1);
|
||||||
|
c.reservedCircuitBreaker2 = getBreakerOption(cmd.bus3Breaker.reservedCircuitBreaker2);
|
||||||
|
c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(cmd.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker);
|
||||||
|
m_udpComm->sendDisSysCmd(c);
|
||||||
|
//d. 闭合低压汇流排断路器
|
||||||
|
disLowBusCmd d;
|
||||||
|
d.unit1CircuitBreaker = getBreakerOption(cmd.bus4Breaker.unit1CircuitBreaker);
|
||||||
|
d.unit2CircuitBreaker = getBreakerOption(cmd.bus4Breaker.unit2CircuitBreaker);
|
||||||
|
d.unit3CircuitBreaker = getBreakerOption(cmd.bus4Breaker.unit3CircuitBreaker);
|
||||||
|
d.unit5CircuitBreaker = getBreakerOption(cmd.bus4Breaker.unit5CircuitBreaker);
|
||||||
|
d.bowPZDeviceCircuitBreaker = getBreakerOption(cmd.bus4Breaker.bowPZDeviceCircuitBreaker);
|
||||||
|
d.reservedCircuitBreaker1 = getBreakerOption(cmd.bus4Breaker.reservedCircuitBreaker1);
|
||||||
|
d.reservedCircuitBreaker2 = getBreakerOption(cmd.bus4Breaker.reservedCircuitBreaker2);
|
||||||
|
d.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(cmd.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker);
|
||||||
|
m_udpComm->sendDisSysCmd(d);
|
||||||
|
//将指令写入数据库
|
||||||
|
m_pm->m_db->insertDisSysCmd(a);
|
||||||
|
m_pm->m_db->insertDisSysCmd(b);
|
||||||
|
m_pm->m_db->insertDisSysCmd(c);
|
||||||
|
m_pm->m_db->insertDisSysCmd(d);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LowerCommManager::clearMsgQueue(){
|
||||||
|
m_udpComm->clearMsgQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LowerCommManager::listenThreadFunc()
|
||||||
|
{
|
||||||
|
cout<<MOOS::ConsoleColours::green()<< "LowerCommManager::listenThreadFunc" << MOOS::ConsoleColours::reset() << endl;
|
||||||
|
unsigned char Buff[1024];
|
||||||
|
while(!m_ListenThread.IsQuitRequested())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nRead = m_udpComm->udpScoket->iRecieveMessage(Buff, sizeof(Buff));
|
||||||
|
cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
|
||||||
|
if(nRead > 0)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if(!m_udpComm->pushMsgToQueue(Buff))
|
||||||
|
{
|
||||||
|
for(int i=0; i<m_udpComm->sError.size(); i++)
|
||||||
|
{
|
||||||
|
cout<<MOOS::ConsoleColours::red()<< m_udpComm->sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const std::exception& e) {
|
||||||
|
cerr << "Error processing message: " << e.what() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印通信错误信息
|
||||||
|
if(!m_udpComm->sError.empty())
|
||||||
|
{
|
||||||
|
for(int i=0; i<m_udpComm->sError.size(); i++)
|
||||||
|
{
|
||||||
|
cout<<MOOS::ConsoleColours::red() << m_udpComm->sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||||
|
}
|
||||||
|
m_udpComm->sError.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const XPCException& e)
|
||||||
|
{
|
||||||
|
cerr << "XPCException in listenThreadFunc" << endl;
|
||||||
|
// 短暂休眠后继续尝试
|
||||||
|
MOOSPause(100);
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
cerr << "Exception in listenThreadFunc: " << e.what() << endl;
|
||||||
|
MOOSPause(100);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
cerr << "Unknown exception in listenThreadFunc" << endl;
|
||||||
|
MOOSPause(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LowerCommManager::startListenThread()
|
||||||
|
{
|
||||||
|
if(!m_ListenThread.IsThreadRunning())
|
||||||
|
{
|
||||||
|
m_ListenThread.Initialise(_ListenCB,this);
|
||||||
|
m_ListenThread.Start();
|
||||||
|
std::cout << "LowerCommManager::startListenThread" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LowerCommManager::stopListenThread()
|
||||||
|
{
|
||||||
|
if(m_ListenThread.IsThreadRunning())
|
||||||
|
{
|
||||||
|
m_ListenThread.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char LowerCommManager::getBreakerOption(char cmd)
|
||||||
|
{
|
||||||
|
if(cmd ==1)
|
||||||
|
return 0x55;
|
||||||
|
else if(cmd ==0)
|
||||||
|
return 0xAA;
|
||||||
|
else
|
||||||
|
return 0x00;
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#ifndef LOWER_COMM_MANAGER_H
|
||||||
|
#define LOWER_COMM_MANAGER_H
|
||||||
|
#define UNIX
|
||||||
|
|
||||||
|
#include "MOOS/libMOOS/Comms/XPCUdpSocket.h"
|
||||||
|
#include "MOOS/libMOOS/Utils/MOOSThread.h"
|
||||||
|
#include "MOOS/libMOOS/Utils/MOOSLock.h"
|
||||||
|
#include "ccuUdpMsg.h"
|
||||||
|
#include "pmSysvariable.h"
|
||||||
|
#include <queue>
|
||||||
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
#include <atomic>
|
||||||
|
#include <vector>
|
||||||
|
#include "udpComm.h"
|
||||||
|
|
||||||
|
class PowerManger; // 前向声明
|
||||||
|
|
||||||
|
class LowerCommManager {
|
||||||
|
public:
|
||||||
|
LowerCommManager(PowerManger* pm, long myPort, long ccuPort, const std::string& cccHost);
|
||||||
|
~LowerCommManager();
|
||||||
|
|
||||||
|
//processPeriodicTasks
|
||||||
|
void processPeriodicTasks();
|
||||||
|
//clearMsgQueue
|
||||||
|
void clearMsgQueue();
|
||||||
|
|
||||||
|
public:
|
||||||
|
CMOOSLock m_CommMutex; // 保护UDP通信资源
|
||||||
|
|
||||||
|
// 初始化UDP通信
|
||||||
|
bool initUdpComm();
|
||||||
|
|
||||||
|
// 更新设备状态
|
||||||
|
bool updateDeviceStates();
|
||||||
|
|
||||||
|
// 发送CCU控制命令
|
||||||
|
bool sendCcuCommand(const ccuColCmd cmd);
|
||||||
|
bool sendDisSysCommand(const disSysBreakerList& cmd);
|
||||||
|
|
||||||
|
// 获取通信状态
|
||||||
|
int getConnectionState() const { return m_connectState; }
|
||||||
|
|
||||||
|
// 启动/停止监听线程
|
||||||
|
void startListenThread();
|
||||||
|
void stopListenThread();
|
||||||
|
|
||||||
|
//转换函数
|
||||||
|
char getBreakerOption(char cmd);
|
||||||
|
|
||||||
|
public:
|
||||||
|
long m_port;
|
||||||
|
long m_ccuPort;
|
||||||
|
std::string m_ccuHost;
|
||||||
|
std::string m_host;
|
||||||
|
|
||||||
|
PowerManger* m_pm;
|
||||||
|
udpComm* m_udpComm;
|
||||||
|
XPCUdpSocket* m_udpSocket;
|
||||||
|
|
||||||
|
CMOOSThread m_ListenThread;
|
||||||
|
int m_connectState;
|
||||||
|
|
||||||
|
// UDP监听线程函数
|
||||||
|
bool listenThreadFunc();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOWER_COMM_MANAGER_H
|
||||||
+205
-216
@@ -14,11 +14,11 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
bool _ListenCB(void * pParam)
|
// bool _ListenCB(void * pParam)
|
||||||
{
|
// {
|
||||||
PowerManger* pMe = (PowerManger* )pParam;
|
// // PowerManger* pMe = (PowerManger* )pParam;
|
||||||
return pMe->ListenLoopUDP();
|
// // return pMe->ListenLoopUDP();
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool _FsmCB(void * pParam)
|
bool _FsmCB(void * pParam)
|
||||||
{
|
{
|
||||||
@@ -57,7 +57,7 @@ PowerManger::PowerManger()
|
|||||||
m_MSDriverCmd = {};
|
m_MSDriverCmd = {};
|
||||||
m_subDisSysCmd = {};
|
m_subDisSysCmd = {};
|
||||||
m_subDisSysState = {};
|
m_subDisSysState = {};
|
||||||
//初始化断路器状态
|
//初始化控制指令
|
||||||
initControlCmd();
|
initControlCmd();
|
||||||
|
|
||||||
//初始化数据库
|
//初始化数据库
|
||||||
@@ -71,6 +71,10 @@ PowerManger::PowerManger()
|
|||||||
m_db->createDriversTables(VAR_TO_STR(m_subDisSysCmd));
|
m_db->createDriversTables(VAR_TO_STR(m_subDisSysCmd));
|
||||||
m_db->createDriversTables(VAR_TO_STR(m_MSDriverCmd));
|
m_db->createDriversTables(VAR_TO_STR(m_MSDriverCmd));
|
||||||
|
|
||||||
|
//初始化UDP通信
|
||||||
|
m_lowerCommManager = new LowerCommManager(this,IPORT,CCUPORT,CCUHOST);
|
||||||
|
m_lowerCommManager->initUdpComm();
|
||||||
|
|
||||||
// 初始化状态机
|
// 初始化状态机
|
||||||
cout << "init fsm" << endl;
|
cout << "init fsm" << endl;
|
||||||
m_fsm.init(this);
|
m_fsm.init(this);
|
||||||
@@ -84,6 +88,8 @@ PowerManger::PowerManger()
|
|||||||
|
|
||||||
PowerManger::~PowerManger()
|
PowerManger::~PowerManger()
|
||||||
{
|
{
|
||||||
|
delete m_db;
|
||||||
|
delete m_lowerCommManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
@@ -165,20 +171,20 @@ bool PowerManger::Iterate()
|
|||||||
{
|
{
|
||||||
AppCastingMOOSApp::Iterate();
|
AppCastingMOOSApp::Iterate();
|
||||||
//1. 更新当前状态
|
//1. 更新当前状态
|
||||||
updatePmState();
|
// updatePmState();
|
||||||
updateConnectState();
|
updateConnectState();
|
||||||
//2. 运行状态机
|
//2. 运行状态机
|
||||||
if (FSM_RUN_IS_OK)
|
// if (FSM_RUN_IS_OK)
|
||||||
m_FsmThread.Start();
|
// m_FsmThread.Start();
|
||||||
else
|
// else
|
||||||
m_FsmThread.Stop();
|
// m_FsmThread.Stop();
|
||||||
//3. 进行操作 每秒执行一次
|
//3. 进行操作 每秒执行一次
|
||||||
if (m_ticker++ % 5 == 0)
|
if (m_ticker++ % 5 == 0)
|
||||||
{
|
{
|
||||||
//a. 配电系统操作
|
//a. 配电系统操作
|
||||||
disSysOption();
|
// disSysOption();
|
||||||
//b. ccu操作
|
//b. ccu操作
|
||||||
ccuOption();
|
// ccuOption();
|
||||||
//c. 上位机反馈
|
//c. 上位机反馈
|
||||||
buildPowerSysReport();
|
buildPowerSysReport();
|
||||||
Notify(PM_TO_DB_SUBDISCMD,m_driver.saveDriverTableToJson(&m_subDisSysCmd));
|
Notify(PM_TO_DB_SUBDISCMD,m_driver.saveDriverTableToJson(&m_subDisSysCmd));
|
||||||
@@ -186,6 +192,7 @@ bool PowerManger::Iterate()
|
|||||||
//d.保存到数据库
|
//d.保存到数据库
|
||||||
writeDataToDB();
|
writeDataToDB();
|
||||||
}
|
}
|
||||||
|
m_lowerCommManager->processPeriodicTasks();
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// string a = m_driver.getSubDisCmdJson(&m_subDisSysCmd);
|
// string a = m_driver.getSubDisCmdJson(&m_subDisSysCmd);
|
||||||
// saveStringToJsonFile(a,"/home/zjk/project/H100/H100PowerManger/data/subDisSysCmd.json");
|
// saveStringToJsonFile(a,"/home/zjk/project/H100/H100PowerManger/data/subDisSysCmd.json");
|
||||||
@@ -199,7 +206,7 @@ bool PowerManger::Iterate()
|
|||||||
// return false;
|
// return false;
|
||||||
//AppCastingMOOSApp::PostReport();
|
//AppCastingMOOSApp::PostReport();
|
||||||
//5. 清空UDP消息队列
|
//5. 清空UDP消息队列
|
||||||
m_udpComm.clearMsgQueue();
|
// m_udpComm.clearMsgQueue();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,23 +244,7 @@ bool PowerManger::OnStartUp()
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerVariables();
|
registerVariables();
|
||||||
//启动UDP监听线程
|
m_lowerCommManager->startListenThread();
|
||||||
if(m_pCcuUdpComm = setUdpScoket(IPORT))
|
|
||||||
{
|
|
||||||
cout<<MOOS::ConsoleColours::green()<< "UDP set succeed!"<< MOOS::ConsoleColours::reset() << endl;
|
|
||||||
m_udpComm.ccuHost = CCUHOST;
|
|
||||||
m_udpComm.ccuPort = CCUPORT;
|
|
||||||
m_udpComm.udpScoket = m_pCcuUdpComm;
|
|
||||||
MOOSTrace("UDP set succeed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<MOOS::ConsoleColours::red()<< "UDP set Fild!"<< MOOS::ConsoleColours::reset() << endl;
|
|
||||||
MOOSTrace("UDP set faile");
|
|
||||||
}
|
|
||||||
m_ListenThread.Initialise(_ListenCB,this);
|
|
||||||
m_ListenThread.Start();
|
|
||||||
m_FsmThread.Initialise(_FsmCB,this);
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,35 +295,35 @@ XPCUdpSocket* PowerManger::setUdpScoket(long lPort)
|
|||||||
return pUdpSocket;
|
return pUdpSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerManger::ListenLoopUDP()
|
// bool PowerManger::ListenLoopUDP()
|
||||||
{
|
// {
|
||||||
unsigned char Buff[MAX_UDP_PKT_SIZE];
|
// unsigned char Buff[MAX_UDP_PKT_SIZE];
|
||||||
while(!m_ListenThread.IsQuitRequested())
|
// while(!m_ListenThread.IsQuitRequested())
|
||||||
{
|
// {
|
||||||
int nRead = m_pCcuUdpComm->iRecieveMessage(Buff,sizeof(Buff));
|
// int nRead = m_pCcuUdpComm->iRecieveMessage(Buff,sizeof(Buff));
|
||||||
cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
|
// cout<<MOOS::ConsoleColours::yellow()<< "RECEVE DATA COUNT:" << nRead << MOOS::ConsoleColours::reset() << endl;
|
||||||
if(nRead > 0)
|
// if(nRead > 0)
|
||||||
{
|
// {
|
||||||
if(!m_udpComm.pushMsgToQueue(Buff))
|
// if(!m_udpComm.pushMsgToQueue(Buff))
|
||||||
{
|
// {
|
||||||
for(int i=0;i<m_udpComm.sError.size();i++)
|
// for(int i=0;i<m_udpComm.sError.size();i++)
|
||||||
{
|
// {
|
||||||
cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
// cout<<MOOS::ConsoleColours::red()<< m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// 打印通信错误信息
|
// // 打印通信错误信息
|
||||||
if(!m_udpComm.sError.empty())
|
// if(!m_udpComm.sError.empty())
|
||||||
{
|
// {
|
||||||
for(int i=0;i<m_udpComm.sError.size();i++)
|
// for(int i=0;i<m_udpComm.sError.size();i++)
|
||||||
{
|
// {
|
||||||
cout<<MOOS::ConsoleColours::red() << m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
// cout<<MOOS::ConsoleColours::red() << m_udpComm.sError[i] << MOOS::ConsoleColours::reset() << endl;
|
||||||
}
|
// }
|
||||||
m_udpComm.sError.clear();
|
// m_udpComm.sError.clear();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool PowerManger::FsmLoop()
|
bool PowerManger::FsmLoop()
|
||||||
{
|
{
|
||||||
@@ -374,108 +365,107 @@ bool PowerManger::updateConnectState()
|
|||||||
connectState++;
|
connectState++;
|
||||||
// cout << "seck:" << seck << endl;
|
// cout << "seck:" << seck << endl;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PowerManger::updatePmState()
|
// bool PowerManger::updatePmState()
|
||||||
{
|
// {
|
||||||
//1. 更新下位机状态
|
// //1. 更新下位机状态
|
||||||
if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
|
// if(!m_udpComm.m_qReceiveCcuStateBuffer.empty())
|
||||||
{
|
// {
|
||||||
double time;
|
// double time;
|
||||||
m_udpComm.popMsgFormQueue(time,m_CcuCurrentState);
|
// m_udpComm.popMsgFormQueue(time,m_CcuCurrentState);
|
||||||
m_pmCurrentState.ccustate = m_CcuCurrentState.data;
|
// m_pmCurrentState.ccustate = m_CcuCurrentState.data;
|
||||||
m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库
|
// m_db->insertCcuData(m_CcuCurrentState.data); //写入数据库
|
||||||
msg_CcuStateFbMsg_Update_time = time;
|
// msg_CcuStateFbMsg_Update_time = time;
|
||||||
}
|
// }
|
||||||
if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty())
|
// if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty())
|
||||||
{
|
// {
|
||||||
double time;
|
// double time;
|
||||||
m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState);
|
// m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState);
|
||||||
m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
|
// m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data;
|
||||||
m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库
|
// m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库
|
||||||
msg_disHighVolBusFbMsg_Update_time = time;
|
// msg_disHighVolBusFbMsg_Update_time = time;
|
||||||
|
|
||||||
disBus1Breaker* pdis1=new disBus1Breaker;
|
// disBus1Breaker* pdis1=new disBus1Breaker;
|
||||||
(m_pmCurrentState.bus1State.fuelCellCircuitBreaker == BREAK_ON) ? pdis1 -> fuelCellCircuitBreaker = 1 : pdis1 -> fuelCellCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.fuelCellCircuitBreaker == BREAK_ON) ? pdis1 -> fuelCellCircuitBreaker = 1 : pdis1 -> fuelCellCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker == BREAK_ON) ? pdis1 -> powerLithiumBatteryCircuitBreaker = 1 : pdis1 -> powerLithiumBatteryCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.powerLithiumBatteryCircuitBreaker == BREAK_ON) ? pdis1 -> powerLithiumBatteryCircuitBreaker = 1 : pdis1 -> powerLithiumBatteryCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker == BREAK_ON) ? pdis1 -> propulsionMotorCircuitBreaker = 1 : pdis1 -> propulsionMotorCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.propulsionMotorCircuitBreaker == BREAK_ON) ? pdis1 -> propulsionMotorCircuitBreaker = 1 : pdis1 -> propulsionMotorCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON) ? pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON) ? pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis1 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker == BREAK_ON) ? pdis1 -> dcDc5ModuleCircuitBreaker = 1 : pdis1 -> dcDc5ModuleCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.dcDc5ModuleCircuitBreaker == BREAK_ON) ? pdis1 -> dcDc5ModuleCircuitBreaker = 1 : pdis1 -> dcDc5ModuleCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker == BREAK_ON) ? pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 1 : pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.bowHighVoltageDistributionBoxCircuitBreaker == BREAK_ON) ? pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 1 : pdis1 -> bowHighVoltageDistributionBoxCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker == BREAK_ON) ? pdis1 -> sternFTDevice45CircuitBreaker = 1 : pdis1 -> sternFTDevice45CircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.sternFTDevice45CircuitBreaker == BREAK_ON) ? pdis1 -> sternFTDevice45CircuitBreaker = 1 : pdis1 -> sternFTDevice45CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch1CircuitBreaker = 1 : pdis1 -> sternRudderSwitch1CircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.sternRudderSwitch1CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch1CircuitBreaker = 1 : pdis1 -> sternRudderSwitch1CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch2CircuitBreaker = 1 : pdis1 -> sternRudderSwitch2CircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.sternRudderSwitch2CircuitBreaker == BREAK_ON) ? pdis1 -> sternRudderSwitch2CircuitBreaker = 1 : pdis1 -> sternRudderSwitch2CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.fbReservedCircuitBreaker == BREAK_ON) ? pdis1 -> fbReservedCircuitBreaker = 1 : pdis1 -> fbReservedCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.fbReservedCircuitBreaker == BREAK_ON) ? pdis1 -> fbReservedCircuitBreaker = 1 : pdis1 -> fbReservedCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.tyzReservedCircuitBreaker == BREAK_ON) ? pdis1 -> tyzReservedCircuitBreaker = 1 : pdis1 -> tyzReservedCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.tyzReservedCircuitBreaker == BREAK_ON) ? pdis1 -> tyzReservedCircuitBreaker = 1 : pdis1 -> tyzReservedCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus1State.reservedCircuitBreaker == BREAK_ON) ? pdis1 -> reservedCircuitBreaker = 1 : pdis1 -> reservedCircuitBreaker = 0;
|
// (m_pmCurrentState.bus1State.reservedCircuitBreaker == BREAK_ON) ? pdis1 -> reservedCircuitBreaker = 1 : pdis1 -> reservedCircuitBreaker = 0;
|
||||||
pdis1 -> paceholder = 0;
|
// pdis1 -> paceholder = 0;
|
||||||
m_currentDisBreakerState.bus1Breaker = *pdis1;
|
// m_currentDisBreakerState.bus1Breaker = *pdis1;
|
||||||
delete pdis1;
|
// delete pdis1;
|
||||||
}
|
// }
|
||||||
if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
|
// if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty())
|
||||||
{
|
// {
|
||||||
double time;
|
// double time;
|
||||||
m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState);
|
// m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState);
|
||||||
m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
|
// m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data;
|
||||||
m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库
|
// m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库
|
||||||
msg_disHighAVolBusFbMsg_Update_time = time;
|
// msg_disHighAVolBusFbMsg_Update_time = time;
|
||||||
|
|
||||||
disBus2Breaker* pdis2=new disBus2Breaker;
|
// disBus2Breaker* pdis2=new disBus2Breaker;
|
||||||
(m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker == BREAK_ON)? pdis2 -> bowFTDevice123CircuitBreaker = 1 : pdis2 -> bowFTDevice123CircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.bowFTDevice123CircuitBreaker == BREAK_ON)? pdis2 -> bowFTDevice123CircuitBreaker = 1 : pdis2 -> bowFTDevice123CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus2State.actuatorCircuitBreaker == BREAK_ON)? pdis2 -> actuatorCircuitBreaker = 1 : pdis2 -> actuatorCircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.actuatorCircuitBreaker == BREAK_ON)? pdis2 -> actuatorCircuitBreaker = 1 : pdis2 -> actuatorCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 1 : pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.mastSteeringGearControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 1 : pdis2 -> mastSteeringGearControlBoxCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus2State.xczCircuitBreaker == BREAK_ON)? pdis2 -> xczCircuitBreaker = 1 : pdis2 -> xczCircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.xczCircuitBreaker == BREAK_ON)? pdis2 -> xczCircuitBreaker = 1 : pdis2 -> xczCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> bowRudderControlBoxCircuitBreaker = 1 : pdis2 -> bowRudderControlBoxCircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.bowRudderControlBoxCircuitBreaker == BREAK_ON)? pdis2 -> bowRudderControlBoxCircuitBreaker = 1 : pdis2 -> bowRudderControlBoxCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker == BREAK_ON)? pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 1 : pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 0;
|
// (m_pmCurrentState.bus2State.openWaterCoverStartCylinderCircuitBreaker == BREAK_ON)? pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 1 : pdis2 -> openWaterCoverStartCylinderCircuitBreaker = 0;
|
||||||
pdis2 -> paceholder = 0;
|
// pdis2 -> paceholder = 0;
|
||||||
m_currentDisBreakerState.bus2Breaker = *pdis2;
|
// m_currentDisBreakerState.bus2Breaker = *pdis2;
|
||||||
delete pdis2;
|
// delete pdis2;
|
||||||
}
|
// }
|
||||||
if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
|
// if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty())
|
||||||
{
|
// {
|
||||||
double time;
|
// double time;
|
||||||
m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState);
|
// m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState);
|
||||||
m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
|
// m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data;
|
||||||
m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库
|
// m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库
|
||||||
msg_disHighBVolBusFbMsg_Update_time = time;
|
// msg_disHighBVolBusFbMsg_Update_time = time;
|
||||||
|
|
||||||
disBus3Breaker* pdis3=new disBus3Breaker;
|
// disBus3Breaker* pdis3=new disBus3Breaker;
|
||||||
(m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON)? pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
// (m_pmCurrentState.bus3State.lithiumBatteryGroupInstrumentCircuitBreaker == BREAK_ON)? pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 1 : pdis3 -> lithiumBatteryGroupInstrumentCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker == BREAK_ON)? pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 1 : pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 0;
|
// (m_pmCurrentState.bus3State.bowLowVoltageDistributionBoxCircuitBreaker == BREAK_ON)? pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 1 : pdis3 -> bowLowVoltageDistributionBoxCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker == BREAK_ON)? pdis3 -> unit4InstrumentDC48VCircuitBreaker = 1 : pdis3 -> unit4InstrumentDC48VCircuitBreaker = 0;
|
// (m_pmCurrentState.bus3State.unit4InstrumentDC48VCircuitBreaker == BREAK_ON)? pdis3 -> unit4InstrumentDC48VCircuitBreaker = 1 : pdis3 -> unit4InstrumentDC48VCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker == BREAK_ON)? pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 1 : pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 0;
|
// (m_pmCurrentState.bus3State.dcC1DCDistributionPanelCircuitBreaker == BREAK_ON)? pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 1 : pdis3 -> dcC1DCDistributionPanelCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus3State.reservedCircuitBreaker1 == BREAK_ON)? pdis3 -> reservedCircuitBreaker1 = 1 : pdis3 -> reservedCircuitBreaker1 = 0;
|
// (m_pmCurrentState.bus3State.reservedCircuitBreaker1 == BREAK_ON)? pdis3 -> reservedCircuitBreaker1 = 1 : pdis3 -> reservedCircuitBreaker1 = 0;
|
||||||
(m_pmCurrentState.bus3State.reservedCircuitBreaker2 == BREAK_ON)? pdis3 -> reservedCircuitBreaker2 = 1 : pdis3 -> reservedCircuitBreaker2 = 0;
|
// (m_pmCurrentState.bus3State.reservedCircuitBreaker2 == BREAK_ON)? pdis3 -> reservedCircuitBreaker2 = 1 : pdis3 -> reservedCircuitBreaker2 = 0;
|
||||||
(m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker == BREAK_ON)? pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 1 : pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 0;
|
// (m_pmCurrentState.bus3State.emergencyLithiumBatteryGroup2CircuitBreaker == BREAK_ON)? pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 1 : pdis3 -> emergencyLithiumBatteryGroup2CircuitBreaker = 0;
|
||||||
pdis3->paceholder = 0;
|
// pdis3->paceholder = 0;
|
||||||
m_currentDisBreakerState.bus3Breaker = *pdis3;
|
// m_currentDisBreakerState.bus3Breaker = *pdis3;
|
||||||
delete pdis3;
|
// delete pdis3;
|
||||||
}
|
// }
|
||||||
if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
|
// if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty())
|
||||||
{
|
// {
|
||||||
double time;
|
// double time;
|
||||||
m_udpComm.popMsgFormQueue(time,m_disLowBusState);
|
// m_udpComm.popMsgFormQueue(time,m_disLowBusState);
|
||||||
m_pmCurrentState.bus4State = m_disLowBusState.data;
|
// m_pmCurrentState.bus4State = m_disLowBusState.data;
|
||||||
m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库
|
// m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库
|
||||||
msg_disLowBusFbMsg_Update_time = time;
|
// msg_disLowBusFbMsg_Update_time = time;
|
||||||
|
|
||||||
disBus4Breaker* pdis4=new disBus4Breaker;
|
// disBus4Breaker* pdis4=new disBus4Breaker;
|
||||||
(m_pmCurrentState.bus4State.unit1CircuitBreaker == BREAK_ON)? pdis4 -> unit1CircuitBreaker = 1 : pdis4 -> unit1CircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.unit1CircuitBreaker == BREAK_ON)? pdis4 -> unit1CircuitBreaker = 1 : pdis4 -> unit1CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus4State.unit2CircuitBreaker == BREAK_ON)? pdis4 -> unit2CircuitBreaker = 1 : pdis4 -> unit2CircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.unit2CircuitBreaker == BREAK_ON)? pdis4 -> unit2CircuitBreaker = 1 : pdis4 -> unit2CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus4State.unit3CircuitBreaker == BREAK_ON)? pdis4 -> unit3CircuitBreaker = 1 : pdis4 -> unit3CircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.unit3CircuitBreaker == BREAK_ON)? pdis4 -> unit3CircuitBreaker = 1 : pdis4 -> unit3CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus4State.unit5CircuitBreaker == BREAK_ON)? pdis4 -> unit5CircuitBreaker = 1 : pdis4 -> unit5CircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.unit5CircuitBreaker == BREAK_ON)? pdis4 -> unit5CircuitBreaker = 1 : pdis4 -> unit5CircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker == BREAK_ON)? pdis4 -> bowPZDeviceCircuitBreaker = 1 : pdis4 -> bowPZDeviceCircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.bowPZDeviceCircuitBreaker == BREAK_ON)? pdis4 -> bowPZDeviceCircuitBreaker = 1 : pdis4 -> bowPZDeviceCircuitBreaker = 0;
|
||||||
(m_pmCurrentState.bus4State.reservedCircuitBreaker1 == BREAK_ON)? pdis4 -> reservedCircuitBreaker1 = 1 : pdis4 -> reservedCircuitBreaker1 = 0;
|
// (m_pmCurrentState.bus4State.reservedCircuitBreaker1 == BREAK_ON)? pdis4 -> reservedCircuitBreaker1 = 1 : pdis4 -> reservedCircuitBreaker1 = 0;
|
||||||
(m_pmCurrentState.bus4State.reservedCircuitBreaker2 == BREAK_ON)? pdis4 -> reservedCircuitBreaker2 = 1 : pdis4 -> reservedCircuitBreaker2 = 0;
|
// (m_pmCurrentState.bus4State.reservedCircuitBreaker2 == BREAK_ON)? pdis4 -> reservedCircuitBreaker2 = 1 : pdis4 -> reservedCircuitBreaker2 = 0;
|
||||||
(m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker == BREAK_ON)? pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 1 : pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 0;
|
// (m_pmCurrentState.bus4State.emergencyLithiumBatteryGroup1CircuitBreaker == BREAK_ON)? pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 1 : pdis4 -> emergencyLithiumBatteryGroup1CircuitBreaker = 0;
|
||||||
pdis4 -> paceholder = 0;
|
// pdis4 -> paceholder = 0;
|
||||||
m_currentDisBreakerState.bus4Breaker = *pdis4;
|
// m_currentDisBreakerState.bus4Breaker = *pdis4;
|
||||||
delete pdis4;
|
// delete pdis4;
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
bool PowerManger::IsSkewed(double dfTimeNow, double * pdfSkew)
|
bool PowerManger::IsSkewed(double dfTimeNow, double * pdfSkew)
|
||||||
@@ -488,68 +478,68 @@ bool PowerManger::IsSkewed(double dfTimeNow, double * pdfSkew)
|
|||||||
return (dfSkew > SKEW_TOLERANCE) ? true : false;
|
return (dfSkew > SKEW_TOLERANCE) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerManger::ccuOption()
|
// void PowerManger::ccuOption()
|
||||||
{
|
// {
|
||||||
m_db->insertCcuSysCmd(m_CcuColCmd);
|
// m_db->insertCcuSysCmd(m_CcuColCmd);
|
||||||
if(!m_udpComm.sendCcuColCmd(m_CcuColCmd))
|
// if(!m_udpComm.sendCcuColCmd(m_CcuColCmd))
|
||||||
cout << "send ccu col cmd failed!" << endl;
|
// cout << "send ccu col cmd failed!" << endl;
|
||||||
}
|
// }
|
||||||
void PowerManger::disSysOption()
|
// void PowerManger::disSysOption()
|
||||||
{
|
// {
|
||||||
|
|
||||||
//根据目标状态进行断路器操作
|
// //根据目标状态进行断路器操作
|
||||||
//a. 高压母线的断路器
|
// //a. 高压母线的断路器
|
||||||
disHighVolBusCmd a;
|
// disHighVolBusCmd a;
|
||||||
a.fuelCellCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker);
|
// a.fuelCellCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker);
|
||||||
a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
// a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||||
a.dcDc5ModuleCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker);
|
// a.dcDc5ModuleCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker);
|
||||||
a.powerLithiumBatteryCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker);
|
// a.powerLithiumBatteryCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker);
|
||||||
a.propulsionMotorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker);
|
// a.propulsionMotorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker);
|
||||||
a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker);
|
// a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker);
|
||||||
a.tyzReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker);
|
// a.tyzReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker);
|
||||||
a.sternFTDevice45CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker);
|
// a.sternFTDevice45CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker);
|
||||||
a.sternRudderSwitch1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch1CircuitBreaker);
|
// a.sternRudderSwitch1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch1CircuitBreaker);
|
||||||
a.sternRudderSwitch2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch2CircuitBreaker);
|
// a.sternRudderSwitch2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.sternRudderSwitch2CircuitBreaker);
|
||||||
a.reservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.reservedCircuitBreaker);
|
// a.reservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.reservedCircuitBreaker);
|
||||||
a.fbReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fbReservedCircuitBreaker);
|
// a.fbReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fbReservedCircuitBreaker);
|
||||||
m_udpComm.sendDisSysCmd(a);
|
// m_udpComm.sendDisSysCmd(a);
|
||||||
//b. 高压汇流排A断路器
|
// //b. 高压汇流排A断路器
|
||||||
disHighAVolBusCmd b;
|
// disHighAVolBusCmd b;
|
||||||
b.bowFTDevice123CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowFTDevice123CircuitBreaker);
|
// b.bowFTDevice123CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowFTDevice123CircuitBreaker);
|
||||||
b.actuatorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.actuatorCircuitBreaker);
|
// b.actuatorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.actuatorCircuitBreaker);
|
||||||
b.mastSteeringGearControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.mastSteeringGearControlBoxCircuitBreaker);
|
// b.mastSteeringGearControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.mastSteeringGearControlBoxCircuitBreaker);
|
||||||
b.xczCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.xczCircuitBreaker);
|
// b.xczCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.xczCircuitBreaker);
|
||||||
b.bowRudderControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowRudderControlBoxCircuitBreaker);
|
// b.bowRudderControlBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.bowRudderControlBoxCircuitBreaker);
|
||||||
b.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker);
|
// b.openWaterCoverStartCylinderCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus2Breaker.openWaterCoverStartCylinderCircuitBreaker);
|
||||||
m_udpComm.sendDisSysCmd(b);
|
// m_udpComm.sendDisSysCmd(b);
|
||||||
//c. 高压汇流排B断路器
|
// //c. 高压汇流排B断路器
|
||||||
disHighBVolBusCmd c;
|
// disHighBVolBusCmd c;
|
||||||
c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
// c.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||||
c.bowLowVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.bowLowVoltageDistributionBoxCircuitBreaker);
|
// c.bowLowVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.bowLowVoltageDistributionBoxCircuitBreaker);
|
||||||
c.unit4InstrumentDC48VCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.unit4InstrumentDC48VCircuitBreaker);
|
// c.unit4InstrumentDC48VCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.unit4InstrumentDC48VCircuitBreaker);
|
||||||
c.dcC1DCDistributionPanelCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.dcC1DCDistributionPanelCircuitBreaker);
|
// c.dcC1DCDistributionPanelCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.dcC1DCDistributionPanelCircuitBreaker);
|
||||||
c.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker1);
|
// c.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker1);
|
||||||
c.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker2);
|
// c.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus3Breaker.reservedCircuitBreaker2);
|
||||||
c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker);
|
// c.emergencyLithiumBatteryGroup2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus3Breaker.emergencyLithiumBatteryGroup2CircuitBreaker);
|
||||||
m_udpComm.sendDisSysCmd(c);
|
// m_udpComm.sendDisSysCmd(c);
|
||||||
//d. 闭合低压汇流排断路器
|
// //d. 闭合低压汇流排断路器
|
||||||
disLowBusCmd d;
|
// disLowBusCmd d;
|
||||||
d.unit1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit1CircuitBreaker);
|
// d.unit1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit1CircuitBreaker);
|
||||||
d.unit2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit2CircuitBreaker);
|
// d.unit2CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit2CircuitBreaker);
|
||||||
d.unit3CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit3CircuitBreaker);
|
// d.unit3CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit3CircuitBreaker);
|
||||||
d.unit5CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit5CircuitBreaker);
|
// d.unit5CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.unit5CircuitBreaker);
|
||||||
d.bowPZDeviceCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.bowPZDeviceCircuitBreaker);
|
// d.bowPZDeviceCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.bowPZDeviceCircuitBreaker);
|
||||||
d.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker1);
|
// d.reservedCircuitBreaker1 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker1);
|
||||||
d.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker2);
|
// d.reservedCircuitBreaker2 = getBreakerOption(m_targetDisBreakerState.bus4Breaker.reservedCircuitBreaker2);
|
||||||
d.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker);
|
// d.emergencyLithiumBatteryGroup1CircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus4Breaker.emergencyLithiumBatteryGroup1CircuitBreaker);
|
||||||
m_udpComm.sendDisSysCmd(d);
|
// m_udpComm.sendDisSysCmd(d);
|
||||||
//将指令写入数据库
|
// //将指令写入数据库
|
||||||
m_db->insertDisSysCmd(a);
|
// m_db->insertDisSysCmd(a);
|
||||||
m_db->insertDisSysCmd(b);
|
// m_db->insertDisSysCmd(b);
|
||||||
m_db->insertDisSysCmd(c);
|
// m_db->insertDisSysCmd(c);
|
||||||
m_db->insertDisSysCmd(d);
|
// m_db->insertDisSysCmd(d);
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
bool PowerManger::saveStringToJsonFile(const string &strJson, const string &filePath)
|
bool PowerManger::saveStringToJsonFile(const string &strJson, const string &filePath)
|
||||||
@@ -568,7 +558,6 @@ bool PowerManger::saveStringToJsonFile(const string &strJson, const string &file
|
|||||||
|
|
||||||
bool PowerManger::writeDataToDB()
|
bool PowerManger::writeDataToDB()
|
||||||
{
|
{
|
||||||
|
|
||||||
// //写入配电系统状态
|
// //写入配电系统状态
|
||||||
// if(!m_db->insertDisCcuData(m_pmCurrentState))
|
// if(!m_db->insertDisCcuData(m_pmCurrentState))
|
||||||
// return false;
|
// return false;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class PowerManagerFsm;
|
|||||||
#include "PowerManagerFsm.hpp"
|
#include "PowerManagerFsm.hpp"
|
||||||
#include "SQLiteDB.h"
|
#include "SQLiteDB.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
|
#include "LowerCommManager.h"
|
||||||
|
|
||||||
#define VAR_TO_STR(var) #var
|
#define VAR_TO_STR(var) #var
|
||||||
|
|
||||||
@@ -99,26 +100,26 @@ class PowerManger : public AppCastingMOOSApp
|
|||||||
double msg_disHighAVolBusFbMsg_Update_time;
|
double msg_disHighAVolBusFbMsg_Update_time;
|
||||||
double msg_disHighBVolBusFbMsg_Update_time;
|
double msg_disHighBVolBusFbMsg_Update_time;
|
||||||
double msg_disLowBusFbMsg_Update_time;
|
double msg_disLowBusFbMsg_Update_time;
|
||||||
|
/************************************************************/
|
||||||
|
/* |<------------FEEDBACK--------<-- */
|
||||||
|
/* | | */
|
||||||
|
/* IN-->+-------[STATE CONTROL]---------+--->OUT */
|
||||||
|
/* */
|
||||||
|
/************************************************************/
|
||||||
public:
|
public:
|
||||||
//===========================交互状态变量==================================
|
//===========================IN============================================
|
||||||
Driver m_driver; //设备驱动
|
DriverTable m_MSDriverCmd;
|
||||||
|
MSControlCmd m_msCmd;
|
||||||
|
//===========================OUT===========================================
|
||||||
|
DriverTable m_subDisSysCmd;
|
||||||
|
ccuColCmd m_CcuColCmd;
|
||||||
|
disSysBreakerList m_targetDisBreakerState;
|
||||||
|
//===========================FEEDBACK======================================
|
||||||
pmState m_pmCurrentState; //能源系统的当前状态
|
pmState m_pmCurrentState; //能源系统的当前状态
|
||||||
disSysBreakerList m_currentDisBreakerState; //配电断路器状态
|
disSysBreakerList m_currentDisBreakerState; //配电断路器状态
|
||||||
disSysBreakerList m_targetDisBreakerState;
|
|
||||||
DriverTable m_currentDriverState;
|
DriverTable m_currentDriverState;
|
||||||
DriverTable m_MSDriverCmd;
|
|
||||||
DriverTable m_subDisSysCmd;
|
|
||||||
DriverTable m_subDisSysState;
|
DriverTable m_subDisSysState;
|
||||||
std::string m_pmEvent; // 状态机事件描述
|
//===========================STATE=========================================
|
||||||
//=============================运行变量======================================
|
|
||||||
long m_lPort;
|
|
||||||
unsigned int m_nReceiveBufferSizeKB;
|
|
||||||
unsigned int m_nSendBufferSizeKB;
|
|
||||||
double m_current_time;
|
|
||||||
unsigned int m_faultNum;
|
|
||||||
unsigned int m_ticker;
|
|
||||||
//===========================================================================
|
|
||||||
//系统运行状态
|
|
||||||
unsigned char workCondition;
|
unsigned char workCondition;
|
||||||
unsigned char currentMod;
|
unsigned char currentMod;
|
||||||
unsigned char powerState;
|
unsigned char powerState;
|
||||||
@@ -126,7 +127,17 @@ class PowerManger : public AppCastingMOOSApp
|
|||||||
vector<unsigned int> faultCode;
|
vector<unsigned int> faultCode;
|
||||||
unsigned int soc;
|
unsigned int soc;
|
||||||
unsigned int sustainableTime;
|
unsigned int sustainableTime;
|
||||||
|
//===========================CONFIG========================================
|
||||||
|
long m_lPort;
|
||||||
|
unsigned int m_nReceiveBufferSizeKB;
|
||||||
|
unsigned int m_nSendBufferSizeKB;
|
||||||
|
double m_current_time;
|
||||||
|
unsigned int m_faultNum;
|
||||||
|
unsigned int m_ticker;
|
||||||
|
//===========================交互状态变量==================================
|
||||||
|
Driver m_driver; //设备驱动
|
||||||
|
std::string m_pmEvent; // 状态机事件描述
|
||||||
|
//=============================运行变量======================================
|
||||||
// 配电和CCU的反馈状态
|
// 配电和CCU的反馈状态
|
||||||
msg_CcuStateFbMsg m_CcuCurrentState;
|
msg_CcuStateFbMsg m_CcuCurrentState;
|
||||||
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
msg_disHighVolBusFbMsg m_disHighVolBusCurrentState;
|
||||||
@@ -135,7 +146,6 @@ class PowerManger : public AppCastingMOOSApp
|
|||||||
msg_disLowBusFbMsg m_disLowBusState;
|
msg_disLowBusFbMsg m_disLowBusState;
|
||||||
|
|
||||||
//下位机操作函数
|
//下位机操作函数
|
||||||
ccuColCmd m_CcuColCmd;
|
|
||||||
void disSysOption();
|
void disSysOption();
|
||||||
void ccuOption();
|
void ccuOption();
|
||||||
|
|
||||||
@@ -143,15 +153,14 @@ class PowerManger : public AppCastingMOOSApp
|
|||||||
void initControlCmd();
|
void initControlCmd();
|
||||||
|
|
||||||
//上位机操作函数
|
//上位机操作函数
|
||||||
MSControlCmd m_msCmd;
|
|
||||||
bool buildPowerSysReport();
|
bool buildPowerSysReport();
|
||||||
bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson);
|
bool getMsCmdFromJson(MSControlCmd &cmd,const string &strJson);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
udpComm m_udpComm;
|
|
||||||
XPCUdpSocket *m_pCcuUdpComm;
|
|
||||||
CMOOSThread m_ListenThread;
|
CMOOSThread m_ListenThread;
|
||||||
CMOOSThread m_FsmThread;
|
CMOOSThread m_FsmThread;
|
||||||
|
LowerCommManager* m_lowerCommManager;
|
||||||
|
|
||||||
// 状态机实例
|
// 状态机实例
|
||||||
PowerManagerFsm m_fsm;
|
PowerManagerFsm m_fsm;
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#include "UpperCommManager.h"
|
||||||
|
#include "PowerManger.h"
|
||||||
|
#include "driver.h"
|
||||||
|
|
||||||
|
UpperCommManager::UpperCommManager(PowerManger* pm) : m_pm(pm) {}
|
||||||
|
|
||||||
|
bool UpperCommManager::processUpperMsg(const string& key, const string& strJson) {
|
||||||
|
if(key == DB_TO_PM_MSCMD) {
|
||||||
|
if(m_pm->getMsCmdFromJson(m_pm->m_msCmd, strJson)) {
|
||||||
|
cout << "get ms cmd:" << strJson << endl;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
cout << MOOS::ConsoleColours::Red << "get ms cmd error:" << strJson
|
||||||
|
<< MOOS::ConsoleColours::reset << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(key == DB_TO_PM_EQUIPMENTCMD) {
|
||||||
|
if(m_pm->m_driver.loadDriverTableFromJson(strJson, m_pm->m_subDisSysCmd) < 0) {
|
||||||
|
cout << MOOS::ConsoleColours::Red << "get sub dis cmd error:" << strJson
|
||||||
|
<< MOOS::ConsoleColours::reset << endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(key == DB_TO_PM_SUBDISSTATE) {
|
||||||
|
if(m_pm->m_driver.loadDriverTableFromJson(strJson, m_pm->m_subDisSysState) < 0) {
|
||||||
|
cout << MOOS::ConsoleColours::Red << "get sub dis state error:" << strJson
|
||||||
|
<< MOOS::ConsoleColours::reset << endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpperCommManager::processPeriodicTasks() {
|
||||||
|
buildPowerSysReport();
|
||||||
|
Notify(PM_TO_DB_SUBDISCMD,
|
||||||
|
m_pm->m_driver.saveDriverTableToJson(&m_pm->m_subDisSysCmd));
|
||||||
|
Notify(PM_TO_DB_EQUIPMENTSTATE,
|
||||||
|
m_pm->m_driver.saveDriverTableToJson(&m_pm->m_currentDriverState));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpperCommManager::buildPowerSysReport() {
|
||||||
|
// 原有buildPowerSysReport实现
|
||||||
|
// 需要从PowerManger.cpp迁移过来
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef UPPER_COMM_MANAGER_H
|
||||||
|
#define UPPER_COMM_MANAGER_H
|
||||||
|
|
||||||
|
#include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h"
|
||||||
|
#include "pmSysvariable.h"
|
||||||
|
#include "driver.h"
|
||||||
|
#include "json/json.h"
|
||||||
|
|
||||||
|
class PowerManger; // 前向声明
|
||||||
|
|
||||||
|
class UpperCommManager {
|
||||||
|
public:
|
||||||
|
UpperCommManager(PowerManger* powerManager);
|
||||||
|
~UpperCommManager();
|
||||||
|
|
||||||
|
// 处理上位机消息
|
||||||
|
bool processUpperMsg(const std::string& key, const std::string& msg);
|
||||||
|
|
||||||
|
// 生成系统报告
|
||||||
|
bool buildSystemReport();
|
||||||
|
|
||||||
|
// 获取控制命令
|
||||||
|
const MSControlCmd& getControlCmd() const { return m_msCmd; }
|
||||||
|
|
||||||
|
// 更新设备命令状态
|
||||||
|
void updateEquipmentCmd(const DriverTable& cmd);
|
||||||
|
|
||||||
|
private:
|
||||||
|
PowerManger* m_powerManager;
|
||||||
|
MSControlCmd m_msCmd;
|
||||||
|
Driver m_driver;
|
||||||
|
|
||||||
|
// 从JSON解析控制命令
|
||||||
|
bool parseControlCmdFromJson(MSControlCmd &cmd, const std::string &strJson);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UPPER_COMM_MANAGER_H
|
||||||
@@ -4,10 +4,17 @@
|
|||||||
|
|
||||||
udpComm::udpComm()
|
udpComm::udpComm()
|
||||||
{
|
{
|
||||||
|
udpScoket = nullptr;
|
||||||
|
ccuHost = "";
|
||||||
|
ccuPort = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
udpComm::~udpComm() {}
|
udpComm::~udpComm() {
|
||||||
|
if (udpScoket) {
|
||||||
|
delete udpScoket;
|
||||||
|
udpScoket = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Checksum udpComm::calculateChecksum(const unsigned char* data, int size)
|
Checksum udpComm::calculateChecksum(const unsigned char* data, int size)
|
||||||
@@ -490,6 +497,12 @@ bool udpComm::sendCcuColCmd(const ccuColCmd cmd)
|
|||||||
msg->checkCode = static_cast<cChecksum>(cc & 0xFF);
|
msg->checkCode = static_cast<cChecksum>(cc & 0xFF);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if(udpScoket == nullptr) {
|
||||||
|
throw std::runtime_error("UDP socket not initialized");
|
||||||
|
}
|
||||||
|
if(ccuHost.empty() || ccuPort <= 0 || ccuPort > 65535) {
|
||||||
|
throw std::runtime_error("Invalid CCU address: " + ccuHost + ":" + std::to_string(ccuPort));
|
||||||
|
}
|
||||||
sendMsg(msgBuf,sizeof(msg_CcuColCmdMsg));
|
sendMsg(msgBuf,sizeof(msg_CcuColCmdMsg));
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
|
|||||||
Reference in New Issue
Block a user