Renan Alves
/
GPS_Test_Code
test code
Fork of GPS_U-blox_NEO-6M_Test_Code by
main.cpp@2:4cc7f42f94c1, 2018-05-25 (annotated)
- Committer:
- renanbmx123
- Date:
- Fri May 25 19:57:58 2018 +0000
- Revision:
- 2:4cc7f42f94c1
- Parent:
- 1:acd907fbcbae
test code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edodm85 | 0:ea14ad6794af | 1 | /* |
renanbmx123 | 2:4cc7f42f94c1 | 2 | * Author: Renan |
renanbmx123 | 2:4cc7f42f94c1 | 3 | * Date: 27-02-18 |
renanbmx123 | 2:4cc7f42f94c1 | 4 | * Notes: Firmware for GPS GP 735T |
edodm85 | 0:ea14ad6794af | 5 | */ |
renanbmx123 | 2:4cc7f42f94c1 | 6 | |
renanbmx123 | 2:4cc7f42f94c1 | 7 | #include "mbed.h" |
renanbmx123 | 2:4cc7f42f94c1 | 8 | #include <stdio.h> |
renanbmx123 | 2:4cc7f42f94c1 | 9 | #include "TextLCD.h" |
edodm85 | 0:ea14ad6794af | 10 | |
renanbmx123 | 2:4cc7f42f94c1 | 11 | int dateRef = 90318; |
renanbmx123 | 2:4cc7f42f94c1 | 12 | |
renanbmx123 | 2:4cc7f42f94c1 | 13 | Serial pc(USBTX,USBRX); |
renanbmx123 | 2:4cc7f42f94c1 | 14 | Serial gps(p9, p10); |
renanbmx123 | 2:4cc7f42f94c1 | 15 | TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 |
edodm85 | 0:ea14ad6794af | 16 | |
edodm85 | 0:ea14ad6794af | 17 | void Init() |
edodm85 | 0:ea14ad6794af | 18 | { |
edodm85 | 0:ea14ad6794af | 19 | gps.baud(9600); |
renanbmx123 | 2:4cc7f42f94c1 | 20 | pc.baud(9600); |
renanbmx123 | 2:4cc7f42f94c1 | 21 | |
edodm85 | 0:ea14ad6794af | 22 | } |
edodm85 | 0:ea14ad6794af | 23 | |
renanbmx123 | 2:4cc7f42f94c1 | 24 | int getGPS(char* cDataBuffer,float *lat,float *lon,float *tmf,float *spd, int *dat, char *ns, char *ew, char *stat) |
renanbmx123 | 2:4cc7f42f94c1 | 25 | { |
renanbmx123 | 2:4cc7f42f94c1 | 26 | char nortSouth, eastWest, status; |
renanbmx123 | 2:4cc7f42f94c1 | 27 | int date,fq, nst; // fix quality, Number of satellites being tracked, 3D fix |
renanbmx123 | 2:4cc7f42f94c1 | 28 | float latitude, longitude, timefix, speed,altitude; |
renanbmx123 | 2:4cc7f42f94c1 | 29 | |
renanbmx123 | 2:4cc7f42f94c1 | 30 | if(strncmp(cDataBuffer,"$GPRMC", 6) == 0) |
renanbmx123 | 2:4cc7f42f94c1 | 31 | { |
renanbmx123 | 2:4cc7f42f94c1 | 32 | sscanf(cDataBuffer, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &nortSouth, &longitude, &eastWest, &speed, &date); |
renanbmx123 | 2:4cc7f42f94c1 | 33 | |
renanbmx123 | 2:4cc7f42f94c1 | 34 | if (latitude !=0) |
renanbmx123 | 2:4cc7f42f94c1 | 35 | *lat = latitude; |
renanbmx123 | 2:4cc7f42f94c1 | 36 | if (longitude != 0) |
renanbmx123 | 2:4cc7f42f94c1 | 37 | *lon = longitude; |
renanbmx123 | 2:4cc7f42f94c1 | 38 | |
renanbmx123 | 2:4cc7f42f94c1 | 39 | *tmf = timefix; |
renanbmx123 | 2:4cc7f42f94c1 | 40 | |
renanbmx123 | 2:4cc7f42f94c1 | 41 | *spd = speed; |
renanbmx123 | 2:4cc7f42f94c1 | 42 | if (date >= dateRef) |
renanbmx123 | 2:4cc7f42f94c1 | 43 | *dat = date; |
renanbmx123 | 2:4cc7f42f94c1 | 44 | |
renanbmx123 | 2:4cc7f42f94c1 | 45 | if (nortSouth == 'N' | nortSouth == 'S') |
renanbmx123 | 2:4cc7f42f94c1 | 46 | *ns = nortSouth; |
renanbmx123 | 2:4cc7f42f94c1 | 47 | if (eastWest == 'W' | eastWest == 'E') |
renanbmx123 | 2:4cc7f42f94c1 | 48 | *ew = eastWest; |
renanbmx123 | 2:4cc7f42f94c1 | 49 | *stat = status; |
renanbmx123 | 2:4cc7f42f94c1 | 50 | // 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); |
renanbmx123 | 2:4cc7f42f94c1 | 51 | // 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); |
renanbmx123 | 2:4cc7f42f94c1 | 52 | return 0; |
renanbmx123 | 2:4cc7f42f94c1 | 53 | } |
renanbmx123 | 2:4cc7f42f94c1 | 54 | if(strncmp(cDataBuffer,"$GPGLL", 6) == 0) |
renanbmx123 | 2:4cc7f42f94c1 | 55 | { |
renanbmx123 | 2:4cc7f42f94c1 | 56 | sscanf(cDataBuffer, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &nortSouth, &longitude, &eastWest, &timefix); |
renanbmx123 | 2:4cc7f42f94c1 | 57 | //pc.printf("%s",cDataBuffer); |
renanbmx123 | 2:4cc7f42f94c1 | 58 | if (latitude !=0) |
renanbmx123 | 2:4cc7f42f94c1 | 59 | *lat = latitude; |
renanbmx123 | 2:4cc7f42f94c1 | 60 | |
renanbmx123 | 2:4cc7f42f94c1 | 61 | if (longitude != 0) |
renanbmx123 | 2:4cc7f42f94c1 | 62 | *lon = longitude; |
renanbmx123 | 2:4cc7f42f94c1 | 63 | |
renanbmx123 | 2:4cc7f42f94c1 | 64 | *tmf = timefix; |
renanbmx123 | 2:4cc7f42f94c1 | 65 | *spd = speed; |
renanbmx123 | 2:4cc7f42f94c1 | 66 | |
renanbmx123 | 2:4cc7f42f94c1 | 67 | if (nortSouth == 'N' | nortSouth == 'S') |
renanbmx123 | 2:4cc7f42f94c1 | 68 | *ns = nortSouth; |
renanbmx123 | 2:4cc7f42f94c1 | 69 | |
renanbmx123 | 2:4cc7f42f94c1 | 70 | if (eastWest == 'W' | eastWest == 'E') |
renanbmx123 | 2:4cc7f42f94c1 | 71 | *ew = eastWest; |
renanbmx123 | 2:4cc7f42f94c1 | 72 | return 0; |
renanbmx123 | 2:4cc7f42f94c1 | 73 | } |
renanbmx123 | 2:4cc7f42f94c1 | 74 | |
renanbmx123 | 2:4cc7f42f94c1 | 75 | if(strncmp(cDataBuffer,"$GPGGA", 6) == 0) |
renanbmx123 | 2:4cc7f42f94c1 | 76 | { |
renanbmx123 | 2:4cc7f42f94c1 | 77 | sscanf(cDataBuffer, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &nortSouth, &longitude, &eastWest, &fq, &nst, &altitude); |
renanbmx123 | 2:4cc7f42f94c1 | 78 | if (latitude !=0) |
renanbmx123 | 2:4cc7f42f94c1 | 79 | *lat = latitude; |
renanbmx123 | 2:4cc7f42f94c1 | 80 | |
renanbmx123 | 2:4cc7f42f94c1 | 81 | if (longitude != 0) |
renanbmx123 | 2:4cc7f42f94c1 | 82 | *lon = longitude; |
renanbmx123 | 2:4cc7f42f94c1 | 83 | |
renanbmx123 | 2:4cc7f42f94c1 | 84 | //*alt = altitude; |
renanbmx123 | 2:4cc7f42f94c1 | 85 | *tmf = timefix; |
renanbmx123 | 2:4cc7f42f94c1 | 86 | |
renanbmx123 | 2:4cc7f42f94c1 | 87 | if (nortSouth == 'N' | nortSouth == 'S') |
renanbmx123 | 2:4cc7f42f94c1 | 88 | *ns = nortSouth; |
renanbmx123 | 2:4cc7f42f94c1 | 89 | |
renanbmx123 | 2:4cc7f42f94c1 | 90 | if (eastWest == 'W' | eastWest == 'E') |
renanbmx123 | 2:4cc7f42f94c1 | 91 | *ew = eastWest; |
renanbmx123 | 2:4cc7f42f94c1 | 92 | return 0; |
renanbmx123 | 2:4cc7f42f94c1 | 93 | |
renanbmx123 | 2:4cc7f42f94c1 | 94 | } |
renanbmx123 | 2:4cc7f42f94c1 | 95 | return -1; |
edodm85 | 0:ea14ad6794af | 96 | |
edodm85 | 0:ea14ad6794af | 97 | |
renanbmx123 | 2:4cc7f42f94c1 | 98 | } |
renanbmx123 | 2:4cc7f42f94c1 | 99 | |
renanbmx123 | 2:4cc7f42f94c1 | 100 | |
edodm85 | 0:ea14ad6794af | 101 | int main() |
edodm85 | 0:ea14ad6794af | 102 | { |
edodm85 | 0:ea14ad6794af | 103 | Init(); |
renanbmx123 | 2:4cc7f42f94c1 | 104 | char Buffer[128],str[7]; |
renanbmx123 | 2:4cc7f42f94c1 | 105 | char ns, ew, status; |
renanbmx123 | 2:4cc7f42f94c1 | 106 | int date,gpsACK; // fix quality, Number of satellites being tracked, 3D fix |
renanbmx123 | 2:4cc7f42f94c1 | 107 | float latitude, longitude, timefix, speed; |
renanbmx123 | 2:4cc7f42f94c1 | 108 | memset(Buffer,0,sizeof(Buffer)); |
renanbmx123 | 2:4cc7f42f94c1 | 109 | date = 0; |
renanbmx123 | 2:4cc7f42f94c1 | 110 | latitude = longitude = timefix = speed = 0; |
renanbmx123 | 2:4cc7f42f94c1 | 111 | ns = ew = status =0; |
edodm85 | 0:ea14ad6794af | 112 | |
edodm85 | 0:ea14ad6794af | 113 | while(true) |
edodm85 | 0:ea14ad6794af | 114 | { |
edodm85 | 0:ea14ad6794af | 115 | if(gps.readable()) |
renanbmx123 | 2:4cc7f42f94c1 | 116 | { |
renanbmx123 | 2:4cc7f42f94c1 | 117 | gps.gets(Buffer,90); |
renanbmx123 | 2:4cc7f42f94c1 | 118 | if(Buffer[0] == '$'){ |
renanbmx123 | 2:4cc7f42f94c1 | 119 | memcpy(str,Buffer, 6); |
renanbmx123 | 2:4cc7f42f94c1 | 120 | //printf("\nrecv: %s\n",str); |
renanbmx123 | 2:4cc7f42f94c1 | 121 | gpsACK = getGPS(Buffer, &latitude, &longitude, &timefix, &speed, &date, &ns, &ew, &status); |
renanbmx123 | 2:4cc7f42f94c1 | 122 | |
edodm85 | 0:ea14ad6794af | 123 | } |
renanbmx123 | 2:4cc7f42f94c1 | 124 | } |
renanbmx123 | 2:4cc7f42f94c1 | 125 | |
renanbmx123 | 2:4cc7f42f94c1 | 126 | if (gpsACK == 0) |
renanbmx123 | 2:4cc7f42f94c1 | 127 | { |
renanbmx123 | 2:4cc7f42f94c1 | 128 | lcd.printf("HORA:%d\n",(int)timefix); |
renanbmx123 | 2:4cc7f42f94c1 | 129 | lcd.printf("DATA:%d\n",date); |
renanbmx123 | 2:4cc7f42f94c1 | 130 | pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, ns, longitude, ew, speed, date); |
renanbmx123 | 2:4cc7f42f94c1 | 131 | wait(.2); |
renanbmx123 | 2:4cc7f42f94c1 | 132 | /* lcd.cls(); |
renanbmx123 | 2:4cc7f42f94c1 | 133 | lcd.printf("LATITUDE:\n%f %c ",latitude,ns); |
renanbmx123 | 2:4cc7f42f94c1 | 134 | wait(2); |
renanbmx123 | 2:4cc7f42f94c1 | 135 | lcd.cls(); |
renanbmx123 | 2:4cc7f42f94c1 | 136 | lcd.printf("LONGITUDE:\n%f %c ",longitude,ew); |
renanbmx123 | 2:4cc7f42f94c1 | 137 | wait(2);*/ |
renanbmx123 | 2:4cc7f42f94c1 | 138 | } |
renanbmx123 | 2:4cc7f42f94c1 | 139 | |
renanbmx123 | 2:4cc7f42f94c1 | 140 | |
renanbmx123 | 2:4cc7f42f94c1 | 141 | } |
edodm85 | 0:ea14ad6794af | 142 | } |
renanbmx123 | 2:4cc7f42f94c1 | 143 | |
renanbmx123 | 2:4cc7f42f94c1 | 144 |