2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 parse_byte(char *data, uint8_t *byte)
30 if (sscanf(d, "%x", &x) != 1)
37 cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry)
44 if (strncmp(input_line, "TELEM", 5) != 0)
47 data = strchr (input_line, ' ');
52 for (i = 0; i < 35; i++) {
53 if (!parse_byte(data, byte))
60 memcpy(telemetry, hex+1, 34);
65 cc_telemetry_cksum(const union ao_telemetry_all *telemetry)
67 const uint8_t *x = (const uint8_t *) telemetry;
70 for (i = 0; i < 34; i++)
76 cc_telemetry_unparse(const union ao_telemetry_all *telemetry, char output_line[CC_TELEMETRY_BUFSIZE])
83 memcpy(hex+1, telemetry, 34);
84 hex[35] = cc_telemetry_cksum(telemetry);
85 strcpy(output_line, "TELEM ");
86 p = strlen(output_line);
87 for (i = 0; i < 36; i++) {
88 sprintf(output_line + p, "%02x", hex[i]);