m3Dpi robot, based on the Pololu 3pi and m3pi. m3Dpi has multiple distance sensors, gyroscope, compass and accelerometer sensor to be fully aware of its environment. With the addition of xbee or nrf24n01 module it has wireless communication capabilities.

Dependencies:   m3Dpi mbed-rtos mbed MbedJSONValue

Revision:
7:9068fc754a0b
Child:
8:5c0833506d67
Child:
11:ccb8653e285f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/jsonReporter.cpp	Thu Dec 03 17:53:04 2015 +0000
@@ -0,0 +1,85 @@
+#include "jsonReporter.h"
+
+JsonReporter::JsonReporter(mbed::Stream* _out, const char _id[]) : out(_out), id(_id)
+{
+    
+}
+
+MbedJSONValue* JsonReporter::jsonFactory()
+{
+    MbedJSONValue* json = new MbedJSONValue();
+    (*json)["id"] = id;
+    return json;
+}
+
+void JsonReporter::print(MbedJSONValue* json)
+{
+    out->printf("%s\n", json->serialize().c_str());
+}
+
+void JsonReporter::time(time_t seconds)
+{
+    char buffer[32];
+    std::strftime(buffer, 32, "%d-%m-%Y %T", localtime(&seconds));
+    MbedJSONValue* jsonTime = jsonFactory();
+    (*jsonTime)["time"] = buffer;
+    print(jsonTime);
+    delete jsonTime;   
+}
+
+void JsonReporter::distance(m3dpi::Distance distance)
+{
+    MbedJSONValue* json = jsonFactory();
+    const char property[] = "distance";
+
+    (*json)[property][0] = distance.front;
+    (*json)[property][1] = distance.front_right;
+    (*json)[property][2] = distance.right;
+    (*json)[property][3] = distance.back_right;
+    (*json)[property][4] = distance.back;
+    (*json)[property][5] = distance.back_left;
+    (*json)[property][6] = distance.left;
+    (*json)[property][7] = distance.front_left;
+
+    print(json);
+    delete json;
+}
+
+void JsonReporter::acceleration(m3dpi::Acceleration acc)
+{
+    MbedJSONValue* json = jsonFactory();
+    const char property[] = "acceleration";
+    
+    (*json)[property]["x"] = acc.x;
+    (*json)[property]["y"] = acc.y;
+    (*json)[property]["z"] = acc.z;
+    
+    print(json);
+    delete json;
+}
+
+void JsonReporter::direction(m3dpi::Direction direction)
+{
+    MbedJSONValue* json = jsonFactory();
+    const char property[] = "direction";
+    
+    (*json)[property]["x"] = direction.x;
+    (*json)[property]["y"] = direction.y;
+    (*json)[property]["z"] = direction.z;
+    
+    print(json);
+    delete json;
+}
+
+void JsonReporter::rotation(m3dpi::Rotation rotation)
+{
+    MbedJSONValue* json = jsonFactory();
+    const char property[] = "rotation";
+    
+    (*json)[property]["x"] = rotation.x;
+    (*json)[property]["y"] = rotation.y;
+    (*json)[property]["z"] = rotation.z;
+    
+    print(json);
+    delete json;
+}