From 08889533f4ba44815904fc748b2639ac44f6bfe1 Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Sun, 14 Jul 2024 08:44:09 +0800 Subject: [PATCH] added various fixes for simple network --- simpleadmin/www/js/parse-settings.js | 135 ++++++++++++++++----------- simpleadmin/www/network.html | 47 +++++++--- 2 files changed, 114 insertions(+), 68 deletions(-) diff --git a/simpleadmin/www/js/parse-settings.js b/simpleadmin/www/js/parse-settings.js index 409cbd5..1262349 100644 --- a/simpleadmin/www/js/parse-settings.js +++ b/simpleadmin/www/js/parse-settings.js @@ -1,60 +1,87 @@ function parseCurrentSettings(rawdata) { - const data = rawdata; + const data = rawdata; - const lines = data.split("\n"); - console.log(lines); + const lines = data.split("\n"); + console.log(lines); - // Remove QUIMSLOT and only take 1 or 2 - this.sim = lines[1].split(":")[1].trim(); - this.apn = lines[3].split(",")[2].replace(/\"/g, ""); - this.cellLock4GStatus = lines[5].split(",")[1].replace(/\"/g, ""); - this.cellLock5GStatus = lines[7].split(",")[1].replace(/\"/g, ""); - this.prefNetwork = lines[9].split(",")[1].replace(/\"/g, ""); - this.nrModeControlStatus = lines[11].split(",")[1].replace(/\"/g, ""); + // Remove QUIMSLOT and only take 1 or 2 + this.sim = lines + .find( + (line) => line.includes("QUIMSLOT: 1") || line.includes("QUIMSLOT: 2") + ) + .split(":")[1] + // remove spaces + .replace(/\s/g, ""); + // .replace(/\"/g, ""); - - let bands = []; - - // Append the values if there is separated by comma with a space. - // i.e. LTE BAND 3, LTE BAND 1 - for (let i = 13; i < 17; i++) { - if (lines[i].split(",").length > 1) { - bands.push(lines[i].split(",")[3].replace(/\"/g, " ")); - } - } - - this.bands = bands; - - - if (this.cellLock4GStatus == 1 && this.cellLock5GStatus == 1) { - this.cellLockStatus = "Locked to 4G and 5G"; - } else if (this.cellLock4GStatus == 1) { - this.cellLockStatus = "Locked to 4G"; - } - else if (this.cellLock5GStatus == 1) { - this.cellLockStatus = "Locked to 5G"; - } - else { - this.cellLockStatus = "Not Locked"; - } - - if (this.nrModeControlStatus == 0) { - this.nrModeControlStatus = "Not Disabled"; - } - else if (this.nrModeControlStatus == 1) { - this.nrModeControlStatus = "SA Disabled"; - } - else { - this.nrModeControlStatus = "NSA Disabled"; - } - - return { - sim: sim, - apn: apn, - cellLockStatus: cellLockStatus, - prefNetwork: prefNetwork, - nrModeControl: nrModeControlStatus, - bands: bands - }; + try { + this.apn = lines + .find((line) => line.includes("+CGCONTRDP: 1,0")) + .split(",")[2] + .replace(/\"/g, ""); + } catch (error) { + this.apn = "Failed fetching APN"; } + this.cellLock4GStatus = lines + .find((line) => line.includes('+QNWLOCK: "common/4g"')) + .split(",")[1] + .replace(/\"/g, ""); + + this.cellLock5GStatus = lines + .find((line) => line.includes('+QNWLOCK: "common/5g"')) + .split(",")[1] + .replace(/\"/g, ""); + + this.prefNetwork = lines + .find((line) => line.includes('+QNWPREFCFG: "mode_pref"')) + .split(",")[1] + .replace(/\"/g, ""); + + this.nrModeControlStatus = lines + .find((line) => line.includes('+QNWPREFCFG: "nr5g_disable_mode"')) + .split(",")[1] + .replace(/\"/g, ""); + + this.apnIP = lines + .find((line) => line.includes("+CGDCONT: 1")) + .split(",")[1] + .replace(/\"/g, ""); + + try { + this.bands = lines + .find((line) => line.includes("+QCAINFO:")) + .split(",")[3] + .replace(/\"/g, ""); + } catch (error) { + this.bands = "Failed fetching bands"; + } + + if (this.cellLock4GStatus == 1 && this.cellLock5GStatus == 1) { + this.cellLockStatus = "Locked to 4G and 5G"; + } else if (this.cellLock4GStatus == 1) { + this.cellLockStatus = "Locked to 4G"; + } else if (this.cellLock5GStatus == 1) { + this.cellLockStatus = "Locked to 5G"; + } else { + this.cellLockStatus = "Not Locked"; + } + + if (this.nrModeControlStatus == 0) { + this.nrModeControlStatus = "Not Disabled"; + } else if (this.nrModeControlStatus == 1) { + this.nrModeControlStatus = "SA Disabled"; + } else { + this.nrModeControlStatus = "NSA Disabled"; + } + + return { + sim: sim, + apn: apn, + apnIP: apnIP, + cellLockStatus: cellLockStatus, + prefNetwork: prefNetwork, + nrModeControl: nrModeControlStatus, + bands: bands, + }; +} diff --git a/simpleadmin/www/network.html b/simpleadmin/www/network.html index 9c03b54..714c75d 100644 --- a/simpleadmin/www/network.html +++ b/simpleadmin/www/network.html @@ -160,26 +160,26 @@ /> - +
@@ -465,6 +465,8 @@ scs: null, band: null, apn: "-", + apnIP: "-", + newApnIP: null, newApn: null, prefNetwork: "-", prefNetworkMode: null, @@ -608,16 +610,20 @@ }, getCurrentSettings() { const atcmd = - 'AT+QUIMSLOT?;+CGCONTRDP=1;+QNWLOCK="common/4g";+QNWLOCK="common/5g";+QNWPREFCFG="mode_pref";+QNWPREFCFG="nr5g_disable_mode";+QCAINFO'; + 'AT+QUIMSLOT?;+CGCONTRDP=1;+QNWLOCK="common/4g";+QNWLOCK="common/5g";+QNWPREFCFG="mode_pref";+QNWPREFCFG="nr5g_disable_mode";+QCAINFO;+CGDCONT?'; this.sendATcommand(atcmd).then((rawdata) => { + console.log(rawdata); const settings = parseCurrentSettings(rawdata); this.sim = settings.sim; this.apn = settings.apn; + this.apnIP = settings.apnIP; this.cellLockStatus = settings.cellLockStatus; this.prefNetwork = settings.prefNetwork; this.nrModeControl = settings.nrModeControl; this.bands = settings.bands; + + console.log(settings); }); }, lockSelectedBands() { @@ -701,8 +707,21 @@ ATNetwork = ""; ATNRMode = ""; + console.log(this.newApnIP); + if (newApn !== null) { - atAPN = `+CGDCONT=1,"IP","${newApn}";`; + if (this.newApnIP === "1") { + atAPN = `+CGDCONT=1,"IPV4","${newApn}";`; + } else if (this.newApnIP === "2") { + atAPN = `+CGDCONT=1,"IPV6","${newApn}";`; + } else if (this.newApnIP === "3") { + atAPN = `+CGDCONT=1,"IPV4V6","${newApn}";`; + } else if (this.newApnIP === "4") { + atAPN = `+CGDCONT=1,"PPP","${newApn}";`; + } else { + console.log("No changes made"); + atAPN = `+CGDCONT=1,"IPV4V6","${newApn}";`; + } } if (newSim !== null) {