summaryrefslogtreecommitdiffstats
path: root/assets/js/rootLantiq.js
diff options
context:
space:
mode:
authorErnesto Castellotti <mail@ernestocastellotti.it>2023-06-09 00:36:09 +0200
committerGitHub <noreply@github.com>2023-06-09 00:36:09 +0200
commit745d8de475e6757d33907db77007126cee920e8a (patch)
treec676b094156eb8498a7faf00982c7c62b507d005 /assets/js/rootLantiq.js
parentConvert changeBaudrate, waitEndImageLoad and flashImageMtd to SerialReadWrite (#229) (diff)
downloadhack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar.gz
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar.bz2
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar.lz
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar.xz
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.tar.zst
hack-gpon.github.io-745d8de475e6757d33907db77007126cee920e8a.zip
Diffstat (limited to 'assets/js/rootLantiq.js')
-rw-r--r--assets/js/rootLantiq.js27
1 files changed, 5 insertions, 22 deletions
diff --git a/assets/js/rootLantiq.js b/assets/js/rootLantiq.js
index 433b060..a3e60b1 100644
--- a/assets/js/rootLantiq.js
+++ b/assets/js/rootLantiq.js
@@ -161,35 +161,18 @@ async function changeBaudrate(port, newBaudrate, currBaudrate, outputErrorCallba
}
async function sendImageMtd(port, data, baudRate, outputErrorCallback, progressCallback) {
- let reader,writer, readableStreamClosed, writerStreamClosed;
+ const serial = new SerialReadWrite(port, baudRate);
try {
- ({ reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate));
- await writer.write(`loady 0x${LOAD_ADDR}\n`);
+ await serial.writeString(`loady 0x${LOAD_ADDR}\n`);
await delay(1000);
- await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); /* XYMini needs reopen the port */
- } catch (err) {
- outputErrorCallback(`Error: ${err.message}`);
- await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed);
- return false;
- }
-
- try {
- await port.open({ baudRate: baudRate });
- reader = port.readable.getReader();
- writer = port.writable.getWriter();
-
- await sendXYMini(reader, writer, data, baudRate, progressCallback);
- await reader.cancel();
- await writer.close();
- await port.close();
+ await sendXYMini(serial, data, progressCallback);
return true;
} catch (err) {
- await reader.cancel();
- await writer.close();
- await port.close();
outputErrorCallback(`Error: ${err.message}`);
return false;
+ } finally {
+ await serial.closePort();
}
}