p2p communication data type

Firmware/software/electronics/mechanics
Post Reply
SH_Lee
Member
Posts: 51
Joined: Tue Feb 18, 2020 8:48 am

p2p communication data type

Post by SH_Lee »

https://www.bitcraze.io/documentation/r ... s/p2p_api/

I'm testing a p2p code.
I successfully conducted several experiments, but I couldn't send data in float format, so I checked the code and I was able to send only 8-bit data.
I want to change this so that 16-bit data can be sent as well, is it too much for the existing radio communication code?

Code: Select all

static P2PPacket pk;
pk.port = 0;
pk.size = 11;
memcpy(pk.data, "Hello World", 11);
radiolinkSendP2PPacketBroadcast(&pk);
Does random alteration of the 'P2Ppacket' data type affect the data loss of communication?
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: p2p communication data type

Post by kimberly »

Yes you can do it. You just have to cast the 16 bit data in the 8 bit array, so each value takes twice the amount of space.

Code: Select all

uint16 arraybig[2] = {270,6000}
memcpy(pk.data. arraybig, 2*sizeof(uint16));
And then you just need to do the same thing on the receiving part.

Code: Select all

uint16 arraybigempty[2];
memcpy(arraybigempty, pk.data, 2*sizeof(uint16));
the size of the copy is 4 bytes (2* sizeof(uint16)); but since you copy it to a uint16 array, it will save it like that.

Just try it out yourself.
Post Reply