Skip to content

Commit

Permalink
Resolve #769. Add settings.geographicRegion. Delete settings.LBandFreq
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulZC committed Jun 5, 2024
1 parent 34e047d commit 7edb87f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 27 deletions.
13 changes: 13 additions & 0 deletions Firmware/RTK_Surveyor/AP-Config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,19 @@
</span>
</div>

<div id="geographicRegionDropdown">
<label for="geographicRegion">Geographic Region:</label>
<select name="geographicRegion" id="geographicRegion" class="form-dropdown mb-2">
<option value="0">US</option>
<option value="1">EU</option>
</select>
<span class="tt" data-bs-placement="right"
title="Select your geographic region. This defines the default L-Band frequency. Default: US">
<span class="icon-info-circle text-primary ms-2"></span>
</span>
<br>
</div>

<div id="ppSettingsConfig">
<div class="form-check mt-3">
<label class="form-check-label" for="autoKeyRenewal">Auto Key Renewal </label>
Expand Down
4 changes: 4 additions & 0 deletions Firmware/RTK_Surveyor/Form.ino
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ void createSettingsString(char *newSettings)
stringRecord(newSettings, "pointPerfectDeviceProfileToken", settings.pointPerfectDeviceProfileToken);
stringRecord(newSettings, "enablePointPerfectCorrections", settings.enablePointPerfectCorrections);
stringRecord(newSettings, "autoKeyRenewal", settings.autoKeyRenewal);
stringRecord(newSettings, "geographicRegion", settings.geographicRegion);

// External PPS/Triggers
stringRecord(newSettings, "enableExternalPulse", settings.enableExternalPulse);
Expand Down Expand Up @@ -1385,6 +1386,9 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr
else if (strcmp(settingName, "autoFirmwareCheckMinutes") == 0)
settings.autoFirmwareCheckMinutes = settingValueBool;

else if (strcmp(settingName, "geographicRegion") == 0)
settings.geographicRegion = settingValue;

// Unused variables - read to avoid errors
else if (strcmp(settingName, "measurementRateSec") == 0)
{
Expand Down
8 changes: 5 additions & 3 deletions Firmware/RTK_Surveyor/NVM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ void recordSystemSettingsToFile(File *settingsFile)
settingsFile->printf("%s=%d\r\n", "debugPpCertificate", settings.debugPpCertificate);

settingsFile->printf("%s=%d\r\n", "updateZEDSettings", settings.updateZEDSettings);
settingsFile->printf("%s=%d\r\n", "LBandFreq", settings.LBandFreq);
settingsFile->printf("%s=%d\r\n", "enableLogging", settings.enableLogging);
settingsFile->printf("%s=%d\r\n", "enableARPLogging", settings.enableARPLogging);
settingsFile->printf("%s=%d\r\n", "ARPLoggingInterval_s", settings.ARPLoggingInterval_s);
Expand Down Expand Up @@ -451,6 +450,8 @@ void recordSystemSettingsToFile(File *settingsFile)
settingsFile->printf("%s=%d\r\n", "enableZedUsb", settings.enableZedUsb);
settingsFile->printf("%s=%d\r\n", "debugWiFiConfig", settings.debugWiFiConfig);

settingsFile->printf("%s=%d\r\n", "geographicRegion", settings.geographicRegion);

// Add new settings above <------------------------------------------------------------>
}

Expand Down Expand Up @@ -1089,8 +1090,6 @@ bool parseLine(char *str, Settings *settings)
if (settings->updateZEDSettings != d)
settings->updateZEDSettings = true; // If there is a discrepancy, push ZED reconfig
}
else if (strcmp(settingName, "LBandFreq") == 0)
settings->LBandFreq = d;
else if (strcmp(settingName, "timeZoneHours") == 0)
settings->timeZoneHours = d;
else if (strcmp(settingName, "timeZoneMinutes") == 0)
Expand Down Expand Up @@ -1377,6 +1376,9 @@ bool parseLine(char *str, Settings *settings)
else if (strcmp(settingName, "debugWiFiConfig") == 0)
settings->debugWiFiConfig = d;

else if (strcmp(settingName, "geographicRegion") == 0)
settings->geographicRegion = d;

// Add new settings above
//<------------------------------------------------------------>

Expand Down
58 changes: 35 additions & 23 deletions Firmware/RTK_Surveyor/menuPP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1148,44 +1148,47 @@ void beginLBand()
theGNSS.checkCallbacks(); // Process any callbacks: ie, eventTriggerReceived
}

uint32_t LBandFreq;
// If we have a fix, check which frequency to use
if (fixType == 2 || fixType == 3 || fixType == 4 || fixType == 5) // 2D, 3D, 3D+DR, or Time
{
if ((longitude > -125 && longitude < -67) && (latitude > -90 && latitude < 90))
int r = 0; // Step through each geographic region
for (; r < numRegionalAreas; r++)
{
if (settings.debugLBand == true)
systemPrintln("Setting L-Band to US");
settings.LBandFreq = 1556290000; // We are in US band
}
else if ((longitude > -25 && longitude < 70) && (latitude > -90 && latitude < 90))
{
if (settings.debugLBand == true)
systemPrintln("Setting L-Band to EU");
settings.LBandFreq = 1545260000; // We are in EU band
if ((longitude >= Regional_Information_Table[r].area.lonWest)
&& (longitude <= Regional_Information_Table[r].area.lonEast)
&& (latitude >= Regional_Information_Table[r].area.latSouth)
&& (latitude <= Regional_Information_Table[r].area.latNorth))
{
LBandFreq = Regional_Information_Table[r].frequency;
if (settings.debugLBand == true)
systemPrintf("Setting L-Band frequency to %s (%dHz)\r\n", Regional_Information_Table[r].name, LBandFreq);
break;
}
}
else
if (r == numRegionalAreas) // Geographic region not found
{
systemPrintln("Error: Unknown band area. Defaulting to US band.");
settings.LBandFreq = 1556290000; // Default to US
LBandFreq = Regional_Information_Table[settings.geographicRegion].frequency;
systemPrintf("Error: Unknown L-Band geographic region. Using %s (%dHz)\r\n", Regional_Information_Table[settings.geographicRegion].name, LBandFreq);
}
recordSystemSettings();
}
else
{
LBandFreq = Regional_Information_Table[settings.geographicRegion].frequency;
if (settings.debugLBand == true)
systemPrintln("No fix available for L-Band frequency determination");
systemPrintf("No fix available for L-Band geographic region determination. Using %s (%dHz)\r\n", Regional_Information_Table[settings.geographicRegion].name, LBandFreq);
}

