Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
149:7fde829ed672
Parent:
130:630d05daed77
Child:
160:24337c83dd1d
--- a/ErrorHandler.cpp	Wed Apr 02 04:38:41 2014 +0000
+++ b/ErrorHandler.cpp	Wed Apr 02 05:14:56 2014 +0000
@@ -62,7 +62,7 @@
 #define ERROR_HANDLER_MEM_STATS(x) \
     int s##x=0;\
     int *h##x = new int [1];\
-    this->m_pc->printf("\r\nMEMORY: stack: 0x%08x  heap: 0x%08x  avail: %d bytes\r\n", &s##x, h##x, &s##x-h##x);\
+    if (this->m_pc != NULL) this->m_pc->printf("\r\nMEMORY: stack: 0x%08x  heap: 0x%08x  avail: %d bytes\r\n", &s##x, h##x, &s##x-h##x);\
     if (h##x > &s##x)\
     error("collision\n");\
     delete [] h##x;\
@@ -120,11 +120,11 @@
     vsprintf(this->m_message, format, args);
     va_end(args);
     if (this->m_mutex != NULL) this->m_mutex->lock();
-    this->m_pc->printf(this->m_message);
+    if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
     #ifdef ENABLE_MEMORY_DEBUG
     ERROR_HANDLER_MEM_STATS(0);
     #endif
-    this->m_pc->printf("\r\n");
+    if (this->m_pc != NULL) this->m_pc->printf("\r\n");
     if (this->m_status_lcd) {
         MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
         if (endpoint != NULL) {
@@ -163,7 +163,7 @@
     vsprintf(this->m_message, format, args);
     va_end(args);
     if (this->m_mutex != NULL) this->m_mutex->lock();
-    this->m_pc->printf(this->m_message);
+    if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
     ERROR_HANDLER_MEM_STATS(0);
     if (this->m_mutex != NULL) this->m_mutex->unlock();
  #endif
@@ -179,17 +179,19 @@
     vsprintf(this->m_message, format, args);
     va_end(args);
     if (this->m_mutex != NULL) this->m_mutex->lock();
-    this->m_pc->printf(this->m_message);
-    this->m_pc->printf("\r\n");
+    if (this->m_pc != NULL) this->m_pc->printf(this->m_message);
+    if (this->m_pc != NULL) this->m_pc->printf("\r\n");
     this->m_lcd->cls();
     this->m_lcd->locate(0,0);
     this->m_lcd->printf(this->m_message);
-    this->m_pc->printf("Press any key to continue...ctrl-c to stop\r\n");
-    char c = this->m_pc->getc();
-    if (c == 0x03) {    // CTRL-C ASCII
+    if (this->m_pc != NULL) { 
+        this->m_pc->printf("Press any key to continue...ctrl-c to stop\r\n");
+        char c = this->m_pc->getc();
+        if (c == 0x03) {    // CTRL-C ASCII
         this->m_pc->printf("ctrl-c: closing down...\r\n");
         if (this->m_mutex != NULL) this->m_mutex->unlock();
-        closedown(1);
+            closedown(1);
+        }
     }
     if (this->m_mutex != NULL) this->m_mutex->unlock();
  #endif
@@ -198,7 +200,7 @@
  // check for exit
  void ErrorHandler::checkForExit() {
     if (this->m_close_mutex != NULL) this->m_close_mutex->lock();
-    if (this->m_pc->readable()) {
+    if (this->m_pc != NULL && this->m_pc->readable()) {
         char c = this->m_pc->getc();
         if (c == 0x03) {    // CTRL-C ASCII
             this->m_pc->printf("ctrl-c: closing down...\r\n");