whatever

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Committer:
sgmcb
Date:
Sat Nov 21 01:27:50 2015 +0000
Revision:
31:f94b8f987b62
Parent:
30:f9bb5aba1155
Child:
32:4b94cb22d338
Friday GPS location online!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:4e3cb26f6019 1 #include "mbed.h"
mazgch 9:26f694bc31b4 2
sgmcb 31:f94b8f987b62 3 #include <string.h>
sgmcb 31:f94b8f987b62 4
sgmcb 31:f94b8f987b62 5 // ublox C027 support libraries
sgmcb 31:f94b8f987b62 6 #include "GPS.h" // GPS support
sgmcb 31:f94b8f987b62 7 #include "MDM.h" // Modem support
sgmcb 31:f94b8f987b62 8
sgmcb 31:f94b8f987b62 9 // AT&T Support
sgmcb 31:f94b8f987b62 10
mazgch 19:f022ff746eb8 11 //------------------------------------------------------------------------------------
sgmcb 31:f94b8f987b62 12 // Cellular modem/SIM parameters
sgmcb 31:f94b8f987b62 13 #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs.
sgmcb 31:f94b8f987b62 14 #define APN "m2m.com.attz" // Defined AT&T M2M APN
sgmcb 31:f94b8f987b62 15 #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 31:f94b8f987b62 16 #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't)
mazgch 19:f022ff746eb8 17 //------------------------------------------------------------------------------------
lawliet 0:4e3cb26f6019 18
sgmcb 30:f9bb5aba1155 19 // Set pinout for LED
sgmcb 30:f9bb5aba1155 20 DigitalOut myled(LED);
sgmcb 30:f9bb5aba1155 21
sgmcb 30:f9bb5aba1155 22 int main(void) {
sgmcb 31:f94b8f987b62 23 printf("\n\n\r----------\r\nI'm alive!\r\n");
sgmcb 30:f9bb5aba1155 24
sgmcb 31:f94b8f987b62 25 // Loading wait
sgmcb 31:f94b8f987b62 26 for(int i = 0; i < 10; i++) {
sgmcb 31:f94b8f987b62 27 myled = !myled;;
sgmcb 30:f9bb5aba1155 28 wait(0.2);
sgmcb 30:f9bb5aba1155 29 }
sgmcb 30:f9bb5aba1155 30
sgmcb 31:f94b8f987b62 31 int ret; // Integer returns
sgmcb 31:f94b8f987b62 32
sgmcb 31:f94b8f987b62 33 // Not 100% sure where this LARGE_DATA flag is being set, but I think we might be using it... (SGM)
sgmcb 31:f94b8f987b62 34 #ifdef LARGE_DATA
sgmcb 31:f94b8f987b62 35 char buf[2048] = "";
sgmcb 31:f94b8f987b62 36 #else
sgmcb 31:f94b8f987b62 37 char buf[512] = "";
sgmcb 31:f94b8f987b62 38 #endif
sgmcb 31:f94b8f987b62 39
sgmcb 31:f94b8f987b62 40 if(sizeof(buf) > 600)
sgmcb 31:f94b8f987b62 41 printf("(Using LARGE_DATA)\r\n");
sgmcb 31:f94b8f987b62 42 else
sgmcb 31:f94b8f987b62 43 printf("(Not using large data)\r\n");
sgmcb 31:f94b8f987b62 44
sgmcb 31:f94b8f987b62 45
sgmcb 31:f94b8f987b62 46 printf("\r\nBegin test loop\r\n");
sgmcb 31:f94b8f987b62 47
sgmcb 31:f94b8f987b62 48 GPSI2C gps; // Initialize GPS object
sgmcb 31:f94b8f987b62 49
sgmcb 31:f94b8f987b62 50 printf("GPS initialized...\r\n");
sgmcb 31:f94b8f987b62 51
sgmcb 31:f94b8f987b62 52
sgmcb 31:f94b8f987b62 53
sgmcb 31:f94b8f987b62 54
sgmcb 31:f94b8f987b62 55
sgmcb 31:f94b8f987b62 56 while( (ret = gps.getMessage(buf, sizeof(buf))) < 1 ) {
sgmcb 31:f94b8f987b62 57 if (ret<0)
sgmcb 31:f94b8f987b62 58 printf("WAIT received from GPS\r\n");
sgmcb 31:f94b8f987b62 59 if (ret==0)
sgmcb 31:f94b8f987b62 60 printf("NOT FOUND received from GPS\r\n");
sgmcb 31:f94b8f987b62 61 myled = !myled;
sgmcb 31:f94b8f987b62 62 wait(1.0);
sgmcb 31:f94b8f987b62 63 }
sgmcb 31:f94b8f987b62 64
sgmcb 31:f94b8f987b62 65 float locationLoopWait = 1.0;
sgmcb 31:f94b8f987b62 66 int locationLoopIter = 0;
sgmcb 31:f94b8f987b62 67 // Get a good GPS message
sgmcb 31:f94b8f987b62 68
sgmcb 31:f94b8f987b62 69 int len = LENGTH(ret);
sgmcb 31:f94b8f987b62 70
sgmcb 31:f94b8f987b62 71 while(true) {
sgmcb 31:f94b8f987b62 72 locationLoopIter++;
sgmcb 31:f94b8f987b62 73
sgmcb 31:f94b8f987b62 74 ret = gps.getMessage(buf, sizeof(buf));
sgmcb 31:f94b8f987b62 75
sgmcb 31:f94b8f987b62 76 // Test for location data in this priority: GLL, RMC, GGA
sgmcb 31:f94b8f987b62 77
sgmcb 31:f94b8f987b62 78 if ( strstr(buf, "GLL") ) {
sgmcb 31:f94b8f987b62 79 char ch = '-';
sgmcb 31:f94b8f987b62 80 // FIX: The getNmeaItem isn't working to capture the check character in a valid GLL code, which is unusual; the workaround seems to be that invalid GLL values DOES find a "V"
sgmcb 31:f94b8f987b62 81 if(!gps.getNmeaItem(6,buf,len,ch)) {
sgmcb 31:f94b8f987b62 82 printf("\n\n\rHave GLL location data after %i seconds and %i requests:\r\n", ( (int) locationLoopWait * locationLoopIter), locationLoopIter );
sgmcb 31:f94b8f987b62 83 printf(buf);
sgmcb 31:f94b8f987b62 84 break;
sgmcb 31:f94b8f987b62 85 }
sgmcb 31:f94b8f987b62 86 else {
sgmcb 31:f94b8f987b62 87 printf("Received invalid GLL data\r\n");
sgmcb 31:f94b8f987b62 88 printf(buf);
sgmcb 31:f94b8f987b62 89
sgmcb 31:f94b8f987b62 90 }
sgmcb 31:f94b8f987b62 91
sgmcb 31:f94b8f987b62 92 }
sgmcb 31:f94b8f987b62 93 else if ( strstr(buf, "RMC") ) {
sgmcb 31:f94b8f987b62 94 printf("RMC loc...");
sgmcb 31:f94b8f987b62 95 //printf(buf); printf("\r\n\n");
sgmcb 31:f94b8f987b62 96
sgmcb 31:f94b8f987b62 97 }
sgmcb 31:f94b8f987b62 98 else if ( strstr(buf, "GGA") ) {
sgmcb 31:f94b8f987b62 99 printf("GGA loc...");
sgmcb 31:f94b8f987b62 100 //printf(buf); printf("\r\n\n");
sgmcb 31:f94b8f987b62 101 }
sgmcb 31:f94b8f987b62 102 else {
sgmcb 31:f94b8f987b62 103 printf("\n\rNo location data this message\r\n");
sgmcb 31:f94b8f987b62 104 }
sgmcb 31:f94b8f987b62 105
sgmcb 31:f94b8f987b62 106 wait(locationLoopWait);
sgmcb 31:f94b8f987b62 107 }// LOOP THAT MOFO
sgmcb 31:f94b8f987b62 108
sgmcb 31:f94b8f987b62 109
sgmcb 31:f94b8f987b62 110 // Begin parsing our GPS value
sgmcb 31:f94b8f987b62 111
sgmcb 31:f94b8f987b62 112 double la = 0, lo = 0; // Declare latitude and longitude variables
sgmcb 31:f94b8f987b62 113
sgmcb 31:f94b8f987b62 114 gps.getNmeaAngle(1,buf,len,la);
sgmcb 31:f94b8f987b62 115 gps.getNmeaAngle(3,buf,len,lo);
sgmcb 31:f94b8f987b62 116
sgmcb 31:f94b8f987b62 117 printf("\r\n\nLatitude: %G\r\nLongitude: %G\r\n", la, lo);
sgmcb 31:f94b8f987b62 118
sgmcb 31:f94b8f987b62 119
sgmcb 31:f94b8f987b62 120
sgmcb 31:f94b8f987b62 121
sgmcb 31:f94b8f987b62 122
sgmcb 31:f94b8f987b62 123
sgmcb 31:f94b8f987b62 124
sgmcb 31:f94b8f987b62 125 /*
sgmcb 31:f94b8f987b62 126
sgmcb 31:f94b8f987b62 127
sgmcb 31:f94b8f987b62 128 if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { // Check if we're getting an NMEA protocol response
sgmcb 31:f94b8f987b62 129
sgmcb 31:f94b8f987b62 130 printf("Indeed, an NMEA protocol response!\r\n");
sgmcb 31:f94b8f987b62 131
sgmcb 31:f94b8f987b62 132 // Check the talker
sgmcb 31:f94b8f987b62 133 if( (buf[0] == '$') || (buf[1] == 'G' ) ) {
sgmcb 31:f94b8f987b62 134 char talkerID[30] = "";
sgmcb 31:f94b8f987b62 135 sprintf(talkerID, "We've got a valid talker=%c%c\r\n", buf[0], buf[1]);
sgmcb 31:f94b8f987b62 136 printf(talkerID);
sgmcb 31:f94b8f987b62 137 }
sgmcb 31:f94b8f987b62 138 }
sgmcb 31:f94b8f987b62 139 */
sgmcb 31:f94b8f987b62 140
sgmcb 31:f94b8f987b62 141
sgmcb 31:f94b8f987b62 142
sgmcb 31:f94b8f987b62 143
sgmcb 30:f9bb5aba1155 144 }
sgmcb 30:f9bb5aba1155 145
sgmcb 30:f9bb5aba1155 146
sgmcb 30:f9bb5aba1155 147
sgmcb 30:f9bb5aba1155 148
sgmcb 30:f9bb5aba1155 149
sgmcb 30:f9bb5aba1155 150
sgmcb 30:f9bb5aba1155 151
sgmcb 30:f9bb5aba1155 152
sgmcb 30:f9bb5aba1155 153
sgmcb 30:f9bb5aba1155 154
sgmcb 30:f9bb5aba1155 155