Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
9:ef0ca2f8a8a6
Parent:
8:abe51ae5ef8b
Child:
15:a6ee32969e8e
--- a/src/ModbusMaster/ModbusMaster.cpp	Tue Sep 06 21:40:04 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp	Tue Sep 06 22:09:39 2016 +0000
@@ -18,24 +18,13 @@
  * @return               none
  *****************************************************************************/
 
-struct Register {
-    std::string name;
-    std::string units;
-    double min;
-    double max;
-    int reg;
-    int rtype;
-    int type;
-    std::string fmt;
-};
-std::map<std::string,Register> IoConfigmap;
-
 void ModbusMaster(void const *args)
 {
     printf("\r%s has started...\n", __func__);
     char scratch_buf[1024];
     MbedJSONValue json_value;
 
+    // configure modbus registers based in all files that start with "input"
     std::vector<mDot::mdot_file> file_list = GLOBAL_mdot->listUserFiles();
     for (std::vector<mDot::mdot_file>::iterator i = file_list.begin(); i != file_list.end(); ++i) {
         if( strncmp( i->name, "input", strlen("input")) == 0 ) {
@@ -52,38 +41,25 @@
             parse( json_value, scratch_buf );
 
             std::string id = json_value["id"].get<std::string>().c_str();
-            IoConfigmap[id].name = json_value["name"].get<std::string>().c_str();
-            IoConfigmap[id].units = json_value["units"].get<std::string>().c_str();
-            IoConfigmap[id].min = json_value["min"].get<double>();
-            IoConfigmap[id].max = json_value["max"].get<double>();
-            IoConfigmap[id].reg = json_value["reg"].get<int>();
-            IoConfigmap[id].rtype = json_value["rtype"].get<int>();
-            IoConfigmap[id].type = json_value["type"].get<int>();
-            IoConfigmap[id].fmt = json_value["fmt"].get<std::string>().c_str();
+            ModbusRegisterMap[id].name = json_value["name"].get<std::string>().c_str();
+            ModbusRegisterMap[id].units = json_value["units"].get<std::string>().c_str();
+            ModbusRegisterMap[id].min = json_value["min"].get<double>();
+            ModbusRegisterMap[id].max = json_value["max"].get<double>();
+            ModbusRegisterMap[id].node = json_value["node"].get<int>();
+            ModbusRegisterMap[id].reg = json_value["reg"].get<int>();
+            ModbusRegisterMap[id].rtype = json_value["rtype"].get<int>();
+            ModbusRegisterMap[id].type = json_value["type"].get<int>();
+            ModbusRegisterMap[id].fmt = json_value["fmt"].get<std::string>().c_str();
 
         }
-        logInfo("file: %s", i->name);
     }
 
+    // read modbus registers that have been configured.
     while ( true ) {
-        // Send request to Fluorometer
-        printf("\rsending request to FLU\n");
-        modbus_read_L1V(1,9,13);
-        // Wait 30mS
-        printf("\rsent request to FLU\n");
-        osDelay(30);
-        printf("\rgetting TRASAR readings\n");
-        // Read data from Fluorometer
-        MB_FLU_VALUES flu_values;
-        if( mbFluGetData( &flu_values ) == false ) {
-            printf("\rCould not get TRASAR readings, power cycle\n");
-            DigitalOut flu_power(PA_11);
-            flu_power = 1; // turn modbus power off
-            osDelay(1000);
-            flu_power = 0; // provide power to the modbus
-            flu_values.trasar = 0.0;
-            osDelay(5000);
-            return;
+
+        std::map<std::string, ModbusRegister>::iterator iter;
+        for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
+//            SendModbusCommand(iter->first.node,(uint16_t)iter->first.reg,13);
         }
     }
 }
@@ -148,7 +124,7 @@
 }
 
 // Read modbus master frame
-void modbus_read_L1V(uint8_t slave_address, uint16_t firstReg, uint16_t noRegs)
+void SendModbusCommand(uint8_t slave_address, uint16_t firstReg, uint16_t noRegs)
 {
     uint8_t L1V[8] = {slave_address, 0x04, 0x00, 0x02, 0x00, 0x02, 0xD1, 0x16};