From 8398442544cfb9574e18887d504a1cca3fa50c43 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 18 Aug 2025 20:27:30 +0200 Subject: [PATCH] Reworked ESPNOW MessageBrokerTask --- main/communication_handler.c | 31 +++++++++++++------------------ main/communication_handler.h | 10 ++++++++++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/main/communication_handler.c b/main/communication_handler.c index d434e5a..c72166b 100644 --- a/main/communication_handler.c +++ b/main/communication_handler.c @@ -35,15 +35,12 @@ void ESP_RegisterTask(CommandPages command, ESP_RegisterTaskCallback callback) { } void ESP_MessageBrokerTask(void *param) { - ParsedMessage_t received_msg; - MessageBrokerTaskParams_t *task_params = (MessageBrokerTaskParams_t *)param; + ESPNOW_MessageInfo received_msg; + ESP_MessageBrokerTaskParams_t *task_params = + (ESP_MessageBrokerTaskParams_t *)param; // Extrahiere die einzelnen Parameter QueueHandle_t msg_queue = task_params->message_queue; - uint8_t *send_message_buffer = task_params->send_buffer; - size_t send_message_buffer_size = task_params->send_buffer_size; - uint8_t *send_payload_buffer = task_params->payload_buffer; - size_t send_payload_buffer_size = task_params->payload_buffer_size; if (msg_queue == NULL) { ESP_LOGE(TAG, "Message queue not initialized. Terminating task."); @@ -54,23 +51,21 @@ void ESP_MessageBrokerTask(void *param) { while (1) { if (xQueueReceive(msg_queue, &received_msg, portMAX_DELAY)) { - //ESP_LOGI(TAG, "Received message from queue: MSGID=0x%02X, Length=%u", - // received_msg.msgid, received_msg.payload_len); + + const BaseMessage *message = (const BaseMessage *)received_msg.data; for (int i = 0; i < mr.num_direct_callbacks; i++) { - if (mr.FunctionList[i].MSGID == received_msg) { - mr.FunctionList[i].callback( - received_msg.msgid, received_msg.data, received_msg.payload_len, - send_payload_buffer, send_payload_buffer_size, - send_message_buffer, send_message_buffer_size); + if (mr.FunctionList[i].MSGID == message->commandPage) { + mr.FunctionList[i].callback(received_msg.esp_now_info, + received_msg.data, received_msg.data_len); } } for (int i = 0; i < mr.num_direct_callbacks; i++) { - if (mr.FunctionList[i].MSGID == received_msg.msgid) { - // TODO: Not yet implemented - // Only send data to task, task should be created beforhead and wait - // for new data in the queue. - } + // if (mr.FunctionList[i].MSGID == received_msg.msgid) { + // TODO: Not yet implemented + // Only send data to task, task should be created beforhead and wait + // for new data in the queue. + //} } } } diff --git a/main/communication_handler.h b/main/communication_handler.h index 1b68c48..644eec4 100644 --- a/main/communication_handler.h +++ b/main/communication_handler.h @@ -138,6 +138,16 @@ struct ESP_MessageBroker { uint8_t num_task_callbacks; }; +typedef struct { + QueueHandle_t message_queue; +} ESP_MessageBrokerTaskParams_t; + +typedef struct { + const esp_now_recv_info_t *esp_now_info; + const uint8_t *data; + int data_len; +} ESPNOW_MessageInfo; + void ESP_InitMessageBroker(); void ESP_RegisterFunction(CommandPages command, ESP_RegisterFunctionCallback callback);