Sille Van Landschoot / Mbed 2 deprecated m3Dpi-helloworld

Dependencies:   m3Dpi mbed-rtos mbed MbedJSONValue

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jsonReporter.cpp Source File

jsonReporter.cpp

00001 #include "jsonReporter.h"
00002 
00003 MbedJSONValue* JsonReporter::jsonFactory()
00004 {
00005     MbedJSONValue* json = new MbedJSONValue();
00006     (*json)["id"] = id;
00007     return json;
00008 }
00009 
00010 void JsonReporter::print(MbedJSONValue* json)
00011 {
00012     out->printf("%s\n", json->serialize().c_str());
00013 }
00014 
00015 void JsonReporter::time(time_t seconds)
00016 {
00017     char buffer[32];
00018     std::strftime(buffer, 32, "%d-%m-%Y %T", localtime(&seconds));
00019     MbedJSONValue* jsonTime = jsonFactory();
00020     (*jsonTime)["time"] = buffer;
00021     print(jsonTime);
00022     delete jsonTime;   
00023 }
00024 
00025 void JsonReporter::distance(m3dpi::Distance distance)
00026 {
00027     MbedJSONValue* json = jsonFactory();
00028     const char property[] = "distance";
00029 
00030     (*json)[property][0] = distance.front;
00031     (*json)[property][1] = distance.front_right;
00032     (*json)[property][2] = distance.right;
00033     (*json)[property][3] = distance.back_right;
00034     (*json)[property][4] = distance.back;
00035     (*json)[property][5] = distance.back_left;
00036     (*json)[property][6] = distance.left;
00037     (*json)[property][7] = distance.front_left;
00038 
00039     print(json);
00040     delete json;
00041 }
00042 
00043 void JsonReporter::acceleration(m3dpi::Acceleration acc)
00044 {
00045     MbedJSONValue* json = jsonFactory();
00046     const char property[] = "acceleration";
00047     
00048     (*json)[property]["x"] = acc.x;
00049     (*json)[property]["y"] = acc.y;
00050     (*json)[property]["z"] = acc.z;
00051     
00052     print(json);
00053     delete json;
00054 }
00055 
00056 void JsonReporter::direction(m3dpi::Direction direction)
00057 {
00058     MbedJSONValue* json = jsonFactory();
00059     const char property[] = "direction";
00060     
00061     (*json)[property]["x"] = direction.x;
00062     (*json)[property]["y"] = direction.y;
00063     (*json)[property]["z"] = direction.z;
00064     
00065     print(json);
00066     delete json;
00067 }
00068 
00069 void JsonReporter::rotation(m3dpi::Rotation rotation)
00070 {
00071     MbedJSONValue* json = jsonFactory();
00072     const char property[] = "rotation";
00073     
00074     (*json)[property]["x"] = rotation.x;
00075     (*json)[property]["y"] = rotation.y;
00076     (*json)[property]["z"] = rotation.z;
00077     
00078     print(json);
00079     delete json;
00080 }