Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
36:f240f5a6d0ed
Parent:
35:6235ef67faa1
Child:
37:7e6986b77f01
--- a/src/CommandParser/cmd.cpp	Fri Sep 09 13:33:54 2016 +0000
+++ b/src/CommandParser/cmd.cpp	Fri Sep 09 15:24:18 2016 +0000
@@ -30,6 +30,7 @@
 
 #include "cmd.h"
 #include <mbed.h>
+#include <utility>
 #include "ntshell.h"
 #include "ntopt.h"
 #include "global.h"
@@ -53,9 +54,10 @@
     {"?",                   "help command",                                     cmd_help            },
     {"create",              "create a control",                                 cmd_create          },
     {"destroy",             "destroy a control",                                cmd_destroy         },
-    {"ccf",                 "create a test control file",                       cmd_ccf             }, 
+    {"ccf",                 "create a test control file",                       cmd_ccf             },
     {"heap",                "show heap statistics",                             cmd_heap            },
     {"help",                "help command",                                     cmd_help            },
+    {"log-level",           "get/set mDot log level",                           cmd_logLevel        },
     {"ls",                  "list user files",                                  cmd_ls              },
     {"modify",              "modify a control",                                 cmd_modify          },
     {"reset",               "reset the controller",                             cmd_reset           },
@@ -64,7 +66,7 @@
     {"rssi-stats",          "get current rssi stats",                           cmd_rssiStats       },
     {"show-controls",       "display active controls",                          cmd_ShowControls    },
     {"snr-stats",           "get current SNR stats",                            cmd_snrStats        },
-    {"stack",               "get thread stack usage stats",                     cmd_stack           }, 
+    {"stack",               "get thread stack usage stats",                     cmd_stack           },
     {"stats",               "get current mDot statistics",                      cmd_stats           },
     {NULL, NULL, NULL}
 };
@@ -151,9 +153,59 @@
     printf("\r\n");
 }
 
+
+/*****************************************************************************
+ * Function:        cmd_logLevel
+ * Description:     get or set the current log-level 
+ *
+ * @param           argc (not used)
+ * @param           argv (not used)
+ * @return          none
+ *****************************************************************************/
+void cmd_logLevel(int argc, char **argv)
+{
+    uint8_t logLevel = 0;
+    
+    const char *mapper[] = { "NONE", 
+                            "FATAL",
+                            "ERROR",
+                            "WARNING",
+                            "INFO",
+                            "DEBUG",
+                            "TRACE" };
+    
+    if ( argc == 1 ) {
+        printf("\r  current log-level set to %s\r\n", 
+            mapper[GLOBAL_mdot->getLogLevel()]);
+        goto usage;
+    }
+
+    if ( argc != 2 ) {
+usage:
+        printf("\rusage: log-level [0-6]\n");
+        printf("\r   0 = NONE\n");
+        printf("\r   1 = FATAL\n");
+        printf("\r   2 = ERROR\n");
+        printf("\r   3 = WARNING\n");
+        printf("\r   4 = INFO\n");
+        printf("\r   5 = DEBUG\n");
+        printf("\r   6 = TRACE\r\n");
+        return;
+    }
+    
+    logLevel = atoi(argv[1]);
+    if ( logLevel > 6 ) 
+        goto usage;
+    
+    // reassign the log level 
+    printf("...setting log-level to %s\r\n", mapper[logLevel]);
+    GLOBAL_mdot->setLogLevel(logLevel); 
+    printf("\r\n");
+}
+
 /*****************************************************************************
  * Function:        cmd_ls
- * Description:     list the user files on flash 
+ * Description:     list the user files on flash
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -163,7 +215,7 @@
 {
     UNUSED(argc);
     UNUSED(argv);
-    
+
     vector<mDot::mdot_file> userFiles;
     userFiles = GLOBAL_mdot->listUserFiles();
     vector<mDot::mdot_file>::iterator pos;
@@ -176,7 +228,7 @@
 
 /*****************************************************************************
  * Function:        cmd_ShowControls
- * Description:     show active controls 
+ * Description:     show active controls
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -193,7 +245,7 @@
 
 /*****************************************************************************
  * Function:        cmd_reset
- * Description:     reset the cpu 
+ * Description:     reset the cpu
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -211,7 +263,7 @@
  * Description:     removes a user file from flash
  *
  * @param           argc-> number of args
- * @param           argv-> filename 
+ * @param           argv-> filename
  * @return          none
  *****************************************************************************/
 void cmd_rm(int argc, char **argv)
@@ -229,7 +281,7 @@
 
 /*****************************************************************************
  * Function:        cmd_create
- * Description:     create a control 
+ * Description:     create a control
  *
  * @param           argc-> number of args
  * @param           argv-> control name, control type
@@ -259,10 +311,10 @@
 
 /*****************************************************************************
  * Function:        cmd_destroy
- * Description:     reset the cpu 
+ * Description:     reset the cpu
  *
  * @param           argc-> number of arguments
- * @param           argv-> control name, control type 
+ * @param           argv-> control name, control type
  * @return          none
  *****************************************************************************/
 void cmd_destroy(int argc, char **argv)
@@ -293,31 +345,31 @@
  * Description:     create a control file
  *
  * @param           argc-> number of args
- * @param           argv-> filename 
+ * @param           argv-> filename
  * @return          none
  *****************************************************************************/
