feat(gateway): enhance UART configuration validation for Modbus and KNX

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-05-11 03:44:14 +08:00
parent bf23cf0b79
commit e94945fc0f
4 changed files with 286 additions and 36 deletions
+10 -7
View File
@@ -504,6 +504,10 @@ bool ValidateChannelBindings() {
ESP_LOGE(kTag, "Modbus serial is configured on UART0, but UART0 is reserved for console");
return false;
}
if (modbus_uart == 0 && kConsoleOnUart0) {
ESP_LOGE(kTag, "Modbus serial UART0 requires moving the ESP-IDF console off UART0");
return false;
}
for (int i = 0; i < CONFIG_GATEWAY_CHANNEL_COUNT; ++i) {
if (channels[i].enabled && channels[i].serial_phy && channels[i].uart_port == modbus_uart) {
ESP_LOGE(kTag, "Modbus serial UART%d conflicts with DALI channel %d serial PHY",
@@ -519,6 +523,10 @@ bool ValidateChannelBindings() {
ESP_LOGE(kTag, "KNX TP UART0 conflicts with the UART0 control bridge");
return false;
}
if (knx_uart == 0 && kConsoleOnUart0) {
ESP_LOGE(kTag, "KNX TP-UART on UART0 requires moving the ESP-IDF console off UART0");
return false;
}
if (kModbusBridgeSupported && kModbusDefaultSerialTransport &&
knx_uart == CONFIG_GATEWAY_MODBUS_SERIAL_UART_PORT) {
ESP_LOGE(kTag, "KNX TP UART%d conflicts with default Modbus serial UART", knx_uart);
@@ -720,10 +728,8 @@ extern "C" void app_main(void) {
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.allow_modbus_uart0 = kModbusAllowUart0 && !k485ControlEnabled;
if (!bridge_config.allow_modbus_uart0) {
bridge_config.reserved_uart_ports.push_back(0);
}
bridge_config.allow_modbus_uart0 = kModbusAllowUart0 && !kConsoleOnUart0 && !k485ControlEnabled;
bridge_config.allow_knx_uart0 = !kConsoleOnUart0 && !k485ControlEnabled;
#if CONFIG_GATEWAY_CHANNEL1_PHY_UART1
bridge_config.reserved_uart_ports.push_back(1);
#elif CONFIG_GATEWAY_CHANNEL1_PHY_UART2
@@ -736,9 +742,6 @@ extern "C" void app_main(void) {
bridge_config.reserved_uart_ports.push_back(2);
#endif
#endif
if (kKnxBridgeSupported) {
bridge_config.reserved_uart_ports.push_back(CONFIG_GATEWAY_KNX_TP_UART_PORT);
}
if (kModbusBridgeSupported) {
gateway::GatewayModbusConfig default_modbus;
#if defined(CONFIG_GATEWAY_MODBUS_DEFAULT_TRANSPORT_RTU)