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)
57 #define AO_CONFIG_DEFAULT_RADIO_10MW 0
59 #ifndef USE_INTERNAL_FLASH
60 #error Please define USE_INTERNAL_FLASH
64 #ifndef AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX
65 # if FLIGHT_LOG_APPEND
66 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_log_max
68 # if USE_INTERNAL_FLASH
69 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config
71 # define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024)
76 #ifndef AO_CONFIG_DEFAULT_RADIO_POWER
77 #define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
79 #define AO_CONFIG_DEFAULT_RADIO_AMP 0
80 #define AO_CONFIG_DEFAULT_APRS_SSID ((uint8_t) (ao_serial_number % 10))
81 #define AO_CONFIG_DEFAULT_RADIO_RATE AO_RADIO_RATE_38400
89 ao_config_write(0, &ao_config, sizeof (ao_config));
90 #if HAS_FLIGHT && HAS_LOG
91 ao_log_write_erase(0);
99 ao_mutex_get(&ao_config_mutex);
101 ao_mutex_put(&ao_config_mutex);
107 #if HAS_RADIO_FORWARD
108 uint32_t ao_send_radio_setting;
112 ao_config_set_radio(void)
114 ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
115 #if HAS_RADIO_FORWARD
116 ao_send_radio_setting = ao_freq_to_set(ao_config.send_frequency, ao_config.radio_cal);
119 #endif /* HAS_RADIO */
126 if (ao_config_loaded)
129 /* Yes, I know ao_storage_read calls ao_storage_setup,
130 * but ao_storage_setup *also* sets ao_storage_config, which we
131 * need before calling ao_storage_read here
134 ao_config_read(0, &ao_config, sizeof (ao_config));
136 if (ao_config.major != AO_CONFIG_MAJOR) {
137 ao_config.major = AO_CONFIG_MAJOR;
140 /* Version 0 stuff */
141 ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
142 memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
143 memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
144 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
145 ao_config._legacy_radio_channel = 0;
147 minor = ao_config.minor;
148 if (minor != AO_CONFIG_MINOR) {
150 ao_pyro_update_version();
152 /* Fixups for minor version 1 */
154 ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
155 /* Fixups for minor version 2 */
157 ao_config.accel_plus_g = 0;
158 ao_config.accel_minus_g = 0;
160 /* Fixups for minor version 3 */
163 ao_config.radio_cal = ao_radio_cal;
165 /* Fixups for minor version 4 */
168 ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
170 /* Fixupes for minor version 5 */
172 ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
174 ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
176 ao_config.radio_enable = AO_RADIO_ENABLE_CORE;
178 memset(&ao_config.aes_key, '\0', AO_AES_LEN);
180 ao_config.frequency = 434550U + ao_config._legacy_radio_channel * 100U;
182 ao_config.apogee_lockout = 0;
185 memset(&ao_config.pyro, '\0', sizeof (ao_config.pyro));
188 ao_config.aprs_interval = AO_CONFIG_DEFAULT_APRS_INTERVAL;
191 ao_config.radio_power = AO_CONFIG_DEFAULT_RADIO_POWER;
195 ao_config.radio_amp = AO_CONFIG_DEFAULT_RADIO_AMP;
199 ao_config.accel_zero_along = 0;
200 ao_config.accel_zero_across = 0;
201 ao_config.accel_zero_through = 0;
203 /* Reset the main accel offsets to force
206 ao_config.accel_plus_g = 0;
207 ao_config.accel_minus_g = 0;
212 ao_config.mid_beep = AO_BEEP_MID_DEFAULT;
216 ao_config.tracker_motion = AO_TRACKER_MOTION_DEFAULT;
217 ao_config.tracker_interval = AO_TRACKER_INTERVAL_DEFAULT;
222 ao_config.pyro_time = AO_CONFIG_DEFAULT_PYRO_TIME;
226 ao_config.aprs_ssid = AO_CONFIG_DEFAULT_APRS_SSID;
230 ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
232 #if HAS_RADIO_FORWARD
234 ao_config.send_frequency = 434550;
238 ao_config.aprs_format = AO_CONFIG_DEFAULT_APRS_FORMAT;
240 #if HAS_FIXED_PAD_BOX
242 ao_config.pad_box = 1;
244 ao_config.pad_idle = 120;
248 ao_config.aprs_offset = 0;
252 ao_config.radio_10mw = AO_CONFIG_DEFAULT_RADIO_10MW;
254 ao_config.minor = AO_CONFIG_MINOR;
260 ao_config.frequency = 434550;
261 ao_config.radio_cal = ao_radio_cal;
263 ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
265 memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
266 sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
269 ao_config_set_radio();
271 ao_config_loaded = 1;
275 _ao_config_edit_start(void)
277 ao_mutex_get(&ao_config_mutex);
282 _ao_config_edit_finish(void)
285 ao_mutex_put(&ao_config_mutex);
291 _ao_config_edit_start();
292 ao_mutex_put(&ao_config_mutex);
298 ao_config_callsign_show(void)
300 printf ("Callsign: \"%s\"\n", ao_config.callsign);
304 ao_config_callsign_set(void)
307 static char callsign[AO_MAX_CALLSIGN + 1];
309 memset(callsign, '\0', sizeof callsign);
312 while (ao_cmd_lex_c != '\n') {
313 if (c < AO_MAX_CALLSIGN)
314 callsign[c++] = ao_cmd_lex_c;
316 ao_cmd_status = ao_cmd_lex_error;
319 if (ao_cmd_status != ao_cmd_success)
321 _ao_config_edit_start();
322 memcpy(&ao_config.callsign, &callsign,
323 AO_MAX_CALLSIGN + 1);
324 _ao_config_edit_finish();
328 ao_config_frequency_show(void)
330 printf("Frequency: %ld\n",
331 ao_config.frequency);
335 ao_config_frequency_set(void)
337 uint32_t r = ao_cmd_decimal();
338 if (ao_cmd_status != ao_cmd_success)
340 _ao_config_edit_start();
341 ao_config.frequency = r;
342 ao_config_set_radio();
343 _ao_config_edit_finish();
345 ao_radio_recv_abort();
351 #if HAS_RADIO_FORWARD
353 ao_config_send_frequency_show(void)
355 printf("Send frequency: %ld\n",
356 ao_config.send_frequency);
360 ao_config_send_frequency_set(void)
363 if (ao_cmd_status != ao_cmd_success)
365 _ao_config_edit_start();
366 ao_config.send_frequency = ao_cmd_lex_u32;
367 ao_config_set_radio();
368 _ao_config_edit_finish();
370 ao_radio_recv_abort();
381 ao_config_main_deploy_show(void)
383 printf("Main deploy: %d meters\n",
384 ao_config.main_deploy);
388 ao_config_main_deploy_set(void)
390 uint32_t r = ao_cmd_decimal();
391 if (ao_cmd_status != ao_cmd_success)
393 _ao_config_edit_start();
394 ao_config.main_deploy = (uint16_t) r;
395 _ao_config_edit_finish();
402 ao_config_accel_calibrate_show(void)
404 printf("Accel cal +1g: %d -1g: %d\n",
405 ao_config.accel_plus_g, ao_config.accel_minus_g);
407 printf ("IMU cal along %d across %d through %d\n",
408 ao_config.accel_zero_along,
409 ao_config.accel_zero_across,
410 ao_config.accel_zero_through);
414 #define ACCEL_CALIBRATE_SAMPLES 1024
415 #define ACCEL_CALIBRATE_SHIFT 10
418 static int16_t accel_cal_along;
419 static int16_t accel_cal_across;
420 static int16_t accel_cal_through;
424 ao_config_accel_calibrate_auto(char *orientation)
428 uint8_t cal_data_ring;
430 int32_t accel_along_total = 0;
431 int32_t accel_across_total = 0;
432 int32_t accel_through_total = 0;
435 printf("Orient antenna %s and press a key...", orientation);
438 puts("\r\n"); flush();
439 puts("Calibrating..."); flush();
440 i = ACCEL_CALIBRATE_SAMPLES;
442 cal_data_ring = ao_sample_data;
444 ao_sleep(&ao_sample_data);
445 while (i && cal_data_ring != ao_sample_data) {
446 accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
448 accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]);
449 accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]);
450 accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]);
452 cal_data_ring = ao_data_ring_next(cal_data_ring);
457 accel_cal_along = (int16_t) (accel_along_total >> ACCEL_CALIBRATE_SHIFT);
458 accel_cal_across = (int16_t) (accel_across_total >> ACCEL_CALIBRATE_SHIFT);
459 accel_cal_through = (int16_t) (accel_through_total >> ACCEL_CALIBRATE_SHIFT);
461 return (int16_t) (accel_total >> ACCEL_CALIBRATE_SHIFT);
465 ao_config_accel_calibrate_set(void)
470 int16_t accel_along_up = 0, accel_along_down = 0;
471 int16_t accel_across_up = 0, accel_across_down = 0;
472 int16_t accel_through_up = 0, accel_through_down = 0;
475 up = (int16_t) ao_cmd_decimal();
476 if (ao_cmd_status != ao_cmd_success)
478 down = (int16_t) ao_cmd_decimal();
479 auto_cal = (up == 0 && ao_cmd_status != ao_cmd_success);
481 up = ao_config_accel_calibrate_auto("up");
483 accel_along_up = accel_cal_along;
484 accel_across_up = accel_cal_across;
485 accel_through_up = accel_cal_through;
487 down = ao_config_accel_calibrate_auto("down");
489 accel_along_down = accel_cal_along;
490 accel_across_down = accel_cal_across;
491 accel_through_down = accel_cal_through;
495 printf("Invalid accel: up (%d) down (%d)\n",
499 _ao_config_edit_start();
500 ao_config.accel_plus_g = up;
501 ao_config.accel_minus_g = down;
504 ao_config.accel_zero_along = (int16_t) ((accel_along_up + accel_along_down) / 2);
505 ao_config.accel_zero_across = (int16_t) ((accel_across_up + accel_across_down) / 2);
506 ao_config.accel_zero_through = (int16_t) ((accel_through_up + accel_through_down) / 2);
510 v = (int16_t) ao_cmd_decimal();
511 if (ao_cmd_status == ao_cmd_success) {
512 ao_config.accel_zero_along = v;
513 v = (int16_t) ao_cmd_decimal();
514 if (ao_cmd_status == ao_cmd_success) {
515 ao_config.accel_zero_across = v;
516 v = (int16_t) ao_cmd_decimal();
517 if (ao_cmd_status == ao_cmd_success)
518 ao_config.accel_zero_through = v;
523 _ao_config_edit_finish();
525 #endif /* HAS_ACCEL */
529 ao_config_apogee_delay_show(void)
531 printf("Apogee delay: %d seconds\n",
532 ao_config.apogee_delay);
536 ao_config_apogee_delay_set(void)
538 uint32_t r = ao_cmd_decimal();
539 if (ao_cmd_status != ao_cmd_success)
542 ao_cmd_status = ao_cmd_lex_error;
545 _ao_config_edit_start();
546 ao_config.apogee_delay = (uint8_t) r;
547 _ao_config_edit_finish();
551 ao_config_apogee_lockout_show(void)
553 printf ("Apogee lockout: %d seconds\n",
554 ao_config.apogee_lockout);
558 ao_config_apogee_lockout_set(void)
560 uint32_t r = ao_cmd_decimal();
561 if (ao_cmd_status != ao_cmd_success)
564 ao_cmd_status = ao_cmd_lex_error;
567 _ao_config_edit_start();
568 ao_config.apogee_lockout = (uint16_t) r;
569 _ao_config_edit_finish();
573 #endif /* HAS_FLIGHT */
577 ao_config_radio_cal_show(void)
579 printf("Radio cal: %ld\n", ao_config.radio_cal);
583 ao_config_radio_cal_set(void)
585 uint32_t r = ao_cmd_decimal();
586 if (ao_cmd_status != ao_cmd_success)
588 _ao_config_edit_start();
589 ao_config.radio_cal = r;
590 ao_config_set_radio();
591 _ao_config_edit_finish();
597 #ifndef HAS_TELEMETRY
598 #error Please define HAS_TELEMETRY
602 ao_config_radio_rate_show(void)
604 printf("Telemetry rate: %d\n", ao_config.radio_rate);
608 ao_config_radio_rate_set(void)
610 uint32_t r = ao_cmd_decimal();
611 if (ao_cmd_status != ao_cmd_success)
613 if (AO_RADIO_RATE_MAX < r) {
614 ao_cmd_status = ao_cmd_lex_error;
617 _ao_config_edit_start();
618 ao_config.radio_rate = (uint8_t) r;
619 _ao_config_edit_finish();
621 ao_telemetry_reset_interval();
624 ao_radio_recv_abort();
632 ao_config_log_show(void)
634 printf("Max flight log: %d kB\n", (int16_t) (ao_config.flight_log_max >> 10));
635 #if FLIGHT_LOG_APPEND
636 printf("Log fixed: 1\n");
640 #if FLIGHT_LOG_APPEND && HAS_CONFIG_SAVE
642 ao_config_log_fix_append(void)
644 _ao_config_edit_start();
645 ao_config.flight_log_max = ao_storage_log_max;
646 _ao_config_edit_finish();
647 ao_mutex_get(&ao_config_mutex);
650 ao_mutex_put(&ao_config_mutex);
655 ao_config_log_set(void)
657 #if FLIGHT_LOG_APPEND
658 printf("Flight log fixed size %u kB\n", (unsigned) (ao_storage_log_max >> 10));
662 r = ao_cmd_decimal();
663 if (ao_cmd_status != ao_cmd_success)
666 if (ao_log_present()) {
667 if (r != ao_config.flight_log_max)
668 printf("Storage must be empty before changing log size\n");
671 if (r > ao_storage_log_max) {
672 printf("Flight log max %u kB\n", (unsigned) (ao_storage_log_max >> 10));
675 _ao_config_edit_start();
676 ao_config.flight_log_max = r & ~(ao_storage_block - 1);
677 _ao_config_edit_finish();
684 ao_config_ignite_mode_show(void)
686 printf("Ignite mode: %d\n", ao_config.ignite_mode);
690 ao_config_ignite_mode_set(void)
692 uint32_t r = ao_cmd_decimal();
693 if (ao_cmd_status != ao_cmd_success)
695 _ao_config_edit_start();
696 ao_config.ignite_mode = (uint8_t) r;
697 _ao_config_edit_finish();
703 ao_config_pad_orientation_show(void)
705 printf("Pad orientation: %d\n", ao_config.pad_orientation);
709 ao_config_pad_orientation_set(void)
711 uint8_t r = ao_cmd_decimal() & 1;
712 if (ao_cmd_status != ao_cmd_success)
714 _ao_config_edit_start();
715 if (ao_config.pad_orientation != r) {
717 t = ao_config.accel_plus_g;
718 ao_config.accel_plus_g = ao_data_accel_invert(ao_config.accel_minus_g);
719 ao_config.accel_minus_g = ao_data_accel_invert(t);
721 ao_config.pad_orientation = r;
722 _ao_config_edit_finish();
728 ao_config_radio_enable_show(void)
730 printf("Radio enable: %d\n", ao_config.radio_enable);
734 ao_config_radio_enable_set(void)
736 uint32_t r = ao_cmd_decimal();
737 if (ao_cmd_status != ao_cmd_success)
739 _ao_config_edit_start();
740 ao_config.radio_enable = r != 0;
741 _ao_config_edit_finish();
742 #if HAS_TELEMETRY && HAS_RADIO_RATE
743 ao_telemetry_reset_interval();
746 #endif /* HAS_RADIO */
750 uint8_t ao_config_aes_seq = 1;
753 ao_config_key_show(void)
757 for (i = 0; i < AO_AES_LEN; i++)
758 printf ("%02x", ao_config.aes_key[i]);
763 ao_config_key_set(void)
767 _ao_config_edit_start();
768 for (i = 0; i < AO_AES_LEN; i++) {
769 uint8_t b = ao_cmd_hexbyte();
770 if (ao_cmd_status != ao_cmd_success)
772 ao_config.aes_key[i] = b;
775 _ao_config_edit_finish();
782 ao_config_aprs_show(void)
784 printf ("APRS interval: %d\n", ao_config.aprs_interval);
788 ao_config_aprs_set(void)
790 uint32_t r = ao_cmd_decimal();
791 if (ao_cmd_status != ao_cmd_success)
793 _ao_config_edit_start();
794 ao_config.aprs_interval = (uint16_t) r;
795 _ao_config_edit_finish();
796 ao_telemetry_reset_interval();
800 ao_config_aprs_offset_show(void)
802 printf ("APRS offset: %d\n", ao_config.aprs_offset);
806 ao_config_aprs_offset_set(void)
808 uint32_t r = ao_cmd_decimal();
809 if (ao_cmd_status != ao_cmd_success)
811 _ao_config_edit_start();
812 ao_config.aprs_offset = (uint8_t) r;
813 _ao_config_edit_finish();
814 ao_telemetry_reset_interval();
817 #endif /* HAS_APRS */
822 ao_config_radio_amp_show(void)
824 printf ("Radio amp setting: %d\n", ao_config.radio_amp);
828 ao_config_radio_amp_set(void)
830 uint16_t r = ao_cmd_decimal();
831 if (ao_cmd_status != ao_cmd_success)
833 _ao_config_edit_start();
834 ao_config.radio_amp = r;
835 _ao_config_edit_finish();
843 ao_config_radio_power_show(void)
845 printf ("Radio power setting: %d\n", ao_config.radio_power);
849 ao_config_radio_power_set(void)
851 uint16_t r = ao_cmd_decimal();
852 if (ao_cmd_status != ao_cmd_success)
854 _ao_config_edit_start();
855 ao_config.radio_power = r;
856 _ao_config_edit_finish();
864 ao_config_radio_10mw_show(void)
866 printf ("Radio 10mw limit: %d\n", ao_config.radio_10mw);
870 ao_config_radio_10mw_set(void)
872 uint32_t r = ao_cmd_decimal();
873 if (ao_cmd_status != ao_cmd_success)
875 _ao_config_edit_start();
876 ao_config.radio_10mw = !!r;
877 _ao_config_edit_finish();
884 ao_config_beep_show(void)
886 printf ("Beeper setting: %d\n", ao_config.mid_beep);
890 ao_config_beep_set(void)
892 uint32_t r = ao_cmd_decimal();
893 if (ao_cmd_status != ao_cmd_success)
895 _ao_config_edit_start();
896 ao_config.mid_beep = (uint8_t) r;
897 _ao_config_edit_finish();
903 ao_config_tracker_show(void)
905 printf ("Tracker setting: %d %d\n",
906 ao_config.tracker_motion,
907 ao_config.tracker_interval);
911 ao_config_tracker_set(void)
915 m = (uint16_t) ao_cmd_decimal();
916 if (ao_cmd_status != ao_cmd_success)
918 i = (uint8_t) ao_cmd_decimal();
919 if (ao_cmd_status != ao_cmd_success)
921 _ao_config_edit_start();
922 ao_config.tracker_motion = m;
923 ao_config.tracker_interval = i;
924 _ao_config_edit_finish();
926 ao_telemetry_reset_interval();
929 #endif /* HAS_TRACKER */
933 ao_config_pyro_time_show(void)
935 printf ("Pyro time: %d\n", ao_config.pyro_time);
939 ao_config_pyro_time_set(void)
941 uint32_t r = ao_cmd_decimal();
942 if (ao_cmd_status != ao_cmd_success)
944 _ao_config_edit_start();
945 ao_config.pyro_time = (uint16_t) r;
946 _ao_config_edit_finish();
952 ao_config_aprs_ssid_show(void)
954 printf ("APRS SSID: %d\n",
955 ao_config.aprs_ssid);
959 ao_config_aprs_ssid_set(void)
961 uint32_t r = ao_cmd_decimal();
962 if (ao_cmd_status != ao_cmd_success)
965 ao_cmd_status = ao_cmd_lex_error;
968 _ao_config_edit_start();
969 ao_config.aprs_ssid = (uint8_t) r;
970 _ao_config_edit_finish();
974 ao_config_aprs_format_set(void)
976 uint32_t r = ao_cmd_decimal();
977 if (ao_cmd_status != ao_cmd_success)
979 _ao_config_edit_start();
980 ao_config.aprs_format = r != 0;
981 _ao_config_edit_finish();
985 ao_config_aprs_format_show(void)
987 printf ("APRS format: %d\n", ao_config.aprs_format);
989 #endif /* HAS_APRS */
991 #if HAS_FIXED_PAD_BOX
993 ao_config_pad_box_show(void)
995 printf ("Pad box: %d\n", ao_config.pad_box);
999 ao_config_pad_box_set(void)
1001 uint32_t r = ao_cmd_decimal();
1002 if (ao_cmd_status != ao_cmd_success)
1004 _ao_config_edit_start();
1005 ao_config.pad_box = (uint8_t) r;
1006 _ao_config_edit_finish();
1010 ao_config_pad_idle_show(void)
1012 printf ("Idle timeout: %d\n", ao_config.pad_idle);
1016 ao_config_pad_idle_set(void)
1018 uint32_t r = ao_cmd_decimal();
1019 if (ao_cmd_status != ao_cmd_success)
1021 _ao_config_edit_start();
1022 ao_config.pad_idle = (uint8_t) r;
1023 _ao_config_edit_finish();
1027 struct ao_config_var {
1034 ao_config_help(void);
1037 ao_config_show(void);
1041 ao_config_save(void);
1044 const struct ao_config_var ao_config_vars[] = {
1045 #if HAS_FLIGHT && HAS_BARO
1046 { "m <meters>\0Main deploy (m)",
1047 ao_config_main_deploy_set, ao_config_main_deploy_show, },
1048 { "d <delay>\0Apogee delay (s)",
1049 ao_config_apogee_delay_set, ao_config_apogee_delay_show },
1050 { "L <seconds>\0Apogee detect lockout (s)",
1051 ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
1052 #endif /* HAS_FLIGHT */
1054 { "F <freq>\0Frequency (kHz)",
1055 ao_config_frequency_set, ao_config_frequency_show },
1056 #if HAS_RADIO_FORWARD
1057 { "R <freq>\0Repeater output frequency (kHz)",
1058 ao_config_send_frequency_set, ao_config_send_frequency_show },
1060 { "c <call>\0Callsign (8 char max)",
1061 ao_config_callsign_set, ao_config_callsign_show },
1062 { "e <0 disable, 1 enable>\0Enable telemetry and RDF",
1063 ao_config_radio_enable_set, ao_config_radio_enable_show },
1064 { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
1065 ao_config_radio_cal_set, ao_config_radio_cal_show },
1067 { "T <rate>\0Telemetry rate (0=38.4, 1=9.6, 2=2.4)",
1068 ao_config_radio_rate_set, ao_config_radio_rate_show },
1071 { "p <setting>\0Radio power setting (0-255)",
1072 ao_config_radio_power_set, ao_config_radio_power_show },
1075 { "d <setting>\0Radio amplifier setting (0-3)",
1076 ao_config_radio_amp_set, ao_config_radio_amp_show },
1078 #endif /* HAS_RADIO */
1080 { "a <+g> <-g>\0Accel calib (0 for auto)",
1081 ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
1082 { "o <0 antenna up, 1 antenna down>\0Pad orientation",
1083 ao_config_pad_orientation_set,ao_config_pad_orientation_show },
1084 #endif /* HAS_ACCEL */
1086 { "l <size>\0Flight log size (kB)",
1087 ao_config_log_set, ao_config_log_show },
1090 { "i <0 dual, 1 apogee, 2 main, 3 booster>\0Igniter mode",
1091 ao_config_ignite_mode_set, ao_config_ignite_mode_show },
1094 { "k <32 hex digits>\0AES encryption key",
1095 ao_config_key_set, ao_config_key_show },
1098 { "P <n,?>\0Pyro channels",
1099 ao_pyro_set, ao_pyro_show },
1100 { "I <ticks>\0Pyro firing time",
1101 ao_config_pyro_time_set, ao_config_pyro_time_show },
1104 { "A <secs>\0APRS packet interval (0 disable)",
1105 ao_config_aprs_set, ao_config_aprs_show },
1108 { "b <val>\0Beeper tone (freq = 1/2 (24e6/32) / beep",
1109 ao_config_beep_set, ao_config_beep_show },
1112 { "t <motion> <interval>\0Tracker configuration",
1113 ao_config_tracker_set, ao_config_tracker_show },
1116 { "S <ssid>\0Set APRS SSID (0-15)",
1117 ao_config_aprs_ssid_set, ao_config_aprs_ssid_show },
1118 { "C <0 compressed, 1 uncompressed>\0APRS format",
1119 ao_config_aprs_format_set, ao_config_aprs_format_show },
1120 { "O <aprs-offset>\0APRS Offset from top of minute",
1121 ao_config_aprs_offset_set, ao_config_aprs_offset_show },
1123 #if HAS_FIXED_PAD_BOX
1124 { "B <box>\0Set pad box (1-99)",
1125 ao_config_pad_box_set, ao_config_pad_box_show },
1126 { "i <seconds>\0Set idle timeout (0 disable)",
1127 ao_config_pad_idle_set, ao_config_pad_idle_show },
1130 { "p <0 no limit, 1 limit>\0Limit radio power to 10mW",
1131 ao_config_radio_10mw_set, ao_config_radio_10mw_show },
1134 ao_config_show, 0 },
1136 { "w\0Write to eeprom",
1137 ao_config_save, 0 },
1140 ao_config_help, 0 },
1153 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1154 if (ao_config_vars[cmd].str[0] == c) {
1155 (*ao_config_vars[cmd].set)();
1158 ao_cmd_status = ao_cmd_syntax_error;
1162 ao_config_help(void)
1165 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1166 printf("%-20s %s\n",
1167 ao_config_vars[cmd].str,
1168 ao_config_vars[cmd].str+1+
1169 strlen(ao_config_vars[cmd].str));
1173 ao_config_show(void)
1177 printf("Config version: %d.%d\n",
1178 ao_config.major, ao_config.minor);
1179 for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
1180 if (ao_config_vars[cmd].show)
1181 (*ao_config_vars[cmd].show)();
1189 ao_config_save(void)
1192 ao_mutex_get(&ao_config_mutex);
1193 if (ao_config_dirty) {
1195 ao_config_dirty = 0;
1198 ao_mutex_put(&ao_config_mutex);
1202 puts("Nothing to save");
1206 const struct ao_cmds ao_config_cmds[] = {
1207 { ao_config_set, "c <var> <value>\0Set config (? for help, s to show)" },
1212 ao_config_init(void)
1214 ao_cmd_register(&ao_config_cmds[0]);