Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
215:309c73f0fff6
Parent:
213:b30d94ecfa84
Parent:
214:52ef35bc44ec
Child:
216:7783e894f7e0
--- a/src/CommandParser/cmd.cpp	Mon Oct 10 16:07:40 2016 +0000
+++ b/src/CommandParser/cmd.cpp	Tue Oct 11 15:33:40 2016 +0000
@@ -81,6 +81,7 @@
     {"modmap",              "dump modbus register map",                         cmd_modmap          },
     {"mod-cmd",             "send command to modbus master",                    cmd_modbusCmd       },
     {"peep",                "push EEP",                                         cmd_peep            },
+    {"regcmd",              "create command to execute on register",            cmd_regcmd          },
     {"reset",               "reset the controller",                             cmd_reset           },
     {"reset-stats",         "reset current mDot statistics",                    cmd_resetStats      },
     {"rm",                  "remove a user file",                               cmd_rm              },
@@ -96,6 +97,7 @@
     {"stats",               "get current mDot statistics",                      cmd_stats           },
     {"time",                "get current time",                                 cmd_time            },
     {"simall",              "simulate multiple inputs",                         cmd_simall          },
+    {"trim-temp",           "adjust temperature from ICE Tube",                 cmd_trimTemp        },
     {NULL, NULL, NULL}
 };
 
@@ -1235,7 +1237,7 @@
         SimulateInputMap["i_bdcond01"].moving_up = true;
 
         ModbusRegisterMap["i_cond_temp01"].simulated = true;
-        SimulateInputMap["i_cond_temp01"].start_value = 25.0;
+        SimulateInputMap["i_cond_temp01"].start_value = 25000.0;
         SimulateInputMap["i_cond_temp01"].min = 0;
         SimulateInputMap["i_cond_temp01"].max = 0;
         SimulateInputMap["i_cond_temp01"].up_step = 0;
@@ -1251,7 +1253,7 @@
         SimulateInputMap["i_ph01"].moving_up = true;
 
         ModbusRegisterMap["i_ph_temp01"].simulated = true;
-        SimulateInputMap["i_ph_temp01"].start_value = 25.0;
+        SimulateInputMap["i_ph_temp01"].start_value = 25000.0;
         SimulateInputMap["i_ph_temp01"].min = 0;
         SimulateInputMap["i_ph_temp01"].max = 0;
         SimulateInputMap["i_ph_temp01"].up_step = 0;
@@ -1633,6 +1635,30 @@
 
     Thread::wait(5000);
 
