Added new Payload Structs for Preperation of OTA Update
This commit is contained in:
parent
0934105952
commit
a8c7c42471
@ -12,12 +12,13 @@
|
||||
static const char *TAG = "ALOX - COM";
|
||||
|
||||
QueueHandle_t messageQueue = NULL; // Warteschlange für empfangene Nachrichten
|
||||
bool hasMaster = false;
|
||||
static bool hasMaster = false;
|
||||
static ClientList *esp_client_list;
|
||||
static uint8_t channelNumber = 0;
|
||||
|
||||
#define MAC_STRING_BUFFER_SIZE 18
|
||||
|
||||
void init_com(ClientList *clients) {
|
||||
void init_com(ClientList *clients, uint8_t wifi_channel) {
|
||||
// Initialisiere die Kommunikations-Warteschlange
|
||||
messageQueue = xQueueCreate(MESSAGE_QUEUE_SIZE, sizeof(BaseMessage));
|
||||
if (messageQueue == NULL) {
|
||||
@ -26,12 +27,12 @@ void init_com(ClientList *clients) {
|
||||
|
||||
esp_client_list = clients;
|
||||
hasMaster = false;
|
||||
channelNumber = wifi_channel;
|
||||
}
|
||||
|
||||
void add_peer(uint8_t *macAddr) {
|
||||
esp_now_peer_info_t peerInfo = {
|
||||
.channel =
|
||||
0, // Standardkanal, sollte uit den anderen Geräten übereinstimmen
|
||||
.channel = channelNumber,
|
||||
.ifidx = ESP_IF_WIFI_STA,
|
||||
.encrypt = false, // Keine Verschlüsselung (kann geändert werden)
|
||||
};
|
||||
@ -94,7 +95,6 @@ void master_broadcast_task(void *param) {
|
||||
|
||||
void master_broadcast_ping(void *param) {
|
||||
while (1) {
|
||||
// BroadCastPayload payload = {};
|
||||
PingPayload payload = {};
|
||||
payload.timestamp = esp_timer_get_time();
|
||||
BaseMessage message =
|
||||
@ -189,6 +189,7 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void client_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
const uint8_t *data, int data_len) {
|
||||
ESP_LOGI(TAG, "SLAVE GOT MESSAGE");
|
||||
@ -239,17 +240,14 @@ void client_data_sending_task(void *param) {
|
||||
while (1) {
|
||||
const char *dataToSend = "DATA:42";
|
||||
ESP_LOGI(TAG, "SEND DATA");
|
||||
esp_now_send(NULL, (uint8_t *)dataToSend,
|
||||
strlen(dataToSend));
|
||||
esp_now_send(NULL, (uint8_t *)dataToSend, strlen(dataToSend));
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
}
|
||||
}
|
||||
|
||||
void client_monitor_task(void *pvParameters) {
|
||||
TickType_t timeout_ticks =
|
||||
pdMS_TO_TICKS(CLIENT_TIMEOUT_MS);
|
||||
TickType_t interval_ticks =
|
||||
pdMS_TO_TICKS(CHECK_INTERVAL_MS);
|
||||
TickType_t timeout_ticks = pdMS_TO_TICKS(CLIENT_TIMEOUT_MS);
|
||||
TickType_t interval_ticks = pdMS_TO_TICKS(CHECK_INTERVAL_MS);
|
||||
|
||||
while (1) {
|
||||
TickType_t now = xTaskGetTickCount();
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define BROADCAST_INTERVAL_MS 500
|
||||
|
||||
@ -27,37 +28,63 @@ static uint8_t broadcast_address[ESP_NOW_ETH_ALEN] = {0xFF, 0xFF, 0xFF,
|
||||
#define MESSAGE_QUEUE_SIZE 10
|
||||
|
||||
typedef enum {
|
||||
BroadCastPage,
|
||||
StatusPage,
|
||||
ConfigPage,
|
||||
PingPage,
|
||||
BroadCastPage,
|
||||
RegisterPage,
|
||||
FirmwarePrepPage,
|
||||
FirmwarePayloadPage,
|
||||
} CommandPages;
|
||||
|
||||
typedef struct {
|
||||
uint32_t uptime;
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t version; // software version
|
||||
uint8_t runningPartition;
|
||||
uint8_t status;
|
||||
uint32_t uptime;
|
||||
} StatusPayload;
|
||||
|
||||
typedef struct {
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t timeslot;
|
||||
} ConfigPayload;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t timestamp;
|
||||
} PingPayload;
|
||||
|
||||
typedef struct {
|
||||
typedef struct __attribute__((packed)) {
|
||||
} BroadCastPayload;
|
||||
|
||||
typedef struct {
|
||||
typedef struct __attribute__((packed)) {
|
||||
bool familierClient;
|
||||
} RegisterPayload;
|
||||
|
||||
typedef union {
|
||||
// TODO: Check checksum fields
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t length; // length of complete firmware
|
||||
uint8_t checksum; // checksum of firmware
|
||||
} FirmwarePrepPayload;
|
||||
|
||||
// TODO: Check checksum fields
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t length;
|
||||
uint8_t checksum;
|
||||
uint32_t address;
|
||||
uint8_t payload[240]; // TODO: need a way to figure out a safe value for this
|
||||
} FirmwarePayload;
|
||||
|
||||
typedef union __attribute__((packed)) {
|
||||
StatusPayload status_payload;
|
||||
ConfigPayload config_payload;
|
||||
PingPayload ping_payload;
|
||||
BroadCastPayload broadcast_payload;
|
||||
RegisterPayload register_payload;
|
||||
FirmwarePrepPayload firmware_prep_payload;
|
||||
FirmwarePayload firmware_payload;
|
||||
} PayloadUnion;
|
||||
|
||||
typedef struct {
|
||||
uint16_t version;
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t version; // protcol version
|
||||
CommandPages commandPage;
|
||||
uint16_t length;
|
||||
PayloadUnion payload;
|
||||
@ -66,7 +93,7 @@ typedef struct {
|
||||
static_assert(sizeof(BaseMessage) <= 255,
|
||||
"BaseMessage darf nicht größer als 255 sein");
|
||||
|
||||
void init_com(ClientList *clients);
|
||||
void init_com(ClientList *clients, uint8_t wifi_channel);
|
||||
int getNextFreeClientId();
|
||||
void add_peer(uint8_t *macAddr);
|
||||
BaseMessage MessageBuilder(CommandPages commandPage, PayloadUnion payload,
|
||||
@ -81,6 +108,7 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
void client_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
const uint8_t *data, int data_len);
|
||||
void client_data_sending_task(void *param);
|
||||
void client_send_random_data_task(void *param);
|
||||
void client_monitor_task(void *pvParameters);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user