2 * Copyright © 2009 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.
21 #include <ao_config.h>
23 #include <ao_sample.h>
30 #include <ao_tracker.h>
33 struct ao_config ao_config;
34 uint8_t ao_config_loaded;
35 uint8_t ao_config_dirty;
36 uint8_t ao_config_mutex;
39 uint8_t ao_force_freq;
42 #ifndef HAS_CONFIG_SAVE
43 #define HAS_CONFIG_SAVE HAS_EEPROM
46 #ifndef AO_CONFIG_DEFAULT_APRS_INTERVAL
47 #define AO_CONFIG_DEFAULT_APRS_INTERVAL 0
49 #define AO_CONFIG_DEFAULT_MAIN_DEPLOY 250
50 #define AO_CONFIG_DEFAULT_RADIO_CHANNEL 0
51 #define AO_CONFIG_DEFAULT_CALLSIGN "N0CALL"
52 #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000
53 #define AO_CONFIG_DEFAULT_APOGEE_DELAY 0
54 #define AO_CONFIG_DEFAULT_IGNITE_MODE AO_IGNITE_MODE_DUAL
55 #define AO_CONFIG_DEFAULT_PAD_ORIENTATION AO_PAD_ORIENTATION_ANTENNA_UP
56 #define AO_CONFIG_DEFAULT_PYRO_TIME AO_MS_TO_TICKS(50)
58 #ifndef USE_INTERNAL_FLASH
59 #error Please define USE_INTERNAL_FLASH
63 #ifndef AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX
64 # if FLIGHT_LOG_APPEND
65 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_log_max
67 # if USE_INTERNAL_FLASH
68 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config
70 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024)
75 #ifndef AO_CONFIG_DEFAULT_RADIO_POWER
76 #define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
78 #define AO_CONFIG_DEFAULT_RADIO_AMP 0
79 #define AO_CONFIG_DEFAULT_APRS_SSID (ao_serial_number % 10)
80 #define AO_CONFIG_DEFAULT_RADIO_RATE AO_RADIO_RATE_38400
88 ao_config_write(0, &ao_config, sizeof (ao_config));
90 ao_log_write_erase(0);
98 ao_mutex_get(&ao_config_mutex);
100 ao_mutex_put(&ao_config_mutex);
106 #if HAS_RADIO_FORWARD
107 uint32_t ao_send_radio_setting;
111 ao_config_set_radio(void)
113 ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
114 #if HAS_RADIO_FORWARD
115 ao_send_radio_setting = ao_freq_to_set(ao_config.send_frequency, ao_config.radio_cal);
118 #endif /* HAS_RADIO */
125 if (ao_config_loaded)
128 /* Yes, I know ao_storage_read calls ao_storage_setup,
129 * but ao_storage_setup *also* sets ao_storage_config, which we
130 * need before calling ao_storage_read here
133 ao_config_read(0, &ao_config, sizeof (ao_config));
135 if (ao_config.major != AO_CONFIG_MAJOR) {
136 ao_config.major = AO_CONFIG_MAJOR;
139 /* Version 0 stuff */
140 ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
141 memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
142 memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
143 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
144 ao_config._legacy_radio_channel = 0;
146 minor = ao_config.minor;
147 if (minor != AO_CONFIG_MINOR) {
148 /* Fixups for minor version 1 */
150 ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
151 /* Fixups for minor version 2 */
153 ao_config.accel_plus_g = 0;
154 ao_config.accel_minus_g = 0;
156 /* Fixups for minor version 3 */
159 ao_config.radio_cal = ao_radio_cal;
161 /* Fixups for minor version 4 */
164 ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
166 /* Fixupes for minor version 5 */
168 ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
170 ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
172 ao_config.radio_enable = AO_RADIO_ENABLE_CORE;
174 memset(&ao_config.aes_key, '\0', AO_AES_LEN);
176 ao_config.frequency = 434550 + ao_config._legacy_radio_channel * 100;
178 ao_config.apogee_lockout = 0;
181 memset(&ao_config.pyro, '\0', sizeof (ao_config.pyro));
184 ao_config.aprs_interval = AO_CONFIG_DEFAULT_APRS_INTERVAL;
187 ao_config.radio_power = AO_CONFIG_DEFAULT_RADIO_POWER;
191 ao_config.radio_amp = AO_CONFIG_DEFAULT_RADIO_AMP;
195 ao_config.accel_zero_along = 0;
196 ao_config.accel_zero_across = 0;
197 ao_config.accel_zero_through = 0;
199 /* Reset the main accel offsets to force
202 ao_config.accel_plus_g = 0;
203 ao_config.accel_minus_g = 0;
208 ao_config.mid_beep = AO_BEEP_MID_DEFAULT;
212 ao_config.tracker_motion = AO_TRACKER_MOTION_DEFAULT;
213 ao_config.tracker_interval = AO_TRACKER_INTERVAL_DEFAULT;
218 ao_config.pyro_time = AO_CONFIG_DEFAULT_PYRO_TIME;
222 ao_config.aprs_ssid = AO_CONFIG_DEFAULT_APRS_SSID;
226 ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
228 #if HAS_RADIO_FORWARD
230 ao_config.send_frequency = 434550;
234 ao_config.aprs_format = AO_CONFIG_DEFAULT_APRS_FORMAT;
236 #if HAS_FIXED_PAD_BOX
238 ao_config.pad_box = 1;
240 ao_config.pad_idle = 120;
244 ao_config.aprs_offset = 0;
246 ao_config.minor = AO_CONFIG_MINOR;
252 ao_config.frequency = 434550;
253 ao_config.radio_cal = ao_radio_cal;
255 ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
257 memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
258 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
261 ao_config_set_radio();
263 ao_config_loaded = 1;
267 _ao_config_edit_start(void)
269 ao_mutex_get(&ao_config_mutex);
274 _ao_config_edit_finish(void)
277 ao_mutex_put(&ao_config_mutex);
283 _ao_config_edit_start();
284 ao_mutex_put(&ao_config_mutex);
290 ao_config_callsign_show(void)
292 printf ("Callsign: \"%s\"\n", ao_config.callsign);
296 ao_config_callsign_set(void)
299 static char callsign[AO_MAX_CALLSIGN + 1];
301 memset(callsign, '\0', sizeof callsign);
304 while (ao_cmd_lex_c != '\n') {
305 if (c < AO_MAX_CALLSIGN)
306 callsign[c++] = ao_cmd_lex_c;
308 ao_cmd_status = ao_cmd_lex_error;
311 if (ao_cmd_status != ao_cmd_success)
313 _ao_config_edit_start();
314 memcpy(&ao_config.callsign, &callsign,
315 AO_MAX_CALLSIGN + 1);
316 _ao_config_edit_finish();
320 ao_config_frequency_show(void)
322 printf("Frequency: %ld\n",
323 ao_config.frequency);
327 ao_config_frequency_set(void)
329 uint32_t r = ao_cmd_decimal();
330 if (ao_cmd_status != ao_cmd_success)
332 _ao_config_edit_start();
333 ao_config.frequency = r;
334 ao_config_set_radio();
335 _ao_config_edit_finish();
337 ao_radio_recv_abort();
343 #if HAS_RADIO_FORWARD
345 ao_config_send_frequency_show(void)
347 printf("Send frequency: %ld\n",
348 ao_config.send_frequency);
352 ao_config_send_frequency_set(void)
355 if (ao_cmd_status != ao_cmd_success)
357 _ao_config_edit_start();
358 ao_config.send_frequency = ao_cmd_lex_u32;
359 ao_config_set_radio();
360 _ao_config_edit_finish();
362 ao_radio_recv_abort();
371 ao_config_main_deploy_show(void)
373 printf("Main deploy: %d meters\n",
374 ao_config.main_deploy);
378 ao_config_main_deploy_set(void)
380 uint32_t r = ao_cmd_decimal();
381 if (ao_cmd_status != ao_cmd_success)
383 _ao_config_edit_start();
384 ao_config.main_deploy = r;
385 _ao_config_edit_finish();
390 ao_config_accel_calibrate_show(void)
392 printf("Accel cal +1g: %d -1g: %d\n",
393 ao_config.accel_plus_g, ao_config.accel_minus_g);
395 printf ("IMU cal along %d across %d through %d\n",
396 ao_config.accel_zero_along,
397 ao_config.accel_zero_across,
398 ao_config.accel_zero_through);
402 #define ACCEL_CALIBRATE_SAMPLES 1024
403 #define ACCEL_CALIBRATE_SHIFT 10
406 static int16_t accel_cal_along;
407 static int16_t accel_cal_across;
408 static int16_t accel_cal_through;
412 ao_config_accel_calibrate_auto(char *orientation)
416 uint8_t cal_data_ring;
418 int32_t accel_along_total = 0;
419 int32_t accel_across_total = 0;
420 int32_t accel_through_total = 0;
423 printf("Orient antenna %s and press a key...", orientation);
426 puts("\r\n"); flush();
427 puts("Calibrating..."); flush();
428 i = ACCEL_CALIBRATE_SAMPLES;
430 cal_data_ring = ao_sample_data;
432 ao_sleep(&ao_sample_data);
433 while (i && cal_data_ring != ao_sample_data) {
434 accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
436 accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]);
437 accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]);
438 accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]);
440 cal_data_ring = ao_data_ring_next(cal_data_ring);
445 accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT;
446 accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT;
447 accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT;
449 return accel_total >> ACCEL_CALIBRATE_SHIFT;
453 ao_config_accel_calibrate_set(void)
458 int16_t accel_along_up = 0, accel_along_down = 0;
459 int16_t accel_across_up = 0, accel_across_down = 0;
460 int16_t accel_through_up = 0, accel_through_down = 0;
463 r = ao_cmd_decimal();
464 if (ao_cmd_status != ao_cmd_success)
467 up = ao_config_accel_calibrate_auto("up");
469 accel_along_up = accel_cal_along;
470 accel_across_up = accel_cal_across;
471 accel_through_up = accel_cal_through;
473 down = ao_config_accel_calibrate_auto("down");
475 accel_along_down = accel_cal_along;
476 accel_across_down = accel_cal_across;
477 accel_through_down = accel_cal_through;
481 r = ao_cmd_decimal();
482 if (ao_cmd_status != ao_cmd_success)
487 printf("Invalid accel: up (%d) down (%d)\n",
491 _ao_config_edit_start();
492 ao_config.accel_plus_g = up;
493 ao_config.accel_minus_g = down;
496 ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2;
497 ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2;
498 ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2;
501 _ao_config_edit_finish();
503 #endif /* HAS_ACCEL */
506 ao_config_apogee_delay_show(void)
508 printf("Apogee delay: %d seconds\n",
509 ao_config.apogee_delay);
513 ao_config_apogee_delay_set(void)
515 uint32_t r = ao_cmd_decimal();
516 if (ao_cmd_status != ao_cmd_success)
518 _ao_config_edit_start();
519 ao_config.apogee_delay = r;
520 _ao_config_edit_finish();
524 ao_config_apogee_lockout_show(void)
526 printf ("Apogee lockout: %d seconds\n",
527 ao_config.apogee_lockout);
531 ao_config_apogee_lockout_set(void)
533 uint16_t r = ao_cmd_decimal();
534 if (ao_cmd_status != ao_cmd_success)
536 _ao_config_edit_start();
537 ao_config.apogee_lockout = r;
538 _ao_config_edit_finish();
541 #endif /* HAS_FLIGHT */
545 ao_config_radio_cal_show(void)
547 printf("Radio cal: %ld\n", ao_config.radio_cal);
551 ao_config_radio_cal_set(void)
553 uint32_t r = ao_cmd_decimal();
554 if (ao_cmd_status != ao_cmd_success)
556 _ao_config_edit_start();
557 ao_config.radio_cal = r;
558 ao_config_set_radio();
559 _ao_config_edit_finish();
565 #ifndef HAS_TELEMETRY
566 #error Please define HAS_TELEMETRY
570 ao_config_radio_rate_show(void)
572 printf("Telemetry rate: %d\n", ao_config.radio_rate);
576 ao_config_radio_rate_set(void)
578 uint16_t r = ao_cmd_decimal();
579 if (ao_cmd_status != ao_cmd_success)
581 if (AO_RADIO_RATE_MAX < r) {
582 ao_cmd_status = ao_cmd_lex_error;
585 _ao_config_edit_start();
586 ao_config.radio_rate = r;
587 _ao_config_edit_finish();
589 ao_telemetry_reset_interval();
592 ao_radio_recv_abort();
600 ao_config_log_show(void)
602 printf("Max flight log: %d kB\n", (int16_t) (ao_config.flight_log_max >> 10));
603 #if FLIGHT_LOG_APPEND
604 printf("Log fixed: 1\n");
608 #if FLIGHT_LOG_APPEND && HAS_CONFIG_SAVE
610 ao_config_log_fix_append(void)
612 _ao_config_edit_start();
613 ao_config.flight_log_max = ao_storage_log_max;
614 _ao_config_edit_finish();
615 ao_mutex_get(&ao_config_mutex);
618 ao_mutex_put(&ao_config_mutex);
623 ao_config_log_set(void)
625 #if FLIGHT_LOG_APPEND
626 printf("Flight log fixed size %d kB\n", ao_storage_log_max >> 10);
628 uint16_t block = (uint16_t) (ao_storage_block >> 10);
629 uint16_t log_max = (uint16_t) (ao_storage_log_max >> 10);
632 r = ao_cmd_decimal();
633 if (ao_cmd_status != ao_cmd_success)
635 if (ao_log_present())
636 printf("Storage must be empty before changing log size\n");
637 else if (block > 1024 && (r & (block - 1)))
638 printf("Flight log size must be multiple of %d kB\n", block);
639 else if (r > log_max)
640 printf("Flight log max %d kB\n", log_max);
642 _ao_config_edit_start();
643 ao_config.flight_log_max = r << 10;
644 _ao_config_edit_finish();
652 ao_config_ignite_mode_show(void)
654 printf("Ignite mode: %d\n", ao_config.ignite_mode);
658 ao_config_ignite_mode_set(void)
660 uint16_t r = ao_cmd_decimal();
661 if (ao_cmd_status != ao_cmd_success)
663 _ao_config_edit_start();
664 ao_config.ignite_mode = r;
665 _ao_config_edit_finish();
671 ao_config_pad_orientation_show(void)
673 printf("Pad orientation: %d\n", ao_config.pad_orientation);
677 ao_config_pad_orientation_set(void)
679 uint16_t r = ao_cmd_decimal() & 1;
680 if (ao_cmd_status != ao_cmd_success)
682 _ao_config_edit_start();
683 if (ao_config.pad_orientation != r) {
685 t = ao_config.accel_plus_g;
686 ao_config.accel_plus_g = ao_data_accel_invert(ao_config.accel_minus_g);
687 ao_config.accel_minus_g = ao_data_accel_invert(t);
689 ao_config.pad_orientation = r;
690 _ao_config_edit_finish();
696 ao_config_radio_enable_show(void)
698 printf("Radio enable: %d\n", ao_config.radio_enable);
702 ao_config_radio_enable_set(void)
704 uint16_t r = ao_cmd_decimal();
705 if (ao_cmd_status != ao_cmd_success)
707 _ao_config_edit_start();
708 ao_config.radio_enable = r;
709 _ao_config_edit_finish();
710 #if HAS_TELEMETRY && HAS_RADIO_RATE
711 ao_telemetry_reset_interval();
714 #endif /* HAS_RADIO */
718 uint8_t ao_config_aes_seq = 1;
721 ao_config_key_show(void)
725 for (i = 0; i < AO_AES_LEN; i++)
726 printf ("%02x", ao_config.aes_key[i]);
731 ao_config_key_set(void)
735 _ao_config_edit_start();
736 for (i = 0; i < AO_AES_LEN; i++) {
737 uint8_t b = ao_cmd_hexbyte();
738 if (ao_cmd_status != ao_cmd_success)
740 ao_config.aes_key[i] = b;
743 _ao_config_edit_finish();
750 ao_config_aprs_show(void)
752 printf ("APRS interval: %d\n", ao_config.aprs_interval);
756 ao_config_aprs_set(void)
758 uint16_t r = ao_cmd_decimal();
759 if (ao_cmd_status != ao_cmd_success)
761 _ao_config_edit_start();
762 ao_config.aprs_interval = r;
763 _ao_config_edit_finish();
764 ao_telemetry_reset_interval();
768 ao_config_aprs_offset_show(void)
770 printf ("APRS offset: %d\n", ao_config.aprs_offset);
774 ao_config_aprs_offset_set(void)
776 uint16_t r = ao_cmd_decimal();
777 if (ao_cmd_status != ao_cmd_success)
779 _ao_config_edit_start();
780 ao_config.aprs_offset = r;
781 _ao_config_edit_finish();
782 ao_telemetry_reset_interval();
785 #endif /* HAS_APRS */
790 ao_config_radio_amp_show(void)
792 printf ("Radio amp setting: %d\n", ao_config.radio_amp);
796 ao_config_radio_amp_set(void)
798 uint16_t r = ao_cmd_decimal();
799 if (ao_cmd_status != ao_cmd_success)
801 _ao_config_edit_start();
802 ao_config.radio_amp = r;
803 _ao_config_edit_finish();
811 ao_config_radio_power_show(void)
813 printf ("Radio power setting: %d\n", ao_config.radio_power);
817 ao_config_radio_power_set(void)
819 uint16_t r = ao_cmd_decimal();
820 if (ao_cmd_status != ao_cmd_success)
822 _ao_config_edit_start();
823 ao_config.radio_power = r;
824 _ao_config_edit_finish();
831 ao_config_beep_show(void)
833 printf ("Beeper setting: %d\n", ao_config.mid_beep);
837 ao_config_beep_set(void)
839 uint16_t r = ao_cmd_decimal();
840 if (ao_cmd_status != ao_cmd_success)
842 _ao_config_edit_start();
843 ao_config.mid_beep = r;
844 _ao_config_edit_finish();
850 ao_config_tracker_show(void)
852 printf ("Tracker setting: %d %d\n",
853 ao_config.tracker_motion,
854 ao_config.tracker_interval);
858 ao_config_tracker_set(void)
861 m = ao_cmd_decimal();
862 if (ao_cmd_status != ao_cmd_success)
864 i = ao_cmd_decimal();
865 if (ao_cmd_status != ao_cmd_success)
867 _ao_config_edit_start();
868 ao_config.tracker_motion = m;
869 ao_config.tracker_interval = i;
870 _ao_config_edit_finish();
872 ao_telemetry_reset_interval();
875 #endif /* HAS_TRACKER */
879 ao_config_pyro_time_show(void)
881 printf ("Pyro time: %d\n", ao_config.pyro_time);
885 ao_config_pyro_time_set(void)
887 uint16_t r = ao_cmd_decimal();
888 if (ao_cmd_status != ao_cmd_success)
890 _ao_config_edit_start();
891 ao_config.pyro_time = r;
892 _ao_config_edit_finish();
898 ao_config_aprs_ssid_show(void)
900 printf ("APRS SSID: %d\n",
901 ao_config.aprs_ssid);
905 ao_config_aprs_ssid_set(void)
907 uint16_t r = ao_cmd_decimal();
908 if (ao_cmd_status != ao_cmd_success)
911 ao_cmd_status = ao_cmd_lex_error;
914 _ao_config_edit_start();
915 ao_config.aprs_ssid = r;
916 _ao_config_edit_finish();
920 ao_config_aprs_format_set(void)
922 uint16_t r = ao_cmd_decimal();
923 if (ao_cmd_status != ao_cmd_success)
925 _ao_config_edit_start();
926 ao_config.aprs_format = r != 0;
927 _ao_config_edit_finish();
931 ao_config_aprs_format_show(void)
933 printf ("APRS format: %d\n", ao_config.aprs_format);
935 #endif /* HAS_APRS */
937 #if HAS_FIXED_PAD_BOX
939 ao_config_pad_box_show(void)
941 printf ("Pad box: %d\n", ao_config.pad_box);
945 ao_config_pad_box_set(void)
947 uint16_t r = ao_cmd_decimal();
948 if (ao_cmd_status != ao_cmd_success)
950 _ao_config_edit_start();
951 ao_config.pad_box = r;
952 _ao_config_edit_finish();
956 ao_config_pad_idle_show(void)
958 printf ("Idle timeout: %d\n", ao_config.pad_idle);
962 ao_config_pad_idle_set(void)
964 uint16_t r = ao_cmd_decimal();
965 if (ao_cmd_status != ao_cmd_success)
967 _ao_config_edit_start();
968 ao_config.pad_idle = r;
969 _ao_config_edit_finish();
973 struct ao_config_var {
980 ao_config_help(void);
983 ao_config_show(void);
987 ao_config_save(void);
990 const struct ao_config_var ao_config_vars[] = {
992 { "m <meters>\0Main deploy (m)",
993 ao_config_main_deploy_set, ao_config_main_deploy_show, },
994 { "d <delay>\0Apogee delay (s)",
995 ao_config_apogee_delay_set, ao_config_apogee_delay_show },
996 { "L <seconds>\0Apogee detect lockout (s)",
997 ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
998 #endif /* HAS_FLIGHT */
1000 { "F <freq>\0Frequency (kHz)",
1001 ao_config_frequency_set, ao_config_frequency_show },
1002 #if HAS_RADIO_FORWARD
1003 { "R <freq>\0Repeater output frequency (kHz)",
1004 ao_config_send_frequency_set, ao_config_send_frequency_show },
1006 { "c <call>\0Callsign (8 char max)",
1007 ao_config_callsign_set, ao_config_callsign_show },
1008 { "e <0 disable, 1 enable>\0Enable telemetry and RDF",
1009 ao_config_radio_enable_set, ao_config_radio_enable_show },
1010 { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
1011 ao_config_radio_cal_set, ao_config_radio_cal_show },
1013 { "T <rate>\0Telemetry rate (0=38.4, 1=9.6, 2=2.4)",
1014 ao_config_radio_rate_set, ao_config_radio_rate_show },
1017 { "p <setting>\0Radio power setting (0-255)",
1018 ao_config_radio_power_set, ao_config_radio_power_show },
1021 { "d <setting>\0Radio amplifier setting (0-3)",
1022 ao_config_radio_amp_set, ao_config_radio_amp_show },
1024 #endif /* HAS_RADIO */
1026 { "a <+g> <-g>\0Accel calib (0 for auto)",
1027 ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
1028 { "o <0 antenna up, 1 antenna down>\0Pad orientation",
1029 ao_config_pad_orientation_set,ao_config_pad_orientation_show },
1030 #endif /* HAS_ACCEL */
1032 { "l <size>\0Flight log size (kB)",
1033 ao_config_log_set, ao_config_log_show },
1036 { "i <0 dual, 1 apogee, 2 main>\0Igniter mode",
1037 ao_config_ignite_mode_set, ao_config_ignite_mode_show },
1040 { "k <32 hex digits>\0AES encryption key",
1041 ao_config_key_set, ao_config_key_show },
1044 { "P <n,?>\0Pyro channels",
1045 ao_pyro_set, ao_pyro_show },
1046 { "I <ticks>\0Pyro firing time",
1047 ao_config_pyro_time_set, ao_config_pyro_time_show },
1050 { "A <secs>\0APRS packet interval (0 disable)",
1051 ao_config_aprs_set, ao_config_aprs_show },
1054 { "b <val>\0Beeper tone (freq = 1/2 (24e6/32) / beep",
1055 ao_config_beep_set, ao_config_beep_show },
1058 { "t <motion> <interval>\0Tracker configuration",
1059 ao_config_tracker_set, ao_config_tracker_show },
1062 { "S <ssid>\0Set APRS SSID (0-15)",
1063 ao_config_aprs_ssid_set, ao_config_aprs_ssid_show },
1064 { "C <0 compressed, 1 uncompressed>\0APRS format",
1065 ao_config_aprs_format_set, ao_config_aprs_format_show },
1066 { "O <aprs-offset>\0APRS Offset from top of minute",
1067 ao_config_aprs_offset_set, ao_config_aprs_offset_show },
1069 #if HAS_FIXED_PAD_BOX
1070 { "B <box>\0Set pad box (1-99)",
1071 ao_config_pad_box_set, ao_config_pad_box_show },
1072 { "i <seconds>\0Set idle timeout (0 disable)",
1073 ao_config_pad_idle_set, ao_config_pad_idle_show },
1076 ao_config_show, 0 },
1078 { "w\0Write to eeprom",
1079 ao_config_save, 0 },
1082 ao_config_help, 0 },
1095 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1096 if (ao_config_vars[cmd].str[0] == c) {
1097 (*ao_config_vars[cmd].set)();
1100 ao_cmd_status = ao_cmd_syntax_error;
1104 ao_config_help(void)
1107 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1108 printf("%-20s %s\n",
1109 ao_config_vars[cmd].str,
1110 ao_config_vars[cmd].str+1+
1111 strlen(ao_config_vars[cmd].str));
1115 ao_config_show(void)
1119 printf("Config version: %d.%d\n",
1120 ao_config.major, ao_config.minor);
1121 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1122 if (ao_config_vars[cmd].show)
1123 (*ao_config_vars[cmd].show)();
1131 ao_config_save(void)
1134 ao_mutex_get(&ao_config_mutex);
1135 if (ao_config_dirty) {
1137 ao_config_dirty = 0;
1140 ao_mutex_put(&ao_config_mutex);
1144 puts("Nothing to save");
1148 const struct ao_cmds ao_config_cmds[] = {
1149 { ao_config_set, "c <var> <value>\0Set config (? for help, s to show)" },
1154 ao_config_init(void)
1156 ao_cmd_register(&ao_config_cmds[0]);