Missing simulator functions and behavior (#1025)

This commit is contained in:
Richard Knoll 2018-08-02 10:33:05 -07:00 committed by GitHub
parent 6884b2bedf
commit 49cd197cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View File

@ -35,6 +35,10 @@ namespace pxsim.basic {
namespace pxsim.control { namespace pxsim.control {
export var inBackground = thread.runInBackground; export var inBackground = thread.runInBackground;
export function createBuffer(sz: number) {
return pxsim.BufferMethods.createBuffer(sz)
}
export function reset() { export function reset() {
U.userError("reset not implemented in simulator yet") U.userError("reset not implemented in simulator yet")
} }

View File

@ -6,6 +6,11 @@ namespace pxsim {
time: number; time: number;
} }
// Extends interface in pxt-core
export interface SimulatorRadioPacketPayload {
bufferData?: Uint8Array;
}
export class RadioDatagram { export class RadioDatagram {
datagram: PacketBuffer[] = []; datagram: PacketBuffer[] = [];
lastReceived: PacketBuffer = RadioDatagram.defaultPacket(); lastReceived: PacketBuffer = RadioDatagram.defaultPacket();
@ -24,7 +29,7 @@ namespace pxsim {
const b = board(); const b = board();
Runtime.postMessage(<SimulatorRadioPacketMessage>{ Runtime.postMessage(<SimulatorRadioPacketMessage>{
type: "radiopacket", type: "radiopacket",
rssi: 70, // Not yet supported rssi: -42, // -42 is the strongest signal
serial: b.radioState.bus.transmitSerialNumber ? pxsim.control.deviceSerialNumber() : 0, serial: b.radioState.bus.transmitSerialNumber ? pxsim.control.deviceSerialNumber() : 0,
time: new Date().getTime(), time: new Date().getTime(),
payload payload
@ -154,8 +159,7 @@ namespace pxsim.radio {
board().radioState.bus.datagram.send({ board().radioState.bus.datagram.send({
type: PacketPayloadType.STRING, type: PacketPayloadType.STRING,
groupId: board().radioState.groupId, groupId: board().radioState.groupId,
// TODO: (microbit master) bufferData: data
//bufferData: data
}); });
} }
@ -212,10 +216,9 @@ namespace pxsim.radio {
return initString(board().radioState.bus.datagram.lastReceived.payload.stringData || ""); return initString(board().radioState.bus.datagram.lastReceived.payload.stringData || "");
} }
// TODO: (microbit master) export function receivedBuffer(): RefBuffer {
// export function receivedBuffer(): RefBuffer { return new RefBuffer(board().radioState.bus.datagram.lastReceived.payload.bufferData || new Uint8Array(0))
// return new RefBuffer(board().radioState.bus.datagram.lastReceived.payload.bufferData || new Uint8Array(0)) }
// }
export function receivedTime(): number { export function receivedTime(): number {
return board().radioState.bus.datagram.lastReceived.time; return board().radioState.bus.datagram.lastReceived.time;

View File

@ -57,4 +57,8 @@ namespace pxsim.serial {
export function redirectToUSB() { export function redirectToUSB() {
// TODO // TODO
} }
export function readBuffer(length: number) {
return pins.createBuffer(length);
}
} }