-void cmd_ccf(int argc, char **argv) 
+void cmd_ccf(int argc, char **argv)
 {
     if ( argc != 2 ) {
-        printf("\rusage: ccf <filename>\r\n"); 
+        printf("\rusage: ccf <filename>\r\n");
         return;
     }
-    
+
     char data_buf[1024];
-    snprintf(data_buf, sizeof(data_buf), 
-        "{ "
-          "\"id\":\"SP\", "
-          "\"name\":\"TRASAR\", "
-          "\"priority\":\"800\", "
-          "\"input\":\"i_tra01\", "
-          "\"output\":\"o_r05\", "
-          "\"prodfact\":\"100\", "
-          "\"halert\":\"115\", "
-          "\"lalert\":\"85\", "
-          "\"hfs\":\"130\", "
-          "\"lfs\":\"70\", "
-          "\"tol\":\"5\" } "
-          );
+    snprintf(data_buf, sizeof(data_buf),
+             "{ "
+             "\"id\":\"SP\", "
+             "\"name\":\"TRASAR\", "
+             "\"priority\":\"800\", "
+             "\"input\":\"i_tra01\", "
+             "\"output\":\"o_r05\", "
+             "\"prodfact\":\"100\", "
+             "\"halert\":\"115\", "
+             "\"lalert\":\"85\", "
+             "\"hfs\":\"130\", "
+             "\"lfs\":\"70\", "
+             "\"tol\":\"5\" } "
+            );
 
     bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 1024);
     if( status != true ) {
@@ -341,7 +393,7 @@
 
 /*****************************************************************************
  * Function:        cmd_modify
- * Description:     modify an active control 
+ * Description:     modify an active control
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -366,7 +418,7 @@
 {
     UNUSED(argc);
     UNUSED(argv);
-    
+
     mDot::mdot_stats stats = GLOBAL_mdot->getStats();
 
     printf("\r         Up: %u\n", stats.Up);
@@ -391,13 +443,13 @@
 {
     UNUSED(argc);
     UNUSED(argv);
-    
+
     GLOBAL_mdot->resetStats();
 }
 
 /*****************************************************************************
  * Function:        cmd_rssiStats
- * Description:     displays mDot RSSI statistics 
+ * Description:     displays mDot RSSI statistics
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -407,7 +459,7 @@
 {
     UNUSED(argc);
     UNUSED(argv);
-    
+
     mDot::rssi_stats s = GLOBAL_mdot->getRssiStats();
 
     printf("\r     Last: %d dB\n", s.last);
@@ -440,7 +492,7 @@
 
 /*****************************************************************************
  * Function:        cmd_stack
- * Description:     display thread stack statisics 
+ * Description:     display thread stack statisics
  *
  * @param           argc (not used)
  * @param           argv (not used)
@@ -448,48 +500,25 @@
  *****************************************************************************/
 void cmd_stack(int argc, char **argv)
 {
-    if ( GLOBAL_analyticsLogger_thread ) {
-        printf("\r AnalyticsLogger        size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_analyticsLogger_thread->stack_size(),
-            GLOBAL_analyticsLogger_thread->free_stack(),
-            GLOBAL_analyticsLogger_thread->used_stack(),
-            GLOBAL_analyticsLogger_thread->max_stack());
-    }
-    if ( GLOBAL_BLE_thread ) {
-        printf("\r BLEHandler             size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_BLE_thread->stack_size(),
-            GLOBAL_BLE_thread->free_stack(),
-            GLOBAL_BLE_thread->used_stack(),
-            GLOBAL_BLE_thread->max_stack());
-    }
-    if ( GLOBAL_CDH_thread ) {
-        printf("\r CloudDataHandler       size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_CDH_thread->stack_size(),
-            GLOBAL_CDH_thread->free_stack(),
-            GLOBAL_CDH_thread->used_stack(),
-            GLOBAL_CDH_thread->max_stack());
+    vector<pair<string, Thread*> > taskList;
+
+    //simply add your task to the list...
+    taskList.push_back(make_pair((string)"AnalyticsLogger",  GLOBAL_analyticsLogger_thread));
+    taskList.push_back(make_pair((string)"BLEHandler",       GLOBAL_BLE_thread));
+    taskList.push_back(make_pair((string)"CloudDataHandler", GLOBAL_CDH_thread));
+    taskList.push_back(make_pair((string)"ConfigHandler",    GLOBAL_configHandler_thread));
+    taskList.push_back(make_pair((string)"ControlTask",      GLOBAL_controlTask_thread));
+    taskList.push_back(make_pair((string)"ModbusMaster",     GLOBAL_modbusMaster_thread));
+
+    for ( vector<pair<string, Thread*> >::iterator pos = taskList.begin();
+            pos != taskList.end(); ++ pos) {
+        printf("\r %-32s size/free/used/max = %u/%u/%u/%u\n",
+            pos->first.c_str(),
+            pos->second->stack_size(),
+            pos->second->free_stack(),
+            pos->second->used_stack(),
+            pos->second->max_stack());
     }
-    if ( GLOBAL_configHandler_thread ) {
-        printf("\r ConfigHandler          size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_configHandler_thread->stack_size(),
-            GLOBAL_configHandler_thread->free_stack(),
-            GLOBAL_configHandler_thread->used_stack(),
-            GLOBAL_configHandler_thread->max_stack());
-    }
-    if ( GLOBAL_controlTask_thread ) {
-        printf("\r ControlTask            size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_controlTask_thread->stack_size(),
-            GLOBAL_controlTask_thread->free_stack(),
-            GLOBAL_controlTask_thread->used_stack(),
-            GLOBAL_controlTask_thread->max_stack());
-    }
-    if ( GLOBAL_modbusMaster_thread ) {
-        printf("\r ModbusMaster           size/free/used/max = %u/%u/%u/%u\n", 
-            GLOBAL_modbusMaster_thread->stack_size(),
-            GLOBAL_modbusMaster_thread->free_stack(),
-            GLOBAL_modbusMaster_thread->used_stack(),
-            GLOBAL_modbusMaster_thread->max_stack());
-    }
-    
+
     printf("\r\n");
 }