pCanBridge: - 配置改为 channel = <通道名>,<IP>,<工作端口> 重复行(兼容旧 can_host/can_port 单通道回退), 每通道一条独立 CanEndpoint(TCP Client) + 接收线程,对应 CANET 的 CAN0=4001..CAN7=4008 - 上行 CAN_0x%08X 不变,m_sSrcAux=通道名区分来源通道 - 下行按 m_sSrcAux 路由到对应通道;回退规则:default_channel > 单通道 > 多通道告警丢弃 - buildReport 逐通道统计(连接/收发帧数/错误/重连) pCCU: - 新增 bcu_can_channel 配置(默认 CAN0),BCU 断路器下行 Post 前 SetSourceAux 指定目标通道, key 保持 CAN_TX_0x%08X(与上行通道标注对称,key 格式不变) 配置/文档:pCanBridge.moos、CanBridge_Info、pCCU.moos、missions/h100.moos、 test/pccu/pccu_it.moos 同步新格式。 验证:伪造 CANET Server 冒烟通过(多通道建链/上行解析发布/SQLite channel 列/ 下行通道路由与回退丢弃/srcAux 经 MOOSDB 往返); pccu 集成测试 PASSED(BCU 断路器下行 3 帧经新路由全部正确); pccuTest 183/183、PowerMangerTests 64/64 通过。
113 lines
4.0 KiB
C++
113 lines
4.0 KiB
C++
#ifndef PCCU_CCU_H
|
||
#define PCCU_CCU_H
|
||
|
||
#define UNIX
|
||
#include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h"
|
||
#include "comm/FcLinkManager.h"
|
||
#include "comm/PmLinkManager.h"
|
||
#include "comm/RcuLinkManager.h"
|
||
#include "core/SystemData.h"
|
||
#include "core/SnapshotBuilder.h"
|
||
#include "core/PowerCoordinator.h"
|
||
#include "core/DisBridge.h"
|
||
#include "store/DbStore.h"
|
||
#include "web/WebServer.h"
|
||
|
||
namespace ccu {
|
||
|
||
//============================================================================
|
||
// CCU:pCCU 程序主类(MOOS 应用外壳)。
|
||
//
|
||
// 数据流:
|
||
// 收 FC 状态(0x0002) -> SystemData 快照 -> 周期整合为 PM 状态(0x0004)发给 pPowerManger
|
||
// 收 PM 操控(0x0001) -> 转发为 FC 控制(0x0001)发给燃料电池
|
||
// 收 PM 参数设定(0x0002) -> 回 PM 参数反馈(0x0003)
|
||
// 收 PM 配电指令(0x0001~0x0004,Sum8短帧) -> DisBridge 原帧转发真实CCU(rcu 链路)
|
||
// 收真实CCU 配电反馈(0x0005~0x0008) -> DisBridge 原帧转发 pPowerManger + 解码显示
|
||
// 收真实CCU 状态报文(0x0004) -> 仅解码显示,不转发(避免状态冲突)
|
||
// 订阅 pCanBridge 透传的 CAN_0x* 消息 -> 解析锂电池 BMS 报文
|
||
// (docs/BMS_协议字段定义.xlsx:总电压/SOC/电流/故障码等)-> SystemData 快照
|
||
// (BMS CAN 协议未定义控制报文,电池侧远程控制暂不可用)
|
||
// 收发全部帧落库 SQLite(锂电池 BMS 解析数据另存 bcu_node 表);网页周期推送 JSON 快照。
|
||
//============================================================================
|
||
|
||
class CCU : public AppCastingMOOSApp {
|
||
public:
|
||
CCU();
|
||
~CCU();
|
||
|
||
protected:
|
||
bool OnNewMail(MOOSMSG_LIST &NewMail);
|
||
bool Iterate();
|
||
bool OnConnectToServer();
|
||
bool OnStartUp();
|
||
bool buildReport();
|
||
void registerVariables();
|
||
|
||
private:
|
||
// 链路收帧处理
|
||
void handleFcMessage(Message* msg, const std::vector<uint8_t>& frame);
|
||
void handlePmMessage(Message* msg, const std::vector<uint8_t>& frame);
|
||
void handleRcuMessage(Message* msg, const std::vector<uint8_t>& frame);
|
||
|
||
// MOOS 订阅消息处理(CAN_0x* 由 pCanBridge 发布)
|
||
void handleCanMessage(CMOOSMsg& msg);
|
||
|
||
// 整合并发送 PM 状态报文
|
||
void sendPmStatus();
|
||
|
||
// 构建网页快照
|
||
std::string buildSnapshot();
|
||
std::string handleApi(const std::string& uri, const std::string& query);
|
||
|
||
// BCU 断路器控制:/api/bcu_ctrl 解析与下发(经 MOOS CAN_TX_* -> pCanBridge)
|
||
std::string handleBcuCtrlApi(const std::string& query);
|
||
// 出队并下发一条 BCU 控制指令(Iterate 调用,MOOS 线程内 Notify 安全)
|
||
void sendPendingBcuCtrl();
|
||
|
||
// 配置
|
||
long m_fcLocalPort = 6000;
|
||
std::string m_fcHost = "192.168.1.162";
|
||
long m_fcPort = 7000;
|
||
|
||
long m_pmLocalPort = 7000;
|
||
std::string m_pmHost = "192.168.0.140";
|
||
long m_pmPort = 5001;
|
||
|
||
// 真实 CCU 桥接链路(配电协议透传)
|
||
bool m_rcuEnable = false; // 默认关闭,.moos 中开启
|
||
long m_rcuLocalPort = 7100;
|
||
std::string m_rcuHost = "192.168.0.200"; // 占位地址,.moos 中改为实际值
|
||
long m_rcuPort = 7000;
|
||
|
||
std::string m_dbPath = "pccu_data.db";
|
||
std::string m_logPath = "pCCU.log";
|
||
int m_webPort = 8080; // 与 pPowerManger(8090)/pPowerMangerHost(18080) 错开
|
||
bool m_webEnable = true;
|
||
|
||
// BCU 断路器控制帧下发的目标 CAN 通道(经 pCanBridge 的 m_sSrcAux 路由)
|
||
std::string m_bcuCanChannel = "CAN0";
|
||
|
||
// CAN BMS 日志节流(避免 60帧/s 刷爆日志)
|
||
double m_lastBmsLog = 0;
|
||
|
||
// 心跳
|
||
uint8_t m_pmHeartbeat = 0;
|
||
double m_lastStatusTx = 0;
|
||
|
||
// 组件
|
||
FcLinkManager* m_fcLink = nullptr;
|
||
PmLinkManager* m_pmLink = nullptr;
|
||
RcuLinkManager* m_rcuLink = nullptr;
|
||
DisBridge* m_bridge = nullptr;
|
||
SystemData* m_sysData = nullptr;
|
||
DbStore* m_db = nullptr;
|
||
SnapshotBuilder* m_snap = nullptr;
|
||
WebServer* m_web = nullptr;
|
||
PowerCoordinator* m_coord = nullptr;
|
||
};
|
||
|
||
} // namespace ccu
|
||
|
||
#endif // PCCU_CCU_H
|