Skip to content

Issue in applyCompensationGGA - LF being truncated #834

@PaulZC

Description

@PaulZC

Prompted by #806 and this forum post:

I suspect applyCompensationGGA can cause the GGA LF (Line Feed) to be truncated...!

I'm still thinking this through, so bear with me.

Two Postcard users have reported the LF being truncated after upgrading to firmware 2.3. Doing a factory reset (s r y) appears to clear the issue.

Could it be dependent on settings.outputTipAltitude?

nmeaApplyCompensation is called on all NMEA messages:

// Handle LLA compensation due to tilt or outputTipAltitude setting
if (type == RTK_NMEA_PARSER_INDEX)
{
nmeaApplyCompensation((char *)parse->buffer, parse->length);
}

If settings.outputTipAltitude is true then applyCompensationGGA is always called (even if tiltIsCorrecting() is false):

// If tilt is off, and outputTipAltitude is disabled, then pass GNSS data without modification
if (tiltIsCorrecting() == false && settings.outputTipAltitude == false)
return;
// Identify sentence type
char sentenceType[strlen("GGA") + 1] = {0};
strncpy(sentenceType, &nmeaSentence[3],
3); // Copy three letters, starting in spot 3. Null terminated from array initializer.
// GGA and GNS sentences get modified in the same way
if (strncmp(sentenceType, "GGA", sizeof(sentenceType)) == 0)
{
applyCompensationGGA(nmeaSentence, sentenceLength);
}

The altitude is extracted and converted to float:

// Extract the altitude
char altitudeStr[strlen("-1602.3481") + 1]; // 4 decimals
strncpy(altitudeStr, &nmeaSentence[altitudeStart], altitudeStop - altitudeStart);
float altitude = (float)atof(altitudeStr);

newAltitude is altitude minus antennaHeight_mm + antennaPhaseCenter_mm:

// If tilt is off and outputTipAltitude is enabled, then subtract pole+ARP from altitude
if (settings.outputTipAltitude == true)
newAltitude = altitude - ((settings.antennaHeight_mm + settings.antennaPhaseCenter_mm) / 1000.0);

newAltitude is always written and always with 4 decimal places:

// Convert altitude double to string
snprintf(coordinateStringDDMM, sizeof(coordinateStringDDMM), "%0.4f", newAltitude);
// Add tilt-compensated Altitude
strncat(newSentence, coordinateStringDDMM, sizeof(newSentence) - 1);

From #806, the LG290P is only outputting 3 decimal places. Because 4 are written, the altitude will always be one character longer.

There is a debug warning. But you would only see it if enableImuCompensationDebug is enabled:

if (strlen(newSentence) > sentenceLength)
{
if (settings.enableImuCompensationDebug == true && !inMainMenu)
systemPrintf("New compensated sentence too long! Orig: %d New: %d\r\n", sentenceLength,
strlen(newSentence));
}

Long story short, the LF gets truncated...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions