feat(gateway): implement GatewayController and enhance GatewayRuntime
- Added GatewayController class to manage gateway operations, including command handling, scene and group management, and BLE state management. - Introduced methods for scene and group storage, including loading, saving, and deleting scenes/groups. - Enhanced GatewayRuntime with BLE management capabilities, including methods to check and set BLE state, and to generate BLE gateway names. - Implemented utility functions for string normalization and CSV parsing. - Added notification sinks for various events in the GatewayController. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#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;
|
||||
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 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
|
||||
Reference in New Issue
Block a user