Skip to content

Commit f41bcce

Browse files
committed
Kinda working...!?
1 parent 893cfc9 commit f41bcce

File tree

3 files changed

+38
-130
lines changed

3 files changed

+38
-130
lines changed

Firmware/RTK_Everywhere/GNSS_Mosaic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ class GNSS_MOSAIC : GNSS
862862

863863
// Send commands out the UART to see if a mosaic module is present
864864
bool isPresent();
865-
bool isPresentOnSerial(HardwareSerial *serialPort, const char *command, const char *response, const char *console);
865+
bool isPresentOnSerial(HardwareSerial *serialPort, const char *command, const char *response, const char *console, int retryLimit = 20);
866866
bool mosaicIsPresentOnFlex();
867867

868868
// Some functions (L-Band area frequency determination) merely need

Firmware/RTK_Everywhere/GNSS_Mosaic.ino

Lines changed: 13 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,8 @@ void GNSS_MOSAIC::begin()
218218
// COM3 can be connected to ESP32 UART2 (switched by SW3)
219219
// COM4 can be connected to ESP32 UART0 (switched by SW2)
220220
// We need to do everything through COM1: configure, transfer RTCM, receive NMEA
221-
// To make life easier for ourselves, we should:
222-
// Not support L-Band
223-
// Not encapsulate RTCMv3 and NMEA in SBF format
224-
// Configure the rtkParse accordingly
225-
// TODO: increase the COM1 baud rate to help. For now, leave it at 115200
221+
// We need to Encapsulate RTCMv3 and NMEA in SBF format. Both SBF and NMEA messages start with "$".
222+
// The alternative would be to add a 'hybrid' parser to the SEMP which can disambiguate SBF and NMEA
226223

