Basis for uBlox-7 driver derived from GPS_CanSat

Dependents:   Crunchtrack_GPS_GSM Battlehack_tracker_1_NO

Fork of GPS_CanSat by JST 2011

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GPS.cpp Source File

GPS.cpp

00001 #include "GPS.h"
00002 
00003 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
00004     //_gps.baud(38400);
00005     _gps.baud(9600);
00006     //_gps.baud(4800);
00007     //_gps.printf("$PSRF103,2,0,0,1*26\r\n");
00008     //_gps.printf("$PSRF103,3,0,0,1*27\r\n");
00009     //_gps.printf("$PSRF103,4,0,0,1*20\r\n");
00010     flag_gps_get = 0;
00011     flag_gps_getend = 0;
00012     _gps.attach(this,&GPS::sample,Serial::RxIrq);
00013     count = 0;
00014     flag_gga = 0;
00015 }
00016 
00017 void GPS::sample() {
00018     getline();
00019     if(flag_gps_getend){
00020         if(sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &_time, &_latitude, &_ns, &_longitude, &_ew, &_lock) >= 1) {
00021             flag_gga = 1;
00022             strcpy(gga,msg);
00023             float degrees = floor(_latitude / 100.0f);
00024             float minutes = _latitude - (degrees * 100.0f);
00025             _latitude = degrees + minutes / 60.0f;
00026             degrees = floor(_longitude / 100.0f);
00027             minutes = _longitude - (degrees * 100.0f);
00028             _longitude = degrees + minutes /60.0f;
00029         }
00030         flag_gps_getend = 0;
00031     }
00032 }
00033 
00034 char* GPS::getGGA(){
00035     if(flag_gga){
00036 //        strcpy(gga,msg);
00037         flag_gga = 0;
00038     }
00039     return gga;
00040 }
00041 
00042 float GPS::longitude(){
00043     return _longitude;
00044 }
00045 
00046 float GPS::latitude(){
00047     return _latitude;
00048 }
00049 
00050 float GPS::time(){
00051     return _time;
00052 }
00053 
00054 int GPS::ns(){
00055     int d;
00056     if(_ns == 'N'){
00057         d = 1;
00058     }else{
00059         d = -1;
00060     }
00061     return d;
00062 }
00063 
00064 int GPS::ew(){
00065     int d;
00066     if(_ew == 'E'){
00067         d = 1;
00068     }else{
00069         d = -1;
00070     }
00071     return d;
00072 }
00073 
00074 int GPS::lock(){
00075     return _lock;
00076 }
00077 
00078 void GPS::getline() {
00079     char temp;
00080     temp = _gps.getc();
00081     if(temp == '$'){
00082         flag_gps_get = 1;
00083         count = 0;
00084     }
00085     if(flag_gps_get){
00086         msg[count] = temp;
00087         if(temp == '\r'){
00088             msg[count] = '\0';
00089             flag_gps_getend = 1;
00090             flag_gps_get = 0;
00091         }
00092         count ++;
00093     }
00094 }