Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lora/lora.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ LORA_STATUS lora_receive_ready() {
// =============================================================================
// lora_receive: receive a buffer from lora fifo with continuous mode
// =============================================================================
LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t* buffer_len_ptr){
LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t buffer_len, uint8_t* num_bytes_received) {
uint8_t timeout_flag;


// LORA_STATUS rx_done = lora_receive_ready(); // We check if we've received a packet.
// If we haven't received a packet, the output will be similar to lora_receive_ready in that case.
Expand All @@ -423,6 +424,11 @@ LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t* buffer_len_ptr){
uint8_t num_bytes;
LORA_STATUS fifo2_status = lora_read_register(LORA_REG_FIFO_RX_NUM_BYTES, &num_bytes);

if (num_bytes > buffer_len)
{
return LORA_BUFFER_UNDERSIZED;
}

#if defined( TESTRECEIVER )
char buf[255];
int len = sprintf( buf, "Numbytes: %d\r\n", num_bytes );
Expand Down Expand Up @@ -450,7 +456,7 @@ LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t* buffer_len_ptr){
pld_xtr_status = lora_read_register(LORA_REG_FIFO_RW, &packet); // Access LoRA FIFO data buffer pointer
buffer_ptr[i] = packet;
}
*buffer_len_ptr = num_bytes;
*num_bytes_received = num_bytes;
if (pld_xtr_status == LORA_OK ) {
return LORA_OK;
} else {
Expand Down
3 changes: 2 additions & 1 deletion lora/lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef enum LORA_STATUS {
LORA_TRANSMIT_FAIL,
LORA_RECEIVE_FAIL,
LORA_TIMEOUT_FAIL,
LORA_BUFFER_UNDERSIZED,
LORA_READY,
LORA_WAITING
} LORA_STATUS;
Expand Down Expand Up @@ -165,6 +166,6 @@ LORA_STATUS lora_transmit(uint8_t* buffer_ptr, uint8_t buffer_len);

LORA_STATUS lora_receive_ready();

LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t* buffer_len_ptr);
LORA_STATUS lora_receive(uint8_t* buffer_ptr, uint8_t buffer_len, uint8_t* num_bytes_received);

#endif