port to cellular
Dependencies: C027_Support M2XStreamClient jsonlite mbed-rtos mbed
Fork of Cellular_m2x-demo-all by
Revision 19:277dd9f95c9d, committed 2015-01-04
- Comitter:
- mazgch
- Date:
- Sun Jan 04 02:17:42 2015 +0000
- Parent:
- 18:416ddef3e86f
- Commit message:
- make gps it threaded
Changed in this revision
diff -r 416ddef3e86f -r 277dd9f95c9d C027_Support.lib --- a/C027_Support.lib Sun Jan 04 01:18:07 2015 +0000 +++ b/C027_Support.lib Sun Jan 04 02:17:42 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/ublox/code/C027_Support/#e347ed0fab5e +http://mbed.org/teams/ublox/code/C027_Support/#709a6386e685
diff -r 416ddef3e86f -r 277dd9f95c9d main.cpp --- a/main.cpp Sun Jan 04 01:18:07 2015 +0000 +++ b/main.cpp Sun Jan 04 02:17:42 2015 +0000 @@ -2,6 +2,8 @@ #include "M2XStreamClient.h" #include "mbed.h" +#include "rtos.h" +#define RTOS_H #include "GPS.h" //GPS //------------------------------------------------------------------------------------ @@ -50,13 +52,45 @@ printf("Elevation: %lf Timestamp: %s\r\n", elevation, timestamp); } +void gpsTask(void const* argument) +{ + GPSI2C gps; + char buf[256]; + while (1) { + int ret = gps.getMessage(buf, sizeof(buf)); + if (ret > 0) { + int len = LENGTH(ret); + if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { + // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS + if ((buf[0] == '$') || buf[1] == 'G') { + #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) + if (_CHECK_TALKER("GGA")) { + //printf("%.*sr\n", len, buf); + char ch; + if (gps.getNmeaAngle(2,buf,len,latitude) && + gps.getNmeaAngle(4,buf,len,longitude) && + gps.getNmeaItem(6,buf,len,ch) && + gps.getNmeaItem(9,buf,len,elevation)) { + printf("GPS Location: %.5f %.5f %.1f %c\r\n", latitude, longitude, elevation, ch); + location_valid = ch == '1' || ch == '2' || ch == '6'; + } + } + } + } + } else + Thread::wait(100); + } +} + int main() { -#if 0 // defined(TARGET_FF_MORPHO) +#if defined(TARGET_STM) MDMSerial mdm(D8,D2); // use the serrial port on D2 / D8 #else MDMSerial mdm; #endif GPSI2C gps; + Thread task2(gpsTask, NULL, osPriorityNormal, 2048); + //mdm.setDebug(4); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) return -1; @@ -66,29 +100,7 @@ Timer tmr; tmr.reset(); tmr.start(); - while (true) { - int ret; - // extract the location information from the GPS NMEA data - while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) { - int len = LENGTH(ret); - if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { - // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS - if ((buf[0] == '$') || buf[1] == 'G') { - #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) - if (_CHECK_TALKER("GGA")) { - char ch; - if (gps.getNmeaAngle(2,buf,len,latitude) && - gps.getNmeaAngle(4,buf,len,longitude) && - gps.getNmeaItem(6,buf,len,ch) && - gps.getNmeaItem(9,buf,len,elevation)) { - printf("GPS Location: %.5f %.5f %.1f %c\r\n", latitude, longitude, elevation, ch); - location_valid = ch == '1' || ch == '2' || ch == '6'; - } - } - } - } - } - + while (1) { if (tmr.read_ms() > 1000) { tmr.reset(); tmr.start(); @@ -122,10 +134,10 @@ #endif } else { - delay(100); + Thread::wait(100); } } mdm.disconnect(); mdm.powerOff(); -} \ No newline at end of file +}
diff -r 416ddef3e86f -r 277dd9f95c9d mbed-rtos.lib --- a/mbed-rtos.lib Sun Jan 04 01:18:07 2015 +0000 +++ b/mbed-rtos.lib Sun Jan 04 02:17:42 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#f1ef95efa5ad +http://mbed.org/users/mbed_official/code/mbed-rtos/#13a25134ac60