Merge pull request #1174 from bkozak-scanimetrics/cc26xx_fix_read_frame_implementation

Cc26xx fix read frame implementation
This commit is contained in:
George Oikonomou 2015-08-15 00:44:26 +01:00
commit 63bb46f01b

View file

@ -1328,33 +1328,55 @@ send(const void *payload, unsigned short payload_len)
return transmit(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 static int
read_frame(void *buf, unsigned short buf_len) read_frame(void *buf, unsigned short buf_len)
{ {
int8_t rssi;
int len = 0; 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) { if(status != DATA_ENTRY_STATUS_FINISHED) {
/* Set status to 0 "Pending" in element */ /* No available data */
GET_FIELD_V(rx_read_entry, dataEntry, status) = DATA_ENTRY_STATUS_PENDING; return 0;
}
if(rx_read_entry[8] > 0) {
memcpy(buf, (char *)&rx_read_entry[9], buf_len);
/* Remove the footer */ if(rx_read_entry[8] < 4) {
len = MIN(buf_len, 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;
}
len = rx_read_entry[8] - 4;
if(len > buf_len) {
PRINTF("RF: too long\n");
RIMESTATS_ADD(toolong);
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); packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
RIMESTATS_ADD(llrx); RIMESTATS_ADD(llrx);
/* Clear the length byte */ release_data_entry();
rx_read_entry[8] = 0;
}
/* Move read entry pointer to next entry */
rx_read_entry = GET_FIELD_V(rx_read_entry, dataEntry, pNextEntry);
}
return len; return len;
} }