From ddd3cdf8fc00adefeb326b714f6041751a4e80f3 Mon Sep 17 00:00:00 2001 From: Lars Beemster Date: Wed, 30 May 2018 18:40:35 +0200 Subject: [PATCH] keep alive and accept some input from keyboard --- fl2k-psk.c | 59 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/fl2k-psk.c b/fl2k-psk.c index 3965764..eaccfcd 100644 --- a/fl2k-psk.c +++ b/fl2k-psk.c @@ -23,6 +23,10 @@ uint32_t fl2k_dev_idx = 0; // Catches ^C and stops static void sighandler(int signum) { cout << "Signal caught, exiting!" << endl; + + fl2k_stop_tx(fl2k_dev); + fl2k_close(fl2k_dev); + exit(0); } @@ -62,32 +66,57 @@ void attach_sighandlers() { sigaction(SIGPIPE, &sigign, nullptr); } +void set_freq_carrier(uint32_t freq) { + uint32_t samplerate = freq * 2; // sample rate twice the frequency gives the smoothest output (TODO: experiment) -int main(int argc, char **argv) { - uint32_t freq_carrier = 14000000; - uint32_t samplerate = freq_carrier * 2; // sample rate twice the frequency gives the smoothest output (TODO: experiment) + // Set the sample rate + int r = fl2k_set_sample_rate(fl2k_dev, samplerate); + if (r < 0) { + cout << "WARNING: Failed to set sample rate. " << r << endl; + } + + /* read back actual frequency */ + samplerate = fl2k_get_sample_rate(fl2k_dev); + cout << "Actual sample rate = " << samplerate << endl; +} + +int main(int argc, char **argv) { attach_sighandlers(); init_txbuffer(); fl2k_open(&fl2k_dev, fl2k_dev_idx); - if (!fl2k_dev) { + if(!fl2k_dev) { cout << "Failed to open fl2k device #" << fl2k_dev_idx << endl; - exit(0); } - cout << "Opened device" << endl; - - int r = fl2k_start_tx(fl2k_dev, fl2k_callback, nullptr, 0); + else { + cout << "Opened device" << endl; + + int r = fl2k_start_tx(fl2k_dev, fl2k_callback, nullptr, 0); + set_freq_carrier(14000000); + } - // Set the sample rate - r = fl2k_set_sample_rate(fl2k_dev, samplerate); - if (r < 0) { - cout << "WARNING: Failed to set sample rate. " << r << endl; + cout << "Press u,d,q to raise or lower frequency, or quit: " << flush; + char c; + while(cin.get(c)) { + switch(c) { + case 'u': + set_freq_carrier(fl2k_get_sample_rate(fl2k_dev) + 1000000); + break; + case 'd': + set_freq_carrier(fl2k_get_sample_rate(fl2k_dev) - 1000000); + break; + case 'q': + exit(0); + break; + default: + break; + } + + cin.ignore(); + cout << "> " << flush; } - /* read back actual frequency */ - samplerate = fl2k_get_sample_rate(fl2k_dev); - cout << "Actual sample rate = " << samplerate << endl; return 0; }