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
133 changes: 73 additions & 60 deletions Firmware/LoRaSerial/Commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool commandAT(const char * commandString)
return true;

case ('F'): //ATF - Restore default parameters
settings = defaultSettings; //Overwrite all system settings with defaults
getDefaultSettings(&settings); //Overwrite all system settings with defaults

validateSettings(); //Modify defaults for each radio type (915, 868, 433, etc)

Expand Down Expand Up @@ -720,19 +720,29 @@ bool commandAT(const char * commandString)
return true;

case ('1'): //ATI31 - Display the VC details
systemPrintTimestamp();
systemPrint("VC ");
systemPrint(cmdVc);
systemPrint(": ");
if (!vc->flags.valid)
systemPrintln("Down, Not valid");
else
if ((settings.operatingMode == MODE_VIRTUAL_CIRCUIT) && (!vc->flags.valid))
{
systemPrintln(vcStateNames[vc->vcState]);
systemPrintTimestamp();
systemPrint(" ID: ");
systemPrintUniqueID(vc->uniqueId);
systemPrintln(vc->flags.valid ? " (Valid)" : " (Invalid)");
systemPrint("VC ");
systemPrint(cmdVc);
systemPrint(": ");
if (!vc->flags.valid)
systemPrintln("Down, Not valid");
}
else
{
if (settings.operatingMode == MODE_VIRTUAL_CIRCUIT)
{
systemPrintTimestamp();
systemPrint("VC ");
systemPrint(cmdVc);
systemPrint(": ");
systemPrintln(vcStateNames[vc->vcState]);
systemPrintTimestamp();
systemPrint(" ID: ");
systemPrintUniqueID(vc->uniqueId);
systemPrintln(vc->flags.valid ? " (Valid)" : " (Invalid)");
}

//Heartbeat metrics
systemPrintTimestamp();
Expand Down Expand Up @@ -762,57 +772,60 @@ bool commandAT(const char * commandString)
outputSerialData(true);
petWDT();

//Transmitter metrics
systemPrintTimestamp();
systemPrintln(" Sent");
systemPrintTimestamp();
systemPrint(" Frames: ");
systemPrintln(vc->framesSent);
systemPrintTimestamp();
systemPrint(" Messages: ");
systemPrintln(vc->messagesSent);
outputSerialData(true);
petWDT();
if ((settings.operatingMode == MODE_VIRTUAL_CIRCUIT) && (!vc->flags.valid))
{
//Transmitter metrics
systemPrintTimestamp();
systemPrintln(" Sent");
systemPrintTimestamp();
systemPrint(" Frames: ");
systemPrintln(vc->framesSent);
systemPrintTimestamp();
systemPrint(" Messages: ");
systemPrintln(vc->messagesSent);
outputSerialData(true);
petWDT();

//Receiver metrics
systemPrintTimestamp();
systemPrintln(" Received");
systemPrintTimestamp();
systemPrint(" Frames: ");
systemPrintln(vc->framesReceived);
systemPrintTimestamp();
systemPrint(" Messages: ");
systemPrintln(vc->messagesReceived);
systemPrintTimestamp();
systemPrint(" Bad Lengths: ");
systemPrintln(vc->badLength);
systemPrintTimestamp();
systemPrint(" Link Failures: ");
systemPrintln(linkFailures);
outputSerialData(true);
petWDT();
//Receiver metrics
systemPrintTimestamp();
systemPrintln(" Received");
systemPrintTimestamp();
systemPrint(" Frames: ");
systemPrintln(vc->framesReceived);
systemPrintTimestamp();
systemPrint(" Messages: ");
systemPrintln(vc->messagesReceived);
systemPrintTimestamp();
systemPrint(" Bad Lengths: ");
systemPrintln(vc->badLength);
systemPrintTimestamp();
systemPrint(" Link Failures: ");
systemPrintln(linkFailures);
outputSerialData(true);
petWDT();

//ACK Management metrics
systemPrintTimestamp();
systemPrintln(" ACK Management");
systemPrintTimestamp();
systemPrint(" Last RX ACK number: ");
systemPrintln(vc->rxAckNumber);
systemPrintTimestamp();
systemPrint(" Next RX ACK number: ");
systemPrintln(vc->rmtTxAckNumber);
systemPrintTimestamp();
systemPrint(" Last TX ACK number: ");
systemPrintln(vc->txAckNumber);
if (txDestVc == cmdVc)
{
//ACK Management metrics
systemPrintTimestamp();
systemPrint(" ackTimer: ");
if (ackTimer)
systemPrintTimestamp(ackTimer + timestampOffset);
else
systemPrint("Not Running");
systemPrintln();
systemPrintln(" ACK Management");
systemPrintTimestamp();
systemPrint(" Last RX ACK number: ");
systemPrintln(vc->rxAckNumber);
systemPrintTimestamp();
systemPrint(" Next RX ACK number: ");
systemPrintln(vc->rmtTxAckNumber);
systemPrintTimestamp();
systemPrint(" Last TX ACK number: ");
systemPrintln(vc->txAckNumber);
if (txDestVc == cmdVc)
{
systemPrintTimestamp();
systemPrint(" ackTimer: ");
if (ackTimer)
systemPrintTimestamp(ackTimer + timestampOffset);
else
systemPrint("Not Running");
systemPrintln();
}
}
}
return true;
Expand Down
10 changes: 9 additions & 1 deletion Firmware/LoRaSerial/LoRaSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ unsigned long retransmitTimeout = 0; //Throttle back re-transmits

//Global variables
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
const Settings defaultSettings;
Settings settings; //Active settings used by the radio
Settings tempSettings; //Temporary settings used for command processing
Settings trainingSettings; //Settings used for training other radios
Expand Down Expand Up @@ -629,6 +628,15 @@ void setup()
arch.beginBoard(); //Initialize the board specific hardware, and ID platform type

loadSettings(); //Load settings from EEPROM

//Use the current radio settings if they are already set
if (!settings.radioBandwidth)
{
//Set the initial radio parameters
getDefaultSettings(&settings);
recordSystemSettings();
}

serialOperatingMode = settings.operatingMode;

beginSerial(settings.serialSpeed);
Expand Down
12 changes: 12 additions & 0 deletions Firmware/LoRaSerial/NVM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ void loadSettings()
{
arch.eepromBegin();

//Use the default settings
getDefaultSettings(&settings);

//Check to see if EEPROM is blank
uint32_t testRead = 0;
if (EEPROM.get(0, testRead) == 0xFFFFFFFF)
Expand Down Expand Up @@ -55,6 +58,15 @@ void loadSettings()
recordSystemSettings();
}

//Merge the default settings with the default radio settings
void getDefaultSettings(Settings * newSettings)
{
const Settings defaultSettings;

//Set the initial radio parameters
*newSettings = defaultSettings;
}

//Modify defaults for each radio type (915, 868, 433, etc)
//Confirm various settings are within regulatory bounds
void validateSettings()
Expand Down
16 changes: 15 additions & 1 deletion Firmware/LoRaSerial/States.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,8 @@ void updateRadioState()
//Start and adjust freq hop ISR based on remote's remaining clock
startChannelTimer();
channelTimerStart -= settings.maxDwellTime;
if (!settings.server)
virtualCircuitList[VC_SERVER].firstHeartbeatMillis = millis();
syncChannelTimer(txSyncClocksUsec, 1);
triggerEvent(TRIGGER_RX_SYNC_CLOCKS);

Expand Down Expand Up @@ -1320,6 +1322,8 @@ void updateRadioState()

//Start and adjust freq hop ISR based on remote's remaining clock
channelTimerStart -= settings.maxDwellTime;
if (!settings.server)
virtualCircuitList[VC_SERVER].firstHeartbeatMillis = millis();
syncChannelTimer(txSyncClocksUsec, 1);

if (settings.debugSync)
Expand Down Expand Up @@ -1434,6 +1438,9 @@ void updateRadioState()
//Sync clock if server sent the heartbeat
if (settings.server == false)
{
if (!settings.server)
virtualCircuitList[VC_SERVER].lastTrafficMillis = millis();

//Adjust freq hop ISR based on server's remaining clock
syncChannelTimer(txHeartbeatUsec, 0);

Expand Down Expand Up @@ -1495,8 +1502,15 @@ void updateRadioState()
if ((millis() - lastPacketReceived) > ((uint32_t)settings.heartbeatTimeout * LINK_BREAK_MULTIPLIER))
{
if (settings.debugSync)
{
systemPrintln("HEARTBEAT Timeout");
if ((!settings.server) && settings.debugHopTimer)
{
systemPrint("Link Uptime: ");
systemPrintln(virtualCircuitList[VC_SERVER].lastTrafficMillis
- virtualCircuitList[VC_SERVER].firstHeartbeatMillis);
}
if (settings.debugSync || settings.debugHopTimer)
{
outputSerialData(true);
dumpClockSynchronization();
}
Expand Down
9 changes: 3 additions & 6 deletions Firmware/LoRaSerial/System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,7 @@ void multiPointLeds()
blinkRadioRssiLed();

//Update the hop LED
if ((millis() - radioCallHistory[RADIO_CALL_hopChannel]) >= RADIO_USE_BLINK_MILLIS)
digitalWrite(YELLOW_LED, LED_OFF);
blinkChannelHopLed(false);

//Update the HEARTBEAT LED
blinkHeartbeatLed(false);
Expand All @@ -1006,8 +1005,7 @@ void p2pLeds()
//Leave the LINK LED (GREEN_LED_2) off

//Update the hop LED
if ((millis() - radioCallHistory[RADIO_CALL_hopChannel]) >= RADIO_USE_BLINK_MILLIS)
digitalWrite(YELLOW_LED, LED_OFF);
blinkChannelHopLed(false);

//Update the HEARTBEAT LED
blinkHeartbeatLed(false);
Expand Down Expand Up @@ -1049,8 +1047,7 @@ void vcLeds()
//Serial RX displayed on the LINK LED (GREEN_LED_2) by blinkSerialRxLed

//Update the hop LED
if ((millis() - radioCallHistory[RADIO_CALL_hopChannel]) >= RADIO_USE_BLINK_MILLIS)
digitalWrite(YELLOW_LED, LED_OFF);
blinkChannelHopLed(false);

//Update the HEARTBEAT LED
blinkHeartbeatLed(false);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/LoRaSerial/Train.ino
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void beginTrainingServer()
void commonTrainingInitialization()
{
//Use common radio settings between the client and server for training
settings = defaultSettings;
getDefaultSettings(&settings);
settings.dataScrambling = true; //Scramble the data
settings.enableCRC16 = true; //Use CRC-16
settings.encryptData = true; //Enable packet encryption
Expand Down
1 change: 1 addition & 0 deletions Firmware/LoRaSerial/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ typedef struct struct_settings {
bool debug = false; //Print basic events: ie, radio state changes
bool debugDatagrams = false; //Print the datagrams
bool debugHeartbeat = false; //Print the HEARTBEAT timing values
bool debugHopTimer = false; //Print the hop timer when the link fails

bool debugNvm = false; //Debug NVM operation
bool debugRadio = false; //Print radio info
Expand Down