add ticks_to_wait parameter for send_packet
This commit is contained in:
parent
6f15b96a79
commit
62e4b286db
@ -280,14 +280,14 @@ esp_err_t sx127x_stop(sx127x_t *handle) {
|
|||||||
return ESP_OK;
|
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_CHECK(data_len < SX127_MAX_PACKET_LEN, "packet len too long: %d", ESP_FAIL, data_len);
|
||||||
sx127x_packet_t packet;
|
sx127x_packet_t packet;
|
||||||
packet.data_len = data_len;
|
packet.data_len = data_len;
|
||||||
packet.data = heap_caps_malloc(data_len, MALLOC_CAP_DMA);
|
packet.data = heap_caps_malloc(data_len, MALLOC_CAP_DMA);
|
||||||
SX127X_CHECK(packet.data != NULL, "malloc error", ESP_ERR_NO_MEM);
|
SX127X_CHECK(packet.data != NULL, "malloc error", ESP_ERR_NO_MEM);
|
||||||
memcpy(packet.data, data, data_len);
|
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);
|
SX127X_CHECK(pdRet == pdTRUE, "tx queue full", ESP_FAIL);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
@ -80,4 +80,4 @@ esp_err_t sx127x_start(sx127x_t *handle);
|
|||||||
|
|
||||||
esp_err_t sx127x_stop(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);
|
||||||
|
@ -111,8 +111,8 @@ void loraOnReceive(int packetSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loraTask(void *params) {
|
void loraTask(void *params) {
|
||||||
char outBuf[20];
|
char tx_buf[20];
|
||||||
const size_t outBufLen = (sizeof(outBuf) / sizeof(uint8_t));
|
const size_t tx_buf_len = (sizeof(tx_buf) / sizeof(tx_buf[0]));
|
||||||
int packet_len;
|
int packet_len;
|
||||||
TickType_t send_period = pdMS_TO_TICKS(2000);
|
TickType_t send_period = pdMS_TO_TICKS(2000);
|
||||||
TickType_t current_time = xTaskGetTickCount();
|
TickType_t current_time = xTaskGetTickCount();
|
||||||
@ -134,17 +134,17 @@ void loraTask(void *params) {
|
|||||||
}
|
}
|
||||||
current_time = xTaskGetTickCount();
|
current_time = xTaskGetTickCount();
|
||||||
if (current_time >= next_send) {
|
if (current_time >= next_send) {
|
||||||
int len = sprintf(outBuf, "hello world %d", packet_num);
|
int written_bytes = snprintf(tx_buf, tx_buf_len, "hello world %d", packet_num);
|
||||||
if (len < 0) {
|
if (written_bytes < 0) {
|
||||||
ESP_LOGE(TAG, "sprintf error: %d", len);
|
ESP_LOGE(TAG, "snprintf error: %d", written_bytes);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
packet_num++;
|
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) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error sending packet: %d", ret);
|
ESP_LOGE(TAG, "error sending packet: %d", ret);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "lora wrote %d bytes\n", len);
|
ESP_LOGI(TAG, "lora wrote %d bytes\n", written_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_time = xTaskGetTickCount();
|
current_time = xTaskGetTickCount();
|
||||||
@ -156,7 +156,7 @@ void loraTask(void *params) {
|
|||||||
void loop(void) {
|
void loop(void) {
|
||||||
ESP_LOGI(TAG, "loop");
|
ESP_LOGI(TAG, "loop");
|
||||||
u8g2_FirstPage(&u8g2);
|
u8g2_FirstPage(&u8g2);
|
||||||
bool recieved_packet = xQueueReceive(lora_packet_recv_queue, &packet, 10);
|
xQueueReceive(lora_packet_recv_queue, &packet, 10);
|
||||||
do {
|
do {
|
||||||
u8g2_DrawRFrame(&u8g2, 0, 0, OLED_W, OLED_H, 4);
|
u8g2_DrawRFrame(&u8g2, 0, 0, OLED_W, OLED_H, 4);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user