Browse Source

add ticks_to_wait parameter for send_packet

ugv_io
Alex Mikhalev 6 years ago
parent
commit
62e4b286db
  1. 4
      components/sx127x_driver/sx127x_driver.c
  2. 2
      components/sx127x_driver/sx127x_driver.h
  3. 16
      main/ugv_main.c

4
components/sx127x_driver/sx127x_driver.c

@ -280,14 +280,14 @@ esp_err_t sx127x_stop(sx127x_t *handle) { @@ -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;
}

2
components/sx127x_driver/sx127x_driver.h

@ -80,4 +80,4 @@ esp_err_t sx127x_start(sx127x_t *handle); @@ -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);

16
main/ugv_main.c

@ -111,8 +111,8 @@ void loraOnReceive(int packetSize) { @@ -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) { @@ -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) { @@ -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);

Loading…
Cancel
Save