Files
gateway/components/gateway_bridge/include/gateway_bridge.hpp
T
Tony 8505958b65 Implement Matter Endpoint Plan Logic and Unit Tests
- Added `gateway_matter_plan.cpp` to define the logic for building Matter endpoint plans, including functions for inferring capabilities and managing allocations based on channel configurations.
- Introduced helper functions to determine the type of Matter endpoints and color methods based on device capabilities.
- Created `gateway_matter_plan_test.cpp` to validate the functionality of the endpoint plan logic with various test cases, ensuring correct behavior for different configurations and address handling.

Signed-off-by: Tony <tonylu@tony-cloud.com>
2026-08-08 08:36:42 +08:00

108 lines
4.0 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "dali_gateway.hpp"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gateway_knx.hpp"
#include "gateway_modbus.hpp"
namespace gateway {
class DaliDomainService;
class GatewayCache;
struct GatewayBridgeHttpResponse {
esp_err_t err{ESP_OK};
std::string body;
};
struct GatewayBridgeServiceConfig {
bool bridge_enabled{true};
bool modbus_enabled{true};
bool modbus_startup_enabled{false};
bool bacnet_enabled{false};
bool bacnet_startup_enabled{false};
bool knx_enabled{false};
bool knx_startup_enabled{false};
bool cloud_enabled{true};
bool cloud_startup_enabled{false};
uint32_t modbus_task_stack_size{6144};
UBaseType_t modbus_task_priority{4};
std::optional<GatewayModbusConfig> default_modbus_config;
bool allow_modbus_uart0{false};
bool allow_knx_uart0{false};
std::vector<int> reserved_uart_ports;
uint32_t bacnet_task_stack_size{8192};
UBaseType_t bacnet_task_priority{5};
bool bacnet_task_stack_in_psram{false};
uint32_t knx_task_stack_size{12288};
UBaseType_t knx_task_priority{5};
std::optional<GatewayKnxConfig> default_knx_config;
std::function<std::string()> gateway_device_name_provider;
std::function<GatewayBridgeHttpResponse()> gateway_settings_getter;
std::function<GatewayBridgeHttpResponse(std::string_view)> gateway_settings_setter;
std::function<std::string(std::string_view)> gateway_settings_cloud_handler;
std::function<GatewayBridgeHttpResponse(std::optional<uint8_t>)> matter_status_getter;
std::function<GatewayBridgeHttpResponse()> matter_onboarding_getter;
std::function<GatewayBridgeHttpResponse(std::string_view, std::optional<uint8_t>,
std::string_view)> matter_action_handler;
GatewayKnxGatewaySnapshotProvider knx_gateway_snapshot_provider;
GatewayKnxGatewayCommandTransactor knx_gateway_command_transactor;
};
class GatewayBridgeService {
public:
GatewayBridgeService(DaliDomainService& dali_domain,
GatewayCache& cache,
GatewayBridgeServiceConfig config = {});
~GatewayBridgeService();
esp_err_t start();
GatewayBridgeHttpResponse handleGet(const std::string& action, int gateway_id = -1,
const std::string& query = {});
GatewayBridgeHttpResponse handlePost(const std::string& action, int gateway_id,
const std::string& body);
std::string handleTransportRequest(uint8_t gateway_id, std::string_view request);
void handleGatewayNameChanged(uint8_t gateway_id);
private:
struct ChannelRuntime;
ChannelRuntime* findRuntime(uint8_t gateway_id);
const ChannelRuntime* findRuntime(uint8_t gateway_id) const;
ChannelRuntime* selectKnxEndpointRuntime();
bool isKnxEndpointRuntime(const ChannelRuntime* runtime) const;
esp_err_t startKnxEndpoint(ChannelRuntime* requested_runtime,
std::set<int>* used_uarts = nullptr);
esp_err_t stopKnxEndpoint(ChannelRuntime* requested_runtime);
DaliBridgeResult routeKnxGroupWrite(uint16_t group_address, const uint8_t* data,
size_t len);
DaliBridgeResult routeKnxGroupObjectWrite(uint16_t group_object_number,
const uint8_t* data, size_t len);
void handleDaliStatusUpdate(const DaliGatewayStatusUpdate& update);
void collectUsedRuntimeResources(uint8_t except_gateway_id,
std::set<uint16_t>* modbus_tcp_ports,
std::set<uint16_t>* knx_udp_ports,
std::set<int>* serial_uarts) const;
DaliDomainService& dali_domain_;
GatewayCache& cache_;
GatewayBridgeServiceConfig config_;
std::vector<std::unique_ptr<ChannelRuntime>> runtimes_;
ChannelRuntime* knx_endpoint_runtime_{nullptr};
};
} // namespace gateway