*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
}
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;
+ }
+}