Skip to content

Commit

Permalink
All new modes confirmed working!
Browse files Browse the repository at this point in the history
Fixed uart queue length bug.
  • Loading branch information
seeul8er committed Apr 22, 2024
1 parent 1ab7508 commit 0d293ec
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 71 deletions.
10 changes: 5 additions & 5 deletions main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void send_to_all_clients(int tcp_clients[], struct udp_conn_list_t *n_udp_conn_l
send_to_all_tcp_clients(tcp_clients, data, data_length);
send_to_all_udp_clients(n_udp_conn_list, data, data_length);
} else {
db_espnow_UART_event_t evt;
db_espnow_uart_event_t evt;
evt.data = malloc(data_length);
memcpy(evt.data, data, data_length);
evt.data_len = data_length;
Expand Down Expand Up @@ -272,16 +272,16 @@ _Noreturn void control_module_esp_now(){
uint8_t msp_message_buffer[UART_BUF_SIZE];
uint8_t serial_buffer[DB_TRANS_BUF_SIZE];
msp_ltm_port_t db_msp_ltm_port;
db_espnow_UART_event_t db_uart_evt;
db_espnow_uart_event_t db_espnow_uart_evt;
uint delay_timer_cnt = 0;

ESP_LOGI(TAG, "Started control module (ESP-NOW)");
while (1) {
read_process_uart(NULL, &transparent_buff_pos, &msp_ltm_buff_pos, msp_message_buffer, serial_buffer,
&db_msp_ltm_port);
if (db_uart_write_queue != NULL && xQueueReceive(db_uart_write_queue, &db_uart_evt, 0) == pdTRUE) {
write_to_uart(db_uart_evt.data, db_uart_evt.data_len);
free(db_uart_evt.data);
if (db_uart_write_queue != NULL && xQueueReceive(db_uart_write_queue, &db_espnow_uart_evt, 0) == pdTRUE) {
write_to_uart(db_espnow_uart_evt.data, db_espnow_uart_evt.data_len);
free(db_espnow_uart_evt.data);
} else {
if (db_uart_write_queue == NULL) ESP_LOGE(TAG, "db_uart_write_queue is NULL!");
// no new data available do nothing
Expand Down
16 changes: 8 additions & 8 deletions main/db_esp_now.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ QueueHandle_t db_uart_write_queue; // Queue that contains data to be written

mbedtls_gcm_context aes;
uint8_t const size_packet_header = sizeof(db_esp_now_packet_header_t);
uint8_t const size_enc_payload = sizeof(db_esp_now_packet_protected_data_t);

/**
* Generates a AES key from a password using pkcs5 - pbkdf2 and mbedTLS
Expand Down Expand Up @@ -198,7 +197,7 @@ int db_decrypt_payload(db_esp_now_packet_t* db_esp_now_packet, uint8_t* decrypt_
* @return false if no packet was sent, true if packet was sent (actual sending will be confirmed by the send-callback)
*/
bool db_read_uart_queue_and_send() {
static db_espnow_UART_event_t evt;
static db_espnow_uart_event_t evt;
static db_esp_now_packet_t db_esp_now_packet = {
.db_esp_now_packet_header.seq_num = 0,
.db_esp_now_packet_header.packet_type = 0
Expand Down Expand Up @@ -273,10 +272,11 @@ void db_espnow_process_rcv_data(uint8_t *data, uint16_t data_len, uint8_t *src_a
last_seq_num = db_esp_now_packet->db_esp_now_packet_header.seq_num;

// Pass data to UART queue
db_espnow_UART_event_t db_uart_evt;
db_uart_evt.data = malloc(len_payload - 1);
// For some reason it seems we cannot directly decrypt to db_espnow_UART_event_t -> Queues get set to NULL
memcpy(db_uart_evt.data, db_decrypted_data, len_payload - 1);
db_espnow_uart_event_t db_uart_evt;
db_uart_evt.data_len = db_decrypted_data[0]; // should be equal to len_payload-1 if everything worked out
db_uart_evt.data = malloc(db_uart_evt.data_len);
// For some reason it seems we cannot directly decrypt to db_espnow_uart_event_t -> Queues get set to NULL
memcpy(db_uart_evt.data, &db_decrypted_data[1], db_uart_evt.data_len);
if (xQueueSend(db_uart_write_queue, &db_uart_evt, ESPNOW_MAXDELAY) != pdTRUE) {
ESP_LOGW(TAG, "Send to db_uart_write_queue failed");
free(db_uart_evt.data);
Expand Down Expand Up @@ -404,8 +404,8 @@ esp_err_t db_espnow_init() {
}

/* Init Queues for communication with control task */
db_espnow_send_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(db_espnow_UART_event_t));
db_uart_write_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(db_espnow_UART_event_t));
db_espnow_send_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(db_espnow_uart_event_t));
db_uart_write_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(db_espnow_uart_event_t));
if (db_espnow_send_queue == NULL) {
ESP_LOGE(TAG, "Create db_espnow_send_queue mutex fail");
return ESP_FAIL;
Expand Down
2 changes: 1 addition & 1 deletion main/db_esp_now.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct {
typedef struct {
uint8_t data_len;
uint8_t *data;
} __attribute__((__packed__)) db_espnow_UART_event_t;
} __attribute__((__packed__)) db_espnow_uart_event_t;

enum {
DB_ESPNOW_ORIGIN_GND = 0,
Expand Down
4 changes: 2 additions & 2 deletions main/db_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ void write_to_uart(const uint8_t data_buffer[], const unsigned int data_length)
int written = uart_write_bytes(UART_NUM, data_buffer, data_length);
if (written > 0) {
ESP_LOGD(TAG, "Wrote %i bytes to UART", written);
} else if (written == 0) {
ESP_LOGW(TAG, "Wrote 0 bytes to UART (%s) - Check if UART is connected.", esp_err_to_name(errno));
} else if (written != data_length) {
ESP_LOGW(TAG, "Wrote 0 of %i bytes to UART.", data_length);
} else {
ESP_LOGE(TAG, "Error writing to UART %s", esp_err_to_name(errno));
}
Expand Down
110 changes: 55 additions & 55 deletions sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1598,61 +1598,6 @@ CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
# CONFIG_WIFI_PROV_STA_FAST_SCAN is not set
# end of Wi-Fi Provisioning Manager

#
# IoT Button
#
CONFIG_BUTTON_PERIOD_TIME_MS=5
CONFIG_BUTTON_DEBOUNCE_TICKS=2
CONFIG_BUTTON_SHORT_PRESS_TIME_MS=180
CONFIG_BUTTON_LONG_PRESS_TIME_MS=1500
CONFIG_BUTTON_LONG_PRESS_TOLERANCE_MS=20
CONFIG_BUTTON_SERIAL_TIME_MS=20
# CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE is not set
CONFIG_ADC_BUTTON_MAX_CHANNEL=3
CONFIG_ADC_BUTTON_MAX_BUTTON_PER_CHANNEL=8
CONFIG_ADC_BUTTON_SAMPLE_TIMES=1
# end of IoT Button

#
# CMake Utilities
#
# CONFIG_CU_RELINKER_ENABLE is not set
# CONFIG_CU_DIAGNOSTICS_COLOR_NEVER is not set
CONFIG_CU_DIAGNOSTICS_COLOR_ALWAYS=y
# CONFIG_CU_DIAGNOSTICS_COLOR_AUTO is not set
# CONFIG_CU_GCC_LTO_ENABLE is not set
# CONFIG_CU_GCC_STRING_1BYTE_ALIGN is not set
# end of CMake Utilities

#
# mDNS
#
CONFIG_MDNS_MAX_INTERFACES=3
CONFIG_MDNS_MAX_SERVICES=10
CONFIG_MDNS_TASK_PRIORITY=1
CONFIG_MDNS_ACTION_QUEUE_LEN=16
CONFIG_MDNS_TASK_STACK_SIZE=4096
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
CONFIG_MDNS_TASK_AFFINITY=0x0
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
CONFIG_MDNS_TIMER_PERIOD_MS=100
# CONFIG_MDNS_NETWORKING_SOCKET is not set
# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set
# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set
CONFIG_MDNS_ENABLE_CONSOLE_CLI=y
# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set
CONFIG_MDNS_MULTIPLE_INSTANCE=y

#
# MDNS Predefined interfaces
#
CONFIG_MDNS_PREDEF_NETIF_STA=y
CONFIG_MDNS_PREDEF_NETIF_AP=y
CONFIG_MDNS_PREDEF_NETIF_ETH=y
# end of MDNS Predefined interfaces
# end of mDNS

#
# ESP-NOW Configuration
#
Expand Down Expand Up @@ -1729,6 +1674,61 @@ CONFIG_ESPNOW_DEBUG_CONSOLE_UART_NUM_0=y
CONFIG_ESPNOW_DEBUG_CONSOLE_UART_NUM=0
# end of ESP-NOW Debug Configuration
# end of ESP-NOW Configuration

#
# IoT Button
#
CONFIG_BUTTON_PERIOD_TIME_MS=5
CONFIG_BUTTON_DEBOUNCE_TICKS=2
CONFIG_BUTTON_SHORT_PRESS_TIME_MS=180
CONFIG_BUTTON_LONG_PRESS_TIME_MS=1500
CONFIG_BUTTON_LONG_PRESS_TOLERANCE_MS=20
CONFIG_BUTTON_SERIAL_TIME_MS=20
# CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE is not set
CONFIG_ADC_BUTTON_MAX_CHANNEL=3
CONFIG_ADC_BUTTON_MAX_BUTTON_PER_CHANNEL=8
CONFIG_ADC_BUTTON_SAMPLE_TIMES=1
# end of IoT Button

#
# CMake Utilities
#
# CONFIG_CU_RELINKER_ENABLE is not set
# CONFIG_CU_DIAGNOSTICS_COLOR_NEVER is not set
CONFIG_CU_DIAGNOSTICS_COLOR_ALWAYS=y
# CONFIG_CU_DIAGNOSTICS_COLOR_AUTO is not set
# CONFIG_CU_GCC_LTO_ENABLE is not set
# CONFIG_CU_GCC_STRING_1BYTE_ALIGN is not set
# end of CMake Utilities

#
# mDNS
#
CONFIG_MDNS_MAX_INTERFACES=3
CONFIG_MDNS_MAX_SERVICES=10
CONFIG_MDNS_TASK_PRIORITY=1
CONFIG_MDNS_ACTION_QUEUE_LEN=16
CONFIG_MDNS_TASK_STACK_SIZE=4096
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
CONFIG_MDNS_TASK_AFFINITY=0x0
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
CONFIG_MDNS_TIMER_PERIOD_MS=100
# CONFIG_MDNS_NETWORKING_SOCKET is not set
# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set
# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set
CONFIG_MDNS_ENABLE_CONSOLE_CLI=y
# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set
CONFIG_MDNS_MULTIPLE_INSTANCE=y

#
# MDNS Predefined interfaces
#
CONFIG_MDNS_PREDEF_NETIF_STA=y
CONFIG_MDNS_PREDEF_NETIF_AP=y
CONFIG_MDNS_PREDEF_NETIF_ETH=y
# end of MDNS Predefined interfaces
# end of mDNS
# end of Component config

# CONFIG_IDF_EXPERIMENTAL_FEATURES is not set
Expand Down

0 comments on commit 0d293ec

Please sign in to comment.