Commit 63bb46f0 authored by George Oikonomou's avatar George Oikonomou
Browse files

Merge pull request #1174 from bkozak-scanimetrics/cc26xx_fix_read_frame_implementation

Cc26xx fix read frame implementation
parents 902b21a3 feec05cd
......@@ -1328,34 +1328,56 @@ send(const void *payload, unsigned short payload_len)
return transmit(payload_len);
}
/*---------------------------------------------------------------------------*/
static void
release_data_entry(void)
{
/* Clear the length byte */
rx_read_entry[8] = 0;
/* Set status to 0 "Pending" in element */
GET_FIELD_V(rx_read_entry, dataEntry, status) = DATA_ENTRY_STATUS_PENDING;
rx_read_entry = GET_FIELD_V(rx_read_entry, dataEntry, pNextEntry);
}
/*---------------------------------------------------------------------------*/
static int
read_frame(void *buf, unsigned short buf_len)
{
int8_t rssi;
int len = 0;
uint8_t status = GET_FIELD_V(rx_read_entry, dataEntry, status);
if(GET_FIELD_V(rx_read_entry, dataEntry, status) == DATA_ENTRY_STATUS_FINISHED) {
/* Set status to 0 "Pending" in element */
GET_FIELD_V(rx_read_entry, dataEntry, status) = DATA_ENTRY_STATUS_PENDING;
if(status != DATA_ENTRY_STATUS_FINISHED) {
/* No available data */
return 0;
}
if(rx_read_entry[8] > 0) {
memcpy(buf, (char *)&rx_read_entry[9], buf_len);
/* Remove the footer */
len = MIN(buf_len, rx_read_entry[8] - 4);
if(rx_read_entry[8] < 4) {
PRINTF("RF: too short\n");
RIMESTATS_ADD(tooshort);
int rssi = (int8_t)rx_read_entry[9 + len + 2];
release_data_entry();
return 0;
}
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
RIMESTATS_ADD(llrx);
len = rx_read_entry[8] - 4;
/* Clear the length byte */
rx_read_entry[8] = 0;
}
if(len > buf_len) {
PRINTF("RF: too long\n");
RIMESTATS_ADD(toolong);
/* Move read entry pointer to next entry */
rx_read_entry = GET_FIELD_V(rx_read_entry, dataEntry, pNextEntry);
release_data_entry();
return 0;
}
memcpy(buf, (char *)&rx_read_entry[9], len);
rssi = (int8_t)rx_read_entry[9 + len + 2];
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
RIMESTATS_ADD(llrx);
release_data_entry();
return len;
}
/*---------------------------------------------------------------------------*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment