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 __xdata struct ao_config ao_config;
34 __pdata uint8_t ao_config_loaded;
35 __pdata uint8_t ao_config_dirty;
36 __xdata uint8_t ao_config_mutex;
39 __xdata uint8_t ao_force_freq;
42 #ifndef AO_CONFIG_DEFAULT_APRS_INTERVAL
43 #define AO_CONFIG_DEFAULT_APRS_INTERVAL 0
45 #define AO_CONFIG_DEFAULT_MAIN_DEPLOY 250
46 #define AO_CONFIG_DEFAULT_RADIO_CHANNEL 0
47 #define AO_CONFIG_DEFAULT_CALLSIGN "N0CALL"
48 #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000
49 #define AO_CONFIG_DEFAULT_APOGEE_DELAY 0
50 #define AO_CONFIG_DEFAULT_IGNITE_MODE AO_IGNITE_MODE_DUAL
51 #define AO_CONFIG_DEFAULT_PAD_ORIENTATION AO_PAD_ORIENTATION_ANTENNA_UP
52 #define AO_CONFIG_DEFAULT_PYRO_TIME AO_MS_TO_TICKS(50)
54 #ifndef USE_INTERNAL_FLASH
55 #error Please define USE_INTERNAL_FLASH
59 #ifndef AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX
60 # if FLIGHT_LOG_APPEND
61 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_log_max
63 # if USE_INTERNAL_FLASH
64 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config
66 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024)
71 #ifndef AO_CONFIG_DEFAULT_RADIO_POWER
72 #define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
74 #define AO_CONFIG_DEFAULT_RADIO_AMP 0
75 #define AO_CONFIG_DEFAULT_APRS_SSID (ao_serial_number % 10)
76 #define AO_CONFIG_DEFAULT_RADIO_RATE AO_RADIO_RATE_38400
84 ao_config_write(0, &ao_config, sizeof (ao_config));
86 ao_log_write_erase(0);
94 ao_mutex_get(&ao_config_mutex);
96 ao_mutex_put(&ao_config_mutex);
102 #if HAS_RADIO_FORWARD
103 __xdata uint32_t ao_send_radio_setting;
107 ao_config_set_radio(void)
109 ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
110 #if HAS_RADIO_FORWARD
111 ao_send_radio_setting = ao_freq_to_set(ao_config.send_frequency, ao_config.radio_cal);
114 #endif /* HAS_RADIO */
121 if (ao_config_loaded)
124 /* Yes, I know ao_storage_read calls ao_storage_setup,
125 * but ao_storage_setup *also* sets ao_storage_config, which we
126 * need before calling ao_storage_read here
129 ao_config_read(0, &ao_config, sizeof (ao_config));
131 if (ao_config.major != AO_CONFIG_MAJOR) {
132 ao_config.major = AO_CONFIG_MAJOR;
135 /* Version 0 stuff */
136 ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
137 ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
138 ao_xmemcpy(&ao_config.callsign, CODE_TO_XDATA(AO_CONFIG_DEFAULT_CALLSIGN),
139 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
140 ao_config._legacy_radio_channel = 0;
142 minor = ao_config.minor;
143 if (minor != AO_CONFIG_MINOR) {
144 /* Fixups for minor version 1 */
146 ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
147 /* Fixups for minor version 2 */
149 ao_config.accel_plus_g = 0;
150 ao_config.accel_minus_g = 0;
152 /* Fixups for minor version 3 */
155 ao_config.radio_cal = ao_radio_cal;
157 /* Fixups for minor version 4 */
160 ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
162 /* Fixupes for minor version 5 */
164 ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
166 ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
168 ao_config.radio_enable = AO_RADIO_ENABLE_CORE;
170 ao_xmemset(&ao_config.aes_key, '\0', AO_AES_LEN);
172 ao_config.frequency = 434550 + ao_config._legacy_radio_channel * 100;
174 ao_config.apogee_lockout = 0;
177 memset(&ao_config.pyro, '\0', sizeof (ao_config.pyro));
180 ao_config.aprs_interval = AO_CONFIG_DEFAULT_APRS_INTERVAL;
183 ao_config.radio_power = AO_CONFIG_DEFAULT_RADIO_POWER;
187 ao_config.radio_amp = AO_CONFIG_DEFAULT_RADIO_AMP;
191 ao_config.accel_zero_along = 0;
192 ao_config.accel_zero_across = 0;
193 ao_config.accel_zero_through = 0;
195 /* Reset the main accel offsets to force
198 ao_config.accel_plus_g = 0;
199 ao_config.accel_minus_g = 0;
204 ao_config.mid_beep = AO_BEEP_MID_DEFAULT;
208 ao_config.tracker_motion = AO_TRACKER_MOTION_DEFAULT;
209 ao_config.tracker_interval = AO_TRACKER_INTERVAL_DEFAULT;
214 ao_config.pyro_time = AO_CONFIG_DEFAULT_PYRO_TIME;
218 ao_config.aprs_ssid = AO_CONFIG_DEFAULT_APRS_SSID;
222 ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
224 #if HAS_RADIO_FORWARD
226 ao_config.send_frequency = 434550;
230 ao_config.aprs_format = AO_CONFIG_DEFAULT_APRS_FORMAT;
232 #if HAS_FIXED_PAD_BOX
234 ao_config.pad_box = 1;
236 ao_config.pad_idle = 120;
238 ao_config.minor = AO_CONFIG_MINOR;
244 ao_config.frequency = 434550;
245 ao_config.radio_cal = ao_radio_cal;
246 ao_xmemcpy(&ao_config.callsign, CODE_TO_XDATA(AO_CONFIG_DEFAULT_CALLSIGN),
247 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
250 ao_config_set_radio();
252 ao_config_loaded = 1;
256 _ao_config_edit_start(void)
258 ao_mutex_get(&ao_config_mutex);
263 _ao_config_edit_finish(void)
266 ao_mutex_put(&ao_config_mutex);
272 _ao_config_edit_start();
273 ao_mutex_put(&ao_config_mutex);
277 ao_config_callsign_show(void)
279 printf ("Callsign: \"%s\"\n", ao_config.callsign);
283 ao_config_callsign_set(void) __reentrant
286 static __xdata char callsign[AO_MAX_CALLSIGN + 1];
288 ao_xmemset(callsign, '\0', sizeof callsign);
291 while (ao_cmd_lex_c != '\n') {
292 if (c < AO_MAX_CALLSIGN)
293 callsign[c++] = ao_cmd_lex_c;
295 ao_cmd_status = ao_cmd_lex_error;
298 if (ao_cmd_status != ao_cmd_success)
300 _ao_config_edit_start();
301 ao_xmemcpy(&ao_config.callsign, &callsign,
302 AO_MAX_CALLSIGN + 1);
303 _ao_config_edit_finish();
309 ao_config_frequency_show(void) __reentrant
311 printf("Frequency: %ld\n",
312 ao_config.frequency);
316 ao_config_frequency_set(void) __reentrant
319 if (ao_cmd_status != ao_cmd_success)
321 _ao_config_edit_start();
322 ao_config.frequency = ao_cmd_lex_u32;
323 ao_config_set_radio();
324 _ao_config_edit_finish();
326 ao_radio_recv_abort();
332 #if HAS_RADIO_FORWARD
334 ao_config_send_frequency_show(void) __reentrant
336 printf("Send frequency: %ld\n",
337 ao_config.send_frequency);
341 ao_config_send_frequency_set(void) __reentrant
344 if (ao_cmd_status != ao_cmd_success)
346 _ao_config_edit_start();
347 ao_config.send_frequency = ao_cmd_lex_u32;
348 ao_config_set_radio();
349 _ao_config_edit_finish();
351 ao_radio_recv_abort();
360 ao_config_main_deploy_show(void) __reentrant
362 printf("Main deploy: %d meters\n",
363 ao_config.main_deploy);
367 ao_config_main_deploy_set(void) __reentrant
370 if (ao_cmd_status != ao_cmd_success)
372 _ao_config_edit_start();
373 ao_config.main_deploy = ao_cmd_lex_i;
374 _ao_config_edit_finish();
379 ao_config_accel_calibrate_show(void) __reentrant
381 printf("Accel cal +1g: %d -1g: %d\n",
382 ao_config.accel_plus_g, ao_config.accel_minus_g);
384 printf ("IMU cal along %d across %d through %d\n",
385 ao_config.accel_zero_along,
386 ao_config.accel_zero_across,
387 ao_config.accel_zero_through);
391 #define ACCEL_CALIBRATE_SAMPLES 1024
392 #define ACCEL_CALIBRATE_SHIFT 10
395 static int16_t accel_cal_along;
396 static int16_t accel_cal_across;
397 static int16_t accel_cal_through;
401 ao_config_accel_calibrate_auto(char *orientation) __reentrant
405 uint8_t cal_data_ring;
407 int32_t accel_along_total = 0;
408 int32_t accel_across_total = 0;
409 int32_t accel_through_total = 0;
412 printf("Orient antenna %s and press a key...", orientation);
415 puts("\r\n"); flush();
416 puts("Calibrating..."); flush();
417 i = ACCEL_CALIBRATE_SAMPLES;
419 cal_data_ring = ao_sample_data;
421 ao_sleep(DATA_TO_XDATA(&ao_sample_data));
422 while (i && cal_data_ring != ao_sample_data) {
423 accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
425 accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]);
426 accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]);
427 accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]);
429 cal_data_ring = ao_data_ring_next(cal_data_ring);
434 accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT;
435 accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT;
436 accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT;
438 return accel_total >> ACCEL_CALIBRATE_SHIFT;
442 ao_config_accel_calibrate_set(void) __reentrant
446 int16_t accel_along_up = 0, accel_along_down = 0;
447 int16_t accel_across_up = 0, accel_across_down = 0;
448 int16_t accel_through_up = 0, accel_through_down = 0;
452 if (ao_cmd_status != ao_cmd_success)
454 if (ao_cmd_lex_i == 0) {
455 up = ao_config_accel_calibrate_auto("up");
457 accel_along_up = accel_cal_along;
458 accel_across_up = accel_cal_across;
459 accel_through_up = accel_cal_through;
461 down = ao_config_accel_calibrate_auto("down");
463 accel_along_down = accel_cal_along;
464 accel_across_down = accel_cal_across;
465 accel_through_down = accel_cal_through;
470 if (ao_cmd_status != ao_cmd_success)
475 printf("Invalid accel: up (%d) down (%d)\n",
479 _ao_config_edit_start();
480 ao_config.accel_plus_g = up;
481 ao_config.accel_minus_g = down;
483 if (ao_cmd_lex_i == 0) {
484 ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2;
485 ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2;
486 ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2;
489 _ao_config_edit_finish();
491 #endif /* HAS_ACCEL */
494 ao_config_apogee_delay_show(void) __reentrant
496 printf("Apogee delay: %d seconds\n",
497 ao_config.apogee_delay);
501 ao_config_apogee_delay_set(void) __reentrant
504 if (ao_cmd_status != ao_cmd_success)
506 _ao_config_edit_start();
507 ao_config.apogee_delay = ao_cmd_lex_i;
508 _ao_config_edit_finish();
512 ao_config_apogee_lockout_show(void) __reentrant
514 printf ("Apogee lockout: %d seconds\n",
515 ao_config.apogee_lockout);
519 ao_config_apogee_lockout_set(void) __reentrant
522 if (ao_cmd_status != ao_cmd_success)
524 _ao_config_edit_start();
525 ao_config.apogee_lockout = ao_cmd_lex_i;
526 _ao_config_edit_finish();
529 #endif /* HAS_FLIGHT */
533 ao_config_radio_cal_show(void) __reentrant
535 printf("Radio cal: %ld\n", ao_config.radio_cal);
539 ao_config_radio_cal_set(void) __reentrant
542 if (ao_cmd_status != ao_cmd_success)
544 _ao_config_edit_start();
545 ao_config.radio_cal = ao_cmd_lex_u32;
546 ao_config_set_radio();
547 _ao_config_edit_finish();
553 #ifndef HAS_TELEMETRY
554 #error Please define HAS_TELEMETRY
558 ao_config_radio_rate_show(void) __reentrant
560 printf("Telemetry rate: %d\n", ao_config.radio_rate);
564 ao_config_radio_rate_set(void) __reentrant
567 if (ao_cmd_status != ao_cmd_success)
569 if (AO_RADIO_RATE_MAX < ao_cmd_lex_i) {
570 ao_cmd_status = ao_cmd_lex_error;
573 _ao_config_edit_start();
574 ao_config.radio_rate = ao_cmd_lex_i;
575 _ao_config_edit_finish();
577 ao_telemetry_reset_interval();
580 ao_radio_recv_abort();
588 ao_config_log_show(void) __reentrant
590 printf("Max flight log: %d kB\n", (int16_t) (ao_config.flight_log_max >> 10));
591 #if FLIGHT_LOG_APPEND
592 printf("Log fixed: 1\n");
596 #if FLIGHT_LOG_APPEND
598 ao_config_log_fix_append(void)
600 _ao_config_edit_start();
601 ao_config.flight_log_max = ao_storage_log_max;
602 _ao_config_edit_finish();
603 ao_mutex_get(&ao_config_mutex);
606 ao_mutex_put(&ao_config_mutex);
611 ao_config_log_set(void) __reentrant
613 #if FLIGHT_LOG_APPEND
614 printf("Flight log fixed size %d kB\n", ao_storage_log_max >> 10);
616 uint16_t block = (uint16_t) (ao_storage_block >> 10);
617 uint16_t log_max = (uint16_t) (ao_storage_log_max >> 10);
620 if (ao_cmd_status != ao_cmd_success)
622 if (ao_log_present())
623 printf("Storage must be empty before changing log size\n");
624 else if (block > 1024 && (ao_cmd_lex_i & (block - 1)))
625 printf("Flight log size must be multiple of %d kB\n", block);
626 else if (ao_cmd_lex_i > log_max)
627 printf("Flight log max %d kB\n", log_max);
629 _ao_config_edit_start();
630 ao_config.flight_log_max = (uint32_t) ao_cmd_lex_i << 10;
631 _ao_config_edit_finish();
639 ao_config_ignite_mode_show(void) __reentrant
641 printf("Ignite mode: %d\n", ao_config.ignite_mode);
645 ao_config_ignite_mode_set(void) __reentrant
648 if (ao_cmd_status != ao_cmd_success)
650 _ao_config_edit_start();
651 ao_config.ignite_mode = ao_cmd_lex_i;
652 _ao_config_edit_finish();
658 ao_config_pad_orientation_show(void) __reentrant
660 printf("Pad orientation: %d\n", ao_config.pad_orientation);
663 #ifndef AO_ACCEL_INVERT
664 #define AO_ACCEL_INVERT 0x7fff
668 ao_config_pad_orientation_set(void) __reentrant
671 if (ao_cmd_status != ao_cmd_success)
673 _ao_config_edit_start();
675 if (ao_config.pad_orientation != ao_cmd_lex_i) {
677 t = ao_config.accel_plus_g;
678 ao_config.accel_plus_g = AO_ACCEL_INVERT - ao_config.accel_minus_g;
679 ao_config.accel_minus_g = AO_ACCEL_INVERT - t;
681 ao_config.pad_orientation = ao_cmd_lex_i;
682 _ao_config_edit_finish();
688 ao_config_radio_enable_show(void) __reentrant
690 printf("Radio enable: %d\n", ao_config.radio_enable);
694 ao_config_radio_enable_set(void) __reentrant
697 if (ao_cmd_status != ao_cmd_success)
699 _ao_config_edit_start();
700 ao_config.radio_enable = ao_cmd_lex_i;
701 _ao_config_edit_finish();
702 #if HAS_TELEMETRY && HAS_RADIO_RATE
703 ao_telemetry_reset_interval();
706 #endif /* HAS_RADIO */
710 __xdata uint8_t ao_config_aes_seq = 1;
713 ao_config_key_show(void) __reentrant
717 for (i = 0; i < AO_AES_LEN; i++)
718 printf ("%02x", ao_config.aes_key[i]);
723 ao_config_key_set(void) __reentrant
727 _ao_config_edit_start();
728 for (i = 0; i < AO_AES_LEN; i++) {
730 if (ao_cmd_status != ao_cmd_success)
732 ao_config.aes_key[i] = ao_cmd_lex_i;
735 _ao_config_edit_finish();
742 ao_config_aprs_show(void)
744 printf ("APRS interval: %d\n", ao_config.aprs_interval);
748 ao_config_aprs_set(void)
751 if (ao_cmd_status != ao_cmd_success)
753 _ao_config_edit_start();
754 ao_config.aprs_interval = ao_cmd_lex_i;
755 _ao_config_edit_finish();
756 ao_telemetry_reset_interval();
759 #endif /* HAS_APRS */
764 ao_config_radio_amp_show(void)
766 printf ("Radio amp setting: %d\n", ao_config.radio_amp);
770 ao_config_radio_amp_set(void)
773 if (ao_cmd_status != ao_cmd_success)
775 _ao_config_edit_start();
776 ao_config.radio_amp = ao_cmd_lex_i;
777 _ao_config_edit_finish();
785 ao_config_radio_power_show(void)
787 printf ("Radio power setting: %d\n", ao_config.radio_power);
791 ao_config_radio_power_set(void)
794 if (ao_cmd_status != ao_cmd_success)
796 _ao_config_edit_start();
797 ao_config.radio_power = ao_cmd_lex_i;
798 _ao_config_edit_finish();
805 ao_config_beep_show(void)
807 printf ("Beeper setting: %d\n", ao_config.mid_beep);
811 ao_config_beep_set(void)
814 if (ao_cmd_status != ao_cmd_success)
816 _ao_config_edit_start();
817 ao_config.mid_beep = ao_cmd_lex_i;
818 _ao_config_edit_finish();
824 ao_config_tracker_show(void)
826 printf ("Tracker setting: %d %d\n",
827 ao_config.tracker_motion,
828 ao_config.tracker_interval);
832 ao_config_tracker_set(void)
836 if (ao_cmd_status != ao_cmd_success)
840 if (ao_cmd_status != ao_cmd_success)
843 _ao_config_edit_start();
844 ao_config.tracker_motion = m;
845 ao_config.tracker_interval = i;
846 _ao_config_edit_finish();
848 ao_telemetry_reset_interval();
851 #endif /* HAS_TRACKER */
855 ao_config_pyro_time_show(void)
857 printf ("Pyro time: %d\n", ao_config.pyro_time);
861 ao_config_pyro_time_set(void)
864 if (ao_cmd_status != ao_cmd_success)
866 _ao_config_edit_start();
867 ao_config.pyro_time = ao_cmd_lex_i;
868 _ao_config_edit_finish();
874 ao_config_aprs_ssid_show(void)
876 printf ("APRS SSID: %d\n",
877 ao_config.aprs_ssid);
881 ao_config_aprs_ssid_set(void)
884 if (ao_cmd_status != ao_cmd_success)
886 if (15 < ao_cmd_lex_i) {
887 ao_cmd_status = ao_cmd_lex_error;
890 _ao_config_edit_start();
891 ao_config.aprs_ssid = ao_cmd_lex_i;
892 _ao_config_edit_finish();
896 ao_config_aprs_format_set(void)
899 if (ao_cmd_status != ao_cmd_success)
901 _ao_config_edit_start();
902 ao_config.aprs_format = ao_cmd_lex_i != 0;
903 _ao_config_edit_finish();
907 ao_config_aprs_format_show(void)
909 printf ("APRS format: %d\n", ao_config.aprs_format);
911 #endif /* HAS_APRS */
913 #if HAS_FIXED_PAD_BOX
915 ao_config_pad_box_show(void)
917 printf ("Pad box: %d\n", ao_config.pad_box);
921 ao_config_pad_box_set(void)
924 if (ao_cmd_status != ao_cmd_success)
926 _ao_config_edit_start();
927 ao_config.pad_box = ao_cmd_lex_i;
928 _ao_config_edit_finish();
932 ao_config_pad_idle_show(void)
934 printf ("Idle timeout: %d\n", ao_config.pad_idle);
938 ao_config_pad_idle_set(void)
941 if (ao_cmd_status != ao_cmd_success)
943 _ao_config_edit_start();
944 ao_config.pad_idle = ao_cmd_lex_i;
945 _ao_config_edit_finish();
949 struct ao_config_var {
951 void (*set)(void) __reentrant;
952 void (*show)(void) __reentrant;
956 ao_config_help(void) __reentrant;
959 ao_config_show(void) __reentrant;
963 ao_config_save(void) __reentrant;
966 __code struct ao_config_var ao_config_vars[] = {
968 { "m <meters>\0Main deploy (m)",
969 ao_config_main_deploy_set, ao_config_main_deploy_show, },
970 { "d <delay>\0Apogee delay (s)",
971 ao_config_apogee_delay_set, ao_config_apogee_delay_show },
972 { "L <seconds>\0Apogee detect lockout (s)",
973 ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
974 #endif /* HAS_FLIGHT */
976 { "F <freq>\0Frequency (kHz)",
977 ao_config_frequency_set, ao_config_frequency_show },
978 #if HAS_RADIO_FORWARD
979 { "R <freq>\0Repeater output frequency (kHz)",
980 ao_config_send_frequency_set, ao_config_send_frequency_show },
982 { "c <call>\0Callsign (8 char max)",
983 ao_config_callsign_set, ao_config_callsign_show },
984 { "e <0 disable, 1 enable>\0Enable telemetry and RDF",
985 ao_config_radio_enable_set, ao_config_radio_enable_show },
986 { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
987 ao_config_radio_cal_set, ao_config_radio_cal_show },
989 { "T <rate>\0Telemetry rate (0=38.4, 1=9.6, 2=2.4)",
990 ao_config_radio_rate_set, ao_config_radio_rate_show },
993 { "p <setting>\0Radio power setting (0-255)",
994 ao_config_radio_power_set, ao_config_radio_power_show },
997 { "d <setting>\0Radio amplifier setting (0-3)",
998 ao_config_radio_amp_set, ao_config_radio_amp_show },
1000 #endif /* HAS_RADIO */
1002 { "a <+g> <-g>\0Accel calib (0 for auto)",
1003 ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
1004 { "o <0 antenna up, 1 antenna down>\0Pad orientation",
1005 ao_config_pad_orientation_set,ao_config_pad_orientation_show },
1006 #endif /* HAS_ACCEL */
1008 { "l <size>\0Flight log size (kB)",
1009 ao_config_log_set, ao_config_log_show },
1012 { "i <0 dual, 1 apogee, 2 main>\0Igniter mode",
1013 ao_config_ignite_mode_set, ao_config_ignite_mode_show },
1016 { "k <32 hex digits>\0AES encryption key",
1017 ao_config_key_set, ao_config_key_show },
1020 { "P <n,?>\0Pyro channels",
1021 ao_pyro_set, ao_pyro_show },
1022 { "I <ticks>\0Pyro firing time",
1023 ao_config_pyro_time_set, ao_config_pyro_time_show },
1026 { "A <secs>\0APRS packet interval (0 disable)",
1027 ao_config_aprs_set, ao_config_aprs_show },
1030 { "b <val>\0Beeper tone (freq = 1/2 (24e6/32) / beep",
1031 ao_config_beep_set, ao_config_beep_show },
1034 { "t <motion> <interval>\0Tracker configuration",
1035 ao_config_tracker_set, ao_config_tracker_show },
1038 { "S <ssid>\0Set APRS SSID (0-15)",
1039 ao_config_aprs_ssid_set, ao_config_aprs_ssid_show },
1040 { "C <0 compressed, 1 uncompressed>\0APRS format",
1041 ao_config_aprs_format_set, ao_config_aprs_format_show },
1043 #if HAS_FIXED_PAD_BOX
1044 { "B <box>\0Set pad box (1-99)",
1045 ao_config_pad_box_set, ao_config_pad_box_show },
1046 { "i <seconds>\0Set idle timeout (0 disable)",
1047 ao_config_pad_idle_set, ao_config_pad_idle_show },
1050 ao_config_show, 0 },
1052 { "w\0Write to eeprom",
1053 ao_config_save, 0 },
1056 ao_config_help, 0 },
1069 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1070 if (ao_config_vars[cmd].str[0] == c) {
1071 (*ao_config_vars[cmd].set)();
1074 ao_cmd_status = ao_cmd_syntax_error;
1078 ao_config_help(void) __reentrant
1081 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1082 printf("%-20s %s\n",
1083 ao_config_vars[cmd].str,
1084 ao_config_vars[cmd].str+1+
1085 strlen(ao_config_vars[cmd].str));
1089 ao_config_show(void) __reentrant
1093 printf("Config version: %d.%d\n",
1094 ao_config.major, ao_config.minor);
1095 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1096 if (ao_config_vars[cmd].show)
1097 (*ao_config_vars[cmd].show)();
1105 ao_config_save(void) __reentrant
1108 ao_mutex_get(&ao_config_mutex);
1109 if (ao_config_dirty) {
1111 ao_config_dirty = 0;
1114 ao_mutex_put(&ao_config_mutex);
1118 puts("Nothing to save");
1122 __code struct ao_cmds ao_config_cmds[] = {
1123 { ao_config_set, "c <var> <value>\0Set config (? for help, s to show)" },
1128 ao_config_init(void)
1130 ao_cmd_register(&ao_config_cmds[0]);