}
#endif
+static void
+ao_config_set_radio(void)
+{
+ ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
+}
+
static void
_ao_config_get(void)
{
ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
if (ao_config.minor < 6)
ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
- if (ao_config.minor < 7)
- ao_config.radio_setting = ao_config.radio_cal;
if (ao_config.minor < 8)
ao_config.radio_enable = TRUE;
if (ao_config.minor < 9)
memset(&ao_config.aes_key, 0, AO_AES_LEN);
-#if HAS_RADIO_CHANNELS
if (ao_config.minor < 10) {
+ ao_config.frequency = 434550;
+#if HAS_RADIO_CHANNELS
ao_xmemset(&ao_config.radio_channels, '\0', sizeof (ao_config.radio_channels));
ao_xmemcpy(&ao_config.radio_channels[0].name[0],
CODE_TO_XDATA("Channel 0"), sizeof("Channel 0"));
ao_config.radio_channels[0].kHz = 434550;
- ao_config.radio_channels[0].radio_setting = ao_config.radio_cal;
- }
#endif
+ }
ao_config.minor = AO_CONFIG_MINOR;
ao_config_dirty = 1;
}
+ ao_config_set_radio();
ao_config_loaded = 1;
}
ao_radio_recv_abort();
}
+void
+ao_config_frequency_show(void) __reentrant
+{
+ printf("Frequency: %ld\n",
+ ao_config.frequency);
+}
+
+void
+ao_config_frequency_set(void) __reentrant
+{
+ ao_cmd_decimal();
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+ _ao_config_edit_start();
+ ao_config.frequency = ao_cmd_lex_u32;
+ ao_config_set_radio();
+ _ao_config_edit_finish();
+ ao_radio_recv_abort();
+}
+
#if HAS_ADC
void
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.radio_setting = ao_config.radio_cal = ao_cmd_lex_u32;
+ ao_config.radio_cal = ao_cmd_lex_u32;
+ ao_config_set_radio();
_ao_config_edit_finish();
}
}
#endif
-void
-ao_config_radio_setting_show(void) __reentrant
-{
- printf("Radio setting: %ld\n", ao_config.radio_setting);
-}
-
-void
-ao_config_radio_setting_set(void) __reentrant
-{
- ao_cmd_decimal();
- if (ao_cmd_status != ao_cmd_success)
- return;
- _ao_config_edit_start();
- ao_config.radio_setting = ao_cmd_lex_u32;
- ao_config.radio_channel = 0;
- _ao_config_edit_finish();
- ao_radio_recv_abort();
-}
-
void
ao_config_radio_enable_show(void) __reentrant
{
uint8_t i;
for (i = 0; i < AO_NUM_CHANNELS; i++)
if (ao_config.radio_channels[i].name[0]) {
- printf("%2d %-16.16s %ld %ld\n",
+ printf("%2d %-16.16s %ld\n",
i,
ao_config.radio_channels[i].name,
- ao_config.radio_channels[i].kHz,
- ao_config.radio_channels[i].radio_setting);
+ ao_config.radio_channels[i].kHz);
}
}
}
ao_cmd_decimal();
ch->kHz = ao_cmd_lex_u32;
- ao_cmd_decimal();
- ch->radio_setting = ao_cmd_lex_u32;
_ao_config_edit_finish();
}
#endif
#endif /* HAS_ADC */
{ "r <channel>\0Radio channel (freq = 434.550 + chan * .1)",
ao_config_radio_channel_set, ao_config_radio_channel_show },
+ { "F <freq>\0Frequency (kHz)",
+ ao_config_frequency_set, ao_config_frequency_show },
{ "c <call>\0Callsign (8 char max)",
ao_config_callsign_set, ao_config_callsign_show },
- { "R <setting>\0Radio freq control (freq = 434.550 * setting/cal)",
- ao_config_radio_setting_set, ao_config_radio_setting_show },
{ "e <0 disable, 1 enable>\0Enable telemetry and RDF",
ao_config_radio_enable_set, ao_config_radio_enable_show },
#if HAS_ACCEL
--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <ao.h>
+
+/*
+ * The provided 'calibration' value is
+ * that needed to tune the radio to precisely 434550kHz.
+ * Use that to 'walk' to the target frequency by following
+ * a 'bresenham' line from 434550kHz to the target
+ * frequency, and updating the radio setting along the way
+ */
+
+int32_t ao_freq_to_set(int32_t freq, int32_t cal) {
+ __pdata int32_t set = 0;
+ uint8_t neg = 0;
+ __pdata int32_t error = -434550 / 2;
+
+ freq -= 434550;
+ if (freq < 0) {
+ neg = 1;
+ freq = -freq;
+ }
+ for (;;) {
+ if (freq == 0 && error <= 0)
+ break;
+ if (error > 0) {
+ error -= 434550;
+ set++;
+ } else {
+ error += cal;
+ freq--;
+ }
+ }
+ if (neg)
+ set = -set;
+ return cal + set;
+}