Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
177:9ec90c8e3ce1
Parent:
172:51dfb4aabc57
Child:
180:b548e289b648
--- a/src/CommandParser/cmd.cpp	Tue Oct 04 12:35:18 2016 +0000
+++ b/src/CommandParser/cmd.cpp	Tue Oct 04 15:46:51 2016 +0000
@@ -67,6 +67,7 @@
     {"create-sp",           "create a setpoint control",                        cmd_createSetpoint  },
     {"create-tm",           "create a timer control",                           cmd_createTimer     },
     {"deep",                "dump EEP",                                         cmd_deep            },
+    {"demo",                "create phase-1 demo files",                        cmd_demo            },
     {"destroy-control",     "destroy a control",                                cmd_destroy         },
     {"heap",                "show heap statistics",                             cmd_heap            },
     {"help",                "help command",                                     cmd_help            },
@@ -415,7 +416,7 @@
         return;
     }
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
     snprintf(data_buf, sizeof(data_buf),
              "{ "
              "\"id\":           \"%s\", "
@@ -431,7 +432,7 @@
              "\"lfs\":          \"70\", "
              "\"tol\":          \"%s\"  }", argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
         return;
@@ -478,7 +479,7 @@
     char time_buf[32];
     sprintf(time_buf, "%lu", time(NULL)+5);
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
     snprintf(data_buf, sizeof(data_buf),
              "{ "
              "\"id\":           \"%s\", "
@@ -489,7 +490,7 @@
             );
 
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
         return;
@@ -521,7 +522,7 @@
     for ( counter = 0; counter < 5; counter++ ) {
         // stuff the file
         sprintf(time_buf, "%lu", time(NULL)+5 + (40 * counter));
-        char data_buf[512];
+        char data_buf[MAX_FILE_SIZE];
         snprintf(data_buf, sizeof(data_buf),
                  "{ "
                  "\"id\":           \"timer-%d\", "
@@ -532,7 +533,7 @@
 
         sprintf(filename, "control_tm_%d_rly1.json", counter);
 
-        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, 512);
+        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, MAX_FILE_SIZE);
         msg = MailBox.alloc();
         memset(msg, 0, sizeof(Message_t));
         msg->action  = ACTION_CREATE;
@@ -549,7 +550,7 @@
     for ( counter = 0; counter < 5; counter++ ) {
         // stuff the file
         sprintf(time_buf, "%lu", time(NULL)+5 + (40 * counter));
-        char data_buf[512];
+        char data_buf[MAX_FILE_SIZE];
         snprintf(data_buf, sizeof(data_buf),
                  "{ "
                  "\"id\":           \"timer-%d\", "
@@ -560,7 +561,7 @@
 
         sprintf(filename, "control_tm_%d_rly2.json", counter);
 
-        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, 512);
+        bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, MAX_FILE_SIZE);
         msg = MailBox.alloc();
         memset(msg, 0, sizeof(Message_t));
         msg->action  = ACTION_CREATE;
@@ -591,7 +592,7 @@
         return;
     }
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
     snprintf(data_buf, sizeof(data_buf),
              "{ "
              "\"id\":           \"%s\",  "
@@ -604,7 +605,7 @@
              "\"percent\":      \"100\"  }", argv[2], argv[3], atoi(argv[4])
             );
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
         return;
@@ -641,7 +642,7 @@
         return;
     }
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
     snprintf(data_buf, sizeof(data_buf),
              "{ "
              "\"id\":       \"%s\", "
@@ -658,7 +659,7 @@
              "\"rfreq\":    \"5\", "
              "\"fmt\":      \"%%.2f\" } ", argv[2], argv[3], argv[4], argv[5]);
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
     }
@@ -686,7 +687,7 @@
         return;
     }
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
     snprintf(data_buf, sizeof(data_buf),
              "{ "
              "\"id\":           \"%s\", "
@@ -698,7 +699,7 @@
              "\"percent\":      \"100\", }", argv[2]
             );
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
     }
@@ -721,7 +722,7 @@
         return;
     }
 
-    char data_buf[512];
+    char data_buf[MAX_FILE_SIZE];
 
     snprintf(data_buf, sizeof(data_buf),
              "{ "
@@ -742,12 +743,12 @@
              "\"scalelo\":  \"0\", "
              "\"scalehi\":  \"100\" }", argv[2], argv[3], argv[4]);
 
-    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, 512);
+    bool status = GLOBAL_mdot->saveUserFile(argv[1], (void *)data_buf, MAX_FILE_SIZE);
     if( status != true ) {
         logInfo("(%d)save file failed, status=%d", __LINE__, status);
     }
 
-    // send a message to the modbust master
+    // send a message to the modbus master
     logInfo("Sending mail to ModbusMasterMailBox, filename=%s", argv[1]);
     Message_t *modbus_mail = ModbusMasterMailBox.alloc();
     modbus_mail->action = ACTION_READ_FILE;
@@ -1127,4 +1128,241 @@
     for (iter = SimulateInputMap.begin(); iter != SimulateInputMap.end(); ++iter) {
         printf("simulated input=%s, min=%2.2f, max=%2.2f, start_value=%2.2f, up_step=%2.2f, down_step=%2.2f\r\n",iter->first.c_str(), SimulateInputMap[iter->first].min, SimulateInputMap[iter->first].max, SimulateInputMap[iter->first].start_value, SimulateInputMap[iter->first].up_step, SimulateInputMap[iter->first].down_step);
     }
+}
+
+void cmd_demo(int argc, char **argv)
+{
+    UNUSED(argc);
+    UNUSED(argv);
+
+    // inputs:
+    //      input_i_tra01.json
+    //      input_i_bdcond01.json
+    // outputs:
+    //      output_o_rly01.json
+    //      output_o_rly02.json
+    // controls
+    //      control_sp_INH_TRA_01.json
+    //      control_sp_BLOWDOWN_01.json
+
+
+    // INPUT: Trasar
+    char buf[MAX_FILE_SIZE];
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\":        \"i_tra01\","
+             "\"name\":      \"Trasar\", "
+             "\"units\":     \"PPM\",    "
+             "\"min\":       \"0\",      "
+             "\"max\":       \"300\",    "
+             "\"node\":      \"1\",      "
+             "\"reg\":       \"9\",      "
+             "\"rtype\":     \"1\",      "
+             "\"type\":      \"0\",      "
+             "\"size\":      \"2\",      "
+             "\"order\":     \"2\",      "
+             "\"fmt\":       \"%%.2f\",   "
+             "\"vcmd\":      \"\",       "
+             "\"rfreq\":     \"5\" }");
+    bool rc = GLOBAL_mdot->saveUserFile("input_i_tra01.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save input_i_tra01.json\n");
+        return;
+    } else {
+        printf("\r...generated input_i_tra01.json\n");
+    }
+
+    Message_t *mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, "input_i_tra01.json", (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+
+    Thread::wait(1000);
+
+
+    // INPUT: Conductivity
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\":        \"i_bdcond01\","
+             "\"name\":      \"Tower Conductivity\", "
+             "\"units\":     \"uS\",    "
+             "\"min\":       \"0\",      "
+             "\"max\":       \"6000\",    "
+             "\"node\":      \"5\",      "
+             "\"reg\":       \"9\",      "
+             "\"rtype\":     \"1\",      "
+             "\"type\":      \"0\",      "
+             "\"size\":      \"2\",      "
+             "\"order\":     \"2\",      "
+             "\"fmt\":       \"%%.2f\",   "
+             "\"vcmd\":      \"\",       "
+             "\"rfreq\":     \"5\" }");
+    rc = GLOBAL_mdot->saveUserFile("input_i_bdcond01.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save input_i_bdcond01.json\n");
+        return;
+    } else {
+        printf("\r...generated input_i_bdcond01.json\n");
+    }
+
+    mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, "input_i_tra02.json", (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+
+    Thread::wait(1000);
+
+    // OUTPUT: Relay 01
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\": \"o_rly01\", "
+             "\"name\": \"Blowdown\", "
+             "\"units\": \"\", "
+             "\"min\":  \"0\", "
+             "\"max\": \"300\", "
+             "\"node\": \"0\", "
+             "\"reg\": \"1\", "
+             "\"rtype\": \"1\", "
+             "\"type\": \"0\", "
+             "\"size\": \"2\", "
+             "\"order\": \"2\", "
+             "\"fmt\": \"%%.2f\", "
+             "\"vcmd\": \"\", "
+             "\"rfreq\": \"5\", "
+             "\"toperiod\": \"0\", "
+             "\"scalelo\": \"0\", "
+             "\"scalehi\": \"100\" }");
+    rc = GLOBAL_mdot->saveUserFile("output_o_rly01.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save output_o_rly01.json\n");
+        return;
+    } else {
+        printf("\r...generated output_o_rly01.json\n");
+    }
+
+    // send a message to the modbus master
+    Message_t *modbus_mail = ModbusMasterMailBox.alloc();
+    modbus_mail->action = ACTION_READ_FILE;
+    strncpy( modbus_mail->controlFile, "output_o_rly01.json", (sizeof(modbus_mail->controlFile)-1));
+    ModbusMasterMailBox.put(modbus_mail);
+
+    Thread::wait(1000);
+
+    // send a message to the output master
+    OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc();
+    output_mail->action = ACTION_NEW;
+    strncpy(output_mail->controlFile, "output_o_rly01.json", sizeof(output_mail->controlFile)-1);
+    OutputMasterMailBox.put(output_mail);
+
+    Thread::wait(1000);
+
+    // OUTPUT: Relay 02
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\": \"o_rly02\", "
+             "\"name\": \"3DTS86\", "
+             "\"units\": \"\", "
+             "\"min\":  \"0\", "
+             "\"max\": \"300\", "
+             "\"node\": \"0\", "
+             "\"reg\": \"2\", "
+             "\"rtype\": \"1\", "
+             "\"type\": \"0\", "
+             "\"size\": \"2\", "
+             "\"order\": \"2\", "
+             "\"fmt\": \"%%.2f\", "
+             "\"vcmd\": \"\", "
+             "\"rfreq\": \"5\", "
+             "\"toperiod\": \"0\", "
+             "\"scalelo\": \"0\", "
+             "\"scalehi\": \"100\" }");
+    rc = GLOBAL_mdot->saveUserFile("output_o_rly02.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save output_o_rly02.json\n");
+        return;
+    } else {
+        printf("\r...generated output_o_rly02.json\n");
+    }
+
+    // send a message to the modbus master
+    modbus_mail = ModbusMasterMailBox.alloc();
+    modbus_mail->action = ACTION_READ_FILE;
+    strncpy( modbus_mail->controlFile, "output_o_rly02.json", (sizeof(modbus_mail->controlFile)-1));
+    ModbusMasterMailBox.put(modbus_mail);
+
+    Thread::wait(1000);
+
+    // send a message to the output master
+    output_mail = OutputMasterMailBox.alloc();
+    output_mail->action = ACTION_NEW;
+    strncpy(output_mail->controlFile, "output_o_rly02.json", sizeof(output_mail->controlFile)-1);
+    OutputMasterMailBox.put(output_mail);
+
+    Thread::wait(1000);
+
+    // SETPOINT: Blowdown
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\": \"BLOWDOWN_01\", "
+             "\"priority\": \"800\", "
+             "\"input\": \"i_bdcond01\", "
+             "\"output\": \"o_rly01\", "
+             "\"setpoint\": \"2000\", "
+             "\"prodfact\": \"\", "
+             "\"actingDir\": \"1\", "
+             "\"halert\": \"2100\", "
+             "\"lalert\": \"1900\", "
+             "\"hfs\": \"2200\", "
+             "\"lfs\": \"1800\", "
+             "\"tol\": \"5\" }");
+    rc = GLOBAL_mdot->saveUserFile("control_sp_bd01.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save control_sp_bd01.json\n");
+        return;
+    } else {
+        printf("\r...generated control_sp_bd01.json\n");
+    }
+
+    Message_t *sp_msg  = MailBox.alloc();
+    memset(sp_msg, 0, sizeof(Message_t));
+    sp_msg->action  = ACTION_CREATE;
+    sp_msg->control = CONTROL_SETPOINT;
+    strncpy(sp_msg->controlFile, "control_sp_bd01.json", sizeof(sp_msg->controlFile)-1);
+
+    MailBox.put(sp_msg);
+
+    Thread::wait(1000);
+
+    // SETPOINT: Trasar
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\": \"INH_TRA_01\", "
+             "\"priority\": \"800\", "
+             "\"input\": \"i_tra01\", "
+             "\"output\": \"o_rly02\", "
+             "\"setpoint\": \"100\", "
+             "\"prodfact\": \"100\", "
+             "\"actingDir\": \"0\", "
+             "\"halert\": \"115\", "
+             "\"lalert\": \"85\", "
+             "\"hfs\": \"130\", "
+             "\"lfs\": \"70\", "
+             "\"tol\": \"5\" }");
+    rc = GLOBAL_mdot->saveUserFile("control_sp_tra01.json", (void *)buf, MAX_FILE_SIZE);
+    if ( rc != true ) {
+        printf("\rFailed to save control_sp_tra01.json\n");
+        return;
+    } else {
+        printf("\r...generated control_sp_tra01.json\n");
+        Thread::wait(500);
+    }
+
+    sp_msg  = MailBox.alloc();
+    memset(sp_msg, 0, sizeof(Message_t));
+    sp_msg->action  = ACTION_CREATE;
+    sp_msg->control = CONTROL_SETPOINT;
+    strncpy(sp_msg->controlFile, "control_sp_tra01.json", sizeof(sp_msg->controlFile)-1);
+
+    MailBox.put(sp_msg);
+    Thread::wait(1000);
 }
\ No newline at end of file