Skip to content

Commit 5c12c5e

Browse files
committed
Merge branch 'release_candidate' of https://github.com/sparkfun/SparkFun_LoRaSerial into release_candidate
2 parents fa8b38b + e0c533e commit 5c12c5e

File tree

11 files changed

+55
-415
lines changed

11 files changed

+55
-415
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bool commandAT(const char * commandString)
8787
case ('B'): //ATB - Break the link
8888

8989
//Compute the time delay
90-
delayMillis = (VC_LINK_BREAK_MULTIPLIER + 2) * settings.heartbeatTimeout;
90+
delayMillis = (LINK_BREAK_MULTIPLIER + 2) * settings.heartbeatTimeout;
9191

9292
//Warn the user of the delay
9393
systemPrint("Delaying ");
@@ -111,7 +111,7 @@ bool commandAT(const char * commandString)
111111
//Idle the system to break the link
112112
//This is required on the server system which does not request an VC number assignment
113113
timer = millis();
114-
while ((millis() - timer) < ((VC_LINK_BREAK_MULTIPLIER + 2) * settings.heartbeatTimeout))
114+
while ((millis() - timer) < ((LINK_BREAK_MULTIPLIER + 2) * settings.heartbeatTimeout))
115115
petWDT();
116116
changeState(RADIO_RESET);
117117

Firmware/LoRaSerial/LoRaSerial.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ bool trainingPreviousRxInProgress = false; //Previous RX status
490490
float originalChannel; //Original channel from HOP table while training is in progress
491491
uint8_t trainingPartnerID[UNIQUE_ID_BYTES]; //Unique ID of the training partner
492492
uint8_t myUniqueId[UNIQUE_ID_BYTES]; // Unique ID of this system
493+
uint32_t buttonPressedTime;
493494

494495
//Virtual-Circuit
495496
int8_t cmdVc; //VC index for ATI commands only

Firmware/LoRaSerial/Serial.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,10 +938,8 @@ void resetSerial()
938938

939939
//Empty the buffers
940940
rxHead = rxTail;
941-
radioTxHead = radioTxTail;
942941
txHead = txTail;
943942
commandRXHead = commandRXTail;
944943
commandTXHead = commandTXTail;
945-
endOfTxData = &outgoingPacket[headerBytes];
946944
commandLength = 0;
947945
}

Firmware/LoRaSerial/States.ino

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,14 @@ void updateRadioState()
721721
triggerEvent(TRIGGER_RX_DATA);
722722

723723
//Place the data in the serial output buffer
724+
if (settings.debugSerial)
725+
{
726+
systemPrint("Moving ");
727+
systemPrint(rxDataBytes);
728+
systemPrintln(" from incomingBuffer to serialTransmitBuffer");
729+
dumpBuffer(rxData, length);
730+
outputSerialData(true);
731+
}
724732
serialBufferOutput(rxData, rxDataBytes);
725733

726734
//Transmit ACK
@@ -750,6 +758,16 @@ void updateRadioState()
750758
case DATAGRAM_REMOTE_COMMAND:
751759
triggerEvent(TRIGGER_RX_COMMAND);
752760

761+
//Debug the remote command operation
762+
if (settings.debugSerial)
763+
{
764+
systemPrint("Moving ");
765+
systemPrint(rxDataBytes);
766+
systemPrintln(" from incomingBuffer to commandRXBuffer");
767+
dumpBuffer(rxData, length);
768+
outputSerialData(true);
769+
}
770+
753771
//Determine the number of bytes received
754772
length = 0;
755773
if ((commandRXHead + rxDataBytes) > sizeof(commandRXBuffer))
@@ -772,9 +790,16 @@ void updateRadioState()
772790
case DATAGRAM_REMOTE_COMMAND_RESPONSE:
773791
triggerEvent(TRIGGER_RX_COMMAND_RESPONSE);
774792

775-
//Print received data. This is blocking but we do not use the serialTransmitBuffer because we're in command mode (and it's not much data to print).
776-
for (int x = 0 ; x < rxDataBytes ; x++)
777-
Serial.write(rxData[x]);
793+
//Print received data.
794+
if (settings.debugSerial)
795+
{
796+
systemPrint("Moving ");
797+
systemPrint(rxDataBytes);
798+
systemPrintln(" from incomingBuffer to serialTransmitBuffer");
799+
dumpBuffer(rxData, length);
800+
outputSerialData(true);
801+
}
802+
serialBufferOutput(rxData, rxDataBytes);
778803

779804
//Transmit ACK
780805
P2P_SEND_ACK(TRIGGER_TX_ACK);
@@ -963,7 +988,7 @@ void updateRadioState()
963988
//----------
964989
//Always check for link timeout
965990
//----------
966-
if ((millis() - linkDownTimer) >= (P2P_LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))
991+
if ((millis() - linkDownTimer) >= (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))
967992
//Break the link
968993
breakLink();
969994
break;
@@ -2461,7 +2486,7 @@ void updateRadioState()
24612486
//Determine if the link has timed out
24622487
vc = &virtualCircuitList[index];
24632488
if ((vc->vcState != VC_STATE_LINK_DOWN) && (serverLinkBroken
2464-
|| ((currentMillis - vc->lastTrafficMillis) > (VC_LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))))
2489+
|| ((currentMillis - vc->lastTrafficMillis) > (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))))
24652490
{
24662491
if (index == VC_SERVER)
24672492
{
@@ -2887,7 +2912,10 @@ void breakLink()
28872912
}
28882913

28892914
//Flush the buffers
2890-
resetSerial();
2915+
if (!inCommandMode)
2916+
resetSerial();
2917+
radioTxHead = radioTxTail;
2918+
endOfTxData = &outgoingPacket[headerBytes];
28912919

28922920
//Reset the radio and the link
28932921
triggerEvent(TRIGGER_RADIO_RESET);
@@ -3052,7 +3080,11 @@ void vcBreakLink(int8_t vcIndex)
30523080
//Flush the buffers
30533081
outputSerialData(true);
30543082
if (vcIndex == myVc)
3083+
{
30553084
resetSerial();
3085+
radioTxHead = radioTxTail;
3086+
endOfTxData = &outgoingPacket[headerBytes];
3087+
}
30563088
}
30573089

30583090
//Place VC in LINK-UP state since it is receiving HEARTBEATs from the remote radio

Firmware/LoRaSerial/System.ino

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ void updateButton()
261261
static bool buttonWasPressed;
262262
uint32_t deltaTime;
263263
static Settings originalSettings;
264-
static uint32_t pressedTime;
265264

266265
if (trainBtn != NULL)
267266
{
@@ -271,9 +270,7 @@ void updateButton()
271270
//Determine the current button state
272271
if (buttonWasPressed)
273272
{
274-
//Update the LEDs
275-
deltaTime = millis() - pressedTime;
276-
buttonLeds(deltaTime);
273+
deltaTime = millis() - buttonPressedTime;
277274
if (!buttonPressed)
278275
{
279276
//Button just released
@@ -319,8 +316,6 @@ void updateButton()
319316
else
320317
{
321318
//The user has stopped training with the button
322-
//Restore the previous settings
323-
settings = originalSettings;
324319
if (inTraining)
325320
{
326321
inTraining = false;
@@ -338,11 +333,14 @@ void updateButton()
338333
if (buttonPressed)
339334
{
340335
//Button just pressed
341-
pressedTime = millis();
336+
buttonPressedTime = millis();
342337

343338
//Save the previous led state
344339
if (!inTraining)
340+
{
345341
originalSettings = settings;
342+
settings.selectLedUse = LEDS_BUTTON_PRESS;
343+
}
346344
}
347345
}
348346

@@ -1064,14 +1062,16 @@ void updateCylonLEDs()
10641062
}
10651063

10661064
//Acknowledge the button press
1067-
void buttonLeds(uint32_t pressedMilliseconds)
1065+
void buttonLeds()
10681066
{
10691067
const uint32_t blinkTime = 1000 / 4; //Blink 4 times per second
10701068
uint8_t on;
10711069
const uint32_t onTime = blinkTime / 2;
1070+
uint32_t pressedMilliseconds;
10721071
uint8_t seconds;
10731072

10741073
//Display the number of seconds the button has been pushed
1074+
pressedMilliseconds = millis() - buttonPressedTime;
10751075
seconds = pressedMilliseconds / 1000;
10761076
setRSSI((pressedMilliseconds >= trainButtonFactoryResetTime) ? 15 : seconds);
10771077

@@ -1146,6 +1146,10 @@ void updateLeds()
11461146
radioLeds();
11471147
break;
11481148

1149+
case LEDS_BUTTON_PRESS:
1150+
buttonLeds();
1151+
break;
1152+
11491153
//Turn off all the LEDs
11501154
case LEDS_ALL_OFF:
11511155
break;

Firmware/LoRaSerial/Virtual_Circuit_Protocol.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
#define VC_HB_CHANNEL (VC_HB_CHANNEL_TIMER + sizeof(uint16_t))
6565
#define VC_HB_END (VC_HB_CHANNEL + sizeof(uint8_t))
6666

67-
#define VC_LINK_BREAK_MULTIPLIER 3 //Number of missing HEARTBEAT timeouts
68-
6967
//ASCII characters
7068
#define START_OF_VC_SERIAL 0x02 //From ASCII table - Start of Text
7169

Firmware/LoRaSerial/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef enum
4343

4444
RadioStates radioState = RADIO_RESET;
4545

46-
#define P2P_LINK_BREAK_MULTIPLIER 3
46+
#define LINK_BREAK_MULTIPLIER 3
4747

4848
typedef struct _RADIO_STATE_ENTRY
4949
{

Firmware/Tools/Sockets.c

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)