Add KNX DALI Gateway Module and Message Queue Implementation

- 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>
This commit is contained in:
Tony
2026-05-15 12:34:13 +08:00
parent 3f15cd7f3f
commit 449a3a801a
41 changed files with 2279 additions and 918 deletions
@@ -0,0 +1,127 @@
#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
@@ -0,0 +1,55 @@
#pragma once
// =============================================================================
// knx_dali_gw — KNX-to-DALI Gateway Component (ESP-IDF)
// =============================================================================
#include "esp_idf_platform.h"
#include "dali_domain.hpp"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
// Forward declarations.
class Bau07B0;
namespace gateway {
namespace knx_dali_gw {
struct KnxDaliGatewayConfig {
std::string nvs_namespace{"knx_dali_gw"};
uint16_t fallback_individual_address{0xfffe};
int dali_channel{0};
};
class KnxDaliGateway {
public:
explicit KnxDaliGateway(const KnxDaliGatewayConfig& config);
~KnxDaliGateway();
KnxDaliGateway(const KnxDaliGateway&) = delete;
KnxDaliGateway& operator=(const KnxDaliGateway&) = delete;
bool init();
void loop();
Bau07B0& knxDevice();
const Bau07B0& knxDevice() const;
void setNetworkInterface(esp_netif_t* netif);
bool handleTunnelFrame(const uint8_t* data, size_t len);
bool handleBusFrame(const uint8_t* data, size_t len);
bool emitGroupValue(uint16_t group_object_number, const uint8_t* data,
size_t len);
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace knx_dali_gw
} // namespace gateway
+66
View File
@@ -0,0 +1,66 @@
#pragma once
// Minimal stub for knxprod.h — generated KNX product definitions.
// The full file (1796 bytes of parameters, 1439 group objects) will be
// adapted in Phase 3 to use the gateway/knx API directly.
// Product identity
#define MAIN_OpenKnxId 0xA4
#define MAIN_ApplicationNumber 1
#define MAIN_ApplicationVersion 5
#define MAIN_OrderNumber "REG1-Dali"
#define MAIN_ParameterSize 1796
#define MAIN_MaxKoNumber 1439
// Parameter type enums (subset)
enum PT_DeviceType : uint8_t {
PT_deviceType_Deaktiviert = 0,
PT_deviceType_DT0 = 1,
PT_deviceType_DT1 = 2,
PT_deviceType_DT6 = 3,
PT_deviceType_DT8 = 4,
};
enum PT_ColorType : uint8_t {
PT_colorType_HSV = 0,
PT_colorType_RGB = 1,
PT_colorType_TW = 2,
PT_colorType_XYY = 3,
};
enum PT_ColorSpace : uint8_t {
PT_colorSpace_rgb = 0,
PT_colorSpace_xy = 1,
};
// Placeholder macros — will be replaced with direct Bau07B0 access in Phase 3.
#define ParamAPP_daynight(channelIndex) (0)
#define ParamAPP_funcBtn(channelIndex) (0)
#define ParamAPP_funcBtnLong(channelIndex) (0)
#define ParamAPP_funcBtnDbl(channelIndex) (0)
#define ParamADR_deviceType(channelIndex) (PT_DeviceType::PT_deviceType_Deaktiviert)
#define ParamADR_type(channelIndex) (0)
#define ParamADR_min(channelIndex) (0)
#define ParamADR_max(channelIndex) (254)
#define ParamADR_stairtime(channelIndex) (0)
#define ParamADR_onDay(channelIndex) (0)
#define ParamADR_onNight(channelIndex) (0)
#define ParamADR_error(channelIndex) (0)
#define ParamADR_queryTime(channelIndex) (0)
#define ParamADR_colorType(channelIndex) (PT_ColorType::PT_colorType_TW)
#define ParamADR_colorSpace(channelIndex) (PT_ColorSpace::PT_colorSpace_rgb)
#define ParamGRP_deviceType(channelIndex) (PT_DeviceType::PT_deviceType_Deaktiviert)
#define ParamGRP_type(channelIndex) (0)
#define ParamGRP_colorType(channelIndex) (PT_ColorType::PT_colorType_TW)
#define ParamHCL_type(channelIndex) (0)
// Group object offset placeholders
#define ADR_KoOffset 0
#define GRP_KoOffset 0
#define HCL_KoOffset 0
#define ADR_KoBlockSize 0
#define GRP_KoBlockSize 0
#define HCL_KoBlockSize 0