NRF Firmware esb.c Packet Counters

Firmware/software/electronics/mechanics
Post Reply
briaruwo
Beginner
Posts: 7
Joined: Fri May 17, 2019 2:40 pm

NRF Firmware esb.c Packet Counters

Post by briaruwo » 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);
}



wydmynd
Beginner
Posts: 29
Joined: Thu Dec 06, 2018 9:25 am

Re: NRF Firmware esb.c Packet Counters

Post by wydmynd » Sun Jun 23, 2019 6:28 am

interesting project! please keep us updated on progress :)

arnaud
Bitcraze
Posts: 2202
Joined: Tue Feb 06, 2007 12:36 pm

Re: NRF Firmware esb.c Packet Counters

Post by arnaud » Mon Aug 12, 2019 8:19 am

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.

briaruwo
Beginner
Posts: 7
Joined: Fri May 17, 2019 2:40 pm

Re: NRF Firmware esb.c Packet Counters

Post by briaruwo » Mon Aug 12, 2019 4:25 pm

Thank you very much, that clears it up nicely!

Post Reply