|
|
// led/Bx6k1YyLedClient.hpp
|
|
|
#ifndef LED_BX6K1YY_CLIENT_HPP
|
|
|
#define LED_BX6K1YY_CLIENT_HPP
|
|
|
|
|
|
#include <cstdint>
|
|
|
#include <string>
|
|
|
|
|
|
namespace led {
|
|
|
|
|
|
// 同步 TCP 客户端。displayText() 内部完成:
|
|
|
// 1) 连 TCP;2) 用 A2 0A 查屏幕宽高;3) 把整段文本按单行下发到指定动态区域。
|
|
|
// areaId = kAreaDefault (0) → 长驻(不超时),用于显示 led.txt 默认内容
|
|
|
// areaId = kAreaTemporary (1) → 60 秒后由控制卡自动删除,用于临时覆盖的 DDS 排队消息
|
|
|
class Bx6k1YyLedClient {
|
|
|
public:
|
|
|
static constexpr int kAreaDefault = 0;
|
|
|
static constexpr int kAreaTemporary = 1;
|
|
|
static constexpr int kTemporaryTimeoutSec = 60;
|
|
|
|
|
|
struct Config {
|
|
|
std::string ip;
|
|
|
uint16_t port = 5005;
|
|
|
int connectTimeoutMs = 1000;
|
|
|
int responseTimeoutMs = 1000;
|
|
|
// 查不到分辨率时的回退值(按工作区 config / 现场屏)
|
|
|
int fallbackScreenWidth = 64;
|
|
|
int fallbackScreenHeight = 32;
|
|
|
// BX-6K1-YY 文本字段按 GBK 发送;如卡固件是 UTF-8 改 "UTF-8"
|
|
|
std::string textEncoding = "GBK";
|
|
|
};
|
|
|
|
|
|
explicit Bx6k1YyLedClient(Config cfg);
|
|
|
~Bx6k1YyLedClient();
|
|
|
|
|
|
Bx6k1YyLedClient(const Bx6k1YyLedClient&) = delete;
|
|
|
Bx6k1YyLedClient& operator=(const Bx6k1YyLedClient&) = delete;
|
|
|
|
|
|
// 失败时不抛异常,把原因写到 error;返回 false 时下次调用会重建连接。
|
|
|
// areaId=0 走长驻;areaId=1 走 60 秒自删。
|
|
|
bool displayText(const std::string& utf8Text, int areaId, std::string& error);
|
|
|
|
|
|
private:
|
|
|
bool ensureConnected(std::string& error);
|
|
|
bool queryScreenSize(int& outW, int& outH, std::string& error);
|
|
|
void closeSocket();
|
|
|
|
|
|
Config m_cfg;
|
|
|
int m_fd = -1;
|
|
|
int m_screenW = 0;
|
|
|
int m_screenH = 0;
|
|
|
};
|
|
|
|
|
|
} // namespace led
|
|
|
|
|
|
#endif
|