Added Switch Case on recive site for payload pagination
This commit is contained in:
parent
7f1369f1cf
commit
b6fbe05312
42
main/main.c
42
main/main.c
@ -33,7 +33,7 @@
|
||||
const char *tag = "Alox";
|
||||
static QueueHandle_t s_espnow_queue;
|
||||
static uint8_t s_broadcast_mac[ESP_NOW_ETH_ALEN] = {0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF};
|
||||
0xFF, 0xFF, 0xFF};
|
||||
static uint16_t s_espnow_seq[2] = {0, 0};
|
||||
static void espnow_deinit(espnow_send_param_t *send_param);
|
||||
|
||||
@ -71,7 +71,8 @@ static void espnow_deinit(espnow_send_param_t *send_param) {
|
||||
void espnow_data_prepare(espnow_send_param_t *send_param) {
|
||||
espnow_data_t *buf = (espnow_data_t *)send_param->buffer;
|
||||
|
||||
ESP_LOGI(tag, "Example_Data_SIZE: %u, send_param_len: %d\n", sizeof(espnow_data_t), send_param->len);
|
||||
ESP_LOGI(tag, "Example_Data_SIZE: %u, send_param_len: %d\n",
|
||||
sizeof(espnow_data_t), send_param->len);
|
||||
assert(send_param->len >= sizeof(espnow_data_t));
|
||||
|
||||
buf->type = IS_BROADCAST_ADDR(send_param->dest_mac)
|
||||
@ -88,7 +89,7 @@ void espnow_data_prepare(espnow_send_param_t *send_param) {
|
||||
}
|
||||
|
||||
static void espnow_send_cb(const uint8_t *mac_addr,
|
||||
esp_now_send_status_t status) {
|
||||
esp_now_send_status_t status) {
|
||||
espnow_event_t evt;
|
||||
espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
|
||||
|
||||
@ -106,7 +107,7 @@ static void espnow_send_cb(const uint8_t *mac_addr,
|
||||
}
|
||||
|
||||
static void espnow_recv_cb(const esp_now_recv_info_t *recv_info,
|
||||
const uint8_t *data, int len) {
|
||||
const uint8_t *data, int len) {
|
||||
espnow_event_t evt;
|
||||
espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb;
|
||||
uint8_t *mac_addr = recv_info->src_addr;
|
||||
@ -143,7 +144,7 @@ static void espnow_recv_cb(const esp_now_recv_info_t *recv_info,
|
||||
}
|
||||
|
||||
int espnow_data_parse(uint8_t *data, uint16_t data_len, uint8_t *state,
|
||||
uint16_t *seq, uint32_t *magic) {
|
||||
uint16_t *seq, uint32_t *magic) {
|
||||
espnow_data_t *buf = (espnow_data_t *)data;
|
||||
uint16_t crc, crc_cal = 0;
|
||||
|
||||
@ -159,16 +160,22 @@ int espnow_data_parse(uint8_t *data, uint16_t data_len, uint8_t *state,
|
||||
buf->crc = 0;
|
||||
crc_cal = esp_crc16_le(UINT16_MAX, (uint8_t const *)buf, data_len);
|
||||
|
||||
if(buf->realPayload.status.isMaster) {
|
||||
ESP_LOGI(tag, "Recived Data from Master");
|
||||
} else {
|
||||
ESP_LOGI(tag, "Recived Data from Slave");
|
||||
switch (buf->unionPage) {
|
||||
case UNION_STATUS:
|
||||
if (buf->realPayload.status.isMaster) {
|
||||
ESP_LOGI(tag, "Recived Data from Master");
|
||||
} else {
|
||||
ESP_LOGI(tag, "Recived Data from Slave");
|
||||
}
|
||||
break;
|
||||
case UNION_SENSORDATA:
|
||||
ESP_LOGI(tag, "Yeah Daten %d", buf->realPayload.sensorData.dataPoint);
|
||||
break;
|
||||
}
|
||||
|
||||
if (crc_cal == crc) {
|
||||
return buf->type;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -184,8 +191,7 @@ static void espnow_task(void *pvParameter) {
|
||||
ESP_LOGI(tag, "Start sending broadcast data");
|
||||
|
||||
/* Start sending broadcast ESPNOW data. */
|
||||
espnow_send_param_t *send_param =
|
||||
(espnow_send_param_t *)pvParameter;
|
||||
espnow_send_param_t *send_param = (espnow_send_param_t *)pvParameter;
|
||||
if (esp_now_send(send_param->dest_mac, send_param->buffer, send_param->len) !=
|
||||
ESP_OK) {
|
||||
ESP_LOGE(tag, "Send error");
|
||||
@ -237,8 +243,8 @@ static void espnow_task(void *pvParameter) {
|
||||
case EXAMPLE_ESPNOW_RECV_CB: {
|
||||
espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb;
|
||||
|
||||
ret = espnow_data_parse(recv_cb->data, recv_cb->data_len,
|
||||
&recv_state, &recv_seq, &recv_magic);
|
||||
ret = espnow_data_parse(recv_cb->data, recv_cb->data_len, &recv_state,
|
||||
&recv_seq, &recv_magic);
|
||||
free(recv_cb->data);
|
||||
if (ret == EXAMPLE_ESPNOW_DATA_BROADCAST) {
|
||||
ESP_LOGI(tag, "Receive %dth broadcast data from: " MACSTR ", len: %d",
|
||||
@ -318,8 +324,7 @@ static void espnow_task(void *pvParameter) {
|
||||
static esp_err_t espnow_init(void) {
|
||||
espnow_send_param_t *send_param;
|
||||
|
||||
s_espnow_queue =
|
||||
xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(espnow_event_t));
|
||||
s_espnow_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(espnow_event_t));
|
||||
if (s_espnow_queue == NULL) {
|
||||
ESP_LOGE(tag, "Create mutex fail");
|
||||
return ESP_FAIL;
|
||||
@ -380,8 +385,7 @@ static esp_err_t espnow_init(void) {
|
||||
memcpy(send_param->dest_mac, s_broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||
espnow_data_prepare(send_param);
|
||||
|
||||
xTaskCreate(espnow_task, "espnow_task", 2048, send_param, 4,
|
||||
NULL);
|
||||
xTaskCreate(espnow_task, "espnow_task", 2048, send_param, 4, NULL);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -397,7 +401,7 @@ void app_main(void) {
|
||||
|
||||
ESP_LOGI(tag, "ESP MASTER State %d\n", isMaster);
|
||||
|
||||
vTaskDelay(500/portTICK_PERIOD_MS);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
||||
wifi_init();
|
||||
espnow_init();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user