Skip to content

Commit 5f92320

Browse files
committed
Add correction source debug print.
Return "None" if correction ID == CORR_NUM.
1 parent 5921fcc commit 5f92320

File tree

3 files changed

+62
-55
lines changed

3 files changed

+62
-55
lines changed

Firmware/RTK_Everywhere/menuCorrectionsPriorities.ino

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
//----------------------------------------
4545
// Locals
4646
//----------------------------------------
47-
static CORRECTION_ID_T correctionSourceId; // ID of correction source
48-
static CORRECTION_MASK_T correctionActive; // Bitmap of active correction sources
47+
static CORRECTION_ID_T correctionSourceId; // ID of correction source
48+
static CORRECTION_MASK_T correctionActive; // Bitmap of active correction sources
4949
static uint32_t correctionLastSeenMsec[CORR_NUM]; // Time when correction was last received
5050

5151
//----------------------------------------
@@ -60,20 +60,17 @@ static uint32_t correctionLastSeenMsec[CORR_NUM]; // Time when correction was la
6060
void correctionSetSourceId(CORRECTION_ID_T id)
6161
{
6262
// When the source priority changes, is new prioity the highest
63-
if ((correctionSourceId >= CORR_NUM)
64-
|| ((correctionActive & (1 << correctionSourceId)) == 0)
65-
|| (settings.correctionsSourcesPriority[id] < settings.correctionsSourcesPriority[correctionSourceId]))
63+
if ((correctionSourceId >= CORR_NUM) || ((correctionActive & (1 << correctionSourceId)) == 0) ||
64+
(settings.correctionsSourcesPriority[id] < settings.correctionsSourcesPriority[correctionSourceId]))
6665
{
6766
// Display the correction source transition
6867
if (settings.debugCorrections)
6968
{
7069
if ((correctionSourceId <= CORR_NUM) && (correctionActive & (1 << correctionSourceId)))
71-
systemPrintf("Correction Source: %s --> %s\r\n",
72-
correctionsSourceNames[correctionSourceId],
70+
systemPrintf("Correction Source: %s --> %s\r\n", correctionsSourceNames[correctionSourceId],
7371
correctionsSourceNames[id]);
7472
else
75-
systemPrintf("Correction Source: None --> %s\r\n",
76-
correctionsSourceNames[id]);
73+
systemPrintf("Correction Source: None --> %s\r\n", correctionsSourceNames[id]);
7774
}
7875

7976
// Set the new correction source
@@ -87,22 +84,23 @@ void correctionSetSourceId(CORRECTION_ID_T id)
8784
// id: correctionsSource value, ID of the correction source
8885
// priority: Priority of the correction source
8986
//----------------------------------------
90-
void correctionPriorityUpdateSource(CORRECTION_ID_T id,
91-
CORRECTION_ID_T priority)
87+
void correctionPriorityUpdateSource(CORRECTION_ID_T id, CORRECTION_ID_T priority)
9288
{
9389
CORRECTION_MASK_T bitMask;
9490

9591
// Validate the id value
9692
if (id >= CORR_NUM)
9793
{
98-
systemPrintf("ERROR: correctionPriorityUpdateSource invalid correction id value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
94+
systemPrintf("ERROR: correctionPriorityUpdateSource invalid correction id value %d, valid range (0 - %d)!\r\n",
95+
id, CORR_NUM - 1);
9996
return;
10097
}
10198

10299
// Validate the id value
103100
if (priority >= CORR_NUM)
104101
{
105-
systemPrintf("ERROR: correctionPriorityUpdateSource invalid priority value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
102+
systemPrintf("ERROR: correctionPriorityUpdateSource invalid priority value %d, valid range (0 - %d)!\r\n", id,
103+
CORR_NUM - 1);
106104
return;
107105
}
108106

@@ -128,7 +126,8 @@ void correctionPriorityDecrease(CORRECTION_ID_T oldPriority)
128126
// Validate the priority value
129127
if (oldPriority >= CORR_NUM)
130128
{
131-
systemPrintf("ERROR: correctionPriorityDecrease invalid correction id value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
129+
systemPrintf("ERROR: correctionPriorityDecrease invalid correction id value %d, valid range (0 - %d)!\r\n", id,
130+
CORR_NUM - 1);
132131
return;
133132
}
134133

@@ -171,16 +170,12 @@ void correctionPriorityDecrease(CORRECTION_ID_T oldPriority)
171170
if (settings.correctionsSourcesPriority[index] == newPriority)
172171
{
173172
if (settings.debugCorrections)
174-
systemPrintf("%s: %d --> %d\r\n",
175-
correctionsSourceNames[index],
176-
settings.correctionsSourcesPriority[index],
177-
oldPriority);
173+
systemPrintf("%s: %d --> %d\r\n", correctionsSourceNames[index],
174+
settings.correctionsSourcesPriority[index], oldPriority);
178175
settings.correctionsSourcesPriority[index] = oldPriority;
179176
}
180177
if (settings.debugCorrections)
181-
systemPrintf("%s: %d --> %d\r\n",
182-
correctionsSourceNames[id],
183-
settings.correctionsSourcesPriority[id],
178+
systemPrintf("%s: %d --> %d\r\n", correctionsSourceNames[id], settings.correctionsSourcesPriority[id],
184179
newPriority);
185180
settings.correctionsSourcesPriority[id] = newPriority;
186181

@@ -202,7 +197,9 @@ void correctionPriorityIncrease(CORRECTION_ID_T oldPriority)
202197
// Validate the id value
203198
if (oldPriority >= CORR_NUM)
204199
{
205-
systemPrintf("ERROR: correctionPriorityIncrease invalid correction priority value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
200+
systemPrintf(
201+
"ERROR: correctionPriorityIncrease invalid correction priority value %d, valid range (0 - %d)!\r\n", id,
202+
CORR_NUM - 1);
206203
return;
207204
}
208205

@@ -245,16 +242,12 @@ void correctionPriorityIncrease(CORRECTION_ID_T oldPriority)
245242
if (settings.correctionsSourcesPriority[index] == newPriority)
246243
{
247244
if (settings.debugCorrections)
248-
systemPrintf("%s: %d --> %d\r\n",
249-
correctionsSourceNames[index],
250-
settings.correctionsSourcesPriority[index],
251-
oldPriority);
245+
systemPrintf("%s: %d --> %d\r\n", correctionsSourceNames[index],
246+
settings.correctionsSourcesPriority[index], oldPriority);
252247
settings.correctionsSourcesPriority[index] = oldPriority;
253248
}
254249
if (settings.debugCorrections)
255-
systemPrintf("%s: %d --> %d\r\n",
256-
correctionsSourceNames[id],
257-
settings.correctionsSourcesPriority[id],
250+
systemPrintf("%s: %d --> %d\r\n", correctionsSourceNames[id], settings.correctionsSourcesPriority[id],
258251
newPriority);
259252
settings.correctionsSourcesPriority[id] = newPriority;
260253

@@ -332,7 +325,7 @@ void menuCorrectionsPriorities()
332325
void correctionDisplayPriorityTable(bool menu)
333326
{
334327
// "a / A) "
335-
const char * blankString = " ";
328+
const char *blankString = " ";
336329
uint32_t currentMsec;
337330
CORRECTION_ID_T id;
338331
char menuString[strlen(blankString) + 1];
@@ -375,20 +368,15 @@ void correctionDisplayPriorityTable(bool menu)
375368

376369
// Display the priority table
377370
if ((id < CORR_NUM) && correctionIsSourceActive(id))
378-
systemPrintf("%s %c %2d active %4d.%03d Sec %s\r\n",
379-
menuString,
380-
(correctionSourceId == id) ? '*' : ' ',
381-
settings.correctionsSourcesPriority[id],
382-
seconds, milliseconds,
383-
correctionsSourceNames[id]);
371+
systemPrintf("%s %c %2d active %4d.%03d Sec %s\r\n", menuString,
372+
(correctionSourceId == id) ? '*' : ' ', settings.correctionsSourcesPriority[id], seconds,
373+
milliseconds, correctionsSourceNames[id]);
384374
else if (id < CORR_NUM)
385-
systemPrintf("%s %2d inactive %s\r\n",
386-
menuString,
387-
settings.correctionsSourcesPriority[id],
388-
correctionsSourceNames[id]);
375+
systemPrintf("%s %2d inactive %s\r\n", menuString,
376+
settings.correctionsSourcesPriority[id], correctionsSourceNames[id]);
389377
else
390-
systemPrintf("%s %2d inactive %s (%d)\r\n",
391-
menu ? blankString : "", -1, "Unknown", id);
378+
systemPrintf("%s %2d inactive %s (%d)\r\n", menu ? blankString : "", -1, "Unknown",
379+
id);
392380
}
393381
}
394382

@@ -400,12 +388,16 @@ void correctionDisplayPriorityTable(bool menu)
400388
// Returns the address of a zero terminated constant name string or
401389
// nullptr when id is invalid
402390
//----------------------------------------
403-
const char * correctionGetName(CORRECTION_ID_T id)
391+
const char *correctionGetName(CORRECTION_ID_T id)
404392
{
393+
if (id == CORR_NUM)
394+
return "None";
395+
405396
// Validate the id value
406-
if (id >= CORR_NUM)
397+
if (id > CORR_NUM)
407398
{
408-
systemPrintf("ERROR: correctionGetName invalid correction id value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
399+
systemPrintf("ERROR: correctionGetName invalid correction id value %d, valid range (0 - %d)!\r\n", id,
400+
CORR_NUM - 1);
409401
return nullptr;
410402
}
411403

@@ -428,9 +420,9 @@ CORRECTION_ID_T correctionGetSource()
428420
// Outputs:
429421
// Returns the correctionsSource ID providing corrections
430422
//----------------------------------------
431-
const char * correctionGetSourceName()
423+
const char *correctionGetSourceName()
432424
{
433-
const char * name;
425+
const char *name;
434426

435427
name = correctionGetName(correctionSourceId);
436428
if (!name)
@@ -457,7 +449,8 @@ bool correctionIsSourceActive(CORRECTION_ID_T id)
457449
// Validate the id value
458450
if (id >= CORR_NUM)
459451
{
460-
systemPrintf("ERROR: correctionIsSourceActive invalid correction id value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
452+
systemPrintf("ERROR: correctionIsSourceActive invalid correction id value %d, valid range (0 - %d)!\r\n", id,
453+
CORR_NUM - 1);
461454
return false;
462455
}
463456

@@ -480,8 +473,7 @@ bool correctionIsSourceActive(CORRECTION_ID_T id)
480473
newPriority = CORR_NUM;
481474
newSource = CORR_NUM;
482475
for (index = 0; index < CORR_NUM; index++)
483-
if ((correctionActive & (1 << index))
484-
&& (settings.correctionsSourcesPriority[index] < newPriority))
476+
if ((correctionActive & (1 << index)) && (settings.correctionsSourcesPriority[index] < newPriority))
485477
{
486478
newPriority = settings.correctionsSourcesPriority[index];
487479
newSource = index;
@@ -494,12 +486,10 @@ bool correctionIsSourceActive(CORRECTION_ID_T id)
494486
if (settings.debugCorrections)
495487
{
496488
if (newSource < CORR_NUM)
497-
systemPrintf("Correction Source: %s --> %s\r\n",
498-
correctionsSourceNames[id],
489+
systemPrintf("Correction Source: %s --> %s\r\n", correctionsSourceNames[id],
499490
correctionsSourceNames[newSource]);
500491
else
501-
systemPrintf("Correction Source: %s --> None\r\n",
502-
correctionsSourceNames[id]);
492+
systemPrintf("Correction Source: %s --> None\r\n", correctionsSourceNames[id]);
503493
}
504494
}
505495
}
@@ -523,7 +513,8 @@ bool correctionLastSeen(CORRECTION_ID_T id)
523513
// Validate the id value
524514
if (id >= CORR_NUM)
525515
{
526-
systemPrintf("ERROR: correctionLastSeen invalid correction id value %d, valid range (0 - %d)!\r\n", id, CORR_NUM - 1);
516+
systemPrintf("ERROR: correctionLastSeen invalid correction id value %d, valid range (0 - %d)!\r\n", id,
517+
CORR_NUM - 1);
527518
return false;
528519
}
529520

@@ -598,6 +589,15 @@ void correctionUpdateSource()
598589

599590
for (id = 0; id < CORR_NUM; id++)
600591
correctionPriorityUpdateSource(id, settings.correctionsSourcesPriority[id]);
592+
593+
// Display the current correction source
594+
if (PERIODIC_DISPLAY(PD_CORRECTION_SOURCE) && !inMainMenu)
595+
{
596+
PERIODIC_CLEAR(PD_CORRECTION_SOURCE);
597+
systemPrintf("Correction Source: %s\r\n", correctionGetSourceName());
598+
599+
// systemPrintf("%s\r\n", PERIODIC_SETTING(PD_RING_BUFFER_MILLIS) ? "Active" : "Inactive");
600+
}
601601
}
602602

603603
//----------------------------------------

Firmware/RTK_Everywhere/menuSystem.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ void menuPeriodicPrint()
11671167
systemPrint("26) RTK state: ");
11681168
systemPrintf("%s\r\n", settings.enablePrintStates ? "Enabled" : "Disabled");
11691169

1170+
systemPrint("27) RTK correction source: ");
1171+
systemPrintf("%s\r\n", PERIODIC_SETTING(PD_CORRECTION_SOURCE) ? "Enabled" : "Disabled");
1172+
11701173
systemPrintln("------ Clients -----");
11711174
systemPrint("40) NTP server data: ");
11721175
systemPrintf("%s\r\n", PERIODIC_SETTING(PD_NTP_SERVER_DATA) ? "Enabled" : "Disabled");
@@ -1289,6 +1292,8 @@ void menuPeriodicPrint()
12891292
settings.enablePrintPosition ^= 1;
12901293
else if (incoming == 26)
12911294
settings.enablePrintStates ^= 1;
1295+
else if (incoming == 27)
1296+
PERIODIC_TOGGLE(PD_CORRECTION_SOURCE);
12921297

12931298
else if (incoming == 40)
12941299
PERIODIC_TOGGLE(PD_NTP_SERVER_DATA);

Firmware/RTK_Everywhere/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ enum PeriodDisplayValues
590590
PD_HTTP_CLIENT_STATE, // 35
591591

592592
PD_PROVISIONING_STATE, // 36
593+
594+
PD_CORRECTION_SOURCE, // 37
593595
// Add new values before this line
594596
};
595597

0 commit comments

Comments
 (0)