Page 1 of 1

[SOLVED] NRF Firmware esb.c Packet Counters

Posted: Wed Jun 19, 2019 2:35 pm
by briaruwo
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);
}

Re: NRF Firmware esb.c Packet Counters

Posted: Sun Jun 23, 2019 6:28 am
by wydmynd
interesting project! please keep us updated on progress :)

Re: NRF Firmware esb.c Packet Counters

Posted: Mon Aug 12, 2019 8:19 am
by arnaud
Hi,

Those are 1 bit counter so increment them is equivalent to inverting the value. I guess it would have been much more clear to write it more like this:

Code: Select all

curr_up = (1+curr_up) & 0x01;
The counters are incremented each time a packet is accepted. The code checks if the counter matches and if it does not, the packet in that direction is sent again. This algorithm is the same used in Bluetooth low energy.

If you want to implement P2P communication, you should not use these counters though since they need to stay in sync with the PC. If you do not transfers data in the ack packet when talking to other Crazyflies, you do not need to have this king of counter for P2P communication, this is what I have been planing to implement.

Re: NRF Firmware esb.c Packet Counters

Posted: Mon Aug 12, 2019 4:25 pm
by briaruwo
Thank you very much, that clears it up nicely!