telemetry
telemetry-master/server-cpp/telemetry-data.cpp@0:ce1984f91f1e, 2015-03-20 (annotated)
- Committer:
- cheryl_he
- Date:
- Fri Mar 20 04:25:32 2015 +0000
- Revision:
- 0:ce1984f91f1e
added telemetry successfully;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cheryl_he | 0:ce1984f91f1e | 1 | /* |
cheryl_he | 0:ce1984f91f1e | 2 | * telemetry-data.cpp |
cheryl_he | 0:ce1984f91f1e | 3 | * |
cheryl_he | 0:ce1984f91f1e | 4 | * Created on: Mar 2, 2015 |
cheryl_he | 0:ce1984f91f1e | 5 | * Author: Ducky |
cheryl_he | 0:ce1984f91f1e | 6 | * |
cheryl_he | 0:ce1984f91f1e | 7 | * Implementation for Telemetry Data classes. |
cheryl_he | 0:ce1984f91f1e | 8 | */ |
cheryl_he | 0:ce1984f91f1e | 9 | #include <telemetry.h> |
cheryl_he | 0:ce1984f91f1e | 10 | #include <string.h> |
cheryl_he | 0:ce1984f91f1e | 11 | |
cheryl_he | 0:ce1984f91f1e | 12 | namespace telemetry { |
cheryl_he | 0:ce1984f91f1e | 13 | void packet_write_string(TransmitPacketInterface& packet, const char* str) { |
cheryl_he | 0:ce1984f91f1e | 14 | // TODO: move into HAL for higher performance? |
cheryl_he | 0:ce1984f91f1e | 15 | while (*str != '\0') { |
cheryl_he | 0:ce1984f91f1e | 16 | packet.write_uint8(*str); |
cheryl_he | 0:ce1984f91f1e | 17 | str++; |
cheryl_he | 0:ce1984f91f1e | 18 | } |
cheryl_he | 0:ce1984f91f1e | 19 | packet.write_uint8('\0'); |
cheryl_he | 0:ce1984f91f1e | 20 | } |
cheryl_he | 0:ce1984f91f1e | 21 | |
cheryl_he | 0:ce1984f91f1e | 22 | size_t Data::get_header_kvrs_length() { |
cheryl_he | 0:ce1984f91f1e | 23 | return 1 + strlen(internal_name) + 1 |
cheryl_he | 0:ce1984f91f1e | 24 | + 1 + strlen(display_name) + 1 |
cheryl_he | 0:ce1984f91f1e | 25 | + 1 + strlen(units) + 1; |
cheryl_he | 0:ce1984f91f1e | 26 | } |
cheryl_he | 0:ce1984f91f1e | 27 | |
cheryl_he | 0:ce1984f91f1e | 28 | void Data::write_header_kvrs(TransmitPacketInterface& packet) { |
cheryl_he | 0:ce1984f91f1e | 29 | packet.write_uint8(RECORDID_INTERNAL_NAME); |
cheryl_he | 0:ce1984f91f1e | 30 | packet_write_string(packet, internal_name); |
cheryl_he | 0:ce1984f91f1e | 31 | packet.write_uint8(RECORDID_DISPLAY_NAME); |
cheryl_he | 0:ce1984f91f1e | 32 | packet_write_string(packet, display_name); |
cheryl_he | 0:ce1984f91f1e | 33 | packet.write_uint8(RECORDID_UNITS); |
cheryl_he | 0:ce1984f91f1e | 34 | packet_write_string(packet, units); |
cheryl_he | 0:ce1984f91f1e | 35 | } |
cheryl_he | 0:ce1984f91f1e | 36 | |
cheryl_he | 0:ce1984f91f1e | 37 | template<> |
cheryl_he | 0:ce1984f91f1e | 38 | uint8_t Numeric<uint8_t>::get_subtype() { |
cheryl_he | 0:ce1984f91f1e | 39 | return NUMERIC_SUBTYPE_UINT; |
cheryl_he | 0:ce1984f91f1e | 40 | } |
cheryl_he | 0:ce1984f91f1e | 41 | template<> |
cheryl_he | 0:ce1984f91f1e | 42 | void Numeric<uint8_t>::serialize_data(uint8_t value, TransmitPacketInterface& packet) { |
cheryl_he | 0:ce1984f91f1e | 43 | packet.write_uint8(value); |
cheryl_he | 0:ce1984f91f1e | 44 | } |
cheryl_he | 0:ce1984f91f1e | 45 | template<> |
cheryl_he | 0:ce1984f91f1e | 46 | uint8_t Numeric<uint8_t>::deserialize_data(ReceivePacketBuffer& packet) { |
cheryl_he | 0:ce1984f91f1e | 47 | return packet.read_uint8(); |
cheryl_he | 0:ce1984f91f1e | 48 | } |
cheryl_he | 0:ce1984f91f1e | 49 | |
cheryl_he | 0:ce1984f91f1e | 50 | template<> |
cheryl_he | 0:ce1984f91f1e | 51 | uint8_t Numeric<uint16_t>::get_subtype() { |
cheryl_he | 0:ce1984f91f1e | 52 | return NUMERIC_SUBTYPE_UINT; |
cheryl_he | 0:ce1984f91f1e | 53 | } |
cheryl_he | 0:ce1984f91f1e | 54 | template<> |
cheryl_he | 0:ce1984f91f1e | 55 | void Numeric<uint16_t>::serialize_data(uint16_t value, TransmitPacketInterface& packet) { |
cheryl_he | 0:ce1984f91f1e | 56 | packet.write_uint16(value); |
cheryl_he | 0:ce1984f91f1e | 57 | } |
cheryl_he | 0:ce1984f91f1e | 58 | template<> |
cheryl_he | 0:ce1984f91f1e | 59 | uint16_t Numeric<uint16_t>::deserialize_data(ReceivePacketBuffer& packet) { |
cheryl_he | 0:ce1984f91f1e | 60 | return packet.read_uint16(); |
cheryl_he | 0:ce1984f91f1e | 61 | } |
cheryl_he | 0:ce1984f91f1e | 62 | |
cheryl_he | 0:ce1984f91f1e | 63 | template<> |
cheryl_he | 0:ce1984f91f1e | 64 | uint8_t Numeric<uint32_t>::get_subtype() { |
cheryl_he | 0:ce1984f91f1e | 65 | return NUMERIC_SUBTYPE_UINT; |
cheryl_he | 0:ce1984f91f1e | 66 | } |
cheryl_he | 0:ce1984f91f1e | 67 | template<> |
cheryl_he | 0:ce1984f91f1e | 68 | void Numeric<uint32_t>::serialize_data(uint32_t value, TransmitPacketInterface& packet) { |
cheryl_he | 0:ce1984f91f1e | 69 | packet.write_uint32(value); |
cheryl_he | 0:ce1984f91f1e | 70 | } |
cheryl_he | 0:ce1984f91f1e | 71 | template<> |
cheryl_he | 0:ce1984f91f1e | 72 | uint32_t Numeric<uint32_t>::deserialize_data(ReceivePacketBuffer& packet) { |
cheryl_he | 0:ce1984f91f1e | 73 | return packet.read_uint32(); |
cheryl_he | 0:ce1984f91f1e | 74 | } |
cheryl_he | 0:ce1984f91f1e | 75 | |
cheryl_he | 0:ce1984f91f1e | 76 | // TODO: move into HAL |
cheryl_he | 0:ce1984f91f1e | 77 | template<> |
cheryl_he | 0:ce1984f91f1e | 78 | uint8_t Numeric<float>::get_subtype() { |
cheryl_he | 0:ce1984f91f1e | 79 | return NUMERIC_SUBTYPE_FLOAT; |
cheryl_he | 0:ce1984f91f1e | 80 | } |
cheryl_he | 0:ce1984f91f1e | 81 | template<> |
cheryl_he | 0:ce1984f91f1e | 82 | void Numeric<float>::serialize_data(float value, TransmitPacketInterface& packet) { |
cheryl_he | 0:ce1984f91f1e | 83 | packet.write_float(value); |
cheryl_he | 0:ce1984f91f1e | 84 | } |
cheryl_he | 0:ce1984f91f1e | 85 | template<> |
cheryl_he | 0:ce1984f91f1e | 86 | float Numeric<float>::deserialize_data(ReceivePacketBuffer& packet) { |
cheryl_he | 0:ce1984f91f1e | 87 | return packet.read_float(); |
cheryl_he | 0:ce1984f91f1e | 88 | } |
cheryl_he | 0:ce1984f91f1e | 89 | |
cheryl_he | 0:ce1984f91f1e | 90 | } |