Added UART MSG IDs and Prep work for OTA
This commit is contained in:
parent
a9779cbade
commit
441347fc95
6
Makefile
6
Makefile
@ -20,6 +20,12 @@ buildIdf:
|
||||
flashMini:
|
||||
idf.py flash -p /dev/ttyACM0
|
||||
|
||||
flashMini2:
|
||||
idf.py flash -p /dev/ttyACM1
|
||||
|
||||
flashMini3:
|
||||
idf.py flash -p /dev/ttyACM2
|
||||
|
||||
monitorMini:
|
||||
idf.py monitor -p /dev/ttyACM0
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
idf_component_register(SRCS "main.c" "uart_handler.c" "communication_handler.c" "client_handler.c" "message_parser.c" "message_builder.c" "message_handler.c"
|
||||
idf_component_register(SRCS "main.c" "uart_handler.c" "communication_handler.c" "client_handler.c" "message_parser.c" "message_builder.c" "message_handler.c" "ota_update.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
# Get the short Git commit hash of the current HEAD.
|
||||
|
||||
31
main/main.c
31
main/main.c
@ -27,11 +27,12 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "message_builder.h"
|
||||
#include "uart_msg_ids.h"
|
||||
|
||||
static const char *TAG = "ALOX - MAIN";
|
||||
static const uint16_t version = 0x0001;
|
||||
static uint8_t send_message_buffer[1024];
|
||||
static uint8_t send_message_payload_buffer[512 - 4];
|
||||
static uint8_t send_message_payload_buffer[512];
|
||||
|
||||
static MessageBrokerTaskParams_t broker_task_params;
|
||||
|
||||
@ -41,8 +42,8 @@ void echoCallback(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
uint8_t *send_payload_buffer, size_t send_payload_buffer_size,
|
||||
uint8_t *send_buffer, size_t send_buffer_size) {
|
||||
ESP_LOGI(TAG, "Echo command 0x01...");
|
||||
int len =
|
||||
build_message(0x01, payload, payload_len, send_buffer, send_buffer_size);
|
||||
int len = build_message(UART_ECHO, payload, payload_len, send_buffer,
|
||||
send_buffer_size);
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG,
|
||||
"Error Building UART Message: payload_len, %d, sendbuffer_size: "
|
||||
@ -72,7 +73,9 @@ void versionCallback(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
send_payload_buffer[1] = (uint8_t)((version >> 8) & 0xFF);
|
||||
memcpy(&send_payload_buffer[2], &BUILD_GIT_HASH, git_build_hash_len);
|
||||
|
||||
int len = build_message(0x02, send_payload_buffer, needed_buffer_size,
|
||||
// currently running partition
|
||||
|
||||
int len = build_message(UART_VERSION, send_payload_buffer, needed_buffer_size,
|
||||
send_buffer, send_buffer_size);
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG,
|
||||
@ -81,7 +84,7 @@ void versionCallback(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
payload_len, send_buffer_size, len);
|
||||
return;
|
||||
}
|
||||
uart_write_bytes(MASTER_UART, send_buffer, len);
|
||||
uart_write_bytes(MASTER_UART, send_buffer, len - 1);
|
||||
}
|
||||
|
||||
void clientInfoCallback(uint8_t msgid, const uint8_t *payload,
|
||||
@ -131,13 +134,16 @@ void clientInfoCallback(uint8_t msgid, const uint8_t *payload,
|
||||
4);
|
||||
memcpy(&send_payload_buffer[offset + 13],
|
||||
&clientList.Clients[i].lastSuccessfullPing, 4);
|
||||
memcpy(&send_payload_buffer[offset + 17],
|
||||
memcpy(&send_payload_buffer[offset + 17],
|
||||
&clientList.Clients[i].clientVersion, 2);
|
||||
}
|
||||
}
|
||||
|
||||
int len = build_message(0x04, send_payload_buffer, needed_buffer_size,
|
||||
send_buffer, send_buffer_size);
|
||||
int len = build_message(UART_CLIENT_INFO, send_payload_buffer,
|
||||
needed_buffer_size, send_buffer, send_buffer_size);
|
||||
|
||||
ESP_LOG_BUFFER_HEX("SEND BUFFER: ", send_buffer, send_buffer_size);
|
||||
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG,
|
||||
"Error Building UART Message: payload_len, %d, sendbuffer_size: "
|
||||
@ -173,8 +179,7 @@ void app_main(void) {
|
||||
wifi_config_t wifi_config = {
|
||||
.sta =
|
||||
{
|
||||
.channel = 1, // Kanal 1, stelle sicher, dass alle Geräte
|
||||
// denselben Kanal verwenden
|
||||
.channel = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
@ -188,7 +193,7 @@ void app_main(void) {
|
||||
ESP_ERROR_CHECK(esp_now_register_recv_cb(client_receive_callback));
|
||||
}
|
||||
|
||||
init_com(&clientList, 1);
|
||||
ret = init_com(&clientList, 1);
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "Could not Init ESP NOW Communication!");
|
||||
}
|
||||
@ -289,7 +294,7 @@ void app_main(void) {
|
||||
// NULL);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Started in Slavemode");
|
||||
xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
||||
NULL);
|
||||
// xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
||||
// NULL);
|
||||
}
|
||||
}
|
||||
|
||||
50
main/ota_update.c
Normal file
50
main/ota_update.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include "ota_update.h"
|
||||
#include "esp_log.h"
|
||||
#include "message_handler.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
static uint8_t updateBuffer[4000];
|
||||
static const char *TAG = "ALOX - OTA";
|
||||
|
||||
void start_uart_update(uint8_t msgid, const uint8_t *payload,
|
||||
size_t payload_len, uint8_t *send_payload_buffer,
|
||||
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
||||
size_t send_buffer_size) {
|
||||
ESP_LOGI(TAG, "OTA Update Uart Command");
|
||||
|
||||
// prepare for writing new partition with ota api
|
||||
// will get 200 bytes each uart message
|
||||
// fill update buffer
|
||||
// write update buffer complete
|
||||
|
||||
/*int len = build_message(0x02, send_payload_buffer, needed_buffer_size,
|
||||
send_buffer, send_buffer_size);
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG,
|
||||
"Error Building UART Message: payload_len, %d, sendbuffer_size: "
|
||||
"%d, mes_len(error): %d",
|
||||
payload_len, send_buffer_size, len);
|
||||
return;
|
||||
}
|
||||
uart_write_bytes(MASTER_UART, send_buffer, len - 1);*/
|
||||
}
|
||||
|
||||
void payload_uart_update(uint8_t msgid, const uint8_t *payload,
|
||||
size_t payload_len, uint8_t *send_payload_buffer,
|
||||
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
||||
size_t send_buffer_size) {
|
||||
ESP_LOGI(TAG, "OTA Update Uart Command");
|
||||
}
|
||||
|
||||
void end_uart_update(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
uint8_t *send_payload_buffer,
|
||||
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
||||
size_t send_buffer_size) {
|
||||
ESP_LOGI(TAG, "OTA Update Uart Command");
|
||||
}
|
||||
|
||||
void init_ota() {
|
||||
RegisterCallback(uint8_t msgid, RegisterFunctionCallback callback);
|
||||
}
|
||||
4
main/ota_update.h
Normal file
4
main/ota_update.h
Normal file
@ -0,0 +1,4 @@
|
||||
#ifndef OTA_UPDATE_H
|
||||
#define OTA_UPDATE_H
|
||||
|
||||
#endif
|
||||
17
main/uart_msg_ids.h
Normal file
17
main/uart_msg_ids.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef UART_MSG_IDS_H
|
||||
#define UART_MSG_IDS_H
|
||||
|
||||
enum UART_MSG_IDS {
|
||||
// MISC
|
||||
UART_ECHO = 0x01,
|
||||
UART_VERSION = 0x02,
|
||||
UART_CLIENT_INFO = 0x03,
|
||||
|
||||
// OTA
|
||||
UART_OTA_START = 0x10,
|
||||
UART_OTA_PAYLOAD = 0x11,
|
||||
UART_OTA_END = 0x12,
|
||||
UART_OTA_STATUS = 0x13,
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user