Improved Go Tool so that the OTA Update Works again

This commit is contained in:
2026-02-08 17:00:41 +01:00
parent c656d4afd7
commit 0bcacb4a53
10 changed files with 362 additions and 35 deletions
+2 -1
View File
@@ -373,8 +373,9 @@ void app_main(void) {
RegisterCallback(UART_CLIENT_INFO, clientInfoCallback);
RegisterCallback(UART_CLIENT_INPUT, fakeDataCallback);
RegisterCallback(UART_OTA_START_ESPNOW, start_ota_update_espnow);
RegisterUART_OTAFunctions();
init_i2c_with_all_devices();
// init_i2c_with_all_devices();
} else {
ESP_LOGI(TAG, "Started in Slavemode");
+5 -2
View File
@@ -13,6 +13,7 @@ void InitMessageBroker() {
}
void RegisterCallback(uint8_t msgid, RegisterFunctionCallback callback) {
ESP_LOGI(TAG, "Registerd Uart Callback for % X", msgid);
mr.FunctionList[mr.num_direct_callbacks].MSGID = msgid;
mr.FunctionList[mr.num_direct_callbacks].callback = callback;
mr.num_direct_callbacks++;
@@ -46,11 +47,13 @@ void 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);
// 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++) {
//ESP_LOGI(TAG, "Searching CALLBACK for %d", received_msg.msgid);
if (mr.FunctionList[i].MSGID == received_msg.msgid) {
//ESP_LOGI(TAG, "FOUND CALLBACK");
mr.FunctionList[i].callback(
received_msg.msgid, received_msg.data, received_msg.payload_len,
send_payload_buffer, send_payload_buffer_size,
+34 -16
View File
@@ -353,14 +353,16 @@ void start_uart_update(uint8_t msgid, const uint8_t *payload,
int part = prepare_ota_update();
// TODO: what does this do? maybe comment it out for now?
uart_ota_start_t *start = (uart_ota_start_t *)send_payload_buffer;
start->partition = part & 0xff;
// TODO: Refine Errors
// Set error
if (part < 0) {
send_payload_buffer[1] = (part * -1) & 0xff;
} else {
send_payload_buffer[0] = part & 0xff;
start->error = 0x01;
}
int send_payload_len = 2;
int send_payload_len = sizeof(uart_ota_start_t);
int len = build_message(UART_OTA_START, send_payload_buffer, send_payload_len,
send_buffer, send_buffer_size);
if (len < 0) {
@@ -375,9 +377,9 @@ void start_uart_update(uint8_t msgid, const uint8_t *payload,
}
esp_err_t write_ota_update(uint32_t write_len, const uint8_t *payload) {
ESP_LOGI(TAG, "write_ota_update: write_len: %d", write_len);
ESP_LOGI(TAG, "write_ota_update: update_buffer_write_index: %d",
update_buffer_write_index);
// ESP_LOGI(TAG, "write_ota_update: write_len: %d", write_len);
// ESP_LOGI(TAG, "write_ota_update: update_buffer_write_index: %d",
// update_buffer_write_index);
if (update_buffer_write_index + write_len > UPDATE_BUFFER_SIZE) {
ESP_LOGI(TAG, "write_ota_update: schreib das update weg!");
esp_err_t err =
@@ -412,15 +414,17 @@ void payload_uart_update(uint8_t msgid, const uint8_t *payload_data_from_uart,
esp_err_t err = write_ota_update(write_len, actual_firmware_data);
uart_ota_ack_t *ack = (uart_ota_ack_t *)send_payload_buffer;
ack->sequence_counter = sequenz_counter;
ack->write_index = update_buffer_write_index;
ack->error = (err == ESP_OK) ? 0x00 : 0x01;
size_t send_payload_len = sizeof(uart_ota_ack_t);
if (err != ESP_OK) {
ESP_LOGE(TAG, "GOT ESP ERROR WRITE OTA %d", err);
}
size_t send_payload_len = 4;
memcpy(send_payload_buffer, &sequenz_counter, 2);
memcpy(&send_payload_buffer[2], &update_buffer_write_index, 2);
send_payload_buffer[4] = 0x00; // error
int len = build_message(UART_OTA_PAYLOAD, send_payload_buffer,
send_payload_len, send_buffer, send_buffer_size);
if (len < 0) {
@@ -442,8 +446,10 @@ void end_uart_update(uint8_t msgid, const uint8_t *payload, size_t payload_len,
esp_err_t err = end_ota_update();
int send_payload_len = 1;
send_payload_buffer[0] = err & 0xff;
uart_ota_end_t *end = (uart_ota_end_t *)send_payload_buffer;
end->error = err & 0xff;
int send_payload_len = sizeof(uart_ota_end_t);
int len = build_message(UART_OTA_END, send_payload_buffer, send_payload_len,
send_buffer, send_buffer_size);
if (len < 0) {
@@ -461,7 +467,9 @@ void end_uart_update(uint8_t msgid, const uint8_t *payload, size_t payload_len,
void init_ota() {
ota_task_queue = xQueueCreate(50, sizeof(ota_task_queue_message_t));
}
void RegisterUART_OTAFunctions() {
RegisterCallback(UART_OTA_START, start_uart_update);
RegisterCallback(UART_OTA_PAYLOAD, payload_uart_update);
RegisterCallback(UART_OTA_END, end_uart_update);
@@ -485,7 +493,17 @@ int prepare_ota_update() {
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
return -2;
}
return 0;
if (update_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) {
return 0;
}
if (update_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_1) {
return 1;
}
// TODO: Unknow partition
return 2;
}
esp_err_t end_ota_update() {
+16
View File
@@ -33,7 +33,23 @@ typedef struct {
ClientList *client_list;
} MasterOTA_TaskParams_t;
typedef struct __attribute__((packed)) {
uint16_t sequence_counter;
uint16_t write_index;
uint8_t error;
} uart_ota_ack_t;
typedef struct __attribute__((packed)) {
uint8_t partition;
uint8_t error;
} uart_ota_start_t;
typedef struct __attribute__((packed)) {
uint8_t error;
} uart_ota_end_t;
void init_ota();
void RegisterUART_OTAFunctions();
void MasterOTATask(void *pvParameter);
void slave_ota_task(void *pvParameter);
+2 -1
View File
@@ -18,7 +18,8 @@ static const char *TAG = "ALOX - UART";
static QueueHandle_t parsed_message_queue;
void init_uart(QueueHandle_t msg_queue_handle) {
uart_config_t uart_config = {.baud_rate = 921600, // 921600, 115200
uart_config_t uart_config = {// .baud_rate = 115200, // 921600, 115200
.baud_rate = 921600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,