#pragma once #include #include #include #include #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 cmd_; std::map sCMD_; std::vector queryCmd_; std::map 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; };