From 62e4b286dbb37850ad9baa8f27efaf055ec3b77e Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Sun, 30 Dec 2018 19:27:58 -0700 Subject: [PATCH] add ticks_to_wait parameter for send_packet --- components/sx127x_driver/sx127x_driver.c | 4 ++-- components/sx127x_driver/sx127x_driver.h | 2 +- main/ugv_main.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/sx127x_driver/sx127x_driver.c b/components/sx127x_driver/sx127x_driver.c index 6ce49cf..28213ab 100644 --- a/components/sx127x_driver/sx127x_driver.c +++ b/components/sx127x_driver/sx127x_driver.c @@ -280,14 +280,14 @@ esp_err_t sx127x_stop(sx127x_t *handle) { return ESP_OK; } -esp_err_t sx127x_send_packet(sx127x_t *handle, char *data, size_t data_len) { +esp_err_t sx127x_send_packet(sx127x_t *handle, char *data, size_t data_len, TickType_t ticks_to_wait) { SX127X_CHECK(data_len < SX127_MAX_PACKET_LEN, "packet len too long: %d", ESP_FAIL, data_len); sx127x_packet_t packet; packet.data_len = data_len; packet.data = heap_caps_malloc(data_len, MALLOC_CAP_DMA); SX127X_CHECK(packet.data != NULL, "malloc error", ESP_ERR_NO_MEM); memcpy(packet.data, data, data_len); - BaseType_t pdRet = xQueueSend(handle->tx_packet_queue, &packet, 0); + BaseType_t pdRet = xQueueSend(handle->tx_packet_queue, &packet, ticks_to_wait); SX127X_CHECK(pdRet == pdTRUE, "tx queue full", ESP_FAIL); return ESP_OK; } diff --git a/components/sx127x_driver/sx127x_driver.h b/components/sx127x_driver/sx127x_driver.h index 9a4cff5..27a3142 100644 --- a/components/sx127x_driver/sx127x_driver.h +++ b/components/sx127x_driver/sx127x_driver.h @@ -80,4 +80,4 @@ esp_err_t sx127x_start(sx127x_t *handle); esp_err_t sx127x_stop(sx127x_t *handle); -esp_err_t sx127x_send_packet(sx127x_t *handle, char *data, size_t data_len); +esp_err_t sx127x_send_packet(sx127x_t *handle, char *data, size_t data_len, TickType_t ticks_to_wait); diff --git a/main/ugv_main.c b/main/ugv_main.c index 031cfa2..a602fc4 100644 --- a/main/ugv_main.c +++ b/main/ugv_main.c @@ -111,8 +111,8 @@ void loraOnReceive(int packetSize) { } void loraTask(void *params) { - char outBuf[20]; - const size_t outBufLen = (sizeof(outBuf) / sizeof(uint8_t)); + char tx_buf[20]; + const size_t tx_buf_len = (sizeof(tx_buf) / sizeof(tx_buf[0])); int packet_len; TickType_t send_period = pdMS_TO_TICKS(2000); TickType_t current_time = xTaskGetTickCount(); @@ -134,17 +134,17 @@ void loraTask(void *params) { } current_time = xTaskGetTickCount(); if (current_time >= next_send) { - int len = sprintf(outBuf, "hello world %d", packet_num); - if (len < 0) { - ESP_LOGE(TAG, "sprintf error: %d", len); + int written_bytes = snprintf(tx_buf, tx_buf_len, "hello world %d", packet_num); + if (written_bytes < 0) { + ESP_LOGE(TAG, "snprintf error: %d", written_bytes); continue; } packet_num++; - esp_err_t ret = sx127x_send_packet(lora, outBuf, len); + esp_err_t ret = sx127x_send_packet(lora, tx_buf, written_bytes, 0); // 0 means error if queue full if (ret != ESP_OK) { ESP_LOGE(TAG, "error sending packet: %d", ret); } else { - ESP_LOGI(TAG, "lora wrote %d bytes\n", len); + ESP_LOGI(TAG, "lora wrote %d bytes\n", written_bytes); } current_time = xTaskGetTickCount(); @@ -156,7 +156,7 @@ void loraTask(void *params) { void loop(void) { ESP_LOGI(TAG, "loop"); u8g2_FirstPage(&u8g2); - bool recieved_packet = xQueueReceive(lora_packet_recv_queue, &packet, 10); + xQueueReceive(lora_packet_recv_queue, &packet, 10); do { u8g2_DrawRFrame(&u8g2, 0, 0, OLED_W, OLED_H, 4);