Files
dali_cpp/include/decode.hpp
T
Tony 211a9a9c41 Enhance DaliDecode: add support for device type decoding and context management
- Introduced new structures and methods for handling device type decoding, including DaliDecodeContext and DeviceTypeDecodeTable.
- Implemented decoding functions for device types DT1, DT4, DT5, DT6, and DT8, with specific command and query handling.
- Updated existing decode methods to incorporate gateway and source parameters for better context tracking.
- Added detailed formatting for device type commands and queries, enhancing the decoding process for various device types.
- Refactored the decode logic to utilize the new context management for maintaining state across different device types.

Signed-off-by: Tony <tonylu@tony-cloud.com>
2026-06-13 14:25:27 +08:00

72 lines
2.3 KiB
C++

#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include "decode_device_type.hpp"
struct DecodedRecord {
std::string text;
std::string type;
int addr = -1;
int cmd = -1;
int proto = -1;
int gateway = -1;
std::string source;
};
class DaliDecode {
public:
bool displayRaw = true;
int responseWindowMs = 100;
int dtr0 = 0;
int dtr1 = 0;
int dtr2 = 0;
DaliDecode();
int isQueryCmd(int cmd) const;
DecodedRecord decodeBright(int addr, int level, int gateway = -1, const std::string& source = "");
DecodedRecord decodeScene(int addr, int sceneCmd, int gateway = -1,
const std::string& source = "");
DecodedRecord decodeCmd(int addr, int c, int gateway = -1, const std::string& source = "");
DecodedRecord decodeSpCmd(int addr, int c, int gateway = -1, const std::string& source = "");
DecodedRecord querySpCMD(int cmdByte, int dataByte, int gateway = -1,
const std::string& source = "");
DecodedRecord decodeQuery(int addr, int c, int gateway = -1, const std::string& source = "",
int deviceType = -1);
DecodedRecord decodeCmdResponse(int value, int gwPrefix = 0xFF, int gateway = -1,
const std::string& source = "");
DecodedRecord decode(int addr, int c, int proto = 0x10, int gateway = -1,
const std::string& source = "");
private:
std::map<int, std::string> cmd_;
std::map<int, std::string> sCMD_;
std::vector<int> queryCmd_;
std::map<int, DaliDecodeContext> contexts_;
static int64_t nowMs();
static std::string hex(int v);
static std::string bin(int v);
static std::string yn(bool b);
static std::string ynUpper(bool b);
static std::string whoLabel(int addr, bool even);
static std::string deviceTypeName(int v);
static std::string lightSourceName(int v);
static std::string booleanQueryLabel(int c);
static std::string fadeTimeLabel(int code);
static std::string fadeRateLabel(int code);
DaliDecodeContext& contextFor(int gateway);
void syncDefaultDtrFromContext();
void syncDefaultDtrToContext();
DecodedRecord decodeDeviceTypeCommand(int addr, int c, const DtCommandSpec& spec, int proto,
int gateway, const std::string& source);
DecodedRecord withRaw(const DecodedRecord& r) const;
};