Skip to content
Snippets Groups Projects
Commit e65c0f65 authored by echicken's avatar echicken :chicken:
Browse files

Eh

parent 3e9a14b7
No related branches found
No related tags found
No related merge requests found
......@@ -328,16 +328,6 @@ export default abstract class Device extends js.global.EventEmitter {
if (this.queue.length > 0) js.setTimeout(this.dequeue, 1000, this);
}
private enqueue(buffer: Uint8Array): void {
const now = Date.now();
this.queue.push(buffer);
if (now - this.lastWrite >= 1000 && this.queue.length < 2) {
this.dequeue();
} else {
js.setTimeout(this.dequeue, Math.max(1, 1000 - (now - this.lastWrite)), this);
}
}
/** Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.ToRadio) message to the device */
write(packet: protobuf.Mesh.ToRadio): void {
if (this.debug) this.log(sbbsdefs.LOG_DEBUG, `ToRadio: ${JSON.stringify(packet)}`);
......@@ -345,9 +335,8 @@ export default abstract class Device extends js.global.EventEmitter {
if (data.length > MAXLEN) this.error(`write: packet length ${data.length} exceeds maximum length ${MAXLEN}`);
const header = [START1, START2, (data.length>>8)&0xFF, data.length&0xFF];
const buffer = new Uint8Array([...header, ...data]);
// const res = this.sendToDevice(buffer);
// if (res) this.lastWrite = Date.now();
this.enqueue(buffer);
this.queue.push(buffer);
js.setTimeout(this.dequeue, Math.max(10, 1000 - (Date.now() - this.lastWrite)), this);
}
/** Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.MeshPacket) based on your parameters and writes it to the device. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment