From 464daa22264ca8c93701d0810d2a8aaf32c6bf54 Mon Sep 17 00:00:00 2001 From: Ernesto Castellotti Date: Wed, 11 Jan 2023 19:16:39 +0100 Subject: Add sfpModel parameter and remove successCallback --- _ont/ont-huawei-ma5671a-root-web.md | 20 ++++++++++++-------- assets/js/rootLantiq.js | 26 +++++++++++++------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/_ont/ont-huawei-ma5671a-root-web.md b/_ont/ont-huawei-ma5671a-root-web.md index efb0d85..18652d7 100644 --- a/_ont/ont-huawei-ma5671a-root-web.md +++ b/_ont/ont-huawei-ma5671a-root-web.md @@ -185,31 +185,35 @@ FALCON => saveenv return; } - await lantiqRootUboot(port, + let result = await lantiqRootUboot(port, "Huawei MA5671A", (msg) => { loading(msg, 0); }, (err) => { showError(err, 0); console.log(err); - }, - () => { - showSuccess("Congratulations! Step completed.", 0); } ); - await unlockHuaweiShell(port, + if (result) { + showSuccess("Congratulations! Step completed.", 0); + } else { + return; + } + + result = await unlockHuaweiShell(port, (msg) => { loading(msg, 1); }, (err) => { showError(err, 1); console.log(err); - }, - () => { - showSuccess("Congratulations! Step completed.", 1); } ); + + if (result) { + showSuccess("Congratulations! Step completed.", 1); + } } diff --git a/assets/js/rootLantiq.js b/assets/js/rootLantiq.js index d68d314..480cf6e 100644 --- a/assets/js/rootLantiq.js +++ b/assets/js/rootLantiq.js @@ -1,4 +1,4 @@ -async function waitUbootStop(writer, reader, outputMsgCallback) { +async function waitUbootStop(writer, reader, sfpModel, outputMsgCallback) { const interval = setInterval(function() { writer.write(String.fromCharCode(3)); }, 10); @@ -7,7 +7,7 @@ async function waitUbootStop(writer, reader, outputMsgCallback) { const { value, done } = await reader.read(); if (value.startsWith('U-Boot')) { - outputMsgCallback("Root in progress: Trigger characters received. DO NOT TOUCH THE HUAWEI MA5671A UNTIL THE PROCEDURE IS COMPLETED!"); + outputMsgCallback(`Root in progress: Trigger characters received. DO NOT TOUCH THE ${sfpModel} UNTIL THE PROCEDURE IS COMPLETED!`); await delay(5000); clearInterval(interval); break; @@ -63,17 +63,17 @@ async function waitFailbackShell(writer, reader, outputMsgCallback) { } } -async function lantiqRootUboot(port, outputMsgCallback, outputErrorCallback, successCallback, baudRate = 115200) { - outputMsgCallback("Please disconnect the Huawei MA5671A from the SFP adapter if it is currently plugged in!"); +async function lantiqRootUboot(port, sfpModel, outputMsgCallback, outputErrorCallback, baudRate = 115200) { + outputMsgCallback(`Please disconnect the ${sfpModel} from the SFP adapter if it is currently plugged in!`); const { reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate, outputErrorCallback); try { await delay(10000); - outputMsgCallback("Now you need to insert the Huawei MA5671A into the SFP adapter, if the procedure does not go ahead, check the connections and then remove and reconnect the Huawei MA5671A again",0); + outputMsgCallback(`Now you need to insert the ${sfpModel} into the SFP adapter, if the procedure does not go ahead, check the connections and then remove and reconnect the ${sfpModel} again`); while(true) { - await waitUbootStop(writer, reader, outputMsgCallback); + await waitUbootStop(writer, reader, sfpModel, outputMsgCallback); const ubootUnlocked = await checkUbootUnlocked(reader); if (ubootUnlocked == true) { @@ -97,16 +97,16 @@ async function lantiqRootUboot(port, outputMsgCallback, outputErrorCallback, suc await delay(1000); } - successCallback(); + await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); + return true; } catch (err) { outputErrorCallback(`Error: ${err.message}`); - } finally { await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); - return; + return false; } } -async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, successCallback, baudRate = 115200) { +async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, baudRate = 115200) { const { reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate, outputErrorCallback); try { @@ -121,11 +121,11 @@ async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, s outputMsgCallback("Root in progress: Umount rootfs partitions..."); writer.write('umount /overlay && umount -a\n'); await delay(1000); - successCallback(); + await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); + return true; } catch (err) { outputErrorCallback(`Error: ${err.message}`); - } finally { await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); - return; + return false; } } -- cgit v1.2.3