Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Firmware/LoRaSerial/LoRaSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down
26 changes: 26 additions & 0 deletions Firmware/LoRaSerial/NVM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
100 changes: 56 additions & 44 deletions Firmware/LoRaSerial/States.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

//====================
Expand Down Expand Up @@ -1589,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;

Expand All @@ -1629,9 +1622,19 @@ void updateRadioState()
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

/*
beginTrainingServer

Command Mode 5 second button press
| |
| ATT |
| |
V |
+<---------------------'
|
| Save current settings
V
commandSaveSettings
|
V
beginTrainingServer
|
V
+<--------------------------------.
Expand All @@ -1645,12 +1648,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
*/

//====================
Expand Down Expand Up @@ -1707,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();
Expand Down
5 changes: 0 additions & 5 deletions Firmware/LoRaSerial/System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Firmware/LoRaSerial/Train.ino
Original file line number Diff line number Diff line change
@@ -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
Expand Down