Skip to content

Commit d794799

Browse files
committed
fully initialize radio in first cycle
1 parent 1571de7 commit d794799

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/ControlTasks/RadioControlTask.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ RadioControlTask::RadioControlTask()
77
void RadioControlTask::init()
88
{
99
if (!sfr::radio::initialized) {
10-
switch (sfr::radio::start_progress) {
11-
case 0:
10+
if (sfr::radio::start_progress == 0) {
1211
#ifdef VERBOSE
13-
Serial.print(F("Radio: Initializing ... "));
12+
Serial.println(F("Radio: Initializing ... "));
1413
#endif
1514
// initialize SX1278 with default settings
1615
code = radio.begin(constants::radio::freq, constants::radio::bw, constants::radio::sf, constants::radio::cr,
@@ -23,10 +22,11 @@ void RadioControlTask::init()
2322
Serial.println(code);
2423
#endif
2524
}
26-
break;
27-
case 1:
25+
}
26+
27+
if (sfr::radio::start_progress == 1) {
2828
#ifdef VERBOSE
29-
Serial.print(F("Radio: Setting CRC parameter ... "));
29+
Serial.println(F("Radio: Setting CRC parameter ... "));
3030
#endif
3131
// set CRC parameter to true so it matches the CRC parameter on the TinyGS side
3232
code = radio.setCRC(true);
@@ -38,25 +38,22 @@ void RadioControlTask::init()
3838
Serial.println(code);
3939
#endif
4040
}
41-
break;
42-
case 2:
41+
42+
if (sfr::radio::start_progress == 2) {
4343
#ifdef VERBOSE
44-
Serial.print(F("Radio: Setting forceLDRO parameter ... "));
44+
Serial.println(F("Radio: Setting forceLDRO parameter ... "));
4545
#endif
46-
// set forceLDRO parameter to true so it matches the forceLDRO parameter on the TinyGS side
47-
code = radio.forceLDRO(true);
48-
if (code == RADIOLIB_ERR_NONE) {
49-
sfr::radio::start_progress++;
50-
} else {
46+
// set forceLDRO parameter to true so it matches the forceLDRO parameter on the TinyGS side
47+
code = radio.forceLDRO(true);
48+
if (code == RADIOLIB_ERR_NONE) {
49+
sfr::radio::initialized = true;
50+
} else {
5151
#ifdef VERBOSE
52-
Serial.print(F("failed, code "));
53-
Serial.println(code);
52+
Serial.print(F("failed, code "));
53+
Serial.println(code);
5454
#endif
55+
}
5556
}
56-
break;
57-
case 3: // completed initialization
58-
sfr::radio::initialized = true;
59-
break;
6057
}
6158
}
6259
}

src/MainControlLoop.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ void MainControlLoop::execute()
6161
Serial.print(F("GPS Altitude (m): "));
6262
Serial.println(sfr::gps::altitude);
6363

64-
Serial.print("Downlink Slot: ");
64+
Serial.print(F("Downlink Slot: "));
6565
Serial.println(sfr::radio::downlink_slot);
6666

67+
Serial.print(F("Alive Time: "));
68+
Serial.println(millis() - sfr::gps::boot_time);
69+
6770
#endif
6871

6972
temp_monitor.execute();

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void setup()
1212
Serial.begin(9600);
1313
#endif
1414

15+
sfr::gps::boot_time = millis();
16+
1517
// sets ChipSat LED high for debugging
1618
pinMode(constants::led::led_pin, OUTPUT);
1719
digitalWrite(constants::led::led_pin, HIGH);
@@ -24,8 +26,6 @@ void setup()
2426
pinMode(constants::gps::tx_pin, OUTPUT);
2527
digitalWrite(constants::gps::tx_pin, LOW);
2628

27-
sfr::gps::boot_time = millis();
28-
2929
// seed random number gen with noise from unconnected analog pin
3030
randomSeed(analogRead(A0));
3131
}

0 commit comments

Comments
 (0)