mirror of
https://github.com/meshcore-dev/flasher.meshcore.dev.git
synced 2026-04-20 22:13:50 +00:00
config.json, img: added new devices
js+html: added url navigation, "notice" support
This commit is contained in:
parent
e023661bbc
commit
e3e09b4b11
19 changed files with 1390 additions and 175 deletions
45
lib/dfu.js
45
lib/dfu.js
|
|
@ -80,30 +80,7 @@ function calcCrc16(data, crc = 0xFFFF) {
|
|||
}
|
||||
|
||||
function sleep(milliseconds) {
|
||||
return new Promise((resolve) => {
|
||||
const startTime = performance.now();
|
||||
const targetTime = startTime + milliseconds;
|
||||
|
||||
function checkTime() {
|
||||
if (performance.now() >= targetTime) {
|
||||
resolve();
|
||||
} else {
|
||||
requestAnimationFrame(checkTime);
|
||||
}
|
||||
}
|
||||
|
||||
const initialDelay = Math.max(0, milliseconds - 16); // Wake up ~1 frame early to start polling
|
||||
|
||||
if (initialDelay > 0) {
|
||||
setTimeout(() => {
|
||||
// Now start the more precise polling
|
||||
checkTime();
|
||||
}, initialDelay);
|
||||
} else {
|
||||
// If the desired sleep is very short, go straight to polling
|
||||
checkTime();
|
||||
}
|
||||
});
|
||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
// --- HciPacket Class (adapted from dfu/dfu_transport_serial.py) ---
|
||||
|
|
@ -219,15 +196,22 @@ export class Dfu {
|
|||
}
|
||||
catch(e) {
|
||||
HciPacket.sequenceNumber = 0;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
reader.releaseLock();
|
||||
}
|
||||
// Decode SLIP
|
||||
const decodedData = this.decodeSlip(buffer);
|
||||
|
||||
// Extract ACK number (assuming it's in the decoded data)
|
||||
if (decodedData.length < 2) { // Check for sufficient length
|
||||
// Extract the SLIP frame between the two 0xC0 delimiters, ignoring any
|
||||
// stale bytes that arrived before the opening delimiter.
|
||||
const firstC0 = buffer.indexOf(0xC0);
|
||||
const secondC0 = buffer.indexOf(0xC0, firstC0 + 1);
|
||||
if (firstC0 === -1 || secondC0 === -1) {
|
||||
throw new Error("Received incomplete ACK.");
|
||||
}
|
||||
const decodedData = this.decodeSlip(buffer.slice(firstC0 + 1, secondC0));
|
||||
|
||||
if (decodedData.length < 2) {
|
||||
throw new Error("Received incomplete ACK.");
|
||||
}
|
||||
const ack = (decodedData[0] >> 3) & 0x07;
|
||||
|
|
@ -358,6 +342,10 @@ export class Dfu {
|
|||
}
|
||||
|
||||
let bytesSent = 0;
|
||||
// Brief stabilization pause before starting data transfer (mirrors Python's implicit
|
||||
// pause at count=0 — it sleeps FLASH_PAGE_WRITE_TIME after the very first packet).
|
||||
await sleep(FLASH_PAGE_WRITE_TIME * 1000);
|
||||
|
||||
// Send firmware packets
|
||||
for (const [index, pkt] of frames.entries()) {
|
||||
await this.sendPacket(pkt);
|
||||
|
|
@ -388,6 +376,7 @@ export class Dfu {
|
|||
}
|
||||
this.transferInProgress = true;
|
||||
this.lastAck = -1; // Reset last ACK
|
||||
HciPacket.sequenceNumber = 0; // Reset HCI sequence number
|
||||
const decoder = new TextDecoder();
|
||||
try {
|
||||
await this.port.open({ baudRate: 115200 }); // Open with correct baudrate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue