Added additional settings (Wi-Fi, screen blanking, etc.)
This commit is contained in:
84
js/rnode.js
84
js/rnode.js
@@ -710,55 +710,49 @@ class RNode {
|
||||
}
|
||||
|
||||
async setWiFiIP(wifiIP) {
|
||||
if (wifiIP == null) {
|
||||
// Clear IP → 0.0.0.0
|
||||
// If null → clear IP to 0.0.0.0
|
||||
if (wifiIP == null) {
|
||||
await this.sendKissCommand([
|
||||
this.CMD_WIFI_IP,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure it's a string
|
||||
if (typeof wifiIP !== "string") {
|
||||
throw new TypeError("Invalid IP address (not a string)");
|
||||
}
|
||||
|
||||
// Split into octets
|
||||
const parts = wifiIP.trim().split(".");
|
||||
if (parts.length !== 4) {
|
||||
throw new Error("Invalid IP address format");
|
||||
}
|
||||
|
||||
// Convert to byte array
|
||||
const ipBytes = new Uint8Array(4);
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const value = Number(parts[i]);
|
||||
|
||||
if (!Number.isInteger(value) || value < 0 || value > 255) {
|
||||
throw new Error(`Invalid IP octet: ${parts[i]}`);
|
||||
}
|
||||
|
||||
ipBytes[i] = value;
|
||||
}
|
||||
|
||||
// Optional debug check
|
||||
console.log("Setting WiFi IP bytes:", [...ipBytes]);
|
||||
|
||||
// Send command (no manual escaping)
|
||||
await this.sendKissCommand([
|
||||
this.CMD_WIFI_IP,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof wifiIP !== "string") {
|
||||
throw new TypeError("Invalid IP address (not a string)");
|
||||
}
|
||||
|
||||
const octets = wifiIP.split(".");
|
||||
if (octets.length !== 4) {
|
||||
throw new Error("Invalid IP address length");
|
||||
}
|
||||
|
||||
const ipBytes = new Uint8Array(4);
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const octet = Number(octets[i]);
|
||||
|
||||
if (!Number.isInteger(octet) || octet < 0 || octet > 255) {
|
||||
throw new Error("Invalid IP octet value");
|
||||
}
|
||||
|
||||
ipBytes[i] = octet;
|
||||
}
|
||||
|
||||
// KISS escape (same as PSK logic)
|
||||
const escaped = [];
|
||||
for (const byte of ipBytes) {
|
||||
if (byte === this.KISS_FEND) {
|
||||
escaped.push(this.KISS_FESC, this.KISS_TFEND);
|
||||
} else if (byte === this.KISS_FESC) {
|
||||
escaped.push(this.KISS_FESC, this.KISS_TFESC);
|
||||
} else {
|
||||
escaped.push(byte);
|
||||
}
|
||||
}
|
||||
|
||||
// Send command exactly like PSK does
|
||||
await this.sendKissCommand([
|
||||
this.CMD_WIFI_IP,
|
||||
...escaped,
|
||||
...ipBytes
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
async setWiFiNM(wifiNM) {
|
||||
if (wifiNM == null) {
|
||||
// Clear netmask → 0.0.0.0
|
||||
|
||||
Reference in New Issue
Block a user