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));
89 #if HAS_FLIGHT && HAS_LOG
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();
373 ao_config_main_deploy_show(void)
375 printf("Main deploy: %d meters\n",
376 ao_config.main_deploy);
380 ao_config_main_deploy_set(void)
382 uint32_t r = ao_cmd_decimal();
383 if (ao_cmd_status != ao_cmd_success)
385 _ao_config_edit_start();
386 ao_config.main_deploy = r;
387 _ao_config_edit_finish();
394 ao_config_accel_calibrate_show(void)
396 printf("Accel cal +1g: %d -1g: %d\n",
397 ao_config.accel_plus_g, ao_config.accel_minus_g);
399 printf ("IMU cal along %d across %d through %d\n",
400 ao_config.accel_zero_along,
401 ao_config.accel_zero_across,
402 ao_config.accel_zero_through);
406 #define ACCEL_CALIBRATE_SAMPLES 1024
407 #define ACCEL_CALIBRATE_SHIFT 10
410 static int16_t accel_cal_along;
411 static int16_t accel_cal_across;
412 static int16_t accel_cal_through;
416 ao_config_accel_calibrate_auto(char *orientation)
420 uint8_t cal_data_ring;
422 int32_t accel_along_total = 0;
423 int32_t accel_across_total = 0;
424 int32_t accel_through_total = 0;
427 printf("Orient antenna %s and press a key...", orientation);
430 puts("\r\n"); flush();
431 puts("Calibrating..."); flush();
432 i = ACCEL_CALIBRATE_SAMPLES;
434 cal_data_ring = ao_sample_data;
436 ao_sleep(&ao_sample_data);
437 while (i && cal_data_ring != ao_sample_data) {
438 accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
440 accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]);
441 accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]);
442 accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]);
444 cal_data_ring = ao_data_ring_next(cal_data_ring);
449 accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT;
450 accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT;
451 accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT;
453 return accel_total >> ACCEL_CALIBRATE_SHIFT;
457 ao_config_accel_calibrate_set(void)
462 int16_t accel_along_up = 0, accel_along_down = 0;
463 int16_t accel_across_up = 0, accel_across_down = 0;
464 int16_t accel_through_up = 0, accel_through_down = 0;
467 r = ao_cmd_decimal();
468 if (ao_cmd_status != ao_cmd_success)
471 up = ao_config_accel_calibrate_auto("up");
473 accel_along_up = accel_cal_along;
474 accel_across_up = accel_cal_across;
475 accel_through_up = accel_cal_through;
477 down = ao_config_accel_calibrate_auto("down");
479 accel_along_down = accel_cal_along;
480 accel_across_down = accel_cal_across;
481 accel_through_down = accel_cal_through;
485 r = ao_cmd_decimal();
486 if (ao_cmd_status != ao_cmd_success)
491 printf("Invalid accel: up (%d) down (%d)\n",
495 _ao_config_edit_start();
496 ao_config.accel_plus_g = up;
497 ao_config.accel_minus_g = down;
500 ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2;
501 ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2;
502 ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2;
505 _ao_config_edit_finish();
507 #endif /* HAS_ACCEL */
511 ao_config_apogee_delay_show(void)
513 printf("Apogee delay: %d seconds\n",
514 ao_config.apogee_delay);
518 ao_config_apogee_delay_set(void)
520 uint32_t r = ao_cmd_decimal();
521 if (ao_cmd_status != ao_cmd_success)
523 _ao_config_edit_start();
524 ao_config.apogee_delay = r;
525 _ao_config_edit_finish();
529 ao_config_apogee_lockout_show(void)
531 printf ("Apogee lockout: %d seconds\n",
532 ao_config.apogee_lockout);
536 ao_config_apogee_lockout_set(void)
538 uint16_t r = ao_cmd_decimal();
539 if (ao_cmd_status != ao_cmd_success)
541 _ao_config_edit_start();
542 ao_config.apogee_lockout = r;
543 _ao_config_edit_finish();
547 #endif /* HAS_FLIGHT */
551 ao_config_radio_cal_show(void)
553 printf("Radio cal: %ld\n", ao_config.radio_cal);
557 ao_config_radio_cal_set(void)
559 uint32_t r = ao_cmd_decimal();
560 if (ao_cmd_status != ao_cmd_success)
562 _ao_config_edit_start();
563 ao_config.radio_cal = r;
564 ao_config_set_radio();
565 _ao_config_edit_finish();
571 #ifndef HAS_TELEMETRY
572 #error Please define HAS_TELEMETRY
576 ao_config_radio_rate_show(void)
578 printf("Telemetry rate: %d\n", ao_config.radio_rate);
582 ao_config_radio_rate_set(void)
584 uint16_t r = ao_cmd_decimal();
585 if (ao_cmd_status != ao_cmd_success)
587 if (AO_RADIO_RATE_MAX < r) {
588 ao_cmd_status = ao_cmd_lex_error;
591 _ao_config_edit_start();
592 ao_config.radio_rate = r;
593 _ao_config_edit_finish();
595 ao_telemetry_reset_interval();
598 ao_radio_recv_abort();
606 ao_config_log_show(void)
608 printf("Max flight log: %d kB\n", (int16_t) (ao_config.flight_log_max >> 10));
609 #if FLIGHT_LOG_APPEND
610 printf("Log fixed: 1\n");
614 #if FLIGHT_LOG_APPEND && HAS_CONFIG_SAVE
616 ao_config_log_fix_append(void)
618 _ao_config_edit_start();
619 ao_config.flight_log_max = ao_storage_log_max;
620 _ao_config_edit_finish();
621 ao_mutex_get(&ao_config_mutex);
624 ao_mutex_put(&ao_config_mutex);
629 ao_config_log_set(void)
631 #if FLIGHT_LOG_APPEND
632 printf("Flight log fixed size %u kB\n", (unsigned) (ao_storage_log_max >> 10));
636 r = ao_cmd_decimal();
637 if (ao_cmd_status != ao_cmd_success)
640 if (ao_log_present()) {
641 if (r != ao_config.flight_log_max)
642 printf("Storage must be empty before changing log size\n");
645 if (r > ao_storage_log_max) {
646 printf("Flight log max %u kB\n", (unsigned) (ao_storage_log_max >> 10));
649 _ao_config_edit_start();
650 ao_config.flight_log_max = r & ~(ao_storage_block - 1);
651 _ao_config_edit_finish();
658 ao_config_ignite_mode_show(void)
660 printf("Ignite mode: %d\n", ao_config.ignite_mode);
664 ao_config_ignite_mode_set(void)
666 uint16_t r = ao_cmd_decimal();
667 if (ao_cmd_status != ao_cmd_success)
669 _ao_config_edit_start();
670 ao_config.ignite_mode = r;
671 _ao_config_edit_finish();
677 ao_config_pad_orientation_show(void)
679 printf("Pad orientation: %d\n", ao_config.pad_orientation);
683 ao_config_pad_orientation_set(void)
685 uint16_t r = ao_cmd_decimal() & 1;
686 if (ao_cmd_status != ao_cmd_success)
688 _ao_config_edit_start();
689 if (ao_config.pad_orientation != r) {
691 t = ao_config.accel_plus_g;
692 ao_config.accel_plus_g = ao_data_accel_invert(ao_config.accel_minus_g);
693 ao_config.accel_minus_g = ao_data_accel_invert(t);
695 ao_config.pad_orientation = r;
696 _ao_config_edit_finish();
702 ao_config_radio_enable_show(void)
704 printf("Radio enable: %d\n", ao_config.radio_enable);
708 ao_config_radio_enable_set(void)
710 uint16_t r = ao_cmd_decimal();
711 if (ao_cmd_status != ao_cmd_success)
713 _ao_config_edit_start();
714 ao_config.radio_enable = r;
715 _ao_config_edit_finish();
716 #if HAS_TELEMETRY && HAS_RADIO_RATE
717 ao_telemetry_reset_interval();
720 #endif /* HAS_RADIO */
724 uint8_t ao_config_aes_seq = 1;
727 ao_config_key_show(void)
731 for (i = 0; i < AO_AES_LEN; i++)
732 printf ("%02x", ao_config.aes_key[i]);
737 ao_config_key_set(void)
741 _ao_config_edit_start();
742 for (i = 0; i < AO_AES_LEN; i++) {
743 uint8_t b = ao_cmd_hexbyte();
744 if (ao_cmd_status != ao_cmd_success)
746 ao_config.aes_key[i] = b;
749 _ao_config_edit_finish();
756 ao_config_aprs_show(void)
758 printf ("APRS interval: %d\n", ao_config.aprs_interval);
762 ao_config_aprs_set(void)
764 uint16_t r = ao_cmd_decimal();
765 if (ao_cmd_status != ao_cmd_success)
767 _ao_config_edit_start();
768 ao_config.aprs_interval = r;
769 _ao_config_edit_finish();
770 ao_telemetry_reset_interval();
774 ao_config_aprs_offset_show(void)
776 printf ("APRS offset: %d\n", ao_config.aprs_offset);
780 ao_config_aprs_offset_set(void)
782 uint16_t r = ao_cmd_decimal();
783 if (ao_cmd_status != ao_cmd_success)
785 _ao_config_edit_start();
786 ao_config.aprs_offset = r;
787 _ao_config_edit_finish();
788 ao_telemetry_reset_interval();
791 #endif /* HAS_APRS */
796 ao_config_radio_amp_show(void)
798 printf ("Radio amp setting: %d\n", ao_config.radio_amp);
802 ao_config_radio_amp_set(void)
804 uint16_t r = ao_cmd_decimal();
805 if (ao_cmd_status != ao_cmd_success)
807 _ao_config_edit_start();
808 ao_config.radio_amp = r;
809 _ao_config_edit_finish();
817 ao_config_radio_power_show(void)
819 printf ("Radio power setting: %d\n", ao_config.radio_power);
823 ao_config_radio_power_set(void)
825 uint16_t r = ao_cmd_decimal();
826 if (ao_cmd_status != ao_cmd_success)
828 _ao_config_edit_start();
829 ao_config.radio_power = r;
830 _ao_config_edit_finish();
837 ao_config_beep_show(void)
839 printf ("Beeper setting: %d\n", ao_config.mid_beep);
843 ao_config_beep_set(void)
845 uint16_t r = ao_cmd_decimal();
846 if (ao_cmd_status != ao_cmd_success)
848 _ao_config_edit_start();
849 ao_config.mid_beep = r;
850 _ao_config_edit_finish();
856 ao_config_tracker_show(void)
858 printf ("Tracker setting: %d %d\n",
859 ao_config.tracker_motion,
860 ao_config.tracker_interval);
864 ao_config_tracker_set(void)
867 m = ao_cmd_decimal();
868 if (ao_cmd_status != ao_cmd_success)
870 i = ao_cmd_decimal();
871 if (ao_cmd_status != ao_cmd_success)
873 _ao_config_edit_start();
874 ao_config.tracker_motion = m;
875 ao_config.tracker_interval = i;
876 _ao_config_edit_finish();
878 ao_telemetry_reset_interval();
881 #endif /* HAS_TRACKER */
885 ao_config_pyro_time_show(void)
887 printf ("Pyro time: %d\n", ao_config.pyro_time);
891 ao_config_pyro_time_set(void)
893 uint16_t r = ao_cmd_decimal();
894 if (ao_cmd_status != ao_cmd_success)
896 _ao_config_edit_start();
897 ao_config.pyro_time = r;
898 _ao_config_edit_finish();
904 ao_config_aprs_ssid_show(void)
906 printf ("APRS SSID: %d\n",
907 ao_config.aprs_ssid);
911 ao_config_aprs_ssid_set(void)
913 uint16_t r = ao_cmd_decimal();
914 if (ao_cmd_status != ao_cmd_success)
917 ao_cmd_status = ao_cmd_lex_error;
920 _ao_config_edit_start();
921 ao_config.aprs_ssid = r;
922 _ao_config_edit_finish();
926 ao_config_aprs_format_set(void)
928 uint16_t r = ao_cmd_decimal();
929 if (ao_cmd_status != ao_cmd_success)
931 _ao_config_edit_start();
932 ao_config.aprs_format = r != 0;
933 _ao_config_edit_finish();
937 ao_config_aprs_format_show(void)
939 printf ("APRS format: %d\n", ao_config.aprs_format);
941 #endif /* HAS_APRS */
943 #if HAS_FIXED_PAD_BOX
945 ao_config_pad_box_show(void)
947 printf ("Pad box: %d\n", ao_config.pad_box);
951 ao_config_pad_box_set(void)
953 uint16_t r = ao_cmd_decimal();
954 if (ao_cmd_status != ao_cmd_success)
956 _ao_config_edit_start();
957 ao_config.pad_box = r;
958 _ao_config_edit_finish();
962 ao_config_pad_idle_show(void)
964 printf ("Idle timeout: %d\n", ao_config.pad_idle);
968 ao_config_pad_idle_set(void)
970 uint16_t r = ao_cmd_decimal();
971 if (ao_cmd_status != ao_cmd_success)
973 _ao_config_edit_start();
974 ao_config.pad_idle = r;
975 _ao_config_edit_finish();
979 struct ao_config_var {
986 ao_config_help(void);
989 ao_config_show(void);
993 ao_config_save(void);
996 const struct ao_config_var ao_config_vars[] = {
997 #if HAS_FLIGHT && HAS_BARO
998 { "m <meters>\0Main deploy (m)",
999 ao_config_main_deploy_set, ao_config_main_deploy_show, },
1000 { "d <delay>\0Apogee delay (s)",
1001 ao_config_apogee_delay_set, ao_config_apogee_delay_show },
1002 { "L <seconds>\0Apogee detect lockout (s)",
1003 ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
1004 #endif /* HAS_FLIGHT */
1006 { "F <freq>\0Frequency (kHz)",
1007 ao_config_frequency_set, ao_config_frequency_show },
1008 #if HAS_RADIO_FORWARD
1009 { "R <freq>\0Repeater output frequency (kHz)",
1010 ao_config_send_frequency_set, ao_config_send_frequency_show },
1012 { "c <call>\0Callsign (8 char max)",
1013 ao_config_callsign_set, ao_config_callsign_show },
1014 { "e <0 disable, 1 enable>\0Enable telemetry and RDF",
1015 ao_config_radio_enable_set, ao_config_radio_enable_show },
1016 { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
1017 ao_config_radio_cal_set, ao_config_radio_cal_show },
1019 { "T <rate>\0Telemetry rate (0=38.4, 1=9.6, 2=2.4)",
1020 ao_config_radio_rate_set, ao_config_radio_rate_show },
1023 { "p <setting>\0Radio power setting (0-255)",
1024 ao_config_radio_power_set, ao_config_radio_power_show },
1027 { "d <setting>\0Radio amplifier setting (0-3)",
1028 ao_config_radio_amp_set, ao_config_radio_amp_show },
1030 #endif /* HAS_RADIO */
1032 { "a <+g> <-g>\0Accel calib (0 for auto)",
1033 ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
1034 { "o <0 antenna up, 1 antenna down>\0Pad orientation",
1035 ao_config_pad_orientation_set,ao_config_pad_orientation_show },
1036 #endif /* HAS_ACCEL */
1038 { "l <size>\0Flight log size (kB)",
1039 ao_config_log_set, ao_config_log_show },
1042 { "i <0 dual, 1 apogee, 2 main, 3 booster>\0Igniter mode",
1043 ao_config_ignite_mode_set, ao_config_ignite_mode_show },
1046 { "k <32 hex digits>\0AES encryption key",
1047 ao_config_key_set, ao_config_key_show },
1050 { "P <n,?>\0Pyro channels",
1051 ao_pyro_set, ao_pyro_show },
1052 { "I <ticks>\0Pyro firing time",
1053 ao_config_pyro_time_set, ao_config_pyro_time_show },
1056 { "A <secs>\0APRS packet interval (0 disable)",
1057 ao_config_aprs_set, ao_config_aprs_show },
1060 { "b <val>\0Beeper tone (freq = 1/2 (24e6/32) / beep",
1061 ao_config_beep_set, ao_config_beep_show },
1064 { "t <motion> <interval>\0Tracker configuration",
1065 ao_config_tracker_set, ao_config_tracker_show },
1068 { "S <ssid>\0Set APRS SSID (0-15)",
1069 ao_config_aprs_ssid_set, ao_config_aprs_ssid_show },
1070 { "C <0 compressed, 1 uncompressed>\0APRS format",
1071 ao_config_aprs_format_set, ao_config_aprs_format_show },
1072 { "O <aprs-offset>\0APRS Offset from top of minute",
1073 ao_config_aprs_offset_set, ao_config_aprs_offset_show },
1075 #if HAS_FIXED_PAD_BOX
1076 { "B <box>\0Set pad box (1-99)",
1077 ao_config_pad_box_set, ao_config_pad_box_show },
1078 { "i <seconds>\0Set idle timeout (0 disable)",
1079 ao_config_pad_idle_set, ao_config_pad_idle_show },
1082 ao_config_show, 0 },
1084 { "w\0Write to eeprom",
1085 ao_config_save, 0 },
1088 ao_config_help, 0 },
1101 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1102 if (ao_config_vars[cmd].str[0] == c) {
1103 (*ao_config_vars[cmd].set)();
1106 ao_cmd_status = ao_cmd_syntax_error;
1110 ao_config_help(void)
1113 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1114 printf("%-20s %s\n",
1115 ao_config_vars[cmd].str,
1116 ao_config_vars[cmd].str+1+
1117 strlen(ao_config_vars[cmd].str));
1121 ao_config_show(void)
1125 printf("Config version: %d.%d\n",
1126 ao_config.major, ao_config.minor);
1127 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1128 if (ao_config_vars[cmd].show)
1129 (*ao_config_vars[cmd].show)();
1137 ao_config_save(void)
1140 ao_mutex_get(&ao_config_mutex);
1141 if (ao_config_dirty) {
1143 ao_config_dirty = 0;
1146 ao_mutex_put(&ao_config_mutex);
1150 puts("Nothing to save");
1154 const struct ao_cmds ao_config_cmds[] = {
1155 { ao_config_set, "c <var> <value>\0Set config (? for help, s to show)" },
1160 ao_config_init(void)
1162 ao_cmd_register(&ao_config_cmds[0]);