Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
122:4db48b933115
Parent:
46:4cb96ab2d1c8
Child:
126:c85ac6a8e9af
--- a/src/ConfigurationHandler/Controls/TimerControl.cpp	Fri Sep 23 12:45:49 2016 +0000
+++ b/src/ConfigurationHandler/Controls/TimerControl.cpp	Fri Sep 23 15:13:04 2016 +0000
@@ -11,15 +11,23 @@
 
 extern mDot *GLOBAL_mdot;
 
+
+//
+// method:      load
+// description: load the pertinents from the control file
+// 
+// @param       _controlFile
+// @return      true if loaded; false otherwise
+//
 bool TimerControl::load(string _controlFile)
-{   
-    MbedJSONValue json_value;           // json parsing element 
-    controlFile = _controlFile;    
- 
+{
+    MbedJSONValue json_value;           // json parsing element
+
     // try to open the control file
-    mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY);
-    if ( file.fd < 0 ) 
+    mDot::mdot_file file = GLOBAL_mdot->openUserFile(_controlFile.c_str(), mDot::FM_RDONLY);
+    if ( file.fd < 0 ) {
         return false;
+    }
 
     // read the data into a buffer
     char dataBuf[1024];
@@ -29,38 +37,52 @@
         logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str());
         return false;
     }
-    
-    // close the file 
+
+    // close the file
     GLOBAL_mdot->closeUserFile(file);
 
     parse(json_value, dataBuf);
 
-    // {
-    //  "tcontrol": {
-    //      "id": "Timer1",
-    //      "name": "Acid Cleaning Cycle",
-    //      "priority":"800",
-    //      "dow":"127",
-    //      "strtw":"1",
-    //      "output":"o_r4",
-    //      "freq":"1",
-    //      "tod": {
-    //          "start":"420",
-    //          "int":"1"
-    //  }
-    // } 
+    controlFile = _controlFile;
+    id          = json_value["id"].get<string>();
+    priority    = atoi(json_value["priority"].get<string>().c_str());
+    dow         = atoi(json_value["dow"].get<string>().c_str());
+    startw      = atoi(json_value["startw"].get<string>().c_str());
+    output      = json_value["output"].get<string>();
+    startHour   = atoi(json_value["startHour"].get<string>().c_str());
+    startMinute = atoi(json_value["startMinute"].get<string>().c_str());
+    duration    = atoi(json_value["duration"].get<string>().c_str());
+
+    return true;
+}
+
+//
+// methid:      display
+// description: display the elements of this timer control object
+//
+// @param       none
+// @return 
+void TimerControl::display(void)
+{
+    char daysOfWeek[24];
     
-    // parse the json data 
-    id           = json_value["id"].get<string>();
-    name         = json_value["name"].get<string>();
-    priority     = atoi(json_value["priority"].get<string>().c_str());
-    dayOfWeek    = atoi(json_value["dow"].get<string>().c_str());
-    startWeek    = atoi(json_value["strtw"].get<string>().c_str());
-    output       = json_value["output"].get<string>().c_str();
-    freq         = atoi(json_value["freq"].get<string>().c_str());
-    
-    // TODO extract
-    tod.start = 0; tod.interval = 0;
-    
-    return true;
+    sprintf(daysOfWeek, "%s %s %s %s %s %s %s %s",
+        (dow & DAY_SUNDAY_MASK)    ? "Su" : "  ",
+        (dow & DAY_MONDAY_MASK)    ? "M"  : " ",
+        (dow & DAY_TUESDAY_MASK)   ? "Tu" : "  ",
+        (dow & DAY_WEDNESDAY_MASK) ? "W"  : " ",
+        (dow & DAY_THURSDAY_MASK)  ? "Th" : "  ",
+        (dow & DAY_FRIDAY_MASK)    ? "F"  : " ",
+        (dow & DAY_SATURDAY_MASK)  ? "Sa" : "  ");
+        
+    printf("\r      controlFile : %s   \n", controlFile.c_str());
+    printf("\r               id : %s   \n", id.c_str());
+    printf("\r         priority : %d   \n", priority);
+    printf("\r              dow : %s   \n", daysOfWeek);
+    printf("\r           startw : %u   \n", startw);
+    printf("\r           output : %s   \n", output.c_str());
+    printf("\r    starting hour : %u   \n", startHour);
+    printf("\r  starting minute : %u   \n", startMinute);
+    printf("\r         duration : %u   \n", duration);   
+    printf("\r\n");
 }
\ No newline at end of file