From 1340d255e1a2fcb9f6862d8068dadd2d42eff4ec Mon Sep 17 00:00:00 2001 From: liamcottle Date: Tue, 16 Jul 2024 12:58:28 +1200 Subject: [PATCH] configuring tnc mode is working --- index.html | 88 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index d191d4e..9b410e8 100644 --- a/index.html +++ b/index.html @@ -68,7 +68,14 @@
-
5. Configure firmware hash (todo: TNC mode: frequency, bandwidth, tx power, spreading factor, coding rate)
+
5. Set Firmware Hash, for now it uses what the board knows, will fix later.
+ +
+ +
+
6. Configure TNC mode: frequency, bandwidth, tx power, spreading factor, coding rate
@@ -337,10 +344,64 @@ // RNS.log("Setting firmware checksum...") // rnode.set_firmware_hash(partition_hash) + // wait a bit for eeprom writes to complete + await Utils.sleepMillis(5000); + // done await rnode.reset(); await rnode.close(); - console.log("done"); + + alert("device has been provisioned!"); + + }, + async setFirmwareHash() { + + // ask for serial port + const serialPort = await this.askForSerialPort(); + if(!serialPort){ + return; + } + + // check if device is an rnode + const rnode = await RNode.fromSerialPort(serialPort); + const isRNode = await rnode.detect(); + if(!isRNode){ + alert("Selected device is not an RNode!"); + return; + } + + // check if device has been provisioned + const rom = await rnode.getRomAsObject(); + const details = rom.parse(); + if(!details || !details.is_provisioned){ + alert("Eeprom is not provisioned. You must do this first!"); + await rnode.close(); + return; + } + + // log old hashes + console.log({ + old_firmware_hash: await rnode.getFirmwareHash(), + old_target_firmware_hash: await rnode.getTargetFirmwareHash(), + }); + + // todo: this works, but we should be calculating the firmware hash from the file, and not giving the board what it already knows + await rnode.setFirmwareHash(await rnode.getFirmwareHash()); + + // wait a bit for eeprom writes to complete + await Utils.sleepMillis(5000); + + // log new hashes + console.log({ + new_firmware_hash: await rnode.getFirmwareHash(), + new_target_firmware_hash: await rnode.getTargetFirmwareHash(), + }); + + // done + await rnode.reset(); + await rnode.close(); + + alert("firmware hash has been set!"); }, async configure() { @@ -368,17 +429,26 @@ return; } - console.log({ - firmware_hash: await rnode.getFirmwareHash(), - target_firmware_hash: await rnode.getTargetFirmwareHash(), - }); + // todo check if firmware hashes match, as config will not save if device has invalid target hash - // todo: this works, but we should be calculating the firmware hash from the file, and not giving the board what it already knows - await rnode.setFirmwareHash(await rnode.getFirmwareHash()); - await Utils.sleepMillis(5000); + // configure + console.log("configuring"); + await rnode.setFrequency(917375000); + await rnode.setBandwidth(125000); + await rnode.setTxPower(17); + await rnode.setSpreadingFactor(8); + await rnode.setCodingRate(5); + await rnode.setRadioStateOn(); + await rnode.saveConfig(); + console.log("configuring: done"); + // wait a bit for eeprom writes to complete + await Utils.sleepMillis(10000); + + // done await rnode.reset(); await rnode.close(); + alert("Device has been configured!"); }, },