GPS receiver, SkyTraq Venus 6, SUP500F with internal smart antenna, reads the raw NMEA information and transfers only the GPGGA info to the laptop. Simple example.

Dependencies:   mbed

Committer:
GerritPathuis
Date:
Sun Jan 02 18:57:24 2011 +0000
Revision:
0:92567322923d
Child:
1:ec3f86128190
rev date 2-1-2011

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:92567322923d 1 #include "mbed.h"
GerritPathuis 0:92567322923d 2 #define ACK 0x06
GerritPathuis 0:92567322923d 3 #define LF 0x0A
GerritPathuis 0:92567322923d 4 #define CR 0x0D
GerritPathuis 0:92567322923d 5 #define NAK 0x15
GerritPathuis 0:92567322923d 6 #define MESS_LEN 100 // maximum message length
GerritPathuis 0:92567322923d 7 #define MAX_STR 20
GerritPathuis 0:92567322923d 8 #define STR_LEN 40
GerritPathuis 0:92567322923d 9
GerritPathuis 0:92567322923d 10 //-------------------------------------------------------------------
GerritPathuis 0:92567322923d 11 // Made by G.Pathuis (gpa@quicknet.nl)
GerritPathuis 0:92567322923d 12 // Program reads the information coming from the GPS receiver
GerritPathuis 0:92567322923d 13 // 65 channel SUP500F 10Hz GPS receiver with integrated Smart antenna
GerritPathuis 0:92567322923d 14 // See www.sparkfun.com GPS-09758 for details and documentation
GerritPathuis 0:92567322923d 15 // Hardware information
GerritPathuis 0:92567322923d 16 // PUF500F pin1 -------------MBED p13
GerritPathuis 0:92567322923d 17 // PUF500F pin2 -------------MBED p14
GerritPathuis 0:92567322923d 18 // PUF500F pin3 -------------MBED GND
GerritPathuis 0:92567322923d 19 // PUF500F pin4 -------------MBED Vout (3.3V @ 75mAmp)
GerritPathuis 0:92567322923d 20 // PUF500F pin5 -------------MBED Vout
GerritPathuis 0:92567322923d 21 // PUF500F pin6 -----LED-----MBED GND
GerritPathuis 0:92567322923d 22 // PUF500F pin7 -------------MBED GND
GerritPathuis 0:92567322923d 23 //
GerritPathuis 0:92567322923d 24 // IMPORTANT REMARK-------------------------------------------------
GerritPathuis 0:92567322923d 25 // This receiver has an integrated antenna and will not work when
GerritPathuis 0:92567322923d 26 // situated near a laptop, PC or MBED
GerritPathuis 0:92567322923d 27 // I used connecting (mbed-receiver) wires with a length of 1 meter
GerritPathuis 0:92567322923d 28 //------------------------------------------------------------------
GerritPathuis 0:92567322923d 29
GerritPathuis 0:92567322923d 30 Serial pc(USBTX, USBRX); // tx, rx
GerritPathuis 0:92567322923d 31 Serial puf500(p13, p14); // tx, rx
GerritPathuis 0:92567322923d 32
GerritPathuis 0:92567322923d 33 char nmea[MESS_LEN] = {0x00}; // raw message from the GPS receiver
GerritPathuis 0:92567322923d 34 char gp[MAX_STR][STR_LEN]; // 40 strings, length is 30
GerritPathuis 0:92567322923d 35
GerritPathuis 0:92567322923d 36 void read_nmea(void); // read nmea message from gps module
GerritPathuis 0:92567322923d 37 int chop_message(void); // chop the nmea messeage
GerritPathuis 0:92567322923d 38 void present_array(void); // send a part of the available info to the laptop
GerritPathuis 0:92567322923d 39
GerritPathuis 0:92567322923d 40 int main() {
GerritPathuis 0:92567322923d 41 pc.baud(9600);
GerritPathuis 0:92567322923d 42 pc.format(8,Serial::None,1);
GerritPathuis 0:92567322923d 43
GerritPathuis 0:92567322923d 44 puf500.baud(9600);
GerritPathuis 0:92567322923d 45 puf500.format(8,Serial::None,1);
GerritPathuis 0:92567322923d 46
GerritPathuis 0:92567322923d 47 pc.printf("Start lurking...\n\r");
GerritPathuis 0:92567322923d 48 while (1) {
GerritPathuis 0:92567322923d 49 read_nmea();
GerritPathuis 0:92567322923d 50 chop_message();
GerritPathuis 0:92567322923d 51 present_array();
GerritPathuis 0:92567322923d 52 }
GerritPathuis 0:92567322923d 53 }
GerritPathuis 0:92567322923d 54
GerritPathuis 0:92567322923d 55 //--------------------read nmea from GPS unit--------------------
GerritPathuis 0:92567322923d 56 void read_nmea(void) {
GerritPathuis 0:92567322923d 57 puf500.scanf("%s,",nmea);
GerritPathuis 0:92567322923d 58 //pc.printf("Raw message %s \n\r",nmea); // just for testing
GerritPathuis 0:92567322923d 59 }
GerritPathuis 0:92567322923d 60
GerritPathuis 0:92567322923d 61 //---------------- chop the nmea message separated by comma's-----------
GerritPathuis 0:92567322923d 62 int chop_message(void) {
GerritPathuis 0:92567322923d 63 for (int k=0; k<MAX_STR; k++) { // just to make sure thet the char array is set to 0x00
GerritPathuis 0:92567322923d 64 for (int l=0; l<STR_LEN; l++) {
GerritPathuis 0:92567322923d 65 gp[k][l]= 0x00;
GerritPathuis 0:92567322923d 66 };
GerritPathuis 0:92567322923d 67 }
GerritPathuis 0:92567322923d 68 int strcnt=0; // string counter
GerritPathuis 0:92567322923d 69 int strpos=0; // position inside the string
GerritPathuis 0:92567322923d 70 for (int k=0; k < MESS_LEN; k++) {
GerritPathuis 0:92567322923d 71 if (nmea[k] == '*') { // detect end of message is found
GerritPathuis 0:92567322923d 72 gp[strcnt][strpos]= 0x00; // close the string with 0x00
GerritPathuis 0:92567322923d 73 return 0; // the work is done, end of this function
GerritPathuis 0:92567322923d 74 }
GerritPathuis 0:92567322923d 75 if (nmea[k] == 0x2c) { // detect the comma
GerritPathuis 0:92567322923d 76 if (strpos == 0) {
GerritPathuis 0:92567322923d 77 gp[strcnt][0]= 'E'; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 78 gp[strcnt][1]= 'm'; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 79 gp[strcnt][2]= 'p'; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 80 gp[strcnt][3]= 't'; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 81 gp[strcnt][4]= 'y'; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 82 gp[strcnt][5]= 0x00; // comma at position zero, string must be empty
GerritPathuis 0:92567322923d 83 } else {
GerritPathuis 0:92567322923d 84 gp[strcnt][strpos]= 0x00; // end the previous string
GerritPathuis 0:92567322923d 85 }
GerritPathuis 0:92567322923d 86 strcnt += 1; // increment to the next string
GerritPathuis 0:92567322923d 87 strpos =0; // start at position zero
GerritPathuis 0:92567322923d 88 } else {
GerritPathuis 0:92567322923d 89 gp[strcnt][strpos]= nmea[k]; // add char to string
GerritPathuis 0:92567322923d 90 strpos += 1;
GerritPathuis 0:92567322923d 91 }
GerritPathuis 0:92567322923d 92 }
GerritPathuis 0:92567322923d 93 return 0;
GerritPathuis 0:92567322923d 94 }
GerritPathuis 0:92567322923d 95
GerritPathuis 0:92567322923d 96 // --------------- Dump only $GPGGA on the screen------------------
GerritPathuis 0:92567322923d 97 void present_array(void) {
GerritPathuis 0:92567322923d 98 if ((gp[0][2]=='P') and (gp[0][3]=='G') and (gp[0][4]=='G') and (gp[0][5]=='A')) {
GerritPathuis 0:92567322923d 99 pc.printf("Chop results ");
GerritPathuis 0:92567322923d 100 for (int k=0; k<MAX_STR; k++) {
GerritPathuis 0:92567322923d 101 pc.printf("r%d=%s ",k, gp[k]);
GerritPathuis 0:92567322923d 102 }
GerritPathuis 0:92567322923d 103 pc.printf("\n\r");
GerritPathuis 0:92567322923d 104 }
GerritPathuis 0:92567322923d 105 }