From 55f9ea114b3c8b48094118e025877d76eb6eadc0 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 14 Feb 2023 08:53:38 -1000 Subject: [PATCH 1/3] Update handling of settings during command mode and training --- Firmware/LoRaSerial/States.ino | 79 +++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index 8e519494..e7ec6b54 100644 --- a/Firmware/LoRaSerial/States.ino +++ b/Firmware/LoRaSerial/States.ino @@ -1483,33 +1483,43 @@ void updateRadioState() //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /* - beginTrainingClient - | - | Save current settings - | - V - +<--------------------------------. - | | - | Send FIND_PARTNER | - | | - V | - RADIO_TRAIN_WAIT_TX_FIND_PARTNER_DONE | - | | - V | Timeout - RADIO_TRAIN_WAIT_RX_RADIO_PARAMETERS -----' - | - | Save settings - | Send ACK + + 2 Second Button Press ATT Command + | | + | | + +--------------------------------------------' | V - RADIO_TRAIN_WAIT_TX_ACK_DONE + commandSaveSettings | V - endTrainingClientServer - | - | Reboot + beginTrainingClient | V + +<--------------------------------------. + | | + | Send FIND_PARTNER | + | | Timeout + V | + RADIO_TRAIN_WAIT_TX_FIND_PARTNER_DONE | + | | + V | + RADIO_TRAIN_WAIT_RX_RADIO_PARAMETERS ---------->+ + | | + | RX RADIO_PARAMETERS | + | ATO | or 2 Second + | Send ACK ATZ | Button Push + V | && (! Command Mode) + RADIO_TRAIN_WAIT_TX_ACK_DONE | + | V + V commandRestoreSettings(writeOnCommandExit) + endTrainingClientServer | + | | + | | + | commandRestoreSettings(true) | + V V + Reboot Return to + Previous mode */ //==================== @@ -1629,9 +1639,19 @@ void updateRadioState() //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /* - beginTrainingServer + + Command Mode 5 second button press + | | + | ATT | + | | + V | + +<---------------------' + | + V + commandSaveSettings | - | Save current settings + V + beginTrainingServer | V +<--------------------------------. @@ -1645,12 +1665,21 @@ void updateRadioState() | RADIO_TRAIN_WAIT_TX_RADIO_PARAMS_DONE -----' | | + | ATO, ATZ or (2 second training button press && ! command mode) + | `---------------. - | ATZ command | - | Reboot + V + commandRestoreSettings(writeOnCommandExit) | V + +----------------------------. + | | + | ATZ command | ATO command + | | + V V + Reboot Return to + Previous Mode */ //==================== From c2bc1ccc3361f1605e6110d2e244943b3a74e576 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 14 Feb 2023 18:18:28 -1000 Subject: [PATCH 2/3] NVM: Add erase function --- Firmware/LoRaSerial/NVM.ino | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Firmware/LoRaSerial/NVM.ino b/Firmware/LoRaSerial/NVM.ino index 46460446..5eb7e703 100644 --- a/Firmware/LoRaSerial/NVM.ino +++ b/Firmware/LoRaSerial/NVM.ino @@ -198,3 +198,29 @@ void nvmSaveVcUniqueId(int8_t vc) if (memcmp(id, virtualCircuitList[vc].uniqueId, sizeof(id)) != 0) nvmSaveUniqueId(vc, virtualCircuitList[vc].uniqueId); } + +//Erase the entire EEPROM +void nvmErase() +{ + int address; + int length; + uint8_t value[64]; + + //Get the EEPROM length + length = EEPROM.length(); + + //Set the erase value + memset(&value, NVM_ERASE_VALUE, sizeof(value)); + + //Erase the EEPROM + address = 0; + while (address < length) + { + petWDT(); + EEPROM.put(address, value); + address += sizeof(value); + } + + //Finish the write + arch.eepromCommit(); +} From 0d5c160c972c9bf5c3b8b3fc4728567bf81157fa Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 15 Feb 2023 17:01:57 -1000 Subject: [PATCH 3/3] Training: Remove switch to server from client --- Firmware/LoRaSerial/LoRaSerial.ino | 3 --- Firmware/LoRaSerial/States.ino | 21 ++------------------- Firmware/LoRaSerial/System.ino | 5 ----- Firmware/LoRaSerial/Train.ino | 6 ------ 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index c56a67c0..0c90addb 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -507,9 +507,6 @@ unsigned long retransmitTimeout = 0; //Throttle back re-transmits //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- const Settings defaultSettings; Settings tempSettings; //Create a duplicate of settings during training so that we can resort as needed -uint8_t originalEncryptionKey[AES_KEY_BYTES] = {0}; //Temp store key if we need to exit button training -uint8_t originalNetID = 0; //Temp store ID if we need to exit button training -bool originalServer = false; //Temp store server setting if we need to exit button training char platformPrefix[25]; //Used for printing platform specific device name, ie "SAMD21 1W 915MHz" //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index e7ec6b54..08028fc6 100644 --- a/Firmware/LoRaSerial/States.ino +++ b/Firmware/LoRaSerial/States.ino @@ -1599,24 +1599,7 @@ void updateRadioState() //Check for a receive timeout else if ((millis() - datagramTimer) > (settings.clientFindPartnerRetryInterval * 1000)) { - //If we are training with button, in P2P mode, and user has not set server mode - //Automatically switch to server - if (trainViaButton - && tempSettings.operatingMode == MODE_POINT_TO_POINT - && originalServer == false) - { - //Give up and change to Server automatically - - settings = tempSettings; //Return to original radio settings - - generateRandomKeysID(); //Generate random netID and AES key - - beginTrainingServer(); //Change to server - } - else - { - xmitDatagramTrainingFindPartner(); //Continue retrying as client - } + xmitDatagramTrainingFindPartner(); } break; @@ -1736,7 +1719,7 @@ void updateRadioState() //then reboot with current settings after a single client acks if (trainViaButton && tempSettings.operatingMode == MODE_POINT_TO_POINT - && originalServer == false) + && tempSettings.server == false) { //Reboot the radio with the newly generated random netID/Key parameters petWDT(); diff --git a/Firmware/LoRaSerial/System.ino b/Firmware/LoRaSerial/System.ino index 7daf84b4..22c282d3 100644 --- a/Firmware/LoRaSerial/System.ino +++ b/Firmware/LoRaSerial/System.ino @@ -278,11 +278,6 @@ void updateButton() { settings = tempSettings; //Return to original radio settings - //Return to original keys, ID, and server state - memcpy(&settings.encryptionKey, &originalEncryptionKey, AES_KEY_BYTES); - settings.netID = originalNetID; - settings.server = originalServer; - recordSystemSettings(); //Record original settings //Reboot the radio diff --git a/Firmware/LoRaSerial/Train.ino b/Firmware/LoRaSerial/Train.ino index 7d0b7543..bb8ae162 100644 --- a/Firmware/LoRaSerial/Train.ino +++ b/Firmware/LoRaSerial/Train.ino @@ -1,12 +1,6 @@ //Select the training protocol void selectTraining() { - //If we are training via button, and in P2P mode, and Server is not set - //we will need these settings if we exit training - memcpy(&originalEncryptionKey, &settings.encryptionKey, AES_KEY_BYTES); - originalNetID = settings.netID; - originalServer = settings.server; - if (settings.server) beginTrainingServer(); else