From 69de24171ccc4ae6258013d680bae9f98663f824 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Feb 2023 09:05:58 -1000 Subject: [PATCH 1/4] Move settings into LoRaSerial with other settings --- Firmware/LoRaSerial/LoRaSerial.ino | 1 + Firmware/LoRaSerial/settings.h | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index 02345167..718cafbc 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -509,6 +509,7 @@ unsigned long retransmitTimeout = 0; //Throttle back re-transmits //Global variables //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- const Settings defaultSettings; +Settings settings; //Active settings used by the radio Settings tempSettings; //Create a duplicate of settings during training so that we can resort as needed char platformPrefix[25]; //Used for printing platform specific device name, ie "SAMD21 1W 915MHz" diff --git a/Firmware/LoRaSerial/settings.h b/Firmware/LoRaSerial/settings.h index f0bae7e3..77df43bb 100644 --- a/Firmware/LoRaSerial/settings.h +++ b/Firmware/LoRaSerial/settings.h @@ -19,7 +19,7 @@ typedef enum RADIO_DISCOVER_SCANNING, RADIO_DISCOVER_WAIT_TX_FIND_PARTNER_DONE, RADIO_DISCOVER_STANDBY, - + //Multi-Point: Datagrams RADIO_MP_STANDBY, RADIO_MP_WAIT_TX_DONE, @@ -518,7 +518,6 @@ typedef struct struct_settings { //-- Add commands to set the parameters //-- Add parameters to routine updateRadioParameters } Settings; -Settings settings; //Monitor which devices on the device are on or offline. struct struct_online { From 628d486a4be3cd42f1e84da90cd3310a1c9abfb8 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Feb 2023 08:51:57 -1000 Subject: [PATCH 2/4] Pass settings address to generateRandomKeysID --- Firmware/LoRaSerial/Commands.ino | 2 +- Firmware/LoRaSerial/Train.ino | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index ac8b1cdf..35f21e29 100644 --- a/Firmware/LoRaSerial/Commands.ino +++ b/Firmware/LoRaSerial/Commands.ino @@ -145,7 +145,7 @@ bool commandAT(const char * commandString) return true; case ('G'): //ATG - Generate a new netID and encryption key - generateRandomKeysID(); + generateRandomKeysID(&tempSettings); return true; case ('I'): //ATI diff --git a/Firmware/LoRaSerial/Train.ino b/Firmware/LoRaSerial/Train.ino index bb8ae162..2333c1f4 100644 --- a/Firmware/LoRaSerial/Train.ino +++ b/Firmware/LoRaSerial/Train.ino @@ -10,7 +10,7 @@ void selectTraining() //Generate new netID/AES key to share //We assume the user needs to maintain their settings (airSpeed, numberOfChannels, freq min/max, bandwidth/spread/hop) //but need to be on a different netID/AES key. -void generateRandomKeysID() +void generateRandomKeysID(Settings * radioSettings) { if ((settings.debug == true) || (settings.debugTraining == true)) { @@ -22,24 +22,24 @@ void generateRandomKeysID() randomSeed(radio.randomByte()); //Generate new NetID - settings.netID = random(0, 256); //Inclusive, exclusive + radioSettings->netID = random(0, 256); //Inclusive, exclusive //Generate new AES Key. User may not be using AES but we still need both radios to have the same key in case they do enable AES. for (int x = 0 ; x < 16 ; x++) - settings.encryptionKey[x] = random(0, 256); //Inclusive, exclusive + radioSettings->encryptionKey[x] = random(0, 256); //Inclusive, exclusive //We do not generate new AES Initial Values here. Those are generated during generateHopTable() based on the unit's settings. if ((settings.debug == true) || (settings.debugTraining == true)) { systemPrint("Select new NetID: "); - systemPrintln(settings.netID); + systemPrintln(radioSettings->netID); systemPrint("Select new Encryption Key:"); for (uint8_t i = 0 ; i < 16 ; i++) { systemPrint(" "); - systemPrint(settings.encryptionKey[i], HEX); + systemPrint(radioSettings->encryptionKey[i], HEX); } systemPrintln(); outputSerialData(true); From f0821fa7456ec9d4933f4e89d77b75db6d0bd672 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Feb 2023 09:24:44 -1000 Subject: [PATCH 3/4] Remove trainingTimer --- Firmware/LoRaSerial/LoRaSerial.ino | 1 - Firmware/LoRaSerial/Train.ino | 1 - 2 files changed, 2 deletions(-) diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index 718cafbc..2270ceef 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -487,7 +487,6 @@ bool trainingPreviousRxInProgress = false; //Previous RX status float originalChannel; //Original channel from HOP table while training is in progress uint8_t trainingPartnerID[UNIQUE_ID_BYTES]; //Unique ID of the training partner uint8_t myUniqueId[UNIQUE_ID_BYTES]; // Unique ID of this system -unsigned long trainingTimer; //Virtual-Circuit int8_t cmdVc; //VC index for ATI commands only diff --git a/Firmware/LoRaSerial/Train.ino b/Firmware/LoRaSerial/Train.ino index 2333c1f4..dc1e9682 100644 --- a/Firmware/LoRaSerial/Train.ino +++ b/Firmware/LoRaSerial/Train.ino @@ -62,7 +62,6 @@ void beginTrainingClient() changeState(RADIO_TRAIN_WAIT_TX_FIND_PARTNER_DONE); else changeState(RADIO_TRAIN_WAIT_RX_RADIO_PARAMETERS); - trainingTimer = millis(); } //Start the training in server mode From 735ddb524ce326038f5b7f113b9f67d6a715acda Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Feb 2023 09:20:02 -1000 Subject: [PATCH 4/4] Use a common reset function --- Firmware/LoRaSerial/Commands.ino | 29 ++++++++++++++++++----------- Firmware/LoRaSerial/States.ino | 4 +--- Firmware/LoRaSerial/Train.ino | 4 +--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index 35f21e29..f87288e3 100644 --- a/Firmware/LoRaSerial/Commands.ino +++ b/Firmware/LoRaSerial/Commands.ino @@ -199,17 +199,7 @@ bool commandAT(const char * commandString) } reportOK(); - if (serialOperatingMode == MODE_VIRTUAL_CIRCUIT) - { - //Notify the PC of the serial port failure - serialOutputByte(START_OF_VC_SERIAL); - serialOutputByte(3); - serialOutputByte(PC_SERIAL_RECONNECT); - serialOutputByte(myVc); - } - outputSerialData(true); - systemFlush(); - systemReset(); + commandReset(); return true; } } @@ -852,6 +842,7 @@ void reportOK() commandComplete(true); } +//Notify the host that the command is complete void commandComplete(bool success) { if (settings.operatingMode == MODE_VIRTUAL_CIRCUIT) @@ -867,6 +858,22 @@ void commandComplete(bool success) } } +//Notify the host of the reset then reboot the system +void commandReset() +{ + if (serialOperatingMode == MODE_VIRTUAL_CIRCUIT) + { + //Notify the PC of the serial port failure + serialOutputByte(START_OF_VC_SERIAL); + serialOutputByte(3); + serialOutputByte(PC_SERIAL_RECONNECT); + serialOutputByte(myVc); + } + outputSerialData(true); + systemFlush(); + systemReset(); +} + //Remove any preceeding or following whitespace chars char * trimCommand() { diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index 08028fc6..4d7e019c 100644 --- a/Firmware/LoRaSerial/States.ino +++ b/Firmware/LoRaSerial/States.ino @@ -1722,9 +1722,7 @@ void updateRadioState() && tempSettings.server == false) { //Reboot the radio with the newly generated random netID/Key parameters - petWDT(); - systemFlush(); - systemReset(); + commandReset; } } break; diff --git a/Firmware/LoRaSerial/Train.ino b/Firmware/LoRaSerial/Train.ino index dc1e9682..3b598185 100644 --- a/Firmware/LoRaSerial/Train.ino +++ b/Firmware/LoRaSerial/Train.ino @@ -205,7 +205,5 @@ void endClientServerTraining(uint8_t event) trainingServerRunning = false; //Reboot the radio with the new parameters - petWDT(); - systemFlush(); - systemReset(); + commandReset(); }