Added Client Status Message/Task to send over UART
This commit is contained in:
parent
d3b6e63cdb
commit
b4ce1a5055
@ -63,6 +63,7 @@ void add_peer(uint8_t *macAddr) {
|
|||||||
memcpy(newClient.macAddr, macAddr, ESP_NOW_ETH_ALEN);
|
memcpy(newClient.macAddr, macAddr, ESP_NOW_ETH_ALEN);
|
||||||
newClient.isAvailable = true;
|
newClient.isAvailable = true;
|
||||||
newClient.lastSuccessfullPing = xTaskGetTickCount();
|
newClient.lastSuccessfullPing = xTaskGetTickCount();
|
||||||
|
newClient.lastPing = 0;
|
||||||
clients[getNextFreeClientId()] = newClient;
|
clients[getNextFreeClientId()] = newClient;
|
||||||
ESP_LOGI(TAG, "New client added.");
|
ESP_LOGI(TAG, "New client added.");
|
||||||
}
|
}
|
||||||
@ -133,13 +134,9 @@ void master_broadcast_ping(void *param) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void master_ping_task(void *param) {
|
void master_ping_task(void *param) {
|
||||||
while (1) {
|
while (1) {
|
||||||
for (size_t i = 0; i < MAX_CLIENTS; i++) {
|
for (size_t i = 0; i < MAX_CLIENTS; i++) {
|
||||||
// ESP_LOGI(TAG, "WANT TO SEND PING TO CLIENT %zu isAvailiable %d", i,
|
|
||||||
// clients[i].isAvailable);
|
|
||||||
if (clients[i].isAvailable) {
|
if (clients[i].isAvailable) {
|
||||||
ESP_LOGI(TAG, "SEND PING TO %zu: %s", i,
|
ESP_LOGI(TAG, "SEND PING TO %zu: %s", i,
|
||||||
MACtoString(clients[i].macAddr));
|
MACtoString(clients[i].macAddr));
|
||||||
@ -150,7 +147,6 @@ void master_ping_task(void *param) {
|
|||||||
esp_now_send(clients[i].macAddr, (uint8_t *)&message,
|
esp_now_send(clients[i].macAddr, (uint8_t *)&message,
|
||||||
sizeof(BaseMessage));
|
sizeof(BaseMessage));
|
||||||
ESP_LOGI(TAG, "SENDING PING!!!!");
|
ESP_LOGI(TAG, "SENDING PING!!!!");
|
||||||
vTaskDelay(pdMS_TO_TICKS(5));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
@ -181,6 +177,7 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
|||||||
memcmp(clients[i].macAddr, esp_now_info->src_addr,
|
memcmp(clients[i].macAddr, esp_now_info->src_addr,
|
||||||
ESP_NOW_ETH_ALEN) == 0) {
|
ESP_NOW_ETH_ALEN) == 0) {
|
||||||
clients[i].lastSuccessfullPing = xTaskGetTickCount();
|
clients[i].lastSuccessfullPing = xTaskGetTickCount();
|
||||||
|
clients[i].lastPing = (diff/1000);
|
||||||
ESP_LOGI(TAG, "Updated client %d: %s last ping time to %lu", i,
|
ESP_LOGI(TAG, "Updated client %d: %s last ping time to %lu", i,
|
||||||
MACtoString(clients[i].macAddr),
|
MACtoString(clients[i].macAddr),
|
||||||
clients[i].lastSuccessfullPing);
|
clients[i].lastSuccessfullPing);
|
||||||
@ -321,3 +318,7 @@ void client_monitor_task(void *pvParameters) {
|
|||||||
vTaskDelay(interval_ticks);
|
vTaskDelay(interval_ticks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientInfo *get_client_info(int entry) {
|
||||||
|
return &clients[entry];
|
||||||
|
}
|
||||||
|
|||||||
@ -68,6 +68,7 @@ typedef struct {
|
|||||||
int rssi;
|
int rssi;
|
||||||
bool isAvailable;
|
bool isAvailable;
|
||||||
TickType_t lastSuccessfullPing;
|
TickType_t lastSuccessfullPing;
|
||||||
|
TickType_t lastPing;
|
||||||
} ClientInfo;
|
} ClientInfo;
|
||||||
|
|
||||||
void init_com();
|
void init_com();
|
||||||
@ -88,4 +89,6 @@ void client_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
|||||||
void client_data_sending_task(void *param);
|
void client_data_sending_task(void *param);
|
||||||
void client_monitor_task(void *pvParameters);
|
void client_monitor_task(void *pvParameters);
|
||||||
|
|
||||||
|
ClientInfo *get_client_info(int entry);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
15
main/main.c
15
main/main.c
@ -11,11 +11,23 @@
|
|||||||
|
|
||||||
#include "communication_handler.h"
|
#include "communication_handler.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "portmacro.h"
|
||||||
#include "uart_handler.h"
|
#include "uart_handler.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
static const char *TAG = "ALOX - MAIN";
|
static const char *TAG = "ALOX - MAIN";
|
||||||
|
|
||||||
|
void SendClientInfoTask() {
|
||||||
|
int clientId = 0;
|
||||||
|
while (1) {
|
||||||
|
ClientInfo info = *get_client_info(clientId);
|
||||||
|
send_client_info(clientId, info.isAvailable, info.lastPing);
|
||||||
|
clientId += 1;
|
||||||
|
clientId = clientId%20;
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||||
@ -65,7 +77,8 @@ void app_main(void) {
|
|||||||
NULL);
|
NULL);
|
||||||
xTaskCreate(client_monitor_task, "MonitorClientTask", 4096, NULL, 1, NULL);
|
xTaskCreate(client_monitor_task, "MonitorClientTask", 4096, NULL, 1, NULL);
|
||||||
init_uart();
|
init_uart();
|
||||||
xTaskCreate(uart_status_task, "MasterUartStatusTask", 4096, NULL, 1, NULL);
|
//xTaskCreate(uart_status_task, "MasterUartStatusTask", 4096, NULL, 1, NULL);
|
||||||
|
xTaskCreate(SendClientInfoTask, "SendCientInfo", 4096, NULL, 1, NULL);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Started in Slavemode");
|
ESP_LOGI(TAG, "Started in Slavemode");
|
||||||
xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include "hal/uart_types.h"
|
#include "hal/uart_types.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "portmacro.h"
|
#include "portmacro.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "uart_handler.h"
|
#include "uart_handler.h"
|
||||||
|
|
||||||
@ -45,3 +47,10 @@ void uart_status_task(void *param) {
|
|||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void send_client_info(int clientid, bool isAvailable, TickType_t lastPing) {
|
||||||
|
char buf[128];
|
||||||
|
snprintf(buf, sizeof(buf), "c%d,status,2,%d,%u\r\n", clientid,
|
||||||
|
isAvailable ? 1 : 0, (unsigned int)lastPing);
|
||||||
|
uart_write_bytes(MASTER_UART, buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|||||||
@ -11,4 +11,6 @@ void init_uart();
|
|||||||
void uart_read_task(void *param);
|
void uart_read_task(void *param);
|
||||||
void uart_status_task(void *param);
|
void uart_status_task(void *param);
|
||||||
|
|
||||||
|
void send_client_info(int clientid, bool isAvailable, TickType_t lastPing);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user