NanoService Example for u-blox Cellular modems

Dependencies:   Beep LM75B MMA7660 mbed nsdl_lib

Fork of NSDL_HelloWorld by Sensinode

Revision:
11:3b7ae478dcd1
Parent:
9:ccb9e53d5471
diff -r 4cb556c7845e -r 3b7ae478dcd1 main.cpp
--- a/main.cpp	Wed Oct 30 00:46:59 2013 +0000
+++ b/main.cpp	Thu Oct 31 20:29:30 2013 +0000
@@ -5,7 +5,7 @@
 #include "Socket.h"
 #include "Endpoint.h"
 #include "UDPSocket.h"
-// #include "C12832_lcd.h"
+#include "C12832_lcd.h"
 #include "nsdl_support.h"
 // Include various resources
 #include "temperature.h"
@@ -13,12 +13,58 @@
 #include "gps.h"
 #include "relay.h"
 
-// static C12832_LCD lcd;
+static C12832_LCD lcd;
+
+// ****************************************************************************
+// Handlers for debugging crashes
+
+#include <rt_misc.h>
+extern char Image$$RW_IRAM1$$ZI$$Limit[];
+
+extern "C" void HardFault_Handler(void)
+{
+    uint32_t zi_limit = (uint32_t)Image$$RW_IRAM1$$ZI$$Limit;
+    uint32_t sp_limit = __current_sp();
+ 
+    zi_limit = (zi_limit + 7) & ~0x7;    // ensure zi_limit is 8-byte aligned
+ 
+    struct __initial_stackheap r;
+    r.heap_base = zi_limit;
+    r.heap_limit = sp_limit;
+    r=r;
+    
+    mbed_die();
+    while(1);
+}
+
+extern "C" void MemManage_Handler(void)
+{
+    mbed_die();
+    while(1);
+}
+
+extern "C" void BusFault_Handler(void)
+{
+    mbed_die();
+    while(1);
+}
+
+extern "C" void UsageFault_Handler(void)
+{
+    mbed_die();
+    while(1);
+}
 
 // ****************************************************************************
 // Configuration section
 
 #define MODEM_UBLOX_CDMA
+//#define MODEM_UBLOX_GSM
+
+#if !defined(MODEM_UBLOX_GSM) && !defined(MODEM_UBLOX_CDMA)
+#warning No modem defined, using GSM by default
+#define MODEM_UBLOX_GSM
+#endif
 
 #ifndef MODEM_APN
 #warning APN not specified, using "internet"
@@ -52,18 +98,26 @@
 uint8_t ep_type[] = {"mbed_device"};
 uint8_t lifetime_ptr[] = {"1200"};
 
-#ifdef MODEM_UBLOX_GSM
-    UbloxUSBGSMModem modem;
-#else
-    UbloxUSBCDMAModem modem(p18, true, 1);
-#endif
 UDPSocket server;
 Endpoint nsp;
 
 // ****************************************************************************
 // u-blox Cellular initialization
+// needed for offline debugging to eliminate the semi-hosting calls
+//extern "C" int mbed_interface_uid(char *uid)
+//{
+//    uid[27] = '1';
+//    uid[28] = 'a';
+//    uid[29] = '5';
+//    uid[30] = 'b';
+//    uid[31] = '3';
+//    uid[32] = '\0';
+//    
+//    return 1;
+//}
 
-static void cellular_init()
+
+static void cellular_init(CellularModem& modem, const char* apn = NULL, const char* username = NULL, const char* password= NULL)
 {
     char mbed_uid[33]; // for creating unique name for the board
 
@@ -79,7 +133,6 @@
     mbed_interface_uid(mbed_uid);
     mbed_uid[32] = '\0';
     strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
-
 }
 
 
@@ -96,8 +149,8 @@
     printf("name: %s", endpoint_name);
     printf("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
 
- //   lcd.locate(0,22);
- //   lcd.printf("EP name:%s\n", endpoint_name);
+    lcd.locate(0,22);
+    lcd.printf("EP name:%s\n", endpoint_name);
 }
 
 // ****************************************************************************
@@ -147,28 +200,46 @@
     return 1;
 }
 
+// running led
+Ticker flash;
+DigitalOut led(LED1);
+void flashLED(void){led = !led;}
+
 // ****************************************************************************
 // Program entry point
 
 int main()
 {
- //   lcd.cls();
- //   lcd.locate(0,0);
- //   lcd.printf("mbed NanoService u-blox");
+    flash.attach(&flashLED, 1.0f);
+    
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("mbed NanoService u-blox");
     printf("mbed NanoService u-blox Example App 0.1\n");
     
+#ifdef MODEM_UBLOX_GSM
+    UbloxUSBGSMModem modem;
+#else
+    UbloxUSBCDMAModem modem(p18, true, 1);
+#endif
+    
     // Initialize Cellular interface first
-    cellular_init();
+    puts("cellular_init");
+    cellular_init(modem);
     
     // Initialize NSP node
+    puts("nsp_init");
     nsp_init();
     
     // Initialize NSDL stack
+    puts("nsdl_init");
     nsdl_init();
     
     // Create NSDL resources
+    puts("create_resources");
     create_resources();
     
     // Run the NSDL event loop (never returns)
+    puts("nsdl_event_loop");
     nsdl_event_loop();
 }