Files
gateway/components/gateway_ble/include/gateway_ble.hpp
T
Tony 4ce3513dd2 feat: Add DALI raw frame handling and USB setup bridge
- Introduced DaliRawFrame structure to encapsulate raw frame data.
- Enhanced DaliDomainService to manage raw frame sinks and processing.
- Implemented raw frame task for asynchronous handling of incoming DALI frames.
- Integrated raw frame handling in GatewayBleBridge and GatewayNetworkService.
- Added GatewayUsbSetupBridge to facilitate USB Serial/JTAG communication with DALI.
- Configured ESP-NOW for wireless communication and setup management.
- Updated GatewayRuntime to support clearing wireless credentials on boot button long press.
- Enhanced CMakeLists to include new components and dependencies.

Co-authored-by: Copilot <copilot@github.com>
2026-04-30 04:15:05 +08:00

63 lines
1.8 KiB
C++

#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
#include "esp_err.h"
struct ble_gap_event;
struct ble_gatt_access_ctxt;
namespace gateway {
class DaliDomainService;
struct DaliRawFrame;
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<uint8_t>& payload);
void handleGatewayNotification(const std::vector<uint8_t>& frame);
void handleDaliRawFrame(const DaliRawFrame& frame);
void handleRawWrite(size_t channel_index, const std::vector<uint8_t>& payload);
void handleGatewayWrite(const std::vector<uint8_t>& 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<bool, 3> notify_enabled_{};
std::array<std::vector<uint8_t>, 3> characteristic_values_{};
std::vector<uint8_t> last_notify_payload_;
int64_t last_notify_at_us_{0};
};
} // namespace gateway