Skip to content

Commit

Permalink
keep alive and accept some input from keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
biemster committed May 30, 2018
1 parent 29576d6 commit ddd3cdf
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions fl2k-psk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

0 comments on commit ddd3cdf

Please sign in to comment.