Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
8:abe51ae5ef8b
Parent:
7:c0c03193612d
Child:
9:ef0ca2f8a8a6
--- a/src/ModbusMaster/ModbusMaster.cpp	Tue Sep 06 20:08:13 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp	Tue Sep 06 21:40:04 2016 +0000
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include "BLEDataHandler.h"
 #include "ModbusMaster.h"
+#include "MbedJSONValue.h"
 
 /*****************************************************************************
  * Function:             ModbusMaster
@@ -17,18 +18,51 @@
  * @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;
 
-    char scratch_buf[1024];
-    bool status = GLOBAL_mdot->readUserFile("scratch.json", (void *)scratch_buf, 1024);
-    if( status != true ) {
-        printf("\r(%d)read file failed, status=%d\n", __LINE__, status);
-    }
-    else
-    {
-        printf("\r(%d)Read File SUCCESS: %s\n", __LINE__, scratch_buf );
+    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 ) {
+
+            printf("\r(%d)FOUND INPUT FILE: %s\n", __LINE__, i->name);
+
+            bool status = GLOBAL_mdot->readUserFile(i->name, (void *)scratch_buf, 1024);
+            if( status != true ) {
+                printf("\r(%d)read file failed, status=%d\n", __LINE__, status);
+            } else {
+                printf("\r(%d)Read File SUCCESS: %s\n", __LINE__, scratch_buf );
+            }
+
+            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();
+
+        }
+        logInfo("file: %s", i->name);
     }
 
     while ( true ) {