227224
// On Facet Flex (with IMU):
228225
// COM1 is connected to the ESP32 UART1
@@ -542,10 +539,8 @@ bool GNSS_MOSAIC::configureNtpMode()
542539
//----------------------------------------
543540
bool GNSS_MOSAIC::configureGNSSCOM(bool enableLBand)
544541
{
545-
// Configure COM1. NMEA and RTCMv3 will be encapsulated in SBF format on Facet mosaic
546-
String setting = String("sdio,COM1,auto,RTCMv3+SBF+NMEA");
547-
if (productVariant == RTK_FACET_MOSAIC)
548-
setting + String("+Encapsulate");
542+
// Configure COM1. NMEA and RTCMv3 will be encapsulated in SBF format
543+
String setting = String("sdio,COM1,auto,RTCMv3+SBF+NMEA+Encapsulate");
549544
if (enableLBand)
550545
setting += String("+LBandBeam1");
551546
setting += String("\n\r");
@@ -2949,96 +2944,23 @@ bool GNSS_MOSAIC::isPresent()
29492944
{
29502945
if (productVariant != RTK_FLEX) // productVariant == RTK_FACET_MOSAIC
29512946
{
2952-
// Mosaic could still be starting up, so allow many retries
2953-
int retries = 0;
2954-
int retryLimit = 20;
2955-
29562947
// Set COM4 to: CMD input (only), SBF output (only)
2957-
while (!sendWithResponse(serial2GNSS, "sdio,COM4,CMD,SBF\n\r", "DataInOut"))
2958-
{
2959-
if (retries == retryLimit)
2960-
break;
2961-
retries++;
2962-
sendWithResponse(serial2GNSS, "SSSSSSSSSSSSSSSSSSSS\n\r", "COM4>"); // Send escape sequence
2963-
}
2964-
2965-
if (retries == retryLimit)
2966-
{
2967-
systemPrintln("Could not communicate with mosaic-X5! Attempting a soft reset...");
2968-
2969-
sendWithResponse(serial2GNSS, "erst,soft,none\n\r", "ResetReceiver");
2970-
2971-
retries = 0;
2972-
2973-
// Set COM4 to: CMD input (only), SBF output (only)
2974-
while (!sendWithResponse(serial2GNSS, "sdio,COM4,CMD,SBF\n\r", "DataInOut"))
2975-
{
2976-
if (retries == retryLimit)
2977-
break;
2978-
retries++;
2979-
sendWithResponse(serial2GNSS, "SSSSSSSSSSSSSSSSSSSS\n\r", "COM4>"); // Send escape sequence
2980-
}
2981-
2982-
if (retries == retryLimit)
2983-
{
2984-
systemPrintln("Could not communicate with mosaic-X5!");
2985-
return(false);
2986-
}
2987-
}
2988-
2989-
// Module responded correctly!
2990-
return (true);
2948+
// Mosaic could still be starting up, so allow many retries
2949+
return isPresentOnSerial(serial2GNSS, "sdio,COM4,CMD,SBF\n\r", "DataInOut", "COM4>", 20);
29912950
}
29922951
else // productVariant == RTK_FLEX
29932952
{
2953+
// Set COM1 to: auto input, RTCMv3+SBF+NMEA+Encapsulate output
29942954
// Mosaic could still be starting up, so allow many retries
2995-
int retries = 0;
2996-
int retryLimit = 20;
2997-
2998-
// Set COM1 to: auto input, RTCMv3+SBF+NMEA output
2999-
while (!sendWithResponse(serialGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA\n\r", "DataInOut"))
3000-
{
3001-
if (retries == retryLimit)
3002-
break;
3003-
retries++;
3004-
sendWithResponse(serialGNSS, "SSSSSSSSSSSSSSSSSSSS\n\r", "COM1>"); // Send escape sequence
3005-
}
3006-
3007-
if (retries == retryLimit)
3008-
{
3009-
systemPrintln("Could not communicate with mosaic-X5! Attempting a soft reset...");
3010-
3011-
sendWithResponse(serialGNSS, "erst,soft,none\n\r", "ResetReceiver");
3012-
3013-
retries = 0;
3014-
3015-
// Set COM1 to: auto input, RTCMv3+SBF+NMEA output
3016-
while (!sendWithResponse(serialGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA\n\r", "DataInOut"))
3017-
{
3018-
if (retries == retryLimit)
3019-
break;
3020-
retries++;
3021-
sendWithResponse(serialGNSS, "SSSSSSSSSSSSSSSSSSSS\n\r", "COM1>"); // Send escape sequence
3022-
}
3023-
3024-
if (retries == retryLimit)
3025-
{
3026-
systemPrintln("Could not communicate with mosaic-X5!");
3027-
return(false);
3028-
}
3029-
}
3030-
3031-
// Module responded correctly!
3032-
return (true);
2955+
return isPresentOnSerial(serialGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA+Encapsulate\n\r", "DataInOut", "COM1>", 20);
30332956
}
30342957
}
30352958

30362959
//Return true if the receiver is detected
3037-
bool GNSS_MOSAIC::isPresentOnSerial(HardwareSerial *serialPort, const char *command, const char *response, const char *console)
2960+
bool GNSS_MOSAIC::isPresentOnSerial(HardwareSerial *serialPort, const char *command, const char *response, const char *console, int retryLimit)
30382961
{
30392962
// Mosaic could still be starting up, so allow many retries
30402963
int retries = 0;
3041-
int retryLimit = 20;
30422964

30432965
while (!sendWithResponse(serialPort, command, response))
30442966
{
@@ -3338,7 +3260,8 @@ bool mosaicIsPresentOnFlex()
33383260
// Check with 115200 initially. If that succeeds, increase to 460800
33393261
serialTestGNSS.begin(115200, SERIAL_8N1, pin_GnssUart_RX, pin_GnssUart_TX);
33403262

3341-
if (mosaic.isPresentOnSerial(&serialTestGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA\n\r", "DataInOut", "COM1>") == true)
3263+
// Only try 3 times. LG290P detection will have been done first. X5 should have booted. Baud rate could be wrong.
3264+
if (mosaic.isPresentOnSerial(&serialTestGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA+Encapsulate\n\r", "DataInOut", "COM1>", 3) == true)
33423265
{
33433266
if (settings.debugGnss)
33443267
systemPrintln("mosaic-X5 detected at 115200 baud");
@@ -3357,7 +3280,8 @@ bool mosaicIsPresentOnFlex()
33573280
serialTestGNSS.end();
33583281
serialTestGNSS.begin(460800, SERIAL_8N1, pin_GnssUart_RX, pin_GnssUart_TX);
33593282

3360-
if (mosaic.isPresentOnSerial(&serialTestGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA\n\r", "DataInOut", "COM1>") == true)
3283+
// Only try 3 times, so we fail and pass on to the next Facet GNSS detection
3284+
if (mosaic.isPresentOnSerial(&serialTestGNSS, "sdio,COM1,auto,RTCMv3+SBF+NMEA+Encapsulate\n\r", "DataInOut", "COM1>", 3) == true)
33613285
{
33623286
// serialGNSS and serial2GNSS have not yet been begun. We need to saveConfiguration manually
33633287
unsigned long start = millis();

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const int ringBufferConsumerEntries = sizeof(ringBufferConsumer) / sizeof(ringBu
7878
#define RTK_RTCM_PARSER_INDEX 2
7979
#define RTK_UBLOX_PARSER_INDEX 3
8080
#define RTK_UNICORE_BINARY_PARSER_INDEX 4
81-
#define RTK_SBF_PARSER_INDEX 5
8281

8382
// List the parsers to be included
8483
SEMP_PARSE_ROUTINE const parserTable[] = {
@@ -87,7 +86,6 @@ SEMP_PARSE_ROUTINE const parserTable[] = {
8786
sempRtcmPreamble,
8887
sempUbloxPreamble,
8988
sempUnicoreBinaryPreamble,
90-
sempSbfPreamble,
9189
};
9290
const int parserCount = sizeof(parserTable) / sizeof(parserTable[0]);
9391

@@ -98,7 +96,6 @@ const char *const parserNames[] = {
9896
"RTCM",
9997
"u-Blox",
10098
"Unicore Binary",
101-
"SBF",
10299
};
103100
const int parserNameCount = sizeof(parserNames) / sizeof(parserNames[0]);
104101

@@ -394,7 +391,7 @@ void gnssReadTask(void *e)
394391
if (settings.debugGnss)
395392
sempEnableDebugOutput(rtkParse);
396393

397-
bool sbfParserNeeded = present.gnss_mosaicX5 && (productVariant != RTK_FLEX);
394+
bool sbfParserNeeded = present.gnss_mosaicX5;
398395

399396
if (sbfParserNeeded)
400397
{
@@ -407,25 +404,30 @@ void gnssReadTask(void *e)
407404
if (!sbfParse)
408405
reportFatalError("Failed to initialize the SBF parser");
409406

410-
// Any data which is not SBF will be passed to the SPARTN parser via the invalid data callback
411-
sempSbfSetInvalidDataCallback(sbfParse, processNonSBFData);
412-
413407
// Uncomment the next line to enable SBF parser debug
414408
// But be careful - you get a lot of "SEMP: Sbf SBF, 0x0002 (2) bytes, invalid preamble2"
415409
// if (settings.debugGnss) sempEnableDebugOutput(sbfParse);
416410

417-
// Initialize the SPARTN parser for the mosaic-X5
418-
spartnParse = sempBeginParser(spartnParserTable, spartnParserCount, spartnParserNames, spartnParserNameCount,
419-
0, // Scratchpad bytes
420-
1200, // Buffer length - SPARTN payload is 1024 bytes max
421-
processUart1SPARTN, // eom Call Back - in mosaic.ino
422-
"spartnParse"); // Parser Name
423-
if (!spartnParse)
424-
reportFatalError("Failed to initialize the SPARTN parser");
425-
426-
// Uncomment the next line to enable SPARTN parser debug
427-
// But be careful - you get a lot of "SEMP: Spartn SPARTN 0 0, 0x00f4 (244) bytes, bad CRC"
428-
// if (settings.debugGnss) sempEnableDebugOutput(spartnParse);
411+
bool spartnParserNeeded = present.gnss_mosaicX5 && (productVariant != RTK_FLEX);
412+
413+
if (spartnParserNeeded)
414+
{
415+
// Any data which is not SBF will be passed to the SPARTN parser via the invalid data callback
416+
sempSbfSetInvalidDataCallback(sbfParse, processNonSBFData);
417+
418+
// Initialize the SPARTN parser for the mosaic-X5
419+
spartnParse = sempBeginParser(spartnParserTable, spartnParserCount, spartnParserNames, spartnParserNameCount,
420+
0, // Scratchpad bytes
421+
1200, // Buffer length - SPARTN payload is 1024 bytes max
422+
processUart1SPARTN, // eom Call Back - in mosaic.ino
423+
"spartnParse"); // Parser Name
424+
if (!spartnParse)
425+
reportFatalError("Failed to initialize the SPARTN parser");
426+
427+
// Uncomment the next line to enable SPARTN parser debug
428+
// But be careful - you get a lot of "SEMP: Spartn SPARTN 0 0, 0x00f4 (244) bytes, bad CRC"
429+
// if (settings.debugGnss) sempEnableDebugOutput(spartnParse);
430+
}
429431
}
430432

431433
// Run task until a request is raised
@@ -455,7 +457,7 @@ void gnssReadTask(void *e)
455457
// device) To allow the Unicore library to send/receive serial commands, we need to block the gnssReadTask
456458
// If the Unicore library does not need lone access, then read from serial port
457459

458-
// For the mosaic-X5, things are different. The mosaic-X5 outputs a raw stream of L-Band bytes,
460+
// For the Facet mosaic-X5, things are different. The mosaic-X5 outputs a raw stream of L-Band bytes,
459461
// interspersed with periodic SBF blocks. The SBF blocks can contain encapsulated NMEA and RTCMv3.
460462
// We need to pass each incoming byte to a SBF parser first, so it can pick out any SBF blocks.
461463
// The SBF parser needs to 'give up' (return) any bytes which are not SBF. We do that using the
@@ -471,6 +473,8 @@ void gnssReadTask(void *e)
471473
// from being parsed from valid SBF blocks and causes the NTRIP server connection to break. We need
472474
// to add extra checks, above and beyond the invalidDataCallback, to make sure that doesn't happen.
473475
// Here we check that the SBF ID and length are expected / valid too.
476+
//
477+
// For Facet Flex mosaic, we need the SBF parser but not the SPARTN parser
474478

475479
if (gnss->isBlocking() == false)
476480
{
@@ -638,12 +642,6 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
638642
systemPrintf("%s %s, 0x%04x (%d) bytes\r\n", parse->parserName, parserNames[type], parse->length,
639643
parse->length);
640644
break;
641-
642-
case RTK_SBF_PARSER_INDEX:
643-
message = sempSbfGetBlockNumber(parse);
644-
systemPrintf("%s %s %d, 0x%04x (%d) bytes\r\n", parse->parserName, parserNames[type], message,
645-
parse->length, parse->length);
646-
break;
647645
}
648646
}
649647

@@ -689,12 +687,6 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
689687
nmeaExtractStdDeviations((char *)parse->buffer, parse->length);
690688
}
691689

692-
// Facet Flex mosaic - pass the SBF to processUart1SBF
693-
if ((present.gnss_mosaicX5) && (productVariant == RTK_FLEX) && (type == RTK_SBF_PARSER_INDEX))
694-
{
695-
processUart1SBF(parse, type);
696-
}
697-
698690
// Determine where to send RTCM data
699691
if (inBaseMode() && type == RTK_RTCM_PARSER_INDEX)
700692
{
@@ -809,14 +801,6 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
809801
parse->length = 0;
810802
}
811803

812-
// Suppress SBF messages from mosaic. Not needed by end GIS apps.
813-
if (type == RTK_SBF_PARSER_INDEX)
814-
{
815-
// Erase buffer
816-
parse->buffer[0] = 0;
817-
parse->length = 0;
818-
}
819-
820804
// Determine if this message will fit into the ring buffer
821805
bytesToCopy = parse->length;
822806
space = availableHandlerSpace;

0 commit comments

Comments
 (0)