cellular port
Dependencies: Beep C027_Support C12832 LM75B MMA7660 mbed-rtos mbed nsdl_lib
This is a port of the NSDL HelloWorld for cellular.
To run the example you need a C027 and the ARM mbed application shield. The example uses cellular instead of ethernet and takes the true position from the GPS instead of using a fixed position.
Diff: main.cpp
- Revision:
- 11:fa12b9f50538
- Parent:
- 10:443e7f741c8e
- Child:
- 12:2799b212c729
--- a/main.cpp Tue Jun 17 07:05:29 2014 +0000 +++ b/main.cpp Wed Jun 18 08:29:25 2014 +0000 @@ -6,7 +6,7 @@ // Include various resources #include "temperature.h" #include "light.h" -#include "gps.h" +#include "gps_res.h" #include "relay.h" #include "UDPSocket.h" @@ -17,6 +17,7 @@ // These parameters are ignored for LISA-C200 variants and can be left NULL. //------------------------------------------------------------------------------------ #include "MDM.h" +#include "GPS.h" //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. #define SIMPIN NULL /*! The APN of your network operator SIM, sometimes it is "internet" check your @@ -56,8 +57,11 @@ nsp.set_address(NSP_ADDRESS, NSP_PORT); NSDL_DEBUG("name: %s", endpoint_name); - NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT); - NSDL_DEBUG("NSDL Demo Portal\n Website: http://%s\n Username: demo\n Password: demo\n", NSP_ADDRESS); + NSDL_DEBUG("NSP=%s - port %d", NSP_ADDRESS, NSP_PORT); + NSDL_DEBUG("NSDL Demo Portal\r\n" + " Website: http://%s\r\n" + " Username: demo\r\n" + " Password: demo", NSP_ADDRESS); lcd.locate(0,22); lcd.printf("EP name:%s\n", endpoint_name); @@ -88,8 +92,10 @@ memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); // Static resources - nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "Sensinode", sizeof("Sensinode")-1); - nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1); + #define _PT(str) sizeof(str)-1, (uint8_t*)str + #define _RSC(str) (uint8_t*)str, sizeof(str)-1 + nsdl_create_static_resource(resource_ptr, _PT("dev/mfg"), 0, 0, _RSC("Sensinode / u-blox")); + nsdl_create_static_resource(resource_ptr, _PT("dev/mdl"), 0, 0, _RSC("NSDL-C cellular mbed device")); // Dynamic resources create_temperature_resource(resource_ptr); @@ -112,20 +118,13 @@ // **************************************************************************** // Program entry point - -int main() +void ndslTask(void const* argument) { - Serial pc(USBTX, USBRX); - pc.baud(115200); - lcd.cls(); - lcd.locate(0,0); - lcd.printf("mbed NanoService demo"); - NSDL_DEBUG("mbed NanoService Example App 0.1\n"); + MDMRtos<MDMSerial> mdm; - MDMRtos<MDMSerial> mdm; //mdm.setDebug(4); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) - return -1; + return; lcd.locate(0,11); @@ -143,7 +142,52 @@ mdm.disconnect(); mdm.powerOff(); - - while(true); - } + +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)) + { + if (!strncmp("$GPGLL", buf, 6)) { + double la = 0, lo = 0; + char ch; + if (gps.getNmeaAngle(1,buf,len,la) && + gps.getNmeaAngle(3,buf,len,lo) && + gps.getNmeaItem(6,buf,len,ch) && ch == 'A') + { + printf("gps update lat %.6f lon %.6f\r\n", la, lo); + gps_resource_set(la,lo); + } + } + } + } else + Thread::wait(100); + } +} + +int main() +{ + Serial pc(USBTX, USBRX); + pc.baud(115200); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("mbed NanoService demo"); + NSDL_DEBUG("mbed NanoService Example App 0.1\r\n"); + + Thread task1(ndslTask, NULL, osPriorityNormal, 4096); + Thread task2(gpsTask, NULL, osPriorityNormal, 2048); + + DigitalOut led(LED); + while(true) { + led = !led; + wait_ms(500); + } +} + +