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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 parse_byte(char *data, uint8_t *byte)
31 if (sscanf(d, "%x", &x) != 1)
38 cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry)
45 if (strncmp(input_line, "TELEM", 5) != 0)
48 data = strchr (input_line, ' ');
53 for (i = 0; i < 35; i++) {
54 if (!parse_byte(data, byte))
61 memcpy(telemetry, hex+1, 34);
66 cc_telemetry_cksum(const union ao_telemetry_all *telemetry)
68 const uint8_t *x = (const uint8_t *) telemetry;
71 for (i = 0; i < 34; i++)
77 cc_telemetry_unparse(const union ao_telemetry_all *telemetry, char output_line[CC_TELEMETRY_BUFSIZE])
84 memcpy(hex+1, telemetry, 34);
85 hex[35] = cc_telemetry_cksum(telemetry);
86 strcpy(output_line, "TELEM ");
87 p = strlen(output_line);
88 for (i = 0; i < 36; i++) {
89 sprintf(output_line + p, "%02x", hex[i]);