Main Page | Data Structures | File List | Data Fields | Globals

gps.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  gps_buffer
struct  gps

Defines

#define GPS_BUF_SIZE   100
#define GPS_BUF_NUM   3
#define DATE   3
#define TIME   4
#define LATITUDE   6
#define LONGITUDE   8
#define FIX   11
#define SPEED   12
#define HPE   1
#define EPE   5
#define NVEL   2
#define EVEL   1

Typedefs

typedef gps_buffer gps_buffer_t
typedef gps gps_t

Enumerations

enum  { EMPTY, READY }

Functions

int init_gps (void)
int evaluate_gps (void)
int gps_add_checksum (char *)
int gps_send (const char *,...)
int gps_show_raw (void)
char * gps_get (void)
int gps_parse (char *)
void get_field_test (void)

Variables

gps_t buf_struct


Define Documentation

#define DATE   3
 

Definition at line 49 of file gps.h.

Referenced by gps_parse().

#define EPE   5
 

Definition at line 56 of file gps.h.

#define EVEL   1
 

Definition at line 58 of file gps.h.

Referenced by gps_parse().

#define FIX   11
 

Definition at line 53 of file gps.h.

Referenced by gps_parse().

#define GPS_BUF_NUM   3
 

Definition at line 47 of file gps.h.

#define GPS_BUF_SIZE   100
 

Definition at line 46 of file gps.h.

#define HPE   1
 

Definition at line 55 of file gps.h.

Referenced by gps_parse().

#define LATITUDE   6
 

Definition at line 51 of file gps.h.

Referenced by gps_parse().

#define LONGITUDE   8
 

Definition at line 52 of file gps.h.

Referenced by gps_parse().

#define NVEL   2
 

Definition at line 57 of file gps.h.

Referenced by gps_parse().

#define SPEED   12
 

Definition at line 54 of file gps.h.

#define TIME   4
 

Definition at line 50 of file gps.h.

Referenced by gps_parse().


Typedef Documentation

typedef struct gps_buffer gps_buffer_t
 

typedef struct gps gps_t
 


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
EMPTY 
READY 

Definition at line 70 of file gps.h.

00070 {EMPTY,READY};


Function Documentation

int evaluate_gps void   ) 
 

Definition at line 180 of file gps.c.

References buf_struct, gps_buffer::data, gps::db, and gps_buffer::status.

Referenced by main().

00180                        {
00181   static char message_buffer[100]="";
00182   static char *buf_ptr = message_buffer;
00183   enum {LOCATE_SENTINEL,CRLF};
00184   static char parser_state=LOCATE_SENTINEL;
00185   static int char_counter=0;
00186   static int current_buffer=0;
00187   char temp;
00188   int ret_val=0;
00189   while ((temp=getchar_gps_nb())) { // Grab a character from the buffer.
00190     switch (parser_state) {
00191     case LOCATE_SENTINEL:
00192       if ((temp=='$')&&(buf_struct.db[current_buffer].status==EMPTY)) {
00193         buf_ptr=buf_struct.db[current_buffer].data;
00194         *buf_ptr++=temp;
00195         parser_state=CRLF;
00196         char_counter=1;
00197       }
00198       break;
00199     case CRLF:
00200       if (temp=='\r') {
00201         *buf_ptr++='\n';
00202         *buf_ptr=0;
00203         buf_struct.db[current_buffer++].status=READY;
00204         if (current_buffer==GPS_BUF_NUM) {
00205           current_buffer=0;
00206         }
00207         parser_state=LOCATE_SENTINEL;
00208       }
00209       else {
00210         if (char_counter++<100) {
00211           *buf_ptr++=temp;
00212         }
00213         else {
00214           parser_state=LOCATE_SENTINEL;
00215         }
00216       }
00217       break;
00218     }
00219   }
00220   return (ret_val);
00221 }

void get_field_test void   ) 
 

Definition at line 97 of file gps.c.

References get_field().

00097                           {
00098   char sentence[]="$foo,,,3,4,5,6,7,8,9,10,11,12*5E";
00099   char field_buf[20]="";
00100   int i;
00101   for (i=0;i<16;i++) {
00102     if (get_field(sentence,field_buf,i)) {
00103       printf("%s\n",field_buf);
00104     }
00105     else {
00106       printf("returned 0\n");
00107     }
00108     flush_uart0();
00109   }
00110 }

Here is the call graph for this function:

int gps_add_checksum char *   ) 
 

Definition at line 237 of file gps.c.

Referenced by gps_send().

00237                                      {
00238   unsigned char sum = '\0';
00239   char c, *p = sentence;
00240   int ret_val=0;
00241 
00242   if (*p == '$') {
00243     p++;
00244   } 
00245   else {
00246     ret_val=1;
00247   }
00248   while ( ((c = *p) != '*') && (c != '\0')) {
00249     sum ^= c;
00250     p++;
00251   }
00252   *p++ = '*';
00253   (void)snprintf(p, 5, "%02X\r\n", (unsigned)sum);
00254   return (ret_val); 
00255 }

char* gps_get void   ) 
 

Definition at line 167 of file gps.c.

References buf_struct, gps_buffer::data, gps::db, and gps_buffer::status.

Referenced by main().

