whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
main.cpp@33:4ed19bed18c0, 2015-12-01 (annotated)
- Committer:
- sgmcb
- Date:
- Tue Dec 01 00:32:19 2015 +0000
- Revision:
- 33:4ed19bed18c0
- Parent:
- 32:4b94cb22d338
- Child:
- 34:f28937f7657d
Functioning refactored getGLL call
Who changed what in which revision?
User | Revision | Line number | New 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 | 32:4b94cb22d338 | 9 | |
sgmcb | 32:4b94cb22d338 | 10 | |
sgmcb | 32:4b94cb22d338 | 11 | |
sgmcb | 32:4b94cb22d338 | 12 | |
sgmcb | 31:f94b8f987b62 | 13 | // AT&T Support |
sgmcb | 31:f94b8f987b62 | 14 | |
mazgch | 19:f022ff746eb8 | 15 | //------------------------------------------------------------------------------------ |
sgmcb | 31:f94b8f987b62 | 16 | // Cellular modem/SIM parameters |
sgmcb | 31:f94b8f987b62 | 17 | #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs. |
sgmcb | 31:f94b8f987b62 | 18 | #define APN "m2m.com.attz" // Defined AT&T M2M APN |
sgmcb | 31:f94b8f987b62 | 19 | #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't) |
sgmcb | 31:f94b8f987b62 | 20 | #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't) |
mazgch | 19:f022ff746eb8 | 21 | //------------------------------------------------------------------------------------ |
lawliet | 0:4e3cb26f6019 | 22 | |
sgmcb | 32:4b94cb22d338 | 23 | // PONY refactored code |
sgmcb | 32:4b94cb22d338 | 24 | #include "PonyLoc.h" |
sgmcb | 32:4b94cb22d338 | 25 | |
sgmcb | 32:4b94cb22d338 | 26 | |
sgmcb | 32:4b94cb22d338 | 27 | |
sgmcb | 32:4b94cb22d338 | 28 | |
sgmcb | 32:4b94cb22d338 | 29 | |
sgmcb | 30:f9bb5aba1155 | 30 | // Set pinout for LED |
sgmcb | 30:f9bb5aba1155 | 31 | DigitalOut myled(LED); |
sgmcb | 30:f9bb5aba1155 | 32 | |
sgmcb | 32:4b94cb22d338 | 33 | extern const char* NMEA_talkers[]; |
sgmcb | 32:4b94cb22d338 | 34 | |
sgmcb | 32:4b94cb22d338 | 35 | |
sgmcb | 32:4b94cb22d338 | 36 | |
sgmcb | 32:4b94cb22d338 | 37 | |
sgmcb | 32:4b94cb22d338 | 38 | // MAIN |
sgmcb | 32:4b94cb22d338 | 39 | |
sgmcb | 30:f9bb5aba1155 | 40 | int main(void) { |
sgmcb | 31:f94b8f987b62 | 41 | printf("\n\n\r----------\r\nI'm alive!\r\n"); |
sgmcb | 30:f9bb5aba1155 | 42 | |
sgmcb | 31:f94b8f987b62 | 43 | // Loading wait |
sgmcb | 31:f94b8f987b62 | 44 | for(int i = 0; i < 10; i++) { |
sgmcb | 31:f94b8f987b62 | 45 | myled = !myled;; |
sgmcb | 30:f9bb5aba1155 | 46 | wait(0.2); |
sgmcb | 30:f9bb5aba1155 | 47 | } |
sgmcb | 30:f9bb5aba1155 | 48 | |
sgmcb | 33:4ed19bed18c0 | 49 | //int ret; // Integer returns |
sgmcb | 33:4ed19bed18c0 | 50 | //int len; // The length of the ret integer |
sgmcb | 33:4ed19bed18c0 | 51 | |
sgmcb | 33:4ed19bed18c0 | 52 | double la = 0, lo = 0; // Declare latitude and longitude variables |
sgmcb | 33:4ed19bed18c0 | 53 | double UTCtime = 0; |
sgmcb | 31:f94b8f987b62 | 54 | |
sgmcb | 31:f94b8f987b62 | 55 | // Not 100% sure where this LARGE_DATA flag is being set, but I think we might be using it... (SGM) |
sgmcb | 31:f94b8f987b62 | 56 | #ifdef LARGE_DATA |
sgmcb | 31:f94b8f987b62 | 57 | char buf[2048] = ""; |
sgmcb | 31:f94b8f987b62 | 58 | #else |
sgmcb | 31:f94b8f987b62 | 59 | char buf[512] = ""; |
sgmcb | 31:f94b8f987b62 | 60 | #endif |
sgmcb | 31:f94b8f987b62 | 61 | |
sgmcb | 33:4ed19bed18c0 | 62 | ////////////////////////////////// |
sgmcb | 31:f94b8f987b62 | 63 | |
sgmcb | 31:f94b8f987b62 | 64 | GPSI2C gps; // Initialize GPS object |
sgmcb | 31:f94b8f987b62 | 65 | printf("GPS initialized...\r\n"); |
sgmcb | 31:f94b8f987b62 | 66 | |
sgmcb | 32:4b94cb22d338 | 67 | /* |
sgmcb | 31:f94b8f987b62 | 68 | while( (ret = gps.getMessage(buf, sizeof(buf))) < 1 ) { |
sgmcb | 31:f94b8f987b62 | 69 | if (ret<0) |
sgmcb | 31:f94b8f987b62 | 70 | printf("WAIT received from GPS\r\n"); |
sgmcb | 31:f94b8f987b62 | 71 | if (ret==0) |
sgmcb | 31:f94b8f987b62 | 72 | printf("NOT FOUND received from GPS\r\n"); |
sgmcb | 31:f94b8f987b62 | 73 | myled = !myled; |
sgmcb | 31:f94b8f987b62 | 74 | wait(1.0); |
sgmcb | 32:4b94cb22d338 | 75 | }*/ |
sgmcb | 33:4ed19bed18c0 | 76 | |
sgmcb | 33:4ed19bed18c0 | 77 | |
sgmcb | 33:4ed19bed18c0 | 78 | |
sgmcb | 33:4ed19bed18c0 | 79 | |
sgmcb | 33:4ed19bed18c0 | 80 | |
sgmcb | 33:4ed19bed18c0 | 81 | |
sgmcb | 33:4ed19bed18c0 | 82 | // How long will we wait before we accept ANY location value? |
sgmcb | 33:4ed19bed18c0 | 83 | float locationLoopWait = 0.25; |
sgmcb | 31:f94b8f987b62 | 84 | |
sgmcb | 32:4b94cb22d338 | 85 | int locationLoopTimeout = 30; |
sgmcb | 32:4b94cb22d338 | 86 | int locationLoopCountout = (float) locationLoopTimeout / locationLoopWait; |
sgmcb | 33:4ed19bed18c0 | 87 | |
sgmcb | 33:4ed19bed18c0 | 88 | // Ready the GPS |
sgmcb | 33:4ed19bed18c0 | 89 | if ( gpsReady(&gps, 5) ) { |
sgmcb | 32:4b94cb22d338 | 90 | |
sgmcb | 33:4ed19bed18c0 | 91 | if ( getGLL(&gps, locationLoopCountout, &la, &lo, &UTCtime) ) { |
sgmcb | 33:4ed19bed18c0 | 92 | printf("Have GLL data:\r\n%s", buf); |
sgmcb | 33:4ed19bed18c0 | 93 | } |
sgmcb | 33:4ed19bed18c0 | 94 | else { |
sgmcb | 33:4ed19bed18c0 | 95 | printf("Timeout; no valid GLL data received"); |
sgmcb | 33:4ed19bed18c0 | 96 | } |
sgmcb | 32:4b94cb22d338 | 97 | |
sgmcb | 33:4ed19bed18c0 | 98 | } |
sgmcb | 33:4ed19bed18c0 | 99 | |
sgmcb | 33:4ed19bed18c0 | 100 | |
sgmcb | 33:4ed19bed18c0 | 101 | |
sgmcb | 33:4ed19bed18c0 | 102 | /* |
sgmcb | 31:f94b8f987b62 | 103 | // Get a good GPS message |
sgmcb | 31:f94b8f987b62 | 104 | |
sgmcb | 33:4ed19bed18c0 | 105 | |
sgmcb | 31:f94b8f987b62 | 106 | |
sgmcb | 32:4b94cb22d338 | 107 | printf("\r\nMessage loop wait=%fs\r\n",locationLoopWait); |
sgmcb | 33:4ed19bed18c0 | 108 | |
sgmcb | 33:4ed19bed18c0 | 109 | int locationLoopIter = 0; |
sgmcb | 31:f94b8f987b62 | 110 | while(true) { |
sgmcb | 31:f94b8f987b62 | 111 | locationLoopIter++; |
sgmcb | 31:f94b8f987b62 | 112 | |
sgmcb | 31:f94b8f987b62 | 113 | ret = gps.getMessage(buf, sizeof(buf)); |
sgmcb | 31:f94b8f987b62 | 114 | |
sgmcb | 31:f94b8f987b62 | 115 | // Test for location data in this priority: GLL, RMC, GGA |
sgmcb | 32:4b94cb22d338 | 116 | #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) |
sgmcb | 31:f94b8f987b62 | 117 | |
sgmcb | 32:4b94cb22d338 | 118 | // TODO: Add check that we're getting NMEA-formatted sentences |
sgmcb | 32:4b94cb22d338 | 119 | |
sgmcb | 32:4b94cb22d338 | 120 | |
sgmcb | 32:4b94cb22d338 | 121 | |
sgmcb | 32:4b94cb22d338 | 122 | |
sgmcb | 32:4b94cb22d338 | 123 | int sentenceType = getNMEAtalker(buf); |
sgmcb | 32:4b94cb22d338 | 124 | //char talkerType[3] = NMEA_talkers[sentenceType]; |
sgmcb | 32:4b94cb22d338 | 125 | printf("Talker type = %s\r\n", NMEA_talkers[sentenceType]); |
sgmcb | 32:4b94cb22d338 | 126 | |
sgmcb | 32:4b94cb22d338 | 127 | if (sentenceType == 5) { |
sgmcb | 32:4b94cb22d338 | 128 | break; |
sgmcb | 32:4b94cb22d338 | 129 | } |
sgmcb | 32:4b94cb22d338 | 130 | |
sgmcb | 32:4b94cb22d338 | 131 | |
sgmcb | 32:4b94cb22d338 | 132 | |
sgmcb | 33:4ed19bed18c0 | 133 | |
sgmcb | 32:4b94cb22d338 | 134 | if ( _CHECK_TALKER("GLL") ) { |
sgmcb | 31:f94b8f987b62 | 135 | char ch = '-'; |
sgmcb | 31:f94b8f987b62 | 136 | // 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 | 137 | if(!gps.getNmeaItem(6,buf,len,ch)) { |
sgmcb | 32:4b94cb22d338 | 138 | printf("\n\n\rHave GLL location data after %f seconds and %i requests:\r\n", ( locationLoopWait * (float) locationLoopIter ), locationLoopIter ); |
sgmcb | 31:f94b8f987b62 | 139 | printf(buf); |
sgmcb | 31:f94b8f987b62 | 140 | break; |
sgmcb | 31:f94b8f987b62 | 141 | } |
sgmcb | 31:f94b8f987b62 | 142 | else { |
sgmcb | 32:4b94cb22d338 | 143 | printf("\rGLL inv..."); |
sgmcb | 32:4b94cb22d338 | 144 | //printf(buf); printf("\r\n"); |
sgmcb | 31:f94b8f987b62 | 145 | } |
sgmcb | 32:4b94cb22d338 | 146 | } |
sgmcb | 32:4b94cb22d338 | 147 | else if ( (_CHECK_TALKER("RMC") || _CHECK_TALKER("GGA")) && locationLoopIter > locationLoopCountout ) { |
sgmcb | 32:4b94cb22d338 | 148 | printf("\r\nTaking non-GLL data due to location timeout\r\n"); |
sgmcb | 32:4b94cb22d338 | 149 | printf(buf); printf("\r\n"); |
sgmcb | 32:4b94cb22d338 | 150 | break; |
sgmcb | 31:f94b8f987b62 | 151 | } |
sgmcb | 32:4b94cb22d338 | 152 | |
sgmcb | 32:4b94cb22d338 | 153 | |
sgmcb | 32:4b94cb22d338 | 154 | else if ( _CHECK_TALKER("RMC") ) { |
sgmcb | 31:f94b8f987b62 | 155 | |
sgmcb | 32:4b94cb22d338 | 156 | printf("\rRMC loc..."); |
sgmcb | 32:4b94cb22d338 | 157 | //printf(buf); printf("\r\n\n"); |
sgmcb | 31:f94b8f987b62 | 158 | } |
sgmcb | 32:4b94cb22d338 | 159 | else if ( _CHECK_TALKER("GGA") ) { |
sgmcb | 32:4b94cb22d338 | 160 | printf("\rGGA loc..."); |
sgmcb | 31:f94b8f987b62 | 161 | //printf(buf); printf("\r\n\n"); |
sgmcb | 31:f94b8f987b62 | 162 | } |
sgmcb | 31:f94b8f987b62 | 163 | else { |
sgmcb | 32:4b94cb22d338 | 164 | printf("\rNo loc..."); |
sgmcb | 31:f94b8f987b62 | 165 | } |
sgmcb | 31:f94b8f987b62 | 166 | |
sgmcb | 32:4b94cb22d338 | 167 | */ |
sgmcb | 32:4b94cb22d338 | 168 | |
sgmcb | 33:4ed19bed18c0 | 169 | //wait(locationLoopWait); |
sgmcb | 33:4ed19bed18c0 | 170 | //}// LOOP THAT MOFO |
sgmcb | 31:f94b8f987b62 | 171 | |
sgmcb | 31:f94b8f987b62 | 172 | |
sgmcb | 31:f94b8f987b62 | 173 | // Begin parsing our GPS value |
sgmcb | 31:f94b8f987b62 | 174 | |
sgmcb | 33:4ed19bed18c0 | 175 | |
sgmcb | 31:f94b8f987b62 | 176 | |
sgmcb | 33:4ed19bed18c0 | 177 | //gps.getNmeaAngle(1,buf,len,la); |
sgmcb | 33:4ed19bed18c0 | 178 | //gps.getNmeaAngle(3,buf,len,lo); |
sgmcb | 31:f94b8f987b62 | 179 | |
sgmcb | 33:4ed19bed18c0 | 180 | printf("Latitude: %G\r\nLongitude: %G\r\nUTC Time:%f\r\n\n", la, lo, UTCtime); |
sgmcb | 33:4ed19bed18c0 | 181 | |
sgmcb | 32:4b94cb22d338 | 182 | |
sgmcb | 32:4b94cb22d338 | 183 | |
sgmcb | 32:4b94cb22d338 | 184 | |
sgmcb | 32:4b94cb22d338 | 185 | |
sgmcb | 32:4b94cb22d338 | 186 | //----- MODEM UP!!! |
sgmcb | 32:4b94cb22d338 | 187 | // Now that we know where we are, let's do something with it (modem-wise...) |
sgmcb | 32:4b94cb22d338 | 188 | |
sgmcb | 32:4b94cb22d338 | 189 | printf("Open modem object mdm\r\n"); |
sgmcb | 32:4b94cb22d338 | 190 | |
sgmcb | 32:4b94cb22d338 | 191 | MDMSerial mdm; |
sgmcb | 32:4b94cb22d338 | 192 | mdm.setDebug(4); // enable this for debugging issues |
sgmcb | 32:4b94cb22d338 | 193 | |
sgmcb | 32:4b94cb22d338 | 194 | |
sgmcb | 32:4b94cb22d338 | 195 | // Create status objects |
sgmcb | 32:4b94cb22d338 | 196 | MDMParser::DevStatus devStatus = {}; |
sgmcb | 32:4b94cb22d338 | 197 | MDMParser::NetStatus netStatus = {}; |
sgmcb | 32:4b94cb22d338 | 198 | |
sgmcb | 32:4b94cb22d338 | 199 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
sgmcb | 32:4b94cb22d338 | 200 | |
sgmcb | 32:4b94cb22d338 | 201 | // How we doing so far? |
sgmcb | 32:4b94cb22d338 | 202 | printf("\r\n-- mdm.init status dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 203 | mdm.dumpDevStatus(&devStatus); |
sgmcb | 32:4b94cb22d338 | 204 | |
sgmcb | 32:4b94cb22d338 | 205 | if (mdmOk) { |
sgmcb | 32:4b94cb22d338 | 206 | // wait until we are connected (SGM: Not sure what this means, since this isn't a loop... |
sgmcb | 32:4b94cb22d338 | 207 | mdmOk = mdm.registerNet(&netStatus); |
sgmcb | 32:4b94cb22d338 | 208 | mdm.dumpNetStatus(&netStatus); |
sgmcb | 32:4b94cb22d338 | 209 | |
sgmcb | 32:4b94cb22d338 | 210 | } |
sgmcb | 32:4b94cb22d338 | 211 | |
sgmcb | 32:4b94cb22d338 | 212 | printf("-- mdm.registerNet status dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 213 | |
sgmcb | 32:4b94cb22d338 | 214 | // Open a data connecction |
sgmcb | 32:4b94cb22d338 | 215 | if(mdmOk) { |
sgmcb | 32:4b94cb22d338 | 216 | |
sgmcb | 32:4b94cb22d338 | 217 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
sgmcb | 32:4b94cb22d338 | 218 | printf("-- mdm.join dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 219 | |
sgmcb | 32:4b94cb22d338 | 220 | |
sgmcb | 32:4b94cb22d338 | 221 | // If we secure an IP address, keep going! |
sgmcb | 32:4b94cb22d338 | 222 | |
sgmcb | 32:4b94cb22d338 | 223 | if (ip != NOIP) { |
sgmcb | 32:4b94cb22d338 | 224 | |
sgmcb | 32:4b94cb22d338 | 225 | printf("\n\n\rWe got's an IP address!\r\n"); |
sgmcb | 32:4b94cb22d338 | 226 | mdm.dumpIp(ip); |
sgmcb | 32:4b94cb22d338 | 227 | |
sgmcb | 32:4b94cb22d338 | 228 | } |
sgmcb | 32:4b94cb22d338 | 229 | } |
sgmcb | 32:4b94cb22d338 | 230 | |
sgmcb | 32:4b94cb22d338 | 231 | // SMS code |
sgmcb | 32:4b94cb22d338 | 232 | while(true) { |
sgmcb | 32:4b94cb22d338 | 233 | wait(5); |
sgmcb | 32:4b94cb22d338 | 234 | if (mdmOk) { |
sgmcb | 32:4b94cb22d338 | 235 | // check the network status |
sgmcb | 32:4b94cb22d338 | 236 | if (mdm.checkNetStatus(&netStatus)) { |
sgmcb | 32:4b94cb22d338 | 237 | printf("\r\n-- mdm.dumpNetStatus\r\n"); |
sgmcb | 32:4b94cb22d338 | 238 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
sgmcb | 32:4b94cb22d338 | 239 | break; |
sgmcb | 32:4b94cb22d338 | 240 | } |
sgmcb | 32:4b94cb22d338 | 241 | } |
sgmcb | 32:4b94cb22d338 | 242 | } |
sgmcb | 32:4b94cb22d338 | 243 | |
sgmcb | 32:4b94cb22d338 | 244 | // Send SMS |
sgmcb | 33:4ed19bed18c0 | 245 | char num1[32] = "+14259749434"; |
sgmcb | 32:4b94cb22d338 | 246 | |
sgmcb | 32:4b94cb22d338 | 247 | char smsText[144]; |
sgmcb | 33:4ed19bed18c0 | 248 | sprintf(smsText, "PONY unit located at: %f, %f, UTC %f", la, lo, UTCtime); |
sgmcb | 32:4b94cb22d338 | 249 | printf("Message: %s\r\n", smsText); |
sgmcb | 32:4b94cb22d338 | 250 | |
sgmcb | 33:4ed19bed18c0 | 251 | |
sgmcb | 32:4b94cb22d338 | 252 | |
sgmcb | 32:4b94cb22d338 | 253 | printf("\r\nSend to: %s\r\n", num1); |
sgmcb | 32:4b94cb22d338 | 254 | if( mdm.smsSend(num1, smsText) ) { |
sgmcb | 32:4b94cb22d338 | 255 | printf("\r\nSMS num1 (AT&T) success!\r\n"); |
sgmcb | 32:4b94cb22d338 | 256 | } |
sgmcb | 32:4b94cb22d338 | 257 | else { |
sgmcb | 32:4b94cb22d338 | 258 | printf("SMS fail. :-( \r\n"); |
sgmcb | 32:4b94cb22d338 | 259 | } |
sgmcb | 32:4b94cb22d338 | 260 | |
sgmcb | 33:4ed19bed18c0 | 261 | |
sgmcb | 32:4b94cb22d338 | 262 | |
sgmcb | 33:4ed19bed18c0 | 263 | } |