X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Flib%2Fcc-telemetry.c;h=88da7f03febfc82f43f9ba05c7db608806bd2ecc;hb=7f6cbfac7c1965add91ebfc28ca3eac4561b4fb6;hp=2cdb9cac82be6444aeccf269c6e10242d3a635a8;hpb=82604193ed0c522c1fba0072b504fe88b027f1ee;p=fw%2Faltos diff --git a/ao-tools/lib/cc-telemetry.c b/ao-tools/lib/cc-telemetry.c index 2cdb9cac..88da7f03 100644 --- a/ao-tools/lib/cc-telemetry.c +++ b/ao-tools/lib/cc-telemetry.c @@ -57,6 +57,36 @@ cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry) } if (hex[0] != 34) return FALSE; - memcpy(telemetry, hex+1, 32); + memcpy(telemetry, hex+1, 34); return TRUE; } + +uint8_t +cc_telemetry_cksum(const union ao_telemetry_all *telemetry) +{ + const uint8_t *x = (const uint8_t *) telemetry; + int i; + uint8_t sum = 0x5a; + for (i = 0; i < 34; i++) + sum += x[i]; + return sum; +} + +void +cc_telemetry_unparse(const union ao_telemetry_all *telemetry, char output_line[CC_TELEMETRY_BUFSIZE]) +{ + uint8_t hex[36]; + int i; + int p; + + hex[0] = 34; + memcpy(hex+1, telemetry, 34); + hex[35] = cc_telemetry_cksum(telemetry); + strcpy(output_line, "TELEM "); + p = strlen(output_line); + for (i = 0; i < 36; i++) { + sprintf(output_line + p, "%02x", hex[i]); + p += 2; + } +} +