#pragma once #include #include #include #include #include #include "esp_err.h" struct ble_gap_event; struct ble_gatt_access_ctxt; namespace gateway { class DaliDomainService; class GatewayController; class GatewayRuntime; class GatewayBleBridge { public: GatewayBleBridge(GatewayController& controller, GatewayRuntime& runtime, DaliDomainService& dali_domain); esp_err_t start(); void handleSync(); int handleGapEvent(struct ble_gap_event* event); int handleAccess(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt); private: static constexpr uint16_t kInvalidConnectionHandle = 0xffff; esp_err_t initNimble(); void refreshDeviceName(); void setEnabled(bool enabled); void startAdvertising(); void stopAdvertising(); void notifyCharacteristic(size_t index, const std::vector& payload); void handleGatewayNotification(const std::vector& frame); void handleRawWrite(size_t channel_index, const std::vector& payload); void handleGatewayWrite(const std::vector& payload); std::string resolvedDeviceName() const; int characteristicIndex(uint16_t attr_handle) const; GatewayController& controller_; GatewayRuntime& runtime_; DaliDomainService& dali_domain_; bool started_{false}; bool synced_{false}; bool enabled_{false}; uint8_t own_addr_type_{0}; uint16_t conn_handle_{kInvalidConnectionHandle}; std::string device_name_; std::array notify_enabled_{}; std::array, 3> characteristic_values_{}; std::vector last_notify_payload_; int64_t last_notify_at_us_{0}; }; } // namespace gateway