[SOLVED] NRF Firmware esb.c Packet Counters
Posted: Wed Jun 19, 2019 2:35 pm
Hello,
I'm working on a project to allow communication between multiple crazyflies and I can't seem to make sense of the code that I've appended below. It seems as though the curr_up and curr_down are counting the packets sent and received, however, there doesn't seem to be any increment, only subtraction of this value from 1 in places, and it's being used in the if statements in a way that I can't make any sense of at all. Does anyone understand what's happening here or have any ideas where I can look to figure it out?
Thanks!
if ((pk->match == ESB_UNICAST_ADDRESS_MATCH))
{
// Match safeLink packet and answer it
if (pk->size == 3 && (pk->data[0]&0xf3) == 0xf3 && pk->data[1] == 0x05) {
has_safelink = pk->data[2];
memcpy(servicePacket.data, pk->data, 3);
servicePacket.size = 3;
setupTx(false);
// Reset packet counters
curr_down = 1;
curr_up = 1;
return;
}
// Good packet received, yea!
if (!has_safelink || (pk->data[0] & 0x08) != curr_up<<3) {
// Push the queue head to push this packet and prepare the next
rxq_head = ((rxq_head+1)%RXQ_LEN);
curr_up = 1-curr_up;
}
if (!has_safelink || (pk->data[0]&0x04) != curr_down<<2) {
curr_down = 1-curr_down;
setupTx(false);
} else {
setupTx(true);
}
I'm working on a project to allow communication between multiple crazyflies and I can't seem to make sense of the code that I've appended below. It seems as though the curr_up and curr_down are counting the packets sent and received, however, there doesn't seem to be any increment, only subtraction of this value from 1 in places, and it's being used in the if statements in a way that I can't make any sense of at all. Does anyone understand what's happening here or have any ideas where I can look to figure it out?
Thanks!
if ((pk->match == ESB_UNICAST_ADDRESS_MATCH))
{
// Match safeLink packet and answer it
if (pk->size == 3 && (pk->data[0]&0xf3) == 0xf3 && pk->data[1] == 0x05) {
has_safelink = pk->data[2];
memcpy(servicePacket.data, pk->data, 3);
servicePacket.size = 3;
setupTx(false);
// Reset packet counters
curr_down = 1;
curr_up = 1;
return;
}
// Good packet received, yea!
if (!has_safelink || (pk->data[0] & 0x08) != curr_up<<3) {
// Push the queue head to push this packet and prepare the next
rxq_head = ((rxq_head+1)%RXQ_LEN);
curr_up = 1-curr_up;
}
if (!has_safelink || (pk->data[0]&0x04) != curr_down<<2) {
curr_down = 1-curr_down;
setupTx(false);
} else {
setupTx(true);
}