ducky's telemetry library

Committer:
ikrase
Date:
Tue Mar 31 19:07:34 2015 +0000
Revision:
0:79b031fc31ac
untested telemetry code

Who changed what in which revision?

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