+    snprintf(buf, sizeof(buf),
+             "{ "
+             "\"id\":\"%s\", "
+             "\"tag\":\"%s\", "
+             "\"opl\":\"%s\", "
+             "\"opr\":\"%s\", "
+             "\"op\":\"%s\", "
+             "\"c\":\"%s\" } ", "TEMP_CONV_PH01", "i_ph_temp01", "i_ph_temp01", "", "/", "1000.0");
+             
+    printf("JSON=%s\r\n",buf);
+             
+    rc = GLOBAL_mdot->saveUserFile("vcmd_TEMP_CONV_PH01.json", (void *)buf, MAX_FILE_SIZE);
+    if( rc != true ) {
+        printf("(%d)save file failed, status=%d\r\n", __LINE__, rc);
+    }
+
+    logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", "vcmd_TEMP_CONV_PH01.json");
+    mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, "vcmd_TEMP_CONV_PH01.json", (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+    
+    Thread::wait(5000);
+
     // OUTPUT: Relay 01
     snprintf(buf, sizeof(buf),
              "{ "
@@ -1721,7 +1747,7 @@
 
     Thread::wait(2000);
 
-#ifdef MORE_CONTROLS
+/*
     // OUTPUT: Relay 03
     snprintf(buf, sizeof(buf),
              "{ "
@@ -1810,7 +1836,7 @@
 
     Thread::wait(2000);
 
-#endif
+*/
     // SETPOINT: Blowdown
     snprintf(buf, sizeof(buf),
              "{ "
@@ -1877,7 +1903,7 @@
     MailBox.put(sp_msg);
     Thread::wait(2000);
 
-#ifdef MORE_CONTROLS
+/*
     // SETPOINT: Acid Base
     snprintf(buf, sizeof(buf),
              "{ "
@@ -1943,7 +1969,7 @@
 
     MailBox.put(sp_msg);
     Thread::wait(2000);
-#endif
+*/
 }
 
 /*****************************************************************************
@@ -2031,4 +2057,135 @@
     mail->action = ACTION_EXEC_CMD;
     strncpy( mail->controlFile, snd_buf, (sizeof(mail->controlFile)-1));
     ModbusMasterMailBox.put(mail);
+}
+
+/*****************************************************************************
+ * Function:        cmd_regcmd
+ * Description:     create register command
+ *
+ * @param           argc-> number of args
+ * @param           argv-> filename
+ * @return          none
+ *****************************************************************************/
+void cmd_regcmd(int argc, char **argv)
+{
+    char filename[64];
+    
+    printf("argc=%d\r\n",argc);
+    
+    if ( argc != 7 ) {
+        printf("\rusage:   regcmd <if> <tag> <opl> <opr> <op> <c>\n");
+        printf("\rexample: regcmd TEMP_CONV_PH01 i_ph_temp01 i_ph_temp01 - / 1000\n");
+        return;
+    }
+    
+    memset( filename, 0, 64 );
+    snprintf( filename, 63, "%s%s%s", "vcmd_", argv[1], ".json" );
+    printf("filename=%s\r\n",filename);
+    
+    std::string opl(argv[4]);
+    
+    printf("argv[4]=%s, opl=%s\r\n",argv[4], opl.c_str());
+    if( opl.c_str()[0] == '-' )
+    {
+        printf("argv[4]=%s, SETTING TO NULL\r\n",argv[4]);
+        opl = "";
+    }
+
+    char data_buf[MAX_FILE_SIZE];
+    snprintf(data_buf, sizeof(data_buf),
+             "{ "
+             "\"id\":\"%s\", "
+             "\"tag\":\"%s\", "
+             "\"opl\":\"%s\", "
+             "\"opr\":\"%s\", "
+             "\"op\":\"%s\", "
+             "\"c\":\"%s\" } ", argv[1], argv[2], argv[3], opl.c_str(), argv[5], argv[6]);
+             
+    printf("JSON=%s\r\n",data_buf);
+             
+    bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, MAX_FILE_SIZE);
+    if( status != true ) {
+        logInfo("(%d)save file failed, status=%d", __LINE__, status);
+    }
+
+    logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", filename);
+    Message_t *mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, filename, (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+}
+
+
+/*****************************************************************************
+ * Function:        cmd_trimTemp
+ * Description:     create register command
+ *
+ * @param           argc-> number of args
+ * @param           argv-> filename
+ * @return          none
+ *****************************************************************************/
+void cmd_trimTemp(int argc, char **argv)
+{
+/*
+
+    char filename[64];
+    
+    memset( filename, 0, 64 );
+    snprintf( filename, 63, "%s%s%s", "vcmd_", "2_DIV_TEMP_PH01", ".json" );
+    printf("filename=%s\r\n",filename);
+
+    char data_buf[MAX_FILE_SIZE];
+    snprintf(data_buf, sizeof(data_buf),
+             "{ "
+             "\"id\":\"%s\", "
+             "\"tag\":\"%s\", "
+             "\"opl\":\"%s\", "
+             "\"opr\":\"%s\", "
+             "\"op\":\"%s\", "
+             "\"c\":\"%s\" } ", "2_DIV_TEMP_PH01", "i_ph_temp01", "i_ph_temp01", "", "/", "1000.0");
+             
+    printf("JSON=%s\r\n",data_buf);
+             
+    bool status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, MAX_FILE_SIZE);
+    if( status != true ) {
+        logInfo("(%d)save file failed, status=%d", __LINE__, status);
+    }
+
+    logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", filename);
+    Message_t *mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, filename, (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+    
+    Thread::wait(5000);
+    
+    memset( filename, 0, 64 );
+    snprintf( filename, 63, "%s%s%s", "vcmd_", "1_CONST_TEMP_PH01", ".json" );
+    printf("filename=%s\r\n",filename);
+
+    snprintf(data_buf, sizeof(data_buf),
+             "{ "
+             "\"id\":\"%s\", "
+             "\"tag\":\"%s\", "
+             "\"opl\":\"%s\", "
+             "\"opr\":\"%s\", "
+             "\"op\":\"%s\", "
+             "\"c\":\"%s\" } ", "1_CONST_TEMP_PH01", "i_ph_temp01", "i_ph_temp01", "", "=", "26000.0");
+             
+    printf("JSON=%s\r\n",data_buf);
+             
+    status = GLOBAL_mdot->saveUserFile(filename, (void *)data_buf, MAX_FILE_SIZE);
+    if( status != true ) {
+        logInfo("(%d)save file failed, status=%d", __LINE__, status);
+    }
+
+    logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", filename);
+    mail = ModbusMasterMailBox.alloc();
+    mail->action = ACTION_READ_FILE;
+    strncpy( mail->controlFile, filename, (sizeof(mail->controlFile)-1));
+    ModbusMasterMailBox.put(mail);
+    
+    Thread::wait(5000);
+*/
 }
\ No newline at end of file