feat(gateway_network): integrate GatewayBridgeService and add bridge handling

- Updated CMakeLists.txt to require gateway_bridge component.
- Modified GatewayNetworkService to include a pointer to GatewayBridgeService.
- Added new HTTP handlers for bridge GET and POST requests.
- Implemented query utility functions for handling request parameters.
- Enhanced response handling for bridge actions with JSON responses.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Tony
2026-05-01 03:54:02 +08:00
parent 2c1aa28d4f
commit d16c289626
19 changed files with 3186 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
idf_component_register(
SRCS "app_main.cpp"
REQUIRES gateway_core gateway_controller gateway_network dali_domain gateway_runtime gateway_ble gateway_usb_setup log
REQUIRES gateway_core gateway_controller gateway_network gateway_bridge dali_domain gateway_runtime gateway_ble gateway_usb_setup log
)
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
+73
View File
@@ -322,6 +322,79 @@ config GATEWAY_SMARTCONFIG_TIMEOUT_SEC
help
Timeout passed to ESP-IDF smartconfig before provisioning restarts internally.
config GATEWAY_BRIDGE_SUPPORTED
bool "dali_cpp bridge runtime is supported"
default y
help
Enables per-channel dali_cpp bridge model provisioning, execution, and protocol adapter state.
config GATEWAY_MODBUS_BRIDGE_SUPPORTED
bool "Modbus TCP bridge is supported"
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
default y
help
Enables the per-channel Modbus TCP adapter backed by DaliModbusBridge. Runtime startup still requires persisted bridge config with Modbus settings.
config GATEWAY_START_MODBUS_BRIDGE_ENABLED
bool "Start Modbus TCP bridge at startup"
depends on GATEWAY_MODBUS_BRIDGE_SUPPORTED
default n
help
Starts configured Modbus TCP listeners at boot. Disabled by default so ports are opened only after provisioning or explicit runtime start.
config GATEWAY_BACNET_BRIDGE_SUPPORTED
bool "BACnet/IP bridge is supported"
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
default n
help
Enables BACnet bridge configuration, binding discovery, and the bacnet-stack BACnet/IP server adapter.
Disable this option for smaller flash builds that do not need BACnet/IP.
config GATEWAY_START_BACNET_BRIDGE_ENABLED
bool "Start BACnet/IP bridge at startup"
depends on GATEWAY_BACNET_BRIDGE_SUPPORTED
default n
help
Starts configured BACnet/IP object bindings at boot. Disabled by default so the UDP BACnet/IP port is opened only after provisioning or explicit runtime start.
config GATEWAY_CLOUD_BRIDGE_SUPPORTED
bool "MQTT cloud bridge is supported"
depends on GATEWAY_BRIDGE_SUPPORTED && GATEWAY_WIFI_SUPPORTED
default y
help
Enables per-channel DaliCloudBridge provisioning and MQTT downlink execution.
config GATEWAY_START_CLOUD_BRIDGE_ENABLED
bool "Start MQTT cloud bridge at startup"
depends on GATEWAY_CLOUD_BRIDGE_SUPPORTED
default n
help
Starts configured MQTT cloud bridges at boot when broker URI and device id are present.
config GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE
int "Modbus bridge task stack bytes"
depends on GATEWAY_MODBUS_BRIDGE_SUPPORTED
range 4096 16384
default 6144
config GATEWAY_BRIDGE_MODBUS_TASK_PRIORITY
int "Modbus bridge task priority"
depends on GATEWAY_MODBUS_BRIDGE_SUPPORTED
range 1 10
default 4
config GATEWAY_BRIDGE_BACNET_TASK_STACK_SIZE
int "BACnet/IP bridge task stack bytes"
depends on GATEWAY_BACNET_BRIDGE_SUPPORTED
range 6144 24576
default 8192
config GATEWAY_BRIDGE_BACNET_TASK_PRIORITY
int "BACnet/IP bridge task priority"
depends on GATEWAY_BACNET_BRIDGE_SUPPORTED
range 1 10
default 5
choice GATEWAY_USB_STARTUP_MODE
prompt "USB Serial/JTAG startup mode"
default GATEWAY_USB_STARTUP_DEBUG_JTAG
+89 -1
View File
@@ -1,5 +1,6 @@
#include "dali_domain.hpp"
#include "gateway_ble.hpp"
#include "gateway_bridge.hpp"
#include "gateway_controller.hpp"
#include "gateway_core.hpp"
#include "gateway_network.hpp"
@@ -57,6 +58,22 @@
#define CONFIG_GATEWAY_SMARTCONFIG_TIMEOUT_SEC 60
#endif
#ifndef CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE
#define CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE 6144
#endif
#ifndef CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_PRIORITY
#define CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_PRIORITY 4
#endif
#ifndef CONFIG_GATEWAY_BRIDGE_BACNET_TASK_STACK_SIZE
#define CONFIG_GATEWAY_BRIDGE_BACNET_TASK_STACK_SIZE 8192
#endif
#ifndef CONFIG_GATEWAY_BRIDGE_BACNET_TASK_PRIORITY
#define CONFIG_GATEWAY_BRIDGE_BACNET_TASK_PRIORITY 5
#endif
namespace {
constexpr const char* kProjectName = "DALI_485_Gateway";
constexpr const char* kProjectVersion = "0.1.0";
@@ -116,9 +133,52 @@ constexpr bool kUsbSetupStartupEnabled = true;
constexpr bool kUsbSetupStartupEnabled = false;
#endif
#ifdef CONFIG_GATEWAY_BRIDGE_SUPPORTED
constexpr bool kBridgeSupported = true;
#else
constexpr bool kBridgeSupported = false;
#endif
#ifdef CONFIG_GATEWAY_MODBUS_BRIDGE_SUPPORTED
constexpr bool kModbusBridgeSupported = true;
#else
constexpr bool kModbusBridgeSupported = false;
#endif
#ifdef CONFIG_GATEWAY_START_MODBUS_BRIDGE_ENABLED
constexpr bool kModbusBridgeStartupEnabled = true;
#else
constexpr bool kModbusBridgeStartupEnabled = false;
#endif
#ifdef CONFIG_GATEWAY_BACNET_BRIDGE_SUPPORTED
constexpr bool kBacnetBridgeSupported = true;
#else
constexpr bool kBacnetBridgeSupported = false;
#endif
#ifdef CONFIG_GATEWAY_START_BACNET_BRIDGE_ENABLED
constexpr bool kBacnetBridgeStartupEnabled = true;
#else
constexpr bool kBacnetBridgeStartupEnabled = false;
#endif
#ifdef CONFIG_GATEWAY_CLOUD_BRIDGE_SUPPORTED
constexpr bool kCloudBridgeSupported = true;
#else
constexpr bool kCloudBridgeSupported = false;
#endif
#ifdef CONFIG_GATEWAY_START_CLOUD_BRIDGE_ENABLED
constexpr bool kCloudBridgeStartupEnabled = true;
#else
constexpr bool kCloudBridgeStartupEnabled = false;
#endif
std::unique_ptr<gateway::DaliDomainService> s_dali_domain;
std::unique_ptr<gateway::GatewayRuntime> s_runtime;
std::unique_ptr<gateway::GatewayController> s_controller;
std::unique_ptr<gateway::GatewayBridgeService> s_bridge;
std::unique_ptr<gateway::GatewayNetworkService> s_network;
std::unique_ptr<gateway::GatewayBleBridge> s_ble_bridge;
std::unique_ptr<gateway::GatewayUsbSetupBridge> s_usb_setup_bridge;
@@ -361,6 +421,29 @@ extern "C" void app_main(void) {
controller_config);
ESP_ERROR_CHECK(s_controller->start());
if (kBridgeSupported) {
gateway::GatewayBridgeServiceConfig bridge_config;
bridge_config.bridge_enabled = true;
bridge_config.modbus_enabled = profile.enable_wifi && kModbusBridgeSupported;
bridge_config.modbus_startup_enabled = profile.enable_wifi && kModbusBridgeSupported &&
kModbusBridgeStartupEnabled;
bridge_config.bacnet_enabled = profile.enable_wifi && kBacnetBridgeSupported;
bridge_config.bacnet_startup_enabled = profile.enable_wifi && kBacnetBridgeSupported &&
kBacnetBridgeStartupEnabled;
bridge_config.cloud_enabled = profile.enable_wifi && kCloudBridgeSupported;
bridge_config.cloud_startup_enabled = profile.enable_wifi && kCloudBridgeSupported &&
kCloudBridgeStartupEnabled;
bridge_config.modbus_task_stack_size =
static_cast<uint32_t>(CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE);
bridge_config.modbus_task_priority =
static_cast<UBaseType_t>(CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_PRIORITY);
bridge_config.bacnet_task_stack_size =
static_cast<uint32_t>(CONFIG_GATEWAY_BRIDGE_BACNET_TASK_STACK_SIZE);
bridge_config.bacnet_task_priority =
static_cast<UBaseType_t>(CONFIG_GATEWAY_BRIDGE_BACNET_TASK_PRIORITY);
s_bridge = std::make_unique<gateway::GatewayBridgeService>(*s_dali_domain, bridge_config);
}
if (profile.enable_wifi || profile.enable_eth) {
gateway::GatewayNetworkServiceConfig network_config;
network_config.wifi_enabled = profile.enable_wifi && kWifiStartupEnabled;
@@ -397,10 +480,15 @@ extern "C" void app_main(void) {
network_config.boot_button_active_low = false;
#endif
s_network = std::make_unique<gateway::GatewayNetworkService>(*s_controller, *s_runtime,
*s_dali_domain, network_config);
*s_dali_domain, network_config,
s_bridge.get());
ESP_ERROR_CHECK(s_network->start());
}
if (s_bridge != nullptr) {
ESP_ERROR_CHECK(s_bridge->start());
}
if (profile.enable_ble) {
s_ble_bridge = std::make_unique<gateway::GatewayBleBridge>(*s_controller, *s_runtime,
*s_dali_domain);
+4 -4
View File
@@ -2,7 +2,7 @@
nvs, data, nvs, 0x9000, 0x6000,
otadata, data, ota, 0xf000, 0x2000,
phy_init, data, phy, 0x11000, 0x1000,
factory, app, factory, 0x20000, 0x180000,
ota_0, app, ota_0, 0x1a0000, 0x180000,
ota_1, app, ota_1, 0x320000, 0x180000,
storage, data, spiffs, 0x4a0000, 0xb60000,
factory, app, factory, 0x20000, 0x400000,
ota_0, app, ota_0, 0x420000, 0x400000,
ota_1, app, ota_1, 0x820000, 0x400000,
storage, data, spiffs, 0xc20000, 0x3e0000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x6000
3 otadata data ota 0xf000 0x2000
4 phy_init data phy 0x11000 0x1000
5 factory app factory 0x20000 0x180000 0x400000
6 ota_0 app ota_0 0x1a0000 0x420000 0x180000 0x400000
7 ota_1 app ota_1 0x320000 0x820000 0x180000 0x400000
8 storage data spiffs 0x4a0000 0xc20000 0xb60000 0x3e0000
+11
View File
@@ -632,6 +632,17 @@ CONFIG_GATEWAY_SMARTCONFIG_SUPPORTED=y
# CONFIG_GATEWAY_START_ESPNOW_SETUP_ENABLED is not set
# CONFIG_GATEWAY_START_SMARTCONFIG_ENABLED is not set
CONFIG_GATEWAY_SMARTCONFIG_TIMEOUT_SEC=60
CONFIG_GATEWAY_BRIDGE_SUPPORTED=y
CONFIG_GATEWAY_MODBUS_BRIDGE_SUPPORTED=y
# CONFIG_GATEWAY_START_MODBUS_BRIDGE_ENABLED is not set
CONFIG_GATEWAY_BACNET_BRIDGE_SUPPORTED=y
# CONFIG_GATEWAY_START_BACNET_BRIDGE_ENABLED is not set
CONFIG_GATEWAY_CLOUD_BRIDGE_SUPPORTED=y
# CONFIG_GATEWAY_START_CLOUD_BRIDGE_ENABLED is not set
CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_STACK_SIZE=6144
CONFIG_GATEWAY_BRIDGE_MODBUS_TASK_PRIORITY=4
CONFIG_GATEWAY_BRIDGE_BACNET_TASK_STACK_SIZE=8192
CONFIG_GATEWAY_BRIDGE_BACNET_TASK_PRIORITY=5
CONFIG_GATEWAY_USB_STARTUP_DEBUG_JTAG=y
# CONFIG_GATEWAY_USB_STARTUP_SETUP_SERIAL is not set
# end of Gateway Startup Services