bool response = true;
response &= i2cLBand.newCfgValset();
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_CENTER_FREQUENCY, settings.LBandFreq); // Default 1539812500 Hz
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_SEARCH_WINDOW, 2200); // Default 2200 Hz
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_SERVICE_ID, 0); // Default 1
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_SERVICE_ID, 21845); // Default 50821
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_DATA_RATE, 2400); // Default 2400 bps
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_DESCRAMBLER, 1); // Default 1
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_DESCRAMBLER_INIT, 26969); // Default 23560
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_PRESCRAMBLING, 0); // Default 0
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_CENTER_FREQUENCY, LBandFreq); // Default 1539812500 Hz
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_SEARCH_WINDOW, 2200); // Default 2200 Hz
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_SERVICE_ID, 0); // Default 1
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_SERVICE_ID, 21845); // Default 50821
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_DATA_RATE, 2400); // Default 2400 bps
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_DESCRAMBLER, 1); // Default 1
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_DESCRAMBLER_INIT, 26969); // Default 23560
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_USE_PRESCRAMBLING, 0); // Default 0
response &= i2cLBand.addCfgValset(UBLOX_CFG_PMP_UNIQUE_WORD, 16238547128276412563ull);
response &=
i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART1, 0); // Diasable UBX-RXM-PMP on UART1. Not used.
Expand Down Expand Up @@ -1268,6 +1271,9 @@ void menuPointPerfect()

systemPrintln("k) Manual Key Entry");

systemPrint("g) Geographic Region: ");
systemPrintln(Regional_Information_Table[settings.geographicRegion].name);

systemPrintln("x) Exit");

byte incoming = getCharacterNumber();
Expand Down Expand Up @@ -1346,6 +1352,12 @@ void menuPointPerfect()
{
menuPointPerfectKeys();
}
else if (incoming == 'g')
{
settings.geographicRegion++;
if (settings.geographicRegion >= numRegionalAreas)
settings.geographicRegion = 0;
}
else if (incoming == 'x')
break;
else if (incoming == INPUT_RESPONSE_GETCHARACTERNUMBER_EMPTY)
Expand Down
35 changes: 34 additions & 1 deletion Firmware/RTK_Surveyor/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,38 @@ const ubxCmd ubxCommands[] = {

#define MAX_UBX_CMD (sizeof(ubxCommands) / sizeof(ubxCmd))

// Regional Support
// Do we want the user to be able to specify which region they are in?
// Or do we want to figure it out based on position?
// If we define a simple 'square' area for each region, we can do both.
// Note: the best way to obtain the L-Band frequencies would be from the MQTT /pp/frequencies/Lb topic.
// But it is easier to record them here, in case we don't have access to MQTT...
// Note: the key distribution topic is provided during ZTP. We don't need to record it here.

typedef struct
{
const double latNorth; // Degrees
const double latSouth; // Degrees
const double lonEast; // Degrees
const double lonWest; // Degrees
} Regional_Area;

typedef struct
{
const char *name; // As defined in the ZTP subscriptions description: EU, US, KR, AU, Japan
const char *topicRegion; // As used in the corrections topic path
const Regional_Area area;
const uint32_t frequency; // L-Band frequency, Hz, if supported. 0 if not supported
} Regional_Information;

const Regional_Information Regional_Information_Table[] =
{
{ "US", "us", { 50.0, 25.0, -60.0, -125.0}, 1556290000 },
{ "EU", "eu", { 72.0, 36.0, 32.0, -11.0}, 1545260000 },
// Note: we only include regions with L-Band coverage. AU, KR and Japan are not included here.
};
const int numRegionalAreas = sizeof(Regional_Information_Table) / sizeof(Regional_Information_Table[0]);

// This is all the settings that can be set on RTK Surveyor. It's recorded to NVM and the config file.
typedef struct
{
Expand Down Expand Up @@ -941,7 +973,6 @@ typedef struct

uint64_t lastKeyAttempt = 0; // Epoch time of last attempt at obtaining keys
bool updateZEDSettings = true; // When in doubt, update the ZED with current settings
uint32_t LBandFreq = 1556290000; // Default to US band

bool debugPpCertificate = false; // Debug Point Perfect certificate management

Expand Down Expand Up @@ -1120,6 +1151,8 @@ typedef struct

bool debugWiFiConfig = false;

int geographicRegion = 0; // Default to US - first entry in Regional_Information_Table

// Add new settings above <------------------------------------------------------------>

} Settings;
Expand Down

0 comments on commit 7edb87f

Please sign in to comment.