You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.9 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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