449a3a801a
- Introduced KnxDaliModule class for handling DALI message queuing, commissioning, and KNX group-object dispatch. - Implemented Message and MessageQueue classes for managing message operations. - Removed obsolete OpenKNX IDF component files and CMake configurations. - Updated submodule reference for KNX. Signed-off-by: Tony <tonylu@tony-cloud.com>
128 lines
4.5 KiB
C++
128 lines
4.5 KiB
C++
#pragma once
|
|
|
|
// =============================================================================
|
|
// dali_gateway_bridge.h — Thin adapter mapping legacy DALI operations to
|
|
// dali_domain / dali_cpp API.
|
|
// =============================================================================
|
|
|
|
#include "dali_domain.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
namespace gateway {
|
|
namespace knx_dali_gw {
|
|
|
|
// DALI target types matching the legacy DaliModule target model.
|
|
enum class DaliTargetKind : uint8_t {
|
|
kShortAddress = 0,
|
|
kGroup = 1,
|
|
kBroadcast = 2,
|
|
};
|
|
|
|
struct DaliTarget {
|
|
DaliTargetKind kind{DaliTargetKind::kShortAddress};
|
|
int address{0}; // short address 0-63, group 0-15, or ignored for broadcast
|
|
};
|
|
|
|
// Encodes a DaliTarget into a raw DALI address byte.
|
|
uint8_t EncodeDaliRawAddr(DaliTarget target);
|
|
|
|
// Decodes a raw DALI address byte into a DaliTarget for a given short address.
|
|
DaliTarget DecodeDaliRawAddr(uint8_t raw_addr, int default_short_address = -1);
|
|
|
|
// Lightweight bridge over DaliDomainService for the KNX-DALI gateway.
|
|
// All operations go through a single DALI channel (gateway_id).
|
|
class DaliGatewayBridge {
|
|
public:
|
|
explicit DaliGatewayBridge(DaliDomainService& dali, uint8_t gateway_id = 0);
|
|
|
|
// ---- Basic send / query ----
|
|
|
|
bool sendRaw(DaliTarget target, uint8_t command) const;
|
|
bool sendExtRaw(DaliTarget target, uint8_t command) const;
|
|
std::optional<uint8_t> queryRaw(DaliTarget target, uint8_t command) const;
|
|
|
|
// ---- Brightness (arc power level) ----
|
|
|
|
bool setArc(DaliTarget target, uint8_t arc) const;
|
|
std::optional<uint8_t> queryActualLevel(int short_address) const;
|
|
|
|
// ---- On / Off / Step / Recall ----
|
|
|
|
bool on(DaliTarget target) const;
|
|
bool off(DaliTarget target) const;
|
|
bool stepUp(DaliTarget target) const;
|
|
bool stepDown(DaliTarget target) const;
|
|
bool recallMax(DaliTarget target) const;
|
|
bool recallMin(DaliTarget target) const;
|
|
bool goToScene(DaliTarget target, uint8_t scene) const;
|
|
|
|
// ---- Queries ----
|
|
|
|
std::optional<uint8_t> queryStatus(int short_address) const;
|
|
std::optional<uint8_t> queryDeviceType(int short_address) const;
|
|
std::optional<uint8_t> queryMinLevel(int short_address) const;
|
|
std::optional<uint8_t> queryMaxLevel(int short_address) const;
|
|
std::optional<uint8_t> queryPowerOnLevel(int short_address) const;
|
|
std::optional<uint8_t> querySystemFailureLevel(int short_address) const;
|
|
std::optional<uint8_t> queryFadeTimeRate(int short_address) const;
|
|
std::optional<uint8_t> queryFadeTime(int short_address) const;
|
|
std::optional<uint16_t> queryGroups(int short_address) const;
|
|
std::optional<uint8_t> querySceneLevel(int short_address, uint8_t scene) const;
|
|
|
|
// ---- DT8 colour ----
|
|
|
|
bool setColourTemperature(int short_address, int kelvin) const;
|
|
bool setColourRGB(int short_address, uint8_t r, uint8_t g, uint8_t b) const;
|
|
std::optional<DaliDomainSnapshot> dt8StatusSnapshot(int short_address) const;
|
|
std::optional<DaliDomainSnapshot> dt8SceneColorReport(int short_address, int scene) const;
|
|
|
|
// ---- Scenes & groups (write operations) ----
|
|
|
|
bool setDtr(uint8_t value) const;
|
|
bool setDtrAsScene(DaliTarget target, uint8_t scene) const;
|
|
bool addToGroup(DaliTarget target, uint8_t group) const;
|
|
bool removeFromGroup(DaliTarget target, uint8_t group) const;
|
|
bool removeFromScene(DaliTarget target, uint8_t scene) const;
|
|
bool setSceneLevel(DaliTarget target, uint8_t scene, uint8_t level) const;
|
|
|
|
// ---- Commissioning ----
|
|
|
|
bool initialise(DaliTarget target) const;
|
|
bool randomise() const;
|
|
bool searchAddrH(uint8_t high) const;
|
|
bool searchAddrM(uint8_t middle) const;
|
|
bool searchAddrL(uint8_t low) const;
|
|
bool compare() const;
|
|
bool withdraw() const;
|
|
bool terminate() const;
|
|
bool programShort(DaliTarget target, uint8_t short_address) const;
|
|
bool verifyShort(DaliTarget target) const;
|
|
std::optional<uint8_t> queryShort(DaliTarget target) const;
|
|
|
|
// High-level addressing.
|
|
bool allocateAllAddr(int start_address = 0) const;
|
|
void stopAllocAddr() const;
|
|
bool resetAndAllocAddr(int start_address = 0, bool remove_addr_first = false,
|
|
bool close_light = false) const;
|
|
|
|
// ---- Bus control ----
|
|
|
|
bool resetBus() const;
|
|
|
|
private:
|
|
DaliDomainService& dali_;
|
|
uint8_t gateway_id_;
|
|
};
|
|
|
|
// Convert DALI arc power level (0-254) to percentage (0.0-100.0).
|
|
double ArcToPercent(uint8_t arc);
|
|
|
|
// Convert percentage (0.0-100.0) to DALI arc power level (0-254).
|
|
uint8_t PercentToArc(double percent);
|
|
|
|
} // namespace knx_dali_gw
|
|
} // namespace gateway
|