Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
122:4db48b933115
Parent:
121:650205ffa656
Child:
124:48119db89152
--- a/src/CommandParser/cmd.cpp	Fri Sep 23 12:45:49 2016 +0000
+++ b/src/CommandParser/cmd.cpp	Fri Sep 23 15:13:04 2016 +0000
@@ -63,6 +63,7 @@
     {"cof",                 "create a test output file",                        cmd_cof             },
     {"create-manual",       "create a manual control",                          cmd_createManual    },
     {"create-setpoint",     "create a setpoint control",                        cmd_createSetpoint  },
+    {"create-timer",        "create a timer control",                           cmd_createTimer     },
     {"destroy-control",     "destroy a control",                                cmd_destroy         },
     {"heap",                "show heap statistics",                             cmd_heap            },
     {"help",                "help command",                                     cmd_help            },
@@ -451,6 +452,73 @@
 }
 
 /*****************************************************************************
+ * Function:        cmd_createTimer
+ * Description:     create control file
+ *
+ * @param           argc-> number of args
+ * @param           argv-> filename
+ * @return          none
+ *****************************************************************************/
+void cmd_createTimer(int argc, char **argv)
+{
+    if ( argc != 9 ) {
+        printf("\rusage: create-timer <filename> <id> <dow> <startw> <output> "
+               "<startHour> <startMinute> <duration>\n");
+        printf("\rexample: create-timer control_tm_1.json timer-1 42 1 o_rly01 "
+               "12 00 60\n");
+        printf("\r   dow is the integer value of or'd bits for each day\n");
+        printf("\r          1 = Sunday\n");
+        printf("\r          2 = Monday\n");
+        printf("\r          4 = Tuesday\n");
+        printf("\r          8 = Wednesday\n");
+        printf("\r         16 = Thursday\n");
+        printf("\r         32 = Friday\n");
+        printf("\r         64 = Saturday\n");
+        return;
+    }
+
+    if ( strncmp(argv[1], CONTROL_TM_STR, strlen(CONTROL_TM_STR)) != 0 ) {
+        printf("\rFilename must be prefixed with control_tm_*\n");
+        return;
+    }
+
+    char data_buf[1024];
+    snprintf(data_buf, sizeof(data_buf),
+             "{ "
+             "\"id\":           \"%s\", "
+             "\"priority\":     \"800\","
+             "\"dow\":          \"%s\", "
+             "\"startw\":       \"%s\", "
+             "\"output\":       \"%s\", "
+             "\"startHour\":    \"%s\", "
+             "\"startMinute\":  \"%s\", "
+             "\"duration\":     \"%s\", }",
+             argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]
+            );
+
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 1024);
+    if( status != true ) {
+        logInfo("(%d)save file failed, status=%d", __LINE__, status);
+        return;
+    }
+    
+    // send a message to the configuration handler to create the control
+    Message_t *msg  = MailBox.alloc();
+    memset(msg, 0, sizeof(Message_t));
+    msg->action  = ACTION_CREATE;
+    msg->control = CONTROL_TIMER;
+    strncpy(msg->controlFile, argv[1], 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);
+    printf("\r\n");
+    return;
+
+}
+
+/*****************************************************************************
  * Function:        cmd_createManual
  * Description:     create a manual control
  *