Skip to content

Commit f1fa121

Browse files
authored
Merge pull request #817 from sparkfun/Add_menuCommonBaseCoords
Add menuCommonBaseCoords
2 parents a32aa38 + e40a86b commit f1fa121

File tree

2 files changed

+358
-4
lines changed

2 files changed

+358
-4
lines changed

Firmware/RTK_Everywhere/menuBase.ino

Lines changed: 264 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static const float maxSurveyInStartingAccuracy = 10.0;
1919
// Set the ECEF coordinates for a known location
2020
void menuBase()
2121
{
22-
int ntripServerOptionOffset = 9; // NTRIP Server menus start at this value
22+
int ntripServerOptionOffset = 10; // NTRIP Server menus start at this value
2323

2424
while (1)
2525
{
@@ -106,9 +106,11 @@ void menuBase()
106106
}
107107
}
108108

109-
systemPrintln("7) Set RTCM Message Rates");
109+
systemPrintln("7) Commonly Used Base Coordinates");
110110

111-
systemPrint("8) Toggle NTRIP Server: ");
111+
systemPrintln("8) Set RTCM Message Rates");
112+
113+
systemPrint("9) Toggle NTRIP Server: ");
112114
if (settings.enableNtripServer == true)
113115
systemPrintln("Enabled");
114116
else
@@ -330,10 +332,19 @@ void menuBase()
330332

331333
else if (incoming == 7)
332334
{
333-
menuMessagesBaseRTCM(); // Set rates for RTCM during Base mode
335+
if (menuCommonBaseCoords()) // Commonly used base coordinates - returns true if coordinates were loaded
336+
// Change GNSS receiver configuration if the receiver is in Base mode, otherwise, just change setting
337+
// This prevents a user, while in Rover mode but changing a Base setting, from entering Base mode
338+
if (gnss->gnssInBaseFixedMode())
339+
gnssConfigure(GNSS_CONFIG_BASE); // Request receiver to use new settings
334340
}
335341

336342
else if (incoming == 8)
343+
{
344+
menuMessagesBaseRTCM(); // Set rates for RTCM during Base mode
345+
}
346+
347+
else if (incoming == 9)
337348
{
338349
settings.enableNtripServer ^= 1;
339350
}
@@ -477,4 +488,253 @@ void menuBaseCoordinateType()
477488
clearBuffer(); // Empty buffer of any newline chars
478489
}
479490

