NanoService Example for u-blox Cellular modems
Dependencies: Beep LM75B MMA7660 mbed nsdl_lib
Fork of NSDL_HelloWorld by
Revision 11:3b7ae478dcd1, committed 2013-10-31
- Comitter:
- sam_grove
- Date:
- Thu Oct 31 20:29:30 2013 +0000
- Parent:
- 10:4cb556c7845e
- Commit message:
- Tested and working with ublox LISA C200 CDMA modem
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Thu Oct 31 20:29:30 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sam_grove/code/C12832_lcd_techcon/#7309050fda9c
--- a/UbloxUSBModem.lib Wed Oct 30 00:46:59 2013 +0000 +++ b/UbloxUSBModem.lib Thu Oct 31 20:29:30 2013 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/UbloxUSBModem/#6e9d98f8c237 +http://mbed.org/users/sam_grove/code/UbloxUSBModem/#041ca14bdd83
--- 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();
}
--- a/nsdl_support.cpp Wed Oct 30 00:46:59 2013 +0000 +++ b/nsdl_support.cpp Thu Oct 31 20:29:30 2013 +0000 @@ -4,14 +4,14 @@ #include "nsdl_support.h" #include "mbed.h" #include "rtos.h" -#include "UbloxUSBGSMModem.h" -#include "UbloxUSBCDMAModem.h" -#include "CellularModem.h" +//#include "UbloxUSBGSMModem.h" +//#include "UbloxUSBCDMAModem.h" +//#include "CellularModem.h" #include "Socket.h" #include "Endpoint.h" #include "UDPSocket.h" -extern UbloxUSBGSMModem modem; +//extern UbloxUSBGSMModem modem; extern Endpoint nsp; extern UDPSocket server; extern char endpoint_name[16];
--- a/resources/gps.cpp Wed Oct 30 00:46:59 2013 +0000
+++ b/resources/gps.cpp Thu Oct 31 20:29:30 2013 +0000
@@ -7,6 +7,7 @@
#define GPS_RES_ID "gps/loc"
static uint8_t res_gps_val[] = {"52.182382,0.178849"};
+//static uint8_t res_gps_val[] = {"30.246278,-97.802546"}; // austin TX
/* Only GET method allowed */
static uint8_t gps_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)



