- 新增 pCCU 复合管控器程序(src/pCCU):FC/PM 双链路(UDP)、协议编解码器 (FcProtocol/PmProtocol/Frame/Message/MessageRegistry)、快照与落库(DbStore)、 内置 WebServer;挂入 src/CMakeLists.txt 与板卡 mission(h100.moos) - 惯导/深度数据:新增 uDevice_insData 消息解析,接入 UpperCommManager, pPowerMangerHost 注册监视,UpmsgTest 覆盖 - pPowerMangerHost 设备控制页增强(web/index.html) - 部署/运维脚本改为 4 个 systemd 服务(moosdb/pPowerManger/pPowerMangerHost/pCCU): deploy/clean-data/fetch-data 同步适配 - 协议文档:归档 0824 控制主机与复合管控器通信协议 xlsx 及关联 docx,移除旧 md - 测试:新增 pccu 单元/集成测试与 disSysTest Python 配电仿真 - 清理:移除未使用的 CCU 状态调试打印 coutMsg;.gitignore 补充编译产物/临时文件忽略
59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#ifndef PCCU_FIELD_CODEC_H
|
|
#define PCCU_FIELD_CODEC_H
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <stdexcept>
|
|
|
|
namespace ccu {
|
|
|
|
//============================================================================
|
|
// FieldCodec:小端序(Little-Endian)编解码原语。
|
|
//
|
|
// 两条协议(FC 协议 / PM 协议)均采用:
|
|
// - 多字节数据小端序
|
|
// - 域起始符 0x40 0x40
|
|
// - 域字节数 = 整个协议包的数据长度
|
|
// 本类提供对裸缓冲区的字段读写,不关心具体业务含义。
|
|
//============================================================================
|
|
|
|
class FieldCodec {
|
|
public:
|
|
// 在 dst 偏移 offset 处写入单字节
|
|
static void putU8(std::vector<uint8_t>& dst, size_t offset, uint8_t v) {
|
|
dst[offset] = v;
|
|
}
|
|
// 小端写入 2 字节
|
|
static void putU16(std::vector<uint8_t>& dst, size_t offset, uint16_t v) {
|
|
dst[offset] = static_cast<uint8_t>(v & 0xFF);
|
|
dst[offset + 1] = static_cast<uint8_t>((v >> 8) & 0xFF);
|
|
}
|
|
// 小端写入 4 字节
|
|
static void putU32(std::vector<uint8_t>& dst, size_t offset, uint32_t v) {
|
|
dst[offset] = static_cast<uint8_t>(v & 0xFF);
|
|
dst[offset + 1] = static_cast<uint8_t>((v >> 8) & 0xFF);
|
|
dst[offset + 2] = static_cast<uint8_t>((v >> 16) & 0xFF);
|
|
dst[offset + 3] = static_cast<uint8_t>((v >> 24) & 0xFF);
|
|
}
|
|
|
|
static uint8_t getU8 (const std::vector<uint8_t>& src, size_t offset) {
|
|
return src[offset];
|
|
}
|
|
static uint16_t getU16(const std::vector<uint8_t>& src, size_t offset) {
|
|
return static_cast<uint16_t>(src[offset]) |
|
|
(static_cast<uint16_t>(src[offset + 1]) << 8);
|
|
}
|
|
static uint32_t getU32(const std::vector<uint8_t>& src, size_t offset) {
|
|
return static_cast<uint32_t>(src[offset]) |
|
|
(static_cast<uint32_t>(src[offset + 1]) << 8) |
|
|
(static_cast<uint32_t>(src[offset + 2]) << 16) |
|
|
(static_cast<uint32_t>(src[offset + 3]) << 24);
|
|
}
|
|
};
|
|
|
|
} // namespace ccu
|
|
|
|
#endif // PCCU_FIELD_CODEC_H
|