This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP-EXP430FR2433: How to parse GPS string?

Part Number: MSP-EXP430FR2433

Tool/software: Code Composer Studio

Hi,

I'm using MSP-EXP430FR2433.

This board does not have enough memory to use sscanf with float format. (like latitude)

1. how to get float value?

2. Sometimes I get $GPRMC,075643.00,A,2237.93764,N,12017.28144,E,,,110618,,,A*7C.
    how to get char array in continuously delimiter?
    I can't get the string "110618"    

simple example:
It is work if the string is "$GPRMC,A,B,C*XX"
but not work in "$GPRMC,,B,C*XX"

#include <msp430.h>

#include <stdio.h>

int main()
{
   //char buf[50]="$GPRMC,A,B,C*XX";
   char buf[50]="$GPRMC,,B,C*XX";
   char tmp1[10]={0},tmp2[10]={0};

   sscanf(buf,"$GPRMC,%[^,],%[^,],*XX",tmp1,tmp2);

   printf(tmp1);
   printf(tmp2);


   return 0;
}

  • This is a how-to-write-the-code kind of question.  We rarely see such questions in this forum.  Other forums, outside of TI, are probably a better choice.

    That said, I can suggest some standard RTS functions that might be helpful.  To split a string up, based on a delimiter like a comma, use strtok.  To see if a string contains a '.', and thus is probably a floating point constant, use strchr.  

    To completely parse a float constant string, without using sscanf, requires a lot of code.  It would probably be smaller than sscanf.  But the size difference may not be enough to matter.

    Thanks and regards,

    -George

  • Dear George,

    Thank you for your response.

    strtok has the same problem.

    Simple example is shown below.

    I will try to find programming forums. :)

    Thanks.

    #include <stdio.h>
    #include <string.h>

    int main()
    {

    char gps[]="$GPRMC,,,075643.00,A,2237.93764,,,A*7C";
    char *token;

    token = strtok(gps, ",");
    printf( "1. %s\n", token );
    token = strtok(NULL, ",");
    printf( "2. %s\n", token );
    token = strtok(NULL, ",");
    printf( "3. %s\n", token );
    token = strtok(NULL, ",");
    printf( "4. %s\n", token );


    return 0;
    }

  • Consider the possibility that printf is not working.  Please see the article Tips for using printf.

    Thanks and regards,

    -George