summaryrefslogtreecommitdiffstats
path: root/assets/js/xymini.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/xymini.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 '')
-rw-r--r--assets/js/xymini.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/assets/js/xymini.js b/assets/js/xymini.js
index a1fd1ca..1b1aaec 100644
--- a/assets/js/xymini.js
+++ b/assets/js/xymini.js
@@ -49,11 +49,11 @@ function crc16(data) {
return crc;
}
-async function detectXYMini(reader) {
+async function detectXYMini(serial) {
const textDecoder = new TextDecoder();
while (true) {
- const { value, done } = await reader.read();
+ const value = await serial.readBytes();
if (value[0] == XYMINI_1K_MAGIC) {
console.log("XYMini: detected");
@@ -91,14 +91,14 @@ function generateXYMiniBlock(blockId, payload) {
return buf;
}
-async function sendXYMini(portReader, portWriter, data, baudRate = 115200, progressCallback) {
+async function sendXYMini(serial, data, progressCallback) {
let blockId = 1;
let size = data.length;
let i = 0;
let nakN = 0;
let wrongCharN = 0;
- await detectXYMini(portReader);
+ await detectXYMini(serial);
while(true) {
const payloadSize = Math.min(PAYLOAD_LEN, size);
@@ -107,12 +107,12 @@ async function sendXYMini(portReader, portWriter, data, baudRate = 115200, progr
const payload = data.slice(i, payloadSize + i);
const block = generateXYMiniBlock(blockId, payload);
- await portWriter.write(block);
+ await serial.writeBytes(block);
} else {
- portWriter.write(new Uint8Array([EOF]));
+ serial.writeBytes(new Uint8Array([EOF]));
}
- const { value, done } = await portReader.read();
+ const value = await serial.readBytes();
if (value[0] == ACK) {
if (!size) {