bitcraze / crazyflie-lib-python

Python library to communicate with Crazyflie
Other
263 stars 896 forks source link

Crazyradio message gets truncated #474

Closed williamleong closed 2 months ago

williamleong commented 2 months ago

Is there some limit to the size of messages sent from the Crazyradio via cflib? I know the limit for P2P is 60 bytes but if I try to send a payload of more than 30 bytes through the Crazyradio with cflib and try to receive it through the P2P callback, the message is truncated.

Sending script:

from cflib.drivers.crazyradio import Crazyradio
import struct

cr = Crazyradio(devid=1)

cr.set_channel(60)
cr.set_data_rate(cr.DR_2MPS)

# Send multicast packet to P2P port 7
cr.set_address((0xff,0xe7,0xe7,0xe7,0xe7)) # sets destination address for outgoing packets
cr.set_ack_enable(False) # disable acknowledgement for outgoing packets

message = (0xff, 0x80, 
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01)

cr.send_packet(message) # sends packet to destination address via radio link
print('[Send] ', message)

message = (0xff, 0x80, 
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01, 0x01,
           0x01, 0x01, 0x01)

cr.send_packet(message) # sends packet to destination address via radio link
print('[Send] ', message)

exit(0)

Output:

[Send]  (255, 128, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
[Send]  (255, 128, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

The sent message appears to be correct, it is one byte longer than the first.

P2P receiving:

void p2pcallbackHandler(P2PPacket *p)
{
  for (uint8_t i = 0; i < p->size; i++)
  {
    DEBUG_PRINT("%u ", (uint8_t)p->data[i]);
  }

  DEBUG_PRINT("\n");
}

Output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 

Each message is received 3 times, but the second message should be longer than the first. It seems to work up to 30 bytes.

ataffanel commented 2 months ago

The Crazyradio is limited to 32Bytes packets so 30Bytes payload for a P2P packet. This is a fundamental limitation of the Crazyradio PA hardware. Crazyradio 2.0 should be able of sending bigger packet but it is currently running a compatiblity firmware that limits it to 32.

In the future, Crazyradio2 should be able to participate to a P2P network with Crazyflies. This will require some more firmware development though.

williamleong commented 2 months ago

Thanks and appreciate the clarification @ataffanel, I thought I was doing something wrong.