491+
// Set commonly used base coordinates
492+
bool menuCommonBaseCoords()
493+
{
494+
int selectedCoords = 0;
495+
bool retVal = false; // Return value - set true if new coords are loaded
496+
497+
while (1)
498+
{
499+
systemPrintln();
500+
systemPrintln("Menu: Commonly Used Base Coordinates\r\n");
501+
502+
int numCoords = 0;
503+
504+
// Step through the common coordinates file
505+
506+
for (int index = 0; index < COMMON_COORDINATES_MAX_STATIONS; index++) // Arbitrary 50 station limit
507+
{
508+
// stationInfo example: LocationA,40.09029479,-105.18505761,1560.089
509+
char stationInfo[100];
510+
511+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
512+
{
513+
// Try SD, then LFS
514+
if (getFileLineSD(stationCoordinateGeodeticFileName, index, stationInfo, sizeof(stationInfo)) ==
515+
true) // fileName, lineNumber, array, arraySize
516+
{
517+
}
518+
else if (getFileLineLFS(stationCoordinateGeodeticFileName, index, stationInfo, sizeof(stationInfo)) ==
519+
true) // fileName, lineNumber, array, arraySize
520+
{
521+
}
522+
else
523+
{
524+
// We could not find this line
525+
break;
526+
}
527+
}
528+
else
529+
{
530+
// Try SD, then LFS
531+
if (getFileLineSD(stationCoordinateECEFFileName, index, stationInfo, sizeof(stationInfo)) ==
532+
true) // fileName, lineNumber, array, arraySize
533+
{
534+
}
535+
else if (getFileLineLFS(stationCoordinateECEFFileName, index, stationInfo, sizeof(stationInfo)) ==
536+
true) // fileName, lineNumber, array, arraySize
537+
{
538+
}
539+
else
540+
{
541+
// We could not find this line
542+
break;
543+
}
544+
}
545+
546+
trim(stationInfo); // Remove trailing whitespace
547+
548+
systemPrintf("%d)%s %s %s\r\n",
549+
numCoords + 1,
550+
numCoords < 9 ? " " : "",
551+
numCoords == selectedCoords ? "->" : " ",
552+
stationInfo
553+
);
554+
numCoords++;
555+
}
556+
557+
systemPrintln("a) Add Coordinates");
558+
systemPrintln("c) Add Current Coordinates");
559+
systemPrintln("d) Delete Coordinates");
560+
systemPrintln("l) Load Coordinates into Fixed Base");
561+
systemPrintln("t) Add Current Coordinates with Timestamp");
562+
systemPrintln("x) Exit");
563+
564+
byte incoming = getUserInputCharacterNumber();
565+
566+
if ((incoming > 0) && (incoming <= numCoords))
567+
selectedCoords = incoming - 1;
568+
else if (incoming == 'a')
569+
{
570+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
571+
{
572+
systemPrintln("Enter new coordinates in Name,Lat,Long,Alt CSV format");
573+
systemPrintln("E.g. SparkFun_HQ,40.09029479,-105.18505761,1560.089");
574+
}
575+
else
576+
{
577+
systemPrintln("Enter new coordinates in Name,X,Y,Z CSV format");
578+
systemPrintln("E.g. SparkFun_HQ,-1280206.568,-4716804.403,4086665.484");
579+
}
580+
581+
char newCoords[100];
582+
char *ptr = newCoords;
583+
if ((getUserInputString(newCoords, sizeof(newCoords)) == INPUT_RESPONSE_VALID) && (strlen(newCoords) > 0))
584+
{
585+
double latx;
586+
double lony;
587+
double altz;
588+
char baseName[100];
589+
if ((sscanf(ptr,"%[^,],%lf,%lf,%lf", baseName, &latx, &lony, &altz) == 4)
590+
&& (strlen(baseName) > 0)
591+
&& (strstr(baseName, " ") == nullptr)) // Check for spaces
592+
{
593+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
594+
{
595+
recordLineToSD(stationCoordinateGeodeticFileName, newCoords);
596+
recordLineToLFS(stationCoordinateGeodeticFileName, newCoords);
597+
}
598+
else
599+
{
600+
recordLineToSD(stationCoordinateECEFFileName, newCoords);
601+
recordLineToLFS(stationCoordinateECEFFileName, newCoords);
602+
}
603+
}
604+
}
605+
}
606+
else if (incoming == 'c')
607+
{
608+
systemPrintln("Enter the name for these coordinates:");
609+
char coordsName[50];
610+
if ((getUserInputString(coordsName, sizeof(coordsName)) == INPUT_RESPONSE_VALID)
611+
&& (strlen(coordsName) > 0)
612+
&& (strstr(coordsName, " ") == nullptr))
613+
{
614+
char newCoords[100];
615+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
616+
{
617+
snprintf(newCoords, sizeof(newCoords), "%s,%.8lf,%.8lf,%.4lf",
618+
coordsName,
619+
gnss->getLatitude(),
620+
gnss->getLongitude(),
621+
gnss->getAltitude() - ((settings.antennaHeight_mm + settings.antennaPhaseCenter_mm) / 1000.0));
622+
recordLineToSD(stationCoordinateGeodeticFileName, newCoords);
623+
recordLineToLFS(stationCoordinateGeodeticFileName, newCoords);
624+
}
625+
else
626+
{
627+
double ecefX = 0;
628+
double ecefY = 0;
629+
double ecefZ = 0;
630+
geodeticToEcef(gnss->getLatitude(), gnss->getLongitude(),
631+
gnss->getAltitude() - ((settings.antennaHeight_mm + settings.antennaPhaseCenter_mm) / 1000.0),
632+
&ecefX, &ecefY, &ecefZ);
633+
snprintf(newCoords, sizeof(newCoords), "%s,%.4lf,%.4lf,%.4lf",
634+
coordsName, ecefX, ecefY, ecefZ);
635+
recordLineToSD(stationCoordinateECEFFileName, newCoords);
636+
recordLineToLFS(stationCoordinateECEFFileName, newCoords);
637+
}
638+
}
639+
}
640+
else if (incoming == 'd')
641+
{
642+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
643+
{
644+
removeLineFromSD(stationCoordinateGeodeticFileName, selectedCoords);
645+
removeLineFromLFS(stationCoordinateGeodeticFileName, selectedCoords);
646+
}
647+
else
648+
{
649+
removeLineFromSD(stationCoordinateECEFFileName, selectedCoords);
650+
removeLineFromLFS(stationCoordinateECEFFileName, selectedCoords);
651+
}
652+
653+
if (selectedCoords > 0)
654+
selectedCoords -= 1;
655+
}
656+
else if (incoming == 'l')
657+
{
658+
char newCoords[100];
659+
char *ptr = newCoords;
660+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
661+
{
662+
if (!getFileLineSD(stationCoordinateGeodeticFileName, selectedCoords, newCoords, sizeof(newCoords)))
663+
getFileLineLFS(stationCoordinateGeodeticFileName, selectedCoords, newCoords, sizeof(newCoords));
664+
double lat;
665+
double lon;
666+
double alt;
667+
char baseName[100];
668+
if (sscanf(ptr,"%[^,],%lf,%lf,%lf", baseName, &lat, &lon, &alt) == 4)
669+
{
670+
settings.fixedLat = lat;
671+
settings.fixedLong = lon;
672+
settings.fixedAltitude = alt; // Assume user has entered pole tip altitude
673+
recordSystemSettings();
674+
retVal = true; // New coords need to be applied
675+
}
676+
}
677+
else
678+
{
679+
if (!getFileLineSD(stationCoordinateECEFFileName, selectedCoords, newCoords, sizeof(newCoords)))
680+
getFileLineLFS(stationCoordinateECEFFileName, selectedCoords, newCoords, sizeof(newCoords));
681+
double x;
682+
double y;
683+
double z;
684+
char baseName[100];
685+
if (sscanf(ptr,"%[^,],%lf,%lf,%lf", baseName, &x, &y, &z) == 4)
686+
{
687+
settings.fixedEcefX = x;
688+
settings.fixedEcefY = y;
689+
settings.fixedEcefZ = z;
690+
recordSystemSettings();
691+
retVal = true; // New coords need to be applied
692+
}
693+
}
694+
}
695+
else if (incoming == 't')
696+
{
697+
char newCoords[100];
698+
struct tm timeinfo = rtc.getTimeStruct();
699+
char timestamp[30];
700+
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H:%M:%S", &timeinfo);
701+
if (settings.fixedBaseCoordinateType == COORD_TYPE_GEODETIC)
702+
{
703+
snprintf(newCoords, sizeof(newCoords), "%s,%.8lf,%.8lf,%.4lf",
704+
timestamp,
705+
gnss->getLatitude(),
706+
gnss->getLongitude(),
707+
gnss->getAltitude() - ((settings.antennaHeight_mm + settings.antennaPhaseCenter_mm) / 1000.0));
708+
recordLineToSD(stationCoordinateGeodeticFileName, newCoords);
709+
recordLineToLFS(stationCoordinateGeodeticFileName, newCoords);
710+
}
711+
else
712+
{
713+
double ecefX = 0;
714+
double ecefY = 0;
715+
double ecefZ = 0;
716+
geodeticToEcef(gnss->getLatitude(), gnss->getLongitude(),
717+
gnss->getAltitude() - ((settings.antennaHeight_mm + settings.antennaPhaseCenter_mm) / 1000.0),
718+
&ecefX, &ecefY, &ecefZ);
719+
snprintf(newCoords, sizeof(newCoords), "%s,%.4lf,%.4lf,%.4lf",
720+
timestamp, ecefX, ecefY, ecefZ);
721+
recordLineToSD(stationCoordinateECEFFileName, newCoords);
722+
recordLineToLFS(stationCoordinateECEFFileName, newCoords);
723+
}
724+
}
725+
else if (incoming == 'x')
726+
break;
727+
else if (incoming == INPUT_RESPONSE_GETCHARACTERNUMBER_EMPTY)
728+
break;
729+
else if (incoming == INPUT_RESPONSE_GETCHARACTERNUMBER_TIMEOUT)
730+
break;
731+
else
732+
printUnknown(incoming);
733+
}
734+
735+
clearBuffer(); // Empty buffer of any newline chars
736+
737+
return retVal;
738+
}
739+
480740
#endif // COMPILE_MENU_BASE

0 commit comments

Comments
 (0)