|
|
// led/BX6K1YYProtocol.hpp
|
|
|
// BX-6K1-YY 协议帧构造/解析(移植自 PuAnLED/Onbon/BX6K1YY/BX6K1YYProtocol.cpp,去 Qt 依赖)
|
|
|
#ifndef LED_BX6K1YY_PROTOCOL_HPP
|
|
|
#define LED_BX6K1YY_PROTOCOL_HPP
|
|
|
|
|
|
#include <cstdint>
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
|
|
|
namespace led {
|
|
|
|
|
|
// 协议常量(来自 BX-6K1-YY 协议文档与 Windows 版实现)
|
|
|
constexpr uint8_t kDeviceType = 0x64; // BX-6K1-YY
|
|
|
constexpr uint8_t kProtocolVersion = 0x02;
|
|
|
constexpr uint16_t kPortDefault = 5005; // BX-6K1-YY 默认 TCP 端口
|
|
|
|
|
|
// 屏幕参数查询(payload = A2 0A 01 00 00)
|
|
|
std::vector<uint8_t> buildScreenParameterQueryFrame();
|
|
|
|
|
|
// 构造下发文本的动态区域帧(payload: A3 06 01 00 00 01 <LE16 areaLen> <area>)
|
|
|
std::vector<uint8_t> buildDynamicTextFrame(const std::string& encodedText,
|
|
|
int screenWidth, int lineHeight,
|
|
|
int areaId,
|
|
|
bool expireWhenNotUpdated,
|
|
|
int timeoutSeconds);
|
|
|
|
|
|
// 删除指定动态区域(payload: A3 07 01 00 00 01 <areaId>)
|
|
|
std::vector<uint8_t> buildDeleteDynamicAreaFrame(int areaId);
|
|
|
|
|
|
// Modbus CRC-16(多项式 0xA001,低字节在前)
|
|
|
uint16_t crc16(const std::vector<uint8_t>& data);
|
|
|
|
|
|
// 把 payload 包成完整帧:8×0xA5 + escape(phy1) + 0x5A
|
|
|
std::vector<uint8_t> makeFrame(const std::vector<uint8_t>& payload);
|
|
|
|
|
|
// 解一帧:校验头/尾、转义还原、CRC16,解出的 PHY1 写到 outPhy1(不含尾部 CRC)
|
|
|
bool decodeFrame(const std::vector<uint8_t>& frame,
|
|
|
std::vector<uint8_t>& outPhy1,
|
|
|
std::string& error);
|
|
|
|
|
|
// 从 PHY1 取出屏幕宽高(payload[9..10]=width, payload[11..12]=height)
|
|
|
bool parseScreenDimensions(const std::vector<uint8_t>& phy1,
|
|
|
int& outWidth, int& outHeight,
|
|
|
std::string& error);
|
|
|
|
|
|
} // namespace led
|
|
|
|
|
|
#endif
|