New Radio API (#287)

* Adding radio API for receiving a packet

* More new radio API changes

* renaming some properties

* Redoing radio packet parsing and updating new callback api
This commit is contained in:
Richard Knoll
2016-10-24 12:55:44 -07:00
committed by Peli de Halleux
parent 3ccc8b7db3
commit 79c89b832a
4 changed files with 383 additions and 128 deletions

65
libs/radio/shims.d.ts vendored
View File

@ -25,7 +25,8 @@ declare namespace radio {
function sendValue(name: string, value: number): void;
/**
* Broadcasts a number over radio to any connected micro:bit in the group.
* Broadcasts a string along with the device serial number
* and running time to any connected micro:bit in the group.
*/
//% help=radio/send-string
//% weight=58
@ -33,8 +34,8 @@ declare namespace radio {
function sendString(msg: string): void;
/**
* Reads a value sent with `stream value` and writes it
* to the serial stream as JSON
* Reads the next packet from the radio queue and and writes it to serial
* as JSON.
*/
//% help=radio/write-value-to-serial
//% weight=3
@ -43,19 +44,13 @@ declare namespace radio {
function writeValueToSerial(): void;
/**
* Reads a number at a given index, between ``0`` and ``3``, from the packet received by ``receive number``. Not supported in simulator.
* @param index index of the number to read from 0 to 3. 1 eg
*/
//% help=radio/received-number-at
//% weight=45 debug=true shim=radio::receivedNumberAt
function receivedNumberAt(index: number): number;
/**
* Reads the next packet as a number from the radio queue.
* Reads the next packet from the radio queue and returns the packet's number
* payload or 0 if the packet did not contain a number.
*/
//% help=radio/receive-number
//% weight=46
//% blockId=radio_datagram_receive block="radio receive number" blockGap=8 shim=radio::receiveNumber
//% blockId=radio_datagram_receive block="radio receive number" blockGap=8
//% advanced=true shim=radio::receiveNumber
function receiveNumber(): number;
/**
@ -63,19 +58,23 @@ declare namespace radio {
*/
//% help=radio/on-data-received
//% weight=50
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8 shim=radio::onDataReceived
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8
//% advanced=true shim=radio::onDataReceived
function onDataReceived(body: () => void): void;
/**
* Reads the next packet as a string and returns it.
* Reads the next packet from the radio queue and returns the packet's string
* payload or the empty string if the packet did not contain a string.
*/
//% blockId=radio_datagram_receive_string block="radio receive string" blockGap=8
//% weight=44
//% help=radio/receive-string shim=radio::receiveString
//% help=radio/receive-string
//% advanced=true shim=radio::receiveString
function receiveString(): string;
/**
* Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.
* Gets the received signal strength indicator (RSSI) from the last packet taken
* from the radio queue (via ``receiveNumber``, ``receiveString``, etc). Not supported in simulator.
* namespace=radio
*/
//% help=radio/received-signal-strength
@ -112,6 +111,38 @@ declare namespace radio {
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit"
//% advanced=true shim=radio::setTransmitSerialNumber
function setTransmitSerialNumber(transmit: boolean): void;
/**
* Returns the number payload from the last packet taken from the radio queue
* (via ``receiveNumber``, ``receiveString``, etc) or 0 if that packet did not
* contain a number.
*/
//% help=radio/received-number shim=radio::receivedNumber
function receivedNumber(): number;
/**
* Returns the serial number of the sender micro:bit from the last packet taken
* from the radio queue (via ``receiveNumber``, ``receiveString``, etc) or 0 if
* that packet did not send a serial number.
*/
//% help=radio/received-serial shim=radio::receivedSerial
function receivedSerial(): number;
/**
* Returns the string payload from the last packet taken from the radio queue
* (via ``receiveNumber``, ``receiveString``, etc) or the empty string if that
* packet did not contain a string.
*/
//% help=radio/received-string shim=radio::receivedString
function receivedString(): string;
/**
* Returns the system time of the sender micro:bit at the moment when it sent the
* last packet taken from the radio queue (via ``receiveNumber``,
* ``receiveString``, etc).
*/
//% help=radio/received-time shim=radio::receivedTime
function receivedTime(): number;
}
// Auto-generated. Do not edit. Really.