Open tapanther opened 3 years ago
The DAL has a ManagedString(PacketBuffer) constructor, but in CODAL this is replaced with ManagedString(ManagedBuffer).
To send a string, there is int send(ManagedString data)
To receive a string, I think this will work:
PacketBuffer p = uBit.radio.datagram.recv();
ManagedString s = ManagedString( (const char *) p.getBytes(), p.length());
or
uint8_t buf[ MICROBIT_RADIO_MAX_PACKET_SIZE];
ManagedString s = ManagedString( buf, uBit.radio.datagram.recv( buf, MICROBIT_RADIO_MAX_PACKET_SIZE));
Possible enhancements...?
Add ManagedString recvString()
to MicroBitRadioDatagram
Add an operator to PacketBuffer
operator ManagedString() { return ManagedString( (const char *) ptr->payload, ptr->length); }
Remake PacketBuffer as a subclass of ManagedBuffer
According to the online API, a
ManagedString
can be created from aPacketBuffer
. As I mentioned in #88 thePacketBuffer
API is missing, but I would assume the conversion should be symmetric (afterall what good is sending a string if you can't receive it!)This doesn't work on the latest commit on master though:
There is a constructor from
ManagedBuffer
for , and with some rigamarole you can jump between the two, but it seems like there should be a more straightforward way to send and receive strings via radio.