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
lib/jsonReporter.cpp@13:d6374484b953, 2015-12-19 (annotated)
- Committer:
- sillevl
- Date:
- Sat Dec 19 15:27:15 2015 +0000
- Revision:
- 13:d6374484b953
- Parent:
- 11:ccb8653e285f
add binary reporter;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sillevl | 7:9068fc754a0b | 1 | #include "jsonReporter.h" |
sillevl | 7:9068fc754a0b | 2 | |
sillevl | 7:9068fc754a0b | 3 | MbedJSONValue* JsonReporter::jsonFactory() |
sillevl | 7:9068fc754a0b | 4 | { |
sillevl | 7:9068fc754a0b | 5 | MbedJSONValue* json = new MbedJSONValue(); |
sillevl | 7:9068fc754a0b | 6 | (*json)["id"] = id; |
sillevl | 7:9068fc754a0b | 7 | return json; |
sillevl | 7:9068fc754a0b | 8 | } |
sillevl | 7:9068fc754a0b | 9 | |
sillevl | 7:9068fc754a0b | 10 | void JsonReporter::print(MbedJSONValue* json) |
sillevl | 7:9068fc754a0b | 11 | { |
sillevl | 7:9068fc754a0b | 12 | out->printf("%s\n", json->serialize().c_str()); |
sillevl | 7:9068fc754a0b | 13 | } |
sillevl | 7:9068fc754a0b | 14 | |
sillevl | 7:9068fc754a0b | 15 | void JsonReporter::time(time_t seconds) |
sillevl | 7:9068fc754a0b | 16 | { |
sillevl | 7:9068fc754a0b | 17 | char buffer[32]; |
sillevl | 7:9068fc754a0b | 18 | std::strftime(buffer, 32, "%d-%m-%Y %T", localtime(&seconds)); |
sillevl | 7:9068fc754a0b | 19 | MbedJSONValue* jsonTime = jsonFactory(); |
sillevl | 7:9068fc754a0b | 20 | (*jsonTime)["time"] = buffer; |
sillevl | 7:9068fc754a0b | 21 | print(jsonTime); |
sillevl | 7:9068fc754a0b | 22 | delete jsonTime; |
sillevl | 7:9068fc754a0b | 23 | } |
sillevl | 7:9068fc754a0b | 24 | |
sillevl | 7:9068fc754a0b | 25 | void JsonReporter::distance(m3dpi::Distance distance) |
sillevl | 7:9068fc754a0b | 26 | { |
sillevl | 7:9068fc754a0b | 27 | MbedJSONValue* json = jsonFactory(); |
sillevl | 7:9068fc754a0b | 28 | const char property[] = "distance"; |
sillevl | 7:9068fc754a0b | 29 | |
sillevl | 7:9068fc754a0b | 30 | (*json)[property][0] = distance.front; |
sillevl | 7:9068fc754a0b | 31 | (*json)[property][1] = distance.front_right; |
sillevl | 7:9068fc754a0b | 32 | (*json)[property][2] = distance.right; |
sillevl | 7:9068fc754a0b | 33 | (*json)[property][3] = distance.back_right; |
sillevl | 7:9068fc754a0b | 34 | (*json)[property][4] = distance.back; |
sillevl | 7:9068fc754a0b | 35 | (*json)[property][5] = distance.back_left; |
sillevl | 7:9068fc754a0b | 36 | (*json)[property][6] = distance.left; |
sillevl | 7:9068fc754a0b | 37 | (*json)[property][7] = distance.front_left; |
sillevl | 7:9068fc754a0b | 38 | |
sillevl | 7:9068fc754a0b | 39 | print(json); |
sillevl | 7:9068fc754a0b | 40 | delete json; |
sillevl | 7:9068fc754a0b | 41 | } |
sillevl | 7:9068fc754a0b | 42 | |
sillevl | 7:9068fc754a0b | 43 | void JsonReporter::acceleration(m3dpi::Acceleration acc) |
sillevl | 7:9068fc754a0b | 44 | { |
sillevl | 7:9068fc754a0b | 45 | MbedJSONValue* json = jsonFactory(); |
sillevl | 7:9068fc754a0b | 46 | const char property[] = "acceleration"; |
sillevl | 7:9068fc754a0b | 47 | |
sillevl | 7:9068fc754a0b | 48 | (*json)[property]["x"] = acc.x; |
sillevl | 7:9068fc754a0b | 49 | (*json)[property]["y"] = acc.y; |
sillevl | 7:9068fc754a0b | 50 | (*json)[property]["z"] = acc.z; |
sillevl | 7:9068fc754a0b | 51 | |
sillevl | 7:9068fc754a0b | 52 | print(json); |
sillevl | 7:9068fc754a0b | 53 | delete json; |
sillevl | 7:9068fc754a0b | 54 | } |
sillevl | 7:9068fc754a0b | 55 | |
sillevl | 7:9068fc754a0b | 56 | void JsonReporter::direction(m3dpi::Direction direction) |
sillevl | 7:9068fc754a0b | 57 | { |
sillevl | 7:9068fc754a0b | 58 | MbedJSONValue* json = jsonFactory(); |
sillevl | 7:9068fc754a0b | 59 | const char property[] = "direction"; |
sillevl | 7:9068fc754a0b | 60 | |
sillevl | 7:9068fc754a0b | 61 | (*json)[property]["x"] = direction.x; |
sillevl | 7:9068fc754a0b | 62 | (*json)[property]["y"] = direction.y; |
sillevl | 7:9068fc754a0b | 63 | (*json)[property]["z"] = direction.z; |
sillevl | 7:9068fc754a0b | 64 | |
sillevl | 7:9068fc754a0b | 65 | print(json); |
sillevl | 7:9068fc754a0b | 66 | delete json; |
sillevl | 7:9068fc754a0b | 67 | } |
sillevl | 7:9068fc754a0b | 68 | |
sillevl | 7:9068fc754a0b | 69 | void JsonReporter::rotation(m3dpi::Rotation rotation) |
sillevl | 7:9068fc754a0b | 70 | { |
sillevl | 7:9068fc754a0b | 71 | MbedJSONValue* json = jsonFactory(); |
sillevl | 7:9068fc754a0b | 72 | const char property[] = "rotation"; |
sillevl | 7:9068fc754a0b | 73 | |
sillevl | 7:9068fc754a0b | 74 | (*json)[property]["x"] = rotation.x; |
sillevl | 7:9068fc754a0b | 75 | (*json)[property]["y"] = rotation.y; |
sillevl | 7:9068fc754a0b | 76 | (*json)[property]["z"] = rotation.z; |
sillevl | 7:9068fc754a0b | 77 | |
sillevl | 7:9068fc754a0b | 78 | print(json); |
sillevl | 7:9068fc754a0b | 79 | delete json; |
sillevl | 7:9068fc754a0b | 80 | } |