Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Author: Renan 00003 * Date: 27-02-18 00004 * Notes: Firmware for GPS GP 735T 00005 */ 00006 00007 #include "mbed.h" 00008 #include <stdio.h> 00009 #include "TextLCD.h" 00010 00011 int dateRef = 90318; 00012 00013 Serial pc(USBTX,USBRX); 00014 Serial gps(D1, D0); 00015 //TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 00016 00017 void Init() 00018 { 00019 gps.baud(9600); 00020 pc.baud(9600); 00021 00022 } 00023 00024 int getGPS(char* cDataBuffer,float *lat,float *lon,float *tmf,float *spd, int *dat, char *ns, char *ew, char *stat) 00025 { 00026 char nortSouth, eastWest, status; 00027 int date,fq, nst; // fix quality, Number of satellites being tracked, 3D fix 00028 float latitude, longitude, timefix, speed,altitude; 00029 00030 if(strncmp(cDataBuffer,"$GPRMC", 6) == 0) 00031 { 00032 sscanf(cDataBuffer, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &nortSouth, &longitude, &eastWest, &speed, &date); 00033 00034 if (latitude !=0) 00035 *lat = latitude*0.01; 00036 if (longitude != 0) 00037 *lon = longitude*0.01; 00038 00039 *tmf = timefix; 00040 00041 *spd = speed; 00042 if (date >= dateRef) 00043 *dat = date; 00044 00045 if (nortSouth == 'N' | nortSouth == 'S') 00046 *ns = nortSouth; 00047 if (eastWest == 'W' | eastWest == 'E') 00048 *ew = eastWest; 00049 *stat = status; 00050 // pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, nortSouth, longitude, eastWest, speed, date); 00051 // pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", *tmf, *stat, *lat, *ns, *lon, *ew, *spd, *dat); 00052 return 0; 00053 } 00054 if(strncmp(cDataBuffer,"$GPGLL", 6) == 0) 00055 { 00056 sscanf(cDataBuffer, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &nortSouth, &longitude, &eastWest, &timefix); 00057 //pc.printf("%s",cDataBuffer); 00058 if (latitude !=0) 00059 *lat = latitude * 0.01; 00060 00061 if (longitude != 0) 00062 *lon = longitude * 0.01; 00063 00064 *tmf = timefix; 00065 *spd = speed; 00066 00067 if (nortSouth == 'N' | nortSouth == 'S') 00068 *ns = nortSouth; 00069 00070 if (eastWest == 'W' | eastWest == 'E') 00071 *ew = eastWest; 00072 return 0; 00073 } 00074 00075 if(strncmp(cDataBuffer,"$GPGGA", 6) == 0) 00076 { 00077 sscanf(cDataBuffer, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &nortSouth, &longitude, &eastWest, &fq, &nst, &altitude); 00078 if (latitude !=0) 00079 *lat = latitude * 0.01; 00080 00081 if (longitude != 0) 00082 *lon = longitude * 0.01; 00083 00084 //*alt = altitude; 00085 *tmf = timefix; 00086 00087 if (nortSouth == 'N' | nortSouth == 'S') 00088 *ns = nortSouth; 00089 00090 if (eastWest == 'W' | eastWest == 'E') 00091 *ew = eastWest; 00092 return 0; 00093 00094 } 00095 return -1; 00096 00097 00098 } 00099 00100 00101 int main() 00102 { 00103 Init(); 00104 char Buffer[128],str[7]; 00105 char ns, ew, status; 00106 int date,gpsACK; // fix quality, Number of satellites being tracked, 3D fix 00107 float latitude, longitude, timefix, speed; 00108 memset(Buffer,0,sizeof(Buffer)); 00109 date = 0; 00110 latitude = longitude = timefix = speed = 0; 00111 ns = ew = status =0; 00112 00113 while(true) 00114 { 00115 if(gps.readable()) 00116 { 00117 gps.gets(Buffer,90); 00118 if(Buffer[0] == '$'){ 00119 memcpy(str,Buffer, 6); 00120 //printf("\nrecv: %s\n",str); 00121 gpsACK = getGPS(Buffer, &latitude, &longitude, &timefix, &speed, &date, &ns, &ew, &status); 00122 00123 } 00124 } 00125 00126 if (gpsACK == 0) 00127 { 00128 //pc.printf("HORA:%d\n",(int)timefix); 00129 //pc.printf("DATA:%d\n",date); 00130 pc.printf(" Latitude: %f , Longitude: %f \r\n", latitude, longitude); 00131 wait(3); 00132 // lcd.cls(); 00133 pc.printf("LATITUDE:\n%f %c \r\n",latitude,ns); 00134 wait(2); 00135 //lcd.cls(); 00136 pc.printf("LONGITUDE:\n%f %c \r\n",longitude,ew); 00137 wait(2); 00138 } 00139 00140 00141 } 00142 } 00143 00144
Generated on Tue Jul 12 2022 20:11:54 by
1.7.2