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";
|
static const char *TAG = "ALOX - COM";
|
||||||
|
|
||||||
QueueHandle_t messageQueue = NULL; // Warteschlange für empfangene Nachrichten
|
QueueHandle_t messageQueue = NULL; // Warteschlange für empfangene Nachrichten
|
||||||
bool hasMaster = false;
|
static bool hasMaster = false;
|
||||||
static ClientList *esp_client_list;
|
static ClientList *esp_client_list;
|
||||||
|
static uint8_t channelNumber = 0;
|
||||||
|
|
||||||
#define MAC_STRING_BUFFER_SIZE 18
|
#define MAC_STRING_BUFFER_SIZE 18
|
||||||
|
|
||||||
void init_com(ClientList *clients) {
|
void init_com(ClientList *clients, uint8_t wifi_channel) {
|
||||||
// Initialisiere die Kommunikations-Warteschlange
|
// Initialisiere die Kommunikations-Warteschlange
|
||||||
messageQueue = xQueueCreate(MESSAGE_QUEUE_SIZE, sizeof(BaseMessage));
|
messageQueue = xQueueCreate(MESSAGE_QUEUE_SIZE, sizeof(BaseMessage));
|
||||||
if (messageQueue == NULL) {
|
if (messageQueue == NULL) {
|
||||||
@ -26,12 +27,12 @@ void init_com(ClientList *clients) {
|
|||||||
|
|
||||||
esp_client_list = clients;
|
esp_client_list = clients;
|
||||||
hasMaster = false;
|
hasMaster = false;
|
||||||
|
channelNumber = wifi_channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_peer(uint8_t *macAddr) {
|
void add_peer(uint8_t *macAddr) {
|
||||||
esp_now_peer_info_t peerInfo = {
|
esp_now_peer_info_t peerInfo = {
|
||||||
.channel =
|
.channel = channelNumber,
|
||||||
0, // Standardkanal, sollte uit den anderen Geräten übereinstimmen
|
|
||||||
.ifidx = ESP_IF_WIFI_STA,
|
.ifidx = ESP_IF_WIFI_STA,
|
||||||
.encrypt = false, // Keine Verschlüsselung (kann geändert werden)
|
.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) {
|
void master_broadcast_ping(void *param) {
|
||||||
while (1) {
|
while (1) {
|
||||||
// BroadCastPayload payload = {};
|
|
||||||
PingPayload payload = {};
|
PingPayload payload = {};
|
||||||
payload.timestamp = esp_timer_get_time();
|
payload.timestamp = esp_timer_get_time();
|
||||||
BaseMessage message =
|
BaseMessage message =
|
||||||
@ -189,6 +189,7 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void client_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) {
|
const uint8_t *data, int data_len) {
|
||||||
ESP_LOGI(TAG, "SLAVE GOT MESSAGE");
|
ESP_LOGI(TAG, "SLAVE GOT MESSAGE");
|
||||||
@ -239,17 +240,14 @@ void client_data_sending_task(void *param) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
const char *dataToSend = "DATA:42";
|
const char *dataToSend = "DATA:42";
|
||||||
ESP_LOGI(TAG, "SEND DATA");
|
ESP_LOGI(TAG, "SEND DATA");
|
||||||
esp_now_send(NULL, (uint8_t *)dataToSend,
|
esp_now_send(NULL, (uint8_t *)dataToSend, strlen(dataToSend));
|
||||||
strlen(dataToSend));
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void client_monitor_task(void *pvParameters) {
|
void client_monitor_task(void *pvParameters) {
|
||||||
TickType_t timeout_ticks =
|
TickType_t timeout_ticks = pdMS_TO_TICKS(CLIENT_TIMEOUT_MS);
|
||||||
pdMS_TO_TICKS(CLIENT_TIMEOUT_MS);
|
TickType_t interval_ticks = pdMS_TO_TICKS(CHECK_INTERVAL_MS);
|
||||||
TickType_t interval_ticks =
|
|
||||||
pdMS_TO_TICKS(CHECK_INTERVAL_MS);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
TickType_t now = xTaskGetTickCount();
|
TickType_t now = xTaskGetTickCount();
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define BROADCAST_INTERVAL_MS 500
|
#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
|
#define MESSAGE_QUEUE_SIZE 10
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BroadCastPage,
|
|
||||||
StatusPage,
|
StatusPage,
|
||||||
|
ConfigPage,
|
||||||
PingPage,
|
PingPage,
|
||||||
|
BroadCastPage,
|
||||||
RegisterPage,
|
RegisterPage,
|
||||||
|
FirmwarePrepPage,
|
||||||
|
FirmwarePayloadPage,
|
||||||
} CommandPages;
|
} CommandPages;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct __attribute__((packed)) {
|
||||||
uint32_t uptime;
|
uint16_t version; // software version
|
||||||
|
uint8_t runningPartition;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
uint32_t uptime;
|
||||||
} StatusPayload;
|
} StatusPayload;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct __attribute__((packed)) {
|
||||||
|
uint8_t timeslot;
|
||||||
|
} ConfigPayload;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) {
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
} PingPayload;
|
} PingPayload;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct __attribute__((packed)) {
|
||||||
} BroadCastPayload;
|
} BroadCastPayload;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct __attribute__((packed)) {
|
||||||
bool familierClient;
|
bool familierClient;
|
||||||
} RegisterPayload;
|
} 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;
|
StatusPayload status_payload;
|
||||||
|
ConfigPayload config_payload;
|
||||||
PingPayload ping_payload;
|
PingPayload ping_payload;
|
||||||
BroadCastPayload broadcast_payload;
|
BroadCastPayload broadcast_payload;
|
||||||
RegisterPayload register_payload;
|
RegisterPayload register_payload;
|
||||||
|
FirmwarePrepPayload firmware_prep_payload;
|
||||||
|
FirmwarePayload firmware_payload;
|
||||||
} PayloadUnion;
|
} PayloadUnion;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct __attribute__((packed)) {
|
||||||
uint16_t version;
|
uint16_t version; // protcol version
|
||||||
CommandPages commandPage;
|
CommandPages commandPage;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
PayloadUnion payload;
|
PayloadUnion payload;
|
||||||
@ -66,7 +93,7 @@ typedef struct {
|
|||||||
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");
|
||||||
|
|
||||||
void init_com(ClientList *clients);
|
void init_com(ClientList *clients, uint8_t wifi_channel);
|
||||||
int getNextFreeClientId();
|
int getNextFreeClientId();
|
||||||
void add_peer(uint8_t *macAddr);
|
void add_peer(uint8_t *macAddr);
|
||||||
BaseMessage MessageBuilder(CommandPages commandPage, PayloadUnion payload,
|
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,
|
void client_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||||
const uint8_t *data, int data_len);
|
const uint8_t *data, int data_len);
|
||||||
void client_data_sending_task(void *param);
|
void client_data_sending_task(void *param);
|
||||||
|
void client_send_random_data_task(void *param);
|
||||||
void client_monitor_task(void *pvParameters);
|
void client_monitor_task(void *pvParameters);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user