IZU2020 / PQAEGPS

Dependents:   IZU2020_AVIONICS IZU2020_AVIONICS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PQAEGPS.cpp Source File

PQAEGPS.cpp

00001 #include "mbed.h"
00002 #include "PQAEGPS.h"
00003 
00004 AEGPS::AEGPS (Serial &gps_serial)
00005 {
00006     _serial = &gps_serial;
00007     _serial->attach(callback(this, &AEGPS::receive), Serial::RxIrq);
00008 }
00009 
00010 void AEGPS::receive()
00011 {
00012     char c = _serial->getc();
00013     if(c == '$') {
00014         index = 0;
00015         flag = 1;
00016     }
00017     if(flag == 1) {
00018         rx_buf[index] = c;
00019         if(c == '\n') {
00020             rx_buf[index + 1] = '\0';
00021             flag = 2;
00022         } else {
00023             index++;
00024         }
00025     }
00026     if(flag == 2) {
00027         sscanf(rx_buf, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,M,%f,M", &sec, &lat, &ns, &lon, &ew, &fix, &sat, &hdop, &alt, &geoid);
00028 
00029         hour = (int)(sec / 10000);
00030         min = (int)(sec - hour * 10000) / 100;
00031         sec = sec - hour * 10000 - min * 100;
00032 
00033         int d;
00034         float m;
00035 
00036         d = (int)lat / 100;
00037         m = lat - (float)d * 100;
00038         lat = (float)d + m / 60;
00039         if(ns == 'S') {
00040             lat = -lat;
00041         }
00042 
00043         d = (int)lon / 100;
00044         m = lon - (float)d * 100;
00045         lon = (float)d + m / 60;
00046         if(ns == 'W') {
00047             lon = -lon;
00048         }
00049 
00050         flag = 0;
00051     }
00052 }
00053 
00054 int AEGPS::get_hour()
00055 {
00056     return hour;
00057 }
00058 
00059 int AEGPS::get_min()
00060 {
00061     return min;
00062 }
00063 
00064 float AEGPS::get_sec()
00065 {
00066     return sec;
00067 }
00068 
00069 float AEGPS::get_lat()
00070 {
00071     return lat;
00072 }
00073 
00074 float AEGPS::get_lon()
00075 {
00076     return lon;
00077 }
00078 
00079 int AEGPS::get_fix()
00080 {
00081     return fix;
00082 }
00083 
00084 int AEGPS::get_sat()
00085 {
00086     return sat;
00087 }
00088 
00089 float AEGPS::get_hdop()
00090 {
00091     return hdop;
00092 }
00093 
00094 float AEGPS::get_alt()
00095 {
00096     return alt;
00097 }
00098 
00099 float AEGPS::get_geoid()
00100 {
00101     return geoid;
00102 }