read radio values
This commit is contained in:
parent
9d1f2e024b
commit
47f9362e5f
@ -82,15 +82,30 @@ namespace radio {
|
|||||||
void readValueToSerial() {
|
void readValueToSerial() {
|
||||||
if (radioEnable() != MICROBIT_OK) return;
|
if (radioEnable() != MICROBIT_OK) return;
|
||||||
PacketBuffer p = uBit.radio.datagram.recv();
|
PacketBuffer p = uBit.radio.datagram.recv();
|
||||||
uint8_t* bytes = packet.getBytes();
|
int length = p.length();
|
||||||
int type;
|
uBit.serial.send("length:");
|
||||||
memcpy(&type, bytes + 28, 4);
|
uBit.serial.send(length);
|
||||||
if (type != RADIO_VALUE_PACKET_TYPE) return;
|
uBit.serial.send("\r\n");
|
||||||
|
if (length < 32) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* bytes = p.getBytes();
|
||||||
|
uint32_t* buf32 = (uint32_t*)bytes;
|
||||||
|
//uint32_t type = buf32[7];
|
||||||
|
//if (type != RADIO_VALUE_PACKET_TYPE)
|
||||||
|
//{
|
||||||
|
// uBit.serial.send("type: ");
|
||||||
|
// uBit.serial.send(type);
|
||||||
|
// uBit.serial.send("\r\n");
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
int serial;
|
int serial;
|
||||||
int time;
|
int time;
|
||||||
char name[12+1]; name[12] = 0;
|
char name[12+1]; name[12] = 0; // memset(name, 0, 13 * sizeof(char));
|
||||||
|
|
||||||
memcpy(&value, bytes, 4);
|
memcpy(&value, bytes, 4);
|
||||||
memcpy(&serial, bytes + 4, 4);
|
memcpy(&serial, bytes + 4, 4);
|
||||||
memcpy(&time, bytes + 8, 4);
|
memcpy(&time, bytes + 8, 4);
|
||||||
|
@ -452,8 +452,8 @@ namespace pxsim.radio {
|
|||||||
export function sendNumbers(value0: number, value1: number, value2: number, value3: number): void {
|
export function sendNumbers(value0: number, value1: number, value2: number, value3: number): void {
|
||||||
board().radio.datagram.send([value0, value1, value2, value3]);
|
board().radio.datagram.send([value0, value1, value2, value3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendValue(name:string, value: number) {
|
export function streamValue(name: string, value: number) {
|
||||||
board().radio.datagram.send([value]);
|
board().radio.datagram.send([value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user