fsdfds
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
MicroBitRadioDatagram Class Reference
Provides a simple broadcast radio abstraction, built upon the raw nrf51822 RADIO module. More...
#include <MicroBitRadioDatagram.h>
Public Member Functions | |
MicroBitRadioDatagram (MicroBitRadio &r) | |
Constructor. | |
int | recv (uint8_t *buf, int len) |
Retrieves packet payload data into the given buffer. | |
PacketBuffer | recv () |
Retreives packet payload data into the given buffer. | |
int | send (uint8_t *buffer, int len) |
Transmits the given buffer onto the broadcast radio. | |
int | send (PacketBuffer data) |
Transmits the given string onto the broadcast radio. | |
int | send (ManagedString data) |
Transmits the given string onto the broadcast radio. | |
void | packetReceived () |
Protocol handler callback. |
Detailed Description
Provides a simple broadcast radio abstraction, built upon the raw nrf51822 RADIO module.
This class provides the ability to broadcast simple text or binary messages to other micro:bits in the vicinity It is envisaged that this would provide the basis for children to experiment with building their own, simple, custom protocols.
- Note:
- This API does not contain any form of encryption, authentication or authorisation. Its purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. For serious applications, BLE should be considered a substantially more secure alternative.
Definition at line 45 of file MicroBitRadioDatagram.h.
Constructor & Destructor Documentation
MicroBitRadioDatagram | ( | MicroBitRadio & | r ) |
Constructor.
Provides a simple broadcast radio abstraction, built upon the raw nrf51822 RADIO module.
Creates an instance of a MicroBitRadioDatagram which offers the ability to broadcast simple text or binary messages to other micro:bits in the vicinity
- Parameters:
-
r The underlying radio module used to send and receive data.
This class provides the ability to broadcast simple text or binary messages to other micro:bits in the vicinity It is envisaged that this would provide the basis for children to experiment with building their own, simple, custom protocols.
- Note:
- This API does not contain any form of encryption, authentication or authorisation. Its purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. For serious applications, BLE should be considered a substantially more secure alternative. Constructor.
Creates an instance of a MicroBitRadioDatagram which offers the ability to broadcast simple text or binary messages to other micro:bits in the vicinity
- Parameters:
-
r The underlying radio module used to send and receive data.
Definition at line 49 of file MicroBitRadioDatagram.cpp.
Member Function Documentation
void packetReceived | ( | ) |
Protocol handler callback.
This is called when the radio receives a packet marked as a datagram.
This function process this packet, and queues it for user reception.
Definition at line 172 of file MicroBitRadioDatagram.cpp.
PacketBuffer recv | ( | ) |
Retreives packet payload data into the given buffer.
If a data packet is already available, then it will be returned immediately to the caller in the form of a PacketBuffer.
- Returns:
- the data received, or an empty PacketBuffer if no data is available.
Definition at line 92 of file MicroBitRadioDatagram.cpp.
int recv | ( | uint8_t * | buf, |
int | len | ||
) |
Retrieves packet payload data into the given buffer.
If a data packet is already available, then it will be returned immediately to the caller. If no data is available then MICROBIT_INVALID_PARAMETER is returned.
- Parameters:
-
buf A pointer to a valid memory location where the received data is to be stored len The maximum amount of data that can safely be stored in 'buf'
- Returns:
- The length of the data stored, or MICROBIT_INVALID_PARAMETER if no data is available, or the memory regions provided are invalid.
Definition at line 66 of file MicroBitRadioDatagram.cpp.
int send | ( | PacketBuffer | data ) |
Transmits the given string onto the broadcast radio.
This is a synchronous call that will wait until the transmission of the packet has completed before returning.
- Parameters:
-
data The packet contents to transmit.
- Returns:
- MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the buffer is invalid, or the number of bytes to transmit is greater than `MICROBIT_RADIO_MAX_PACKET_SIZE + MICROBIT_RADIO_HEADER_SIZE`.
Definition at line 146 of file MicroBitRadioDatagram.cpp.
int send | ( | ManagedString | data ) |
Transmits the given string onto the broadcast radio.
This is a synchronous call that will wait until the transmission of the packet has completed before returning.
- Parameters:
-
data The packet contents to transmit.
- Returns:
- MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the buffer is invalid, or the number of bytes to transmit is greater than `MICROBIT_RADIO_MAX_PACKET_SIZE + MICROBIT_RADIO_HEADER_SIZE`.
Definition at line 162 of file MicroBitRadioDatagram.cpp.
int send | ( | uint8_t * | buffer, |
int | len | ||
) |
Transmits the given buffer onto the broadcast radio.
This is a synchronous call that will wait until the transmission of the packet has completed before returning.
- Parameters:
-
buffer The packet contents to transmit. len The number of bytes to transmit.
- Returns:
- MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the buffer is invalid, or the number of bytes to transmit is greater than `MICROBIT_RADIO_MAX_PACKET_SIZE + MICROBIT_RADIO_HEADER_SIZE`.
Definition at line 119 of file MicroBitRadioDatagram.cpp.
Generated on Wed Jul 13 2022 00:58:04 by 1.7.2