Bug 55533 - New nmea parser leaves LF in the buffer and discards following sentences
Summary: New nmea parser leaves LF in the buffer and discards following sentences
Status: NEW
Alias: None
Product: Gypsy
Classification: Unclassified
Component: General (show other bugs)
Version: unspecified
Hardware: ARM Linux (All)
: medium normal
Assignee: iain
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-02 12:42 UTC by Christopher Vogl
Modified: 2012-10-02 12:42 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Christopher Vogl 2012-10-02 12:42:56 UTC
gypsy_nmea_parser_received_data() in gypsy-nmea-parser.c watches out for <CR>.
NMEA sentences may come in in chunks and if the second to last chunk ends with a <CR>, the following <LF> is left in the buffer and consequently the next sentence starts with a <LF>. nmea_parse_sentence() in nmea-parser.c invalidates a sentence that does not start with '$'.
I am using a Telit UC864-G. NMEA sentences come in in several chunks and thus most of them get discarded because of that.

A solution would be to ignore a sentence with a <LF> at the beginning.
The following code works for me:

static gboolean
gypsy_nmea_parser_received_data (GypsyParser *parser,
                                 gsize        length,
                                 GError     **error)
{
    GypsyNmeaParser *nmea = GYPSY_NMEA_PARSER (parser);
    GypsyNmeaParserPrivate *priv = nmea->priv;
    char *eos = NULL;

    priv->chars_in_buffer += length;

    /* Append a '\0' to the data so we never run off the end.
       The '\0' will be overwritten by the next call to received_data */
    *(priv->buffer + priv->chars_in_buffer) = '\0';

    /* NMEA sentences end with <CR><LF>,
       so find the <LF> at the end of each sentence */
    while ((eos = strchr (priv->buffer, '\n'))) {
        int sentence_length;

        sentence_length = (eos - priv->buffer);

        if (sentence_length > 1) {
            /* terminate the string at the <CR> */
            *(eos-1) = '\0';

            g_debug ("NMEA sentence: %s", priv->buffer);
            if (nmea_parse_sentence (priv->ctxt, priv->buffer, NULL) == FALSE) {
                g_debug ("Invalid sentence: %s", priv->buffer);
            }
        }

        if (sentence_length > 0) {
            /* Remove the sentence from the buffer */
            memset (priv->buffer, 0, sentence_length + 2);
            priv->chars_in_buffer = 0;
        }
    }

    return TRUE;
}


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.