2 * Copyright © 2012 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.
23 parse_hex(const char *data, int *result)
29 while (isspace (*data))
31 for (i = 0; i < sizeof (d) - 1 && isxdigit(*data); i++)
34 if (sscanf(d, "%x", &x) != 1)
41 parse_uint16(const char *data, uint16_t *result)
44 data = parse_hex(data, &x);
50 parse_uint8(const char *data, uint8_t *result)
53 data = parse_hex(data, &x);
59 parse_eeprom(const char *input_line, struct ao_log_mega *l) {
63 if (input_line[1] != ' ')
65 if (!isupper(input_line[0]))
68 l->type = input_line[0];
70 line = input_line + 2;
72 line = parse_uint16(line, &l->tick);
73 for (b = 0; b < 28; b++) {
76 line = parse_uint8(line, &l->u.bytes[b]);
82 l->u.config_int.kind = (t); \
88 parse_config(const char *input_line, struct ao_log_mega *l) {
89 if (sscanf (input_line, "Config version: %d.%d",
90 &l->u.config_int.data[0],
91 &l->u.config_int.data[1]))
92 YUP(AO_CONFIG_CONFIG);
93 if (sscanf (input_line, "Main deploy: %d",
94 &l->u.config_int.data[0]))
96 if (sscanf (input_line, "Apogee delay: %d",
97 &l->u.config_int.data[0]))
98 YUP(AO_CONFIG_APOGEE);
99 if (sscanf (input_line, "Apogee lockout: %d",
100 &l->u.config_int.data[0]))
101 YUP(AO_CONFIG_LOCKOUT);
102 if (sscanf (input_line, "Frequency: %d",
103 &l->u.config_int.data[0]))
104 YUP(AO_CONFIG_FREQUENCY);
105 if (sscanf (input_line, "Radio enable: %d",
106 &l->u.config_int.data[0]))
107 YUP(AO_CONFIG_RADIO_ENABLE);
108 if (sscanf (input_line, "Accel cal +1g: %d -1g: %d",
109 &l->u.config_int.data[0],
110 &l->u.config_int.data[1]))
111 YUP(AO_CONFIG_ACCEL_CAL);
112 if (sscanf (input_line, "Radio cal: %d",
113 &l->u.config_int.data[0]))
114 YUP(AO_CONFIG_RADIO_CAL);
115 if (sscanf (input_line, "Max flight log: %d",
116 &l->u.config_int.data[0]))
117 YUP(AO_CONFIG_MAX_LOG);
118 if (sscanf (input_line, "Ignite mode: %d",
119 &l->u.config_int.data[0]))
120 YUP(AO_CONFIG_IGNITE_MODE);
121 if (sscanf (input_line, "Pad orientation: %d",
122 &l->u.config_int.data[0]))
123 YUP(AO_CONFIG_PAD_ORIENTATION);
124 if (sscanf (input_line, "serial-number %d",
125 &l->u.config_int.data[0]))
126 YUP(AO_CONFIG_SERIAL_NUMBER);
127 if (sscanf (input_line, "log-format %d",
128 &l->u.config_int.data[0]))
129 YUP(AO_CONFIG_LOG_FORMAT);
130 if (sscanf (input_line, "ms5607 reserved: %d",
131 &l->u.config_int.data[0]))
132 YUP(AO_CONFIG_MS5607_RESERVED);
133 if (sscanf (input_line, "ms5607 sens: %d",
134 &l->u.config_int.data[0]))
135 YUP(AO_CONFIG_MS5607_SENS);
136 if (sscanf (input_line, "ms5607 off: %d",
137 &l->u.config_int.data[0]))
138 YUP(AO_CONFIG_MS5607_OFF);
139 if (sscanf (input_line, "ms5607 tcs: %d",
140 &l->u.config_int.data[0]))
141 YUP(AO_CONFIG_MS5607_TCS);
142 if (sscanf (input_line, "ms5607 tco: %d",
143 &l->u.config_int.data[0]))
144 YUP(AO_CONFIG_MS5607_TCO);
145 if (sscanf (input_line, "ms5607 tref: %d",
146 &l->u.config_int.data[0]))
147 YUP(AO_CONFIG_MS5607_TREF);
148 if (sscanf (input_line, "ms5607 tempsens: %d",
149 &l->u.config_int.data[0]))
150 YUP(AO_CONFIG_MS5607_TEMPSENS);
151 if (sscanf (input_line, "ms5607 crc: %d",
152 &l->u.config_int.data[0]))
153 YUP(AO_CONFIG_MS5607_CRC);
158 cc_mega_parse(const char *input_line, struct ao_log_mega *l) {
159 return parse_eeprom(input_line, l) || parse_config(input_line, l);