diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index ac8b1cdf..f87288e3 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 @@ -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/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index 02345167..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 @@ -509,6 +508,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/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 bb8ae162..3b598185 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); @@ -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 @@ -206,7 +205,5 @@ void endClientServerTraining(uint8_t event) trainingServerRunning = false; //Reboot the radio with the new parameters - petWDT(); - systemFlush(); - systemReset(); + commandReset(); } 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 {