P2P Communication; how to send float Values?

Post here to get support
Post Reply
xStream
Beginner
Posts: 1
Joined: Thu Dec 16, 2021 12:28 pm

P2P Communication; how to send float Values?

Post by xStream »

Hello Guys,
I have a problem regarding the Peer to Peer Communication of my Crazyflie Drones. I want the Drones to send P2P-Messages to eachother. The messages shall contain the x,y,z Positon estimated by the Kalman-Filter. I can obtain the Positions and print them to the console by useing DEBUG_PRINT(..). My Problem is that I cannot convert the float values to strings to send them via the P2P-Payload (common functions like sprintf, snprintf aren't working). Any suggestions?
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: P2P Communication; how to send float Values?

Post by kristoffer »

Hi!

The P2PPacket contains a buffer you can write any data you like to, for instance something like this:

typedef struct {
float x;
float y;
float z;
} myType_t;

// Or use one of the types in stabilizer_types.h

// ...

myType_t myData;
myData.x = 17.0f;
myData.y = 47.0f;
myData.z = 11.0f;

memcpy(packet.data, &myData, sizeof(myData));
packet.size = sizeof(myData);

radiolinkSendP2PPacketBroadcast(&packet);
Post Reply