feat(gateway): enhance UART configuration validation for Modbus and KNX
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -655,10 +655,18 @@ esp_err_t GatewayKnxTpIpRouter::start(uint32_t task_stack_size, UBaseType_t task
|
||||
}
|
||||
stop_requested_ = false;
|
||||
last_error_.clear();
|
||||
if (!configureSocket()) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (!configureTpUart()) {
|
||||
closeSockets();
|
||||
return ESP_FAIL;
|
||||
}
|
||||
const BaseType_t created = xTaskCreate(&GatewayKnxTpIpRouter::TaskEntry, "gw_knx_ip",
|
||||
task_stack_size, this, task_priority, &task_handle_);
|
||||
if (created != pdPASS) {
|
||||
task_handle_ = nullptr;
|
||||
closeSockets();
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
started_ = true;
|
||||
@@ -668,6 +676,11 @@ esp_err_t GatewayKnxTpIpRouter::start(uint32_t task_stack_size, UBaseType_t task
|
||||
esp_err_t GatewayKnxTpIpRouter::stop() {
|
||||
stop_requested_ = true;
|
||||
closeSockets();
|
||||
const TaskHandle_t current_task = xTaskGetCurrentTaskHandle();
|
||||
for (int attempt = 0; task_handle_ != nullptr && task_handle_ != current_task && attempt < 50;
|
||||
++attempt) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -680,15 +693,6 @@ void GatewayKnxTpIpRouter::TaskEntry(void* arg) {
|
||||
}
|
||||
|
||||
void GatewayKnxTpIpRouter::taskLoop() {
|
||||
if (!configureSocket()) {
|
||||
finishTask();
|
||||
return;
|
||||
}
|
||||
if (!configureTpUart()) {
|
||||
finishTask();
|
||||
return;
|
||||
}
|
||||
|
||||
std::array<uint8_t, 768> buffer{};
|
||||
while (!stop_requested_) {
|
||||
sockaddr_in remote{};
|
||||
|
||||
Reference in New Issue
Block a user