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/binaryReporter.cpp@13:d6374484b953, 2015-12-19 (annotated)
- Committer:
- sillevl
- Date:
- Sat Dec 19 15:27:15 2015 +0000
- Revision:
- 13:d6374484b953
add binary reporter;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sillevl | 13:d6374484b953 | 1 | #include "binaryReporter.h" |
sillevl | 13:d6374484b953 | 2 | |
sillevl | 13:d6374484b953 | 3 | void BinaryReporter::print(char* data, int size) |
sillevl | 13:d6374484b953 | 4 | { |
sillevl | 13:d6374484b953 | 5 | for(int i = 0; i < size; i++){ |
sillevl | 13:d6374484b953 | 6 | out->putc(data[i]); |
sillevl | 13:d6374484b953 | 7 | } |
sillevl | 13:d6374484b953 | 8 | } |
sillevl | 13:d6374484b953 | 9 | |
sillevl | 13:d6374484b953 | 10 | void BinaryReporter::time(time_t seconds) |
sillevl | 13:d6374484b953 | 11 | { |
sillevl | 13:d6374484b953 | 12 | |
sillevl | 13:d6374484b953 | 13 | } |
sillevl | 13:d6374484b953 | 14 | |
sillevl | 13:d6374484b953 | 15 | void BinaryReporter::distance(m3dpi::Distance distance) |
sillevl | 13:d6374484b953 | 16 | { |
sillevl | 13:d6374484b953 | 17 | const int SIZE = 13; |
sillevl | 13:d6374484b953 | 18 | char data[SIZE] = {START,'a', SIZE-1, DISTANCE}; |
sillevl | 13:d6374484b953 | 19 | data [4] = distance.front; |
sillevl | 13:d6374484b953 | 20 | data [5] = distance.front_right; |
sillevl | 13:d6374484b953 | 21 | data [6] = distance.right; |
sillevl | 13:d6374484b953 | 22 | data [7] = distance.back_right; |
sillevl | 13:d6374484b953 | 23 | data [8] = distance.back; |
sillevl | 13:d6374484b953 | 24 | data [9] = distance.back_left; |
sillevl | 13:d6374484b953 | 25 | data [10] = distance.left; |
sillevl | 13:d6374484b953 | 26 | data [11] = distance.front_left; |
sillevl | 13:d6374484b953 | 27 | data [12] = 0x00; // checksum |
sillevl | 13:d6374484b953 | 28 | print(data, SIZE); |
sillevl | 13:d6374484b953 | 29 | } |
sillevl | 13:d6374484b953 | 30 | |
sillevl | 13:d6374484b953 | 31 | void BinaryReporter::acceleration(m3dpi::Acceleration acc) |
sillevl | 13:d6374484b953 | 32 | { |
sillevl | 13:d6374484b953 | 33 | const int SIZE = 11; |
sillevl | 13:d6374484b953 | 34 | char data[SIZE] = {START,'a', SIZE-1, ACCELERATION}; |
sillevl | 13:d6374484b953 | 35 | data[4] = acc.x / 256; |
sillevl | 13:d6374484b953 | 36 | data[5] = acc.x % 256; |
sillevl | 13:d6374484b953 | 37 | data[6] = acc.y / 256; |
sillevl | 13:d6374484b953 | 38 | data[5] = acc.y % 256; |
sillevl | 13:d6374484b953 | 39 | data[8] = acc.z / 256; |
sillevl | 13:d6374484b953 | 40 | data[9] = acc.z % 256; |
sillevl | 13:d6374484b953 | 41 | data [10] = 0x00; // checksum |
sillevl | 13:d6374484b953 | 42 | print(data, SIZE); |
sillevl | 13:d6374484b953 | 43 | } |
sillevl | 13:d6374484b953 | 44 | |
sillevl | 13:d6374484b953 | 45 | void BinaryReporter::direction(m3dpi::Direction direction) |
sillevl | 13:d6374484b953 | 46 | { |
sillevl | 13:d6374484b953 | 47 | const int SIZE = 11; |
sillevl | 13:d6374484b953 | 48 | char data[SIZE] = {START,'a', SIZE-1, DIRECTION}; |
sillevl | 13:d6374484b953 | 49 | data[4] = direction.x / 256; |
sillevl | 13:d6374484b953 | 50 | data[5] = direction.x % 256; |
sillevl | 13:d6374484b953 | 51 | data[6] = direction.y / 256; |
sillevl | 13:d6374484b953 | 52 | data[5] = direction.y % 256; |
sillevl | 13:d6374484b953 | 53 | data[8] = direction.z / 256; |
sillevl | 13:d6374484b953 | 54 | data[9] = direction.z % 256; |
sillevl | 13:d6374484b953 | 55 | data [10] = 0x00; // checksum |
sillevl | 13:d6374484b953 | 56 | print(data, SIZE); |
sillevl | 13:d6374484b953 | 57 | } |
sillevl | 13:d6374484b953 | 58 | |
sillevl | 13:d6374484b953 | 59 | void BinaryReporter::rotation(m3dpi::Rotation rotation) |
sillevl | 13:d6374484b953 | 60 | { |
sillevl | 13:d6374484b953 | 61 | const int SIZE = 11; |
sillevl | 13:d6374484b953 | 62 | char data[SIZE] = {START,'a', SIZE-1, ROTATION}; |
sillevl | 13:d6374484b953 | 63 | data[4] = rotation.x / 256; |
sillevl | 13:d6374484b953 | 64 | data[5] = rotation.x % 256; |
sillevl | 13:d6374484b953 | 65 | data[6] = rotation.y / 256; |
sillevl | 13:d6374484b953 | 66 | data[5] = rotation.y % 256; |
sillevl | 13:d6374484b953 | 67 | data[8] = rotation.z / 256; |
sillevl | 13:d6374484b953 | 68 | data[9] = rotation.z % 256; |
sillevl | 13:d6374484b953 | 69 | data [10] = 0x00; // checksum |
sillevl | 13:d6374484b953 | 70 | print(data, SIZE); |
sillevl | 13:d6374484b953 | 71 | } |