Page 1 of 1

p2p communication data type

Posted: Fri Oct 09, 2020 9:12 am
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?

Re: p2p communication data type

Posted: Mon Oct 12, 2020 9:45 am
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.