00167                     {
00168   char *ret_val=0;
00169   static int gps_buf=0;
00170   if (buf_struct.db[gps_buf].status==READY) {
00171     ret_val=buf_struct.db[gps_buf].data;
00172     buf_struct.db[gps_buf++].status=EMPTY;
00173     if (gps_buf==GPS_BUF_NUM) {
00174       gps_buf=0;
00175     }
00176   }
00177   return (ret_val);
00178 }

int gps_parse char *   ) 
 

Definition at line 112 of file gps.c.

References DATE, EVEL, FIX, get_field(), HPE, LATITUDE, LONGITUDE, NVEL, and TIME.

Referenced by main().

00112                                {
00113   static int gps_avail=0;
00114   char buf[20];
00115   const char PGRMF[]="$PGRMF";
00116   const char PGRME[]="$PGRME";
00117   const char PGRMV[]="$PGRMV";
00118   int ret_val=0;
00119 
00120   if (get_field(sentence,buf,0)) {
00121     if (!strcmp(buf,PGRMF)) {
00122       if (get_field(sentence,buf,FIX)) {
00123         if ((gps_avail=atoi(buf))) {
00124           if (get_field(sentence,buf,DATE)) {
00125             printf("DATE=%s ",buf);
00126           }
00127           if (get_field(sentence,buf,TIME)) {
00128             printf("TIME=%s ",buf);
00129           }
00130           if (get_field(sentence,buf,LATITUDE)) {
00131             printf("LAT=%s ",buf);
00132           }
00133           if (get_field(sentence,buf,LONGITUDE)) {
00134             printf("LON=%s ",buf);
00135           }
00136         }
00137         else {
00138           printf("NO FIX\n");
00139         }
00140         flush_uart0();
00141       }
00142     }
00143     else if (!strcmp(buf,PGRME)) {
00144       if (gps_avail) {
00145         if (get_field(sentence,buf,HPE)) {
00146           printf("ERR=%s ",buf);
00147           flush_uart0();
00148         }
00149       }
00150     }
00151     else if (!strcmp(buf,PGRMV)) {
00152       if (gps_avail) {
00153         if (get_field(sentence,buf,NVEL)) {
00154           printf("NVEL=%s ",buf);
00155         }
00156         if (get_field(sentence,buf,EVEL)) {
00157           printf("EVEL=%s ",buf);
00158         }
00159         printf("\n");
00160         flush_uart0();
00161       }
00162     }
00163   }
00164   return(ret_val);
00165 }

Here is the call graph for this function:

int gps_send const char *  ,
  ...
 

Definition at line 257 of file gps.c.

References gps_add_checksum().

Referenced by init_gps().

00257                                     {
00258   static int init=0;
00259   int ret_val=0;
00260   char buf[100];
00261   if (!init) {
00262     uprintf(&putchar_gps,"\r\n"); // Send a CR/LF to clean out any previous partial commands. 
00263     init=1;
00264   }
00265   va_list ap;
00266   va_start(ap, fmt) ;
00267   (void)vsnprintf(buf, sizeof(buf)-5, fmt, ap);
00268   va_end(ap);
00269   if (fmt[0] == '$') {
00270     strcat(buf, "*");
00271     if (gps_add_checksum(buf)) {
00272       ret_val=1;
00273     }
00274   } 
00275   else {
00276     strcat(buf, "\r\n");
00277   }
00278   if (!ret_val) {
00279     uprintf(&putchar_gps,"%s",buf);
00280     flush_uart1();
00281   }
00282   return (ret_val);
00283 }

Here is the call graph for this function:

int gps_show_raw void   ) 
 

Definition at line 223 of file gps.c.

00223                        {
00224   char temp;
00225   char message_buffer[100]="";
00226   char *buf_ptr = message_buffer;
00227   
00228   while ((temp=getchar_gps_nb())) {
00229     *buf_ptr++=temp;
00230   }
00231   *buf_ptr=0;
00232   printf("%s",message_buffer);
00233   flush_uart0();
00234   return (1);
00235 }

int init_gps void   ) 
 

Definition at line 54 of file gps.c.

References buf_struct, gps::db, gps_send(), and gps_buffer::status.

Referenced by main().

00054                    {
00055   buf_struct.db[0].status=EMPTY;     // Initialize the structures used to store the GPS sentences
00056   buf_struct.db[1].status=EMPTY;
00057   
00058   gps_send("$PGRMC,,,,,,,,,,,,2,,"); // Turn on the periodic pulse output from the GPS. 
00059   gps_send("$PGRMC1,,,,,,,,,,,,,2"); // Periodic Pulse will turn off when GPS data not available. 
00060   gps_send("$PGRMO,,2");             // Turn on all of the sentences
00061   while (!flush_uart1());
00062   gps_send("$PGRMO,PGRMF,1");        // Turn on the GPS Fix Data Sentence
00063   gps_send("$PGRMO,PGRME,1");        // Turn on the Estimate Error Sentence
00064   gps_send("$PGRMO,PGRMV,1");        // Turn on the 3D Velocity Information
00065   return (0);
00066 }

Here is the call graph for this function:


Variable Documentation

gps_t buf_struct
 

Definition at line 52 of file gps.c.

Referenced by evaluate_gps(), gps_get(), and init_gps().


Generated on Fri Nov 3 15:17:27 2006 for VCS Application by  doxygen 1.3.9.1