Files
H100PowerManger/src/pCCU/store/DbStore.h
T
zjk 5b8f0b1421 锂电池改用 BCU-MBMS CAN 协议按节点解析 + bcu_node 解析数据落库 + 板卡对时脚本
- pCCU/CanBms:按《04KT38电池BCU-MBMS通信(CAN)定义》重写解码,
  BmsStatus 单状态模型改为 BcuNodeStatus 多节点模型(0x10XX00YY,
  节点地址 01~36h),支持 0x0000 电压/电流/SOC/告警码、0x0001 单体
  电压、0x0002 单体温度、0x0003 继电器、0x0006 绝缘/端口电压、
  0x0010 告警位(附录1 中文码表)六类报文
- 平均单体温度偏移修正:协议文档 BYTE5 写"偏移0"有误,实测固件与
  最高/最低一致均带 -40℃ 偏移(实车 0x10020002 原始 68/69 减 40 后
  为 28/29℃,落在最低28~最高30区间内,按文档直读则超出物理范围)
- pCCU/DbStore:新增 bcu_node 解析数据表,锂电池 BMS 报文每帧落一行
  节点合成状态(原 comm_log 仅原始帧,BMS/CAN 帧此前不落 pCCU 库),
  buildReport 增加 BMS 记录数
- 快照/网页:BCU 按节点分组展示(告警位解析中文含义、数据 age),
  PM 状态报文锂电池/应急电池卡片
- pPowerManger:新增 iport 本地输入端口配置(UDP bind 延迟到
  OnStartUp 读取配置后执行,保证 iport/ccuhost/ccuport 生效),
  各 mission 文件补充注释
- test:CAN BCU 解码用例按新协议/新偏移更新(实车抓包 + 文档示例值),
  133 项全部通过
- docs:删除旧 BMS 协议(xlsx/20230324docx),归档 04KT38 BCU-MBMS
  CAN 定义、配电控制器通信协议 20260824、配电系统 CAN 通讯协议
- scripts:新增 sync-board-time.sh,223 板卡(RK3588)时间校正
  (本机为基准 + RTT 折半补偿对时,尽力写 RTC,支持 status/--time)
2026-09-01 12:58:33 +08:00

81 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef PCCU_DB_STORE_H
#define PCCU_DB_STORE_H
#include <cstdint>
#include <string>
#include <mutex>
#include <vector>
#include "../comm/LinkManager.h"
#include "../protocol/CanBms.h"
struct sqlite3;
struct sqlite3_stmt;
namespace ccu {
//============================================================================
// DbStore:SQLite 存储。
//
// 设计要点(应对协议变更):
// - 以“原始帧日志”为主表(comm_log),收发全部数据按帧落库,
// 协议字段变化不会导致建表失败。
// - 提供按 link / direction / msg_id 的查询接口供网页展示。
// - 锂电池 BMS/CAN 协议字段固定,另设解析数据表 bcu_node:
// 每收到一帧 BMS 报文,把该 BCU 节点的合成状态落一行
// (电压/电流/SOC/单体电压温度/继电器/绝缘/告警位)。
// 复用仓库内 src/pPowerManger/sqlit3/sqlite3.c 与 sqlite3.h。
//============================================================================
struct CommLogRow {
long long id;
double time;
std::string link; // fc / pm
int direction; // 0=收 1=发
uint16_t msgId;
std::string msgName;
int length;
int checksumOk;
std::string hex;
};
class DbStore : public ILinkLogSink {
public:
explicit DbStore(const std::string& dbPath);
~DbStore();
bool open();
void close();
bool isOpen() const { return m_db != nullptr; }
std::string lastError() const { return m_lastError; }
// 实现 ILinkLogSink:原始帧落库(收发双向)
void onRawFrame(int direction, uint16_t msgId, const std::string& link,
const std::vector<uint8_t>& data, bool checksumOk) override;
// 锂电池解析数据落库(bcu_node 表):addr=节点地址(1~54),
// func=本次触发落库的 BCU 报文功能码,v=合并后的节点最新状态
void insertBcuNode(uint8_t addr, uint8_t func, const BcuNodeStatus& v);
// 查询最近 N 条记录(可限定链路/方向/消息id;limit<=0 表示默认 100)
std::vector<CommLogRow> queryRecent(const std::string& link, int direction,
uint16_t msgId, int limit);
long long count() const;
long long countBcu() const;
private:
bool exec(const char* sql);
bool prepareInsert();
bool prepareBcuInsert();
std::string m_dbPath;
sqlite3* m_db = nullptr;
sqlite3_stmt* m_stmtInsert = nullptr;
sqlite3_stmt* m_stmtBcuInsert = nullptr;
mutable std::mutex m_mutex;
std::string m_lastError;
};
} // namespace ccu
#endif // PCCU_DB_STORE_H