Menu

Send a nmea sentence to a GPS receiver

Help
Matthew A
2011-03-04
2014-07-29
  • Matthew A

    Matthew A - 2011-03-04

    Hi,

    I'm trying to figure out how I can use this library to request a NMEA sentence from a GPS device.  I don't really know where to start looking in the .c and .h files.  The sample files do not do think to my understanding (I can't really tell what they do).  Can someone please help me?

     
  • glenn_gsi

    glenn_gsi - 2014-02-13

    I think you will find that the parser knows nothing about gps hardware. Its only job is to parse a text NMEA sentence. That sentence can be typed in by you or obtained from a gps.

    The gps modules simply send some NMEA sentences (plain text) that hold position, time data etc. at certain time intervals, usually one second. Your task is to capture the sentence and pass it to the NMEA parser.

    I believe that all gps modules provide an rs232 interface of some sort. Usually 4800 baud at a minimum.

    I would try to look at the output of your gps and see if you can see it sending data. Be sure that you know what voltages are present on the rs232 lines of both the gps and the receiver of the messages. You don't want to attach a 3V3 gps rs232 to a +-12V pc rs232.

    Glenn

     
  • glenn_gsi

    glenn_gsi - 2014-07-29

    Here is a short piece of code that turns off messages on a cheap eBay sourced V.KEL vk16E gps module.
    Setting 0 in VK16E.d1 will turn off that message
    Setting 1 in VK16E.d1 will request that message from the gps, so you could turn them all off and then request them when required.

    This particular snippet will turn off all messages except RMC. RMC will only be tx'd every 10 seconds. This is useful if you only need location and time from the gps and wish to reduce the amount of processor time reqd to handle messages.

    The function GPSAddMessageToCB((circBuffType *)pvk->sentence); sends the message to a circular buffer for Tx to the gps. Not included here as this will be implementation dependent. This version runs on an ARM chip

    Glenn

    void GPS_MakeSentence(PVK16E nmea);

    typedef struct vk16e_s
    {
    nmeaId_t id;
    uint8_t d0;
    uint8_t d1;
    uint8_t d2;
    uint8_t d3;
    char sentence[MAX_NMEA_SENT_SENTENCE+1];
    }VK16E, *PVK16E;

    typedef enum nmeaSentence_e
    {
    nmea_GGA=0,
    nmea_GLL,
    nmea_GSA,
    nmea_GSV,
    nmea_RMC,
    nmea_VTG,
    nmea_Query=20,
    nmea_QueryRate_GGA,
    nmea_QueryRate_GLL,
    nmea_QueryRate_GSA,
    nmea_QueryRate_GSV,
    nmea_QueryRate_RMC,
    nmea_QueryRate_VTG,
    }nmeaId_t;

    void SomeGPSFuntion()
    {
    pvk=(PVK16E)bget(sizeof (VK16E));
    /******
    ! \brief
    *turn off GSV messages
    ******/
    pvk->id=nmea_QueryRate_GSV; //the function to perform
    //data associated with the function
    pvk->d0=nmea_GSV; //the id of the sentence to query
    pvk->d1=0; //0=set rate. 1=query
    pvk->d2=0; //send ever x seconds
    pvk->d3=0; //with checksum==1, we will usually send a 0
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);

    /******
    ! \brief
    *turn off GLL messages
    ******/
    pvk->id=nmea_QueryRate_GLL;
    //ids are data fields sent to GPS
    pvk->d0=nmea_GLL; //the id of the sentence to query
    pvk->d1=0; //0=set rate, 1=query
    pvk->d2=0; //send every x seconds
    pvk->d3=0; //with checksum==1, we will usually send a 0
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);

    /******
    ! \brief
    *turn off GSA messages
    ******/
    pvk->id=nmea_QueryRate_GSA;
    //ids are data fields sent to GPS
    pvk->d0=nmea_GSA; //the id of the sentence to query
    pvk->d1=0; //0=set rate, 1=query
    pvk->d2=0; //send every x seconds
    pvk->d3=0; //with checksum==1, we will usually send a 0
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);

    /******
    ! \brief
    *turn off VTG messages
    ******/
    pvk->id=nmea_QueryRate_VTG;
    //ids are data fields sent to GPS
    pvk->d0=nmea_VTG; //the id of the sentence to query
    pvk->d1=0; //0=set rate, 1=query
    pvk->d2=0; //send every x seconds
    pvk->d3=0; //with checksum==1, we will usually send a 0
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);

    /******
    ! \brief
    *Send GGA every ten seconds
    ******/
    pvk->id=nmea_QueryRate_GGA;
    //ids are data fields sent to GPS
    pvk->d0=nmea_GGA; //the id of the sentence to query
    pvk->d1=0; //0=set rate, 1=query
    pvk->d2=0; //send every x seconds
    pvk->d3=1; //with checksum==1, we will usually send a 0
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);

    /******
    ! \brief
    Send RMC every ten seconds
    Should send a checksum according to docs
    ******/
    pvk->id=nmea_QueryRate_RMC;
    //ids are data fields sent to GPS
    pvk->d0=nmea_RMC; //the id of the sentence to query
    pvk->d1=0; //0=set rate, 1=query
    pvk->d2=10; //send every x seconds
    pvk->d3=1; //with checksum==1
    GPS_MakeSentence(pvk);
    GPSAddMessageToCB((circBuffType *)pvk->sentence);
    }

    void GPS_MakeSentence(PVK16E nmea)
    {

    switch (nmea->id)
    {
    case nmea_GGA:
    case nmea_GLL:
    case nmea_GSA:
    case nmea_GSV:
    case nmea_RMC:
    case nmea_VTG:
        break;
    case nmea_Query:
        break;
    case nmea_QueryRate_GGA:
    case nmea_QueryRate_GLL:
    case nmea_QueryRate_GSA:
    case nmea_QueryRate_GSV:
    case nmea_QueryRate_RMC:
    case nmea_QueryRate_VTG:
    {
        char cs_str[5];
        snprintf(nmea->sentence,MAX_NMEA_SENTENCE,"$PSRF103,%.2i,%.2i,%.2i,%.2i*",nmea->d0,nmea->d1,nmea->d2,nmea->d3);
        char *c=nmea->sentence+1;       //step over the '$' to calculate checksum. Req by gps
    
        uint8_t cs=0;
        while(*c != '*')
        {
            cs ^= *c;
            c++;
        }
        snprintf(cs_str,5,"%.2X\r\n",cs);
        strcat(nmea->sentence,cs_str);
    }
        break;
    
        default:
            //gs_assert_failed(__FILE__,__LINE__);
        break;
    }
    

    }

     

Log in to post a comment.