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
31 changes: 19 additions & 12 deletions Firmware/LoRaSerial/Commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion Firmware/LoRaSerial/LoRaSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions Firmware/LoRaSerial/States.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 6 additions & 9 deletions Firmware/LoRaSerial/Train.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -206,7 +205,5 @@ void endClientServerTraining(uint8_t event)
trainingServerRunning = false;

//Reboot the radio with the new parameters
petWDT();
systemFlush();
systemReset();
commandReset();
}
3 changes: 1 addition & 2 deletions Firmware/LoRaSerial/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down