From 8efba515f533f399df05010a3c1384442897840f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 28 Feb 2013 11:01:05 +0000 Subject: rda1846dongle: using get and set freq at command_handler git-svn-id: https://svn.spreadspace.org/mur.sat@688 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/rda1846dongle/rda1846dongle.c | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'software') diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c index 618b7ea..4bc4c2f 100644 --- a/software/rda1846dongle/rda1846dongle.c +++ b/software/rda1846dongle/rda1846dongle.c @@ -41,13 +41,43 @@ #include "rda1846.h" -void handle_cmd(uint8_t cmd) +#define DEFAULT_FREQ 145900 +int32_t current_freq_kHz = DEFAULT_FREQ; + +static int32_t print_actual_freq(void) +{ + int32_t f = rda1846_get_freq_kHz(); + if(f < 0) + printf("actual frequency: NaN MHz"); + else + printf("actual frequency: %d.%03d MHz", (uint16_t)(f / 1000), (uint16_t)(f % 1000)); + return f; +} + +static void update_current_freq(void) +{ + printf("setting frequency to %d.%03d MHz .. ", (uint16_t)(current_freq_kHz / 1000), + (uint16_t)(current_freq_kHz % 1000)); + if(rda1846_set_freq_kHz(current_freq_kHz)) + printf("error\r\n"); + else + printf("ok\r\n"); + + current_freq_kHz = print_actual_freq(); + if(current_freq_kHz < 0) + current_freq_kHz = DEFAULT_FREQ; +} + +static void handle_cmd(uint8_t cmd) { switch(cmd) { case '0': led_off(); break; case '1': led_on(); break; case 't': led_toggle(); break; case 'r': reset2bootloader(); break; + case 'f': print_actual_freq(); break; + case '+': current_freq_kHz+=500; update_current_freq(); break; + case '-': current_freq_kHz-=500; update_current_freq(); break; default: printf("error\r\n"); return; } printf("ok\r\n"); @@ -61,10 +91,10 @@ int main(void) cpu_init(); led_init(); usbio_init(); + sei(); rda1846_init(); - - sei(); + rda1846_set_freq_kHz(current_freq_kHz); for(;;) { int16_t BytesReceived = usbio_bytes_received(); -- cgit v1.2.3