summaryrefslogtreecommitdiff
path: root/ao-tools/lib/cc-telemetry.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-03-09 20:39:31 -0800
committerKeith Packard <keithp@keithp.com>2013-03-09 20:39:31 -0800
commit9b460d38bc2685bca7f530b7749c0e0381f6264c (patch)
tree8eb7463a9ad0c63b3e6df3ae7d3692ee27214d78 /ao-tools/lib/cc-telemetry.c
parent0803da851e2e061affc172fdde6301652d1be755 (diff)
ao-tools/lib: Add cc_telemetry_unparse
This takes a telemetry structure and generates a string version Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib/cc-telemetry.c')
-rw-r--r--ao-tools/lib/cc-telemetry.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/ao-tools/lib/cc-telemetry.c b/ao-tools/lib/cc-telemetry.c
index 99da2680..88da7f03 100644
--- a/ao-tools/lib/cc-telemetry.c
+++ b/ao-tools/lib/cc-telemetry.c
@@ -60,3 +60,33 @@ cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry)
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;
+ }
+}
+