kosma / minmea

a lightweight GPS NMEA 0183 parser library in pure C
Do What The F*ck You Want To Public License
755 stars 246 forks source link

multiple messages in one stream #27

Closed diggit closed 6 years ago

diggit commented 6 years ago

Hi, I am using your library on STM32 and Ublox Neo-M8P. All received messages are in one string. There are no NULL terminations. To make minmea work directly with such block, I had to do few changes in minmea.c.

Here is diff:

50,51c50,51
<     if (strlen(sentence) > MINMEA_MAX_LENGTH + 3)
<         return false;
---
>     // if (strlen(sentence) > MINMEA_MAX_LENGTH + 3)
>     //     return false;
82c82
<     if (*sentence && strcmp(sentence, "\n") && strcmp(sentence, "\r\n"))
---
>     if (*sentence && strncmp(sentence, "\n",1) && strncmp(sentence, "\r\n", 2))
613a614
> 

I had to:

I can make these changes configurable using preprocessor conditionals. Are you interested in merging such changes?

You saved me a lot of time, neat library!

kosma commented 6 years ago

Hi, That would be a bit of a kludge. Maybe you could just preprocess the data slightly and insert NUL terminators where needed, like this?

char *line = buff;
while (*line) {
    char *newline = strpbrk(line, "\r\n");
    if (newline) { *newline = '\0'; }
    minmea_parse(line);
    if (newline)
        line = newline+1;
    else
        break;
}
kosma commented 6 years ago

PS. Be aware that STM32F1 is known to generate EMI that disrupts GPS receiver operation. Here's an arcane thread on an arcane Polish forum:

https://www.elektroda.pl/rtvforum/topic1541960.html

I've verified it and indeed, just doing flash fetches on STM32F103 is enough to significantly interfere with GPS. You can test it yourself by running the following code on an MCU and bringing it close to any GPS antenna (including, for example, smartphone antenna):

while (1) {
    asm("nop");
    asm("nop");
    asm("nop");
    /* lots of repetitions, at least 16 of them */
    asm("nop");
}

We had a product where the interference was in range of 10dB (a lot in GPS world). If possible, try to mitigate it by 1. moving idle loop to RAM, 2. moving MCU away from GPS antenna/receiver.

diggit commented 6 years ago

Tanks for suggestion about NUL teminators. That is probably cleaner way to go. I just wanted to minimize MCU usage. There are other things that need to be taken care of in time.

Current design is based on STM32F7. GNSS receiver is placed away from MCU and external active antenna is used so there should not be problem. Reception is stable and strong. Thanks for info, I'll keep it in mind for more minimalistic designs in future. mcu_board

kosma commented 6 years ago

STM32F7 should fare much better; it's only F1 that causes trouble. Good luck with the project!