WIP changes to ota update
This commit is contained in:
parent
6e4525df38
commit
b29512d922
@ -8,9 +8,74 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
static const char *TAG = "ALOX - COM";
|
static const char *TAG = "ALOX - COM";
|
||||||
|
|
||||||
|
static struct ESP_MessageBroker mr;
|
||||||
|
|
||||||
|
void ESP_InitMessageBroker() {
|
||||||
|
mr.num_direct_callbacks = 0;
|
||||||
|
mr.num_task_callbacks = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESP_RegisterFunction(CommandPages command,
|
||||||
|
ESP_RegisterFunctionCallback callback) {
|
||||||
|
mr.FunctionList[mr.num_direct_callbacks].MSGID = command;
|
||||||
|
mr.FunctionList[mr.num_direct_callbacks].callback = callback;
|
||||||
|
mr.num_direct_callbacks++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESP_RegisterTask(CommandPages command, ESP_RegisterTaskCallback callback) {
|
||||||
|
mr.TaskList[mr.num_task_callbacks].MSGID = command;
|
||||||
|
mr.TaskList[mr.num_task_callbacks].task = callback;
|
||||||
|
mr.num_task_callbacks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESP_MessageBrokerTask(void *param) {
|
||||||
|
ParsedMessage_t received_msg;
|
||||||
|
MessageBrokerTaskParams_t *task_params = (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.");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Message broker task started.");
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QueueHandle_t messageQueue = NULL; // Warteschlange für empfangene Nachrichten
|
QueueHandle_t messageQueue = NULL; // Warteschlange für empfangene Nachrichten
|
||||||
static bool hasMaster = false;
|
static bool hasMaster = false;
|
||||||
static ClientList *esp_client_list;
|
static ClientList *esp_client_list;
|
||||||
|
|||||||
@ -116,6 +116,33 @@ typedef struct __attribute__((packed)) {
|
|||||||
static_assert(sizeof(BaseMessage) <= 255,
|
static_assert(sizeof(BaseMessage) <= 255,
|
||||||
"BaseMessage darf nicht größer als 255 sein");
|
"BaseMessage darf nicht größer als 255 sein");
|
||||||
|
|
||||||
|
typedef void (*ESP_RegisterFunctionCallback)(
|
||||||
|
const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
||||||
|
typedef void (*ESP_RegisterTaskCallback)(
|
||||||
|
const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
||||||
|
|
||||||
|
struct ESP_RegisterdFunction {
|
||||||
|
CommandPages MSGID;
|
||||||
|
ESP_RegisterFunctionCallback callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ESP_RegisterdTask {
|
||||||
|
CommandPages MSGID;
|
||||||
|
ESP_RegisterTaskCallback task;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ESP_MessageBroker {
|
||||||
|
struct ESP_RegisterdFunction FunctionList[64];
|
||||||
|
uint8_t num_direct_callbacks;
|
||||||
|
struct ESP_RegisterdTask TaskList[64];
|
||||||
|
uint8_t num_task_callbacks;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ESP_InitMessageBroker();
|
||||||
|
void ESP_RegisterFunction(CommandPages command,
|
||||||
|
ESP_RegisterFunctionCallback callback);
|
||||||
|
void ESP_RegisterTask(CommandPages command, ESP_RegisterTaskCallback callback);
|
||||||
|
|
||||||
int init_com(ClientList *clients, uint8_t wifi_channel);
|
int init_com(ClientList *clients, uint8_t wifi_channel);
|
||||||
int getNextFreeClientId();
|
int getNextFreeClientId();
|
||||||
int add_peer(uint8_t *macAddr);
|
int add_peer(uint8_t *macAddr);
|
||||||
|
|||||||
@ -113,6 +113,7 @@ esp_err_t write_ota_update(uint32_t write_len, const uint8_t *payload) {
|
|||||||
|
|
||||||
memcpy(&update_buffer[update_buffer_write_index], payload, write_len);
|
memcpy(&update_buffer[update_buffer_write_index], payload, write_len);
|
||||||
update_buffer_write_index += write_len;
|
update_buffer_write_index += write_len;
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void payload_uart_update(uint8_t msgid, const uint8_t *payload,
|
void payload_uart_update(uint8_t msgid, const uint8_t *payload,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user