Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
161:500f03d11fc4
Parent:
160:201b88aa08c1
Child:
169:c503848823aa
diff -r 201b88aa08c1 -r 500f03d11fc4 src/CommandParser/cmd.cpp
--- a/src/CommandParser/cmd.cpp	Fri Sep 30 14:44:04 2016 +0000
+++ b/src/CommandParser/cmd.cpp	Fri Sep 30 16:42:51 2016 +0000
@@ -61,6 +61,7 @@
     {"cat",                 "cat a file",                                       cmd_cat             },
     {"cif",                 "create a test input file",                         cmd_cif             },
     {"cmf",                 "create a manual control file",                     cmd_cmf             },
+    {"cmt",                 "create multiple timers",                           cmd_cmt             },
     {"cof",                 "create a test output file",                        cmd_cof             },
     {"create-manual",       "create a manual control",                          cmd_createManual    },
     {"create-setpoint",     "create a setpoint control",                        cmd_createSetpoint  },
@@ -485,7 +486,7 @@
              "\"output\":       \"%s\", "
              "\"priority\":     \"%s\", "
              "\"starttime\":    \"%s\", "
-             "\"duration\":     \"%s\", ", argv[2], argv[3], argv[4], time_buf, argv[5]
+             "\"duration\":     \"%s\"  ", argv[2], argv[3], argv[4], time_buf, argv[5]
             );
 
 
@@ -511,6 +512,70 @@
 
 }
 
+void cmd_cmt(int argc, char **argv)
+{
+    char time_buf[32];
+    unsigned int counter = 0;
+    char filename[32];
+    Message_t *msg;
+
+    for ( counter = 0; counter < 5; counter++ ) {
+        // stuff the file
+        sprintf(time_buf, "%lu", time(NULL)+5 + (40 * counter));
+        char data_buf[1024];
+        snprintf(data_buf, sizeof(data_buf),
+                 "{ "
+                 "\"id\":           \"timer-%d\", "
+                 "\"output\":       \"o_rly1\", "
+                 "\"priority\":     \"750\", "
+                 "\"starttime\":    \"%s\", "
+                 "\"duration\":     \"30\"  ", counter, time_buf);
+
+        sprintf(filename, "control_tm_%d_rly1.json", counter);
+
+        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, 1024);
+        msg = MailBox.alloc();
+        memset(msg, 0, sizeof(Message_t));
+        msg->action  = ACTION_CREATE;
+        msg->control = CONTROL_TIMER;
+        strncpy(msg->controlFile, filename, sizeof(msg->controlFile)-1);
+
+        printf("%s: Sending a create request for control %s type = %u\r\n",
+               __func__, msg->controlFile, msg->control);
+
+        MailBox.put(msg);
+        Thread::wait(1000);
+    }
+
+    for ( counter = 0; counter < 5; counter++ ) {
+        // stuff the file
+        sprintf(time_buf, "%lu", time(NULL)+5 + (40 * counter));
+        char data_buf[1024];
+        snprintf(data_buf, sizeof(data_buf),
+                 "{ "
+                 "\"id\":           \"timer-%d\", "
+                 "\"output\":       \"o_rly2\", "
+                 "\"priority\":     \"750\", "
+                 "\"starttime\":    \"%s\", "
+                 "\"duration\":     \"30\"  ", counter, time_buf);
+
+        sprintf(filename, "control_tm_%d_rly2.json", counter);
+
+        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, 1024);
+        msg = MailBox.alloc();
+        memset(msg, 0, sizeof(Message_t));
+        msg->action  = ACTION_CREATE;
+        msg->control = CONTROL_TIMER;
+        strncpy(msg->controlFile, filename, sizeof(msg->controlFile)-1);
+
+        printf("%s: Sending a create request for control %s type = %u\r\n",
+               __func__, msg->controlFile, msg->control);
+
+        MailBox.put(msg);
+        Thread::wait(1000);
+    }
+}
+
 /*****************************************************************************
  * Function:        cmd_createManual
  * Description:     create a manual control