From 9205767f9450fd4a792ee93d8db25b9cfe4109ca Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 2 Sep 2017 15:41:11 +0200 Subject: SDR: Display spectrum graph together with channel numbers and position --- src/common/display.h | 2 +- src/common/display_spectrum.c | 36 +++++++++++++++++++++++++++++++++++- src/common/sdr.c | 6 +++--- src/tv/main.c | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/common/display.h b/src/common/display.h index 6f75662..cc284fb 100644 --- a/src/common/display.h +++ b/src/common/display.h @@ -49,7 +49,7 @@ void display_iq_on(int on); void display_iq_limit_scroll(int on); void display_iq(float *samples, int length); -void display_spectrum_init(int samplerate); +void display_spectrum_init(int samplerate, double center_frequency); void display_spectrum_on(int on); void display_spectrum_limit_scroll(int on); void display_spectrum(float *samples, int length); diff --git a/src/common/display_spectrum.c b/src/common/display_spectrum.c index bc1a50b..ee7823c 100644 --- a/src/common/display_spectrum.c +++ b/src/common/display_spectrum.c @@ -33,10 +33,11 @@ static char screen[HEIGHT][MAX_DISPLAY_WIDTH]; static uint8_t screen_color[HEIGHT][MAX_DISPLAY_WIDTH]; static int spectrum_on = 0; static double db = 100; +static double center_frequency, frequency_range; static dispspectrum_t disp; -void display_spectrum_init(int samplerate) +void display_spectrum_init(int samplerate, double _center_frequency) { memset(&disp, 0, sizeof(disp)); disp.interval_max = (double)samplerate * DISPLAY_INTERVAL + 0.5; @@ -44,6 +45,9 @@ void display_spectrum_init(int samplerate) if (disp.interval_max < MAX_DISPLAY_SPECTRUM - 1) disp.interval_max = MAX_DISPLAY_SPECTRUM - 1; memset(buffer_max, 0, sizeof(buffer_max)); + + center_frequency = _center_frequency; + frequency_range = (double)samplerate; } void display_spectrum_on(int on) @@ -90,6 +94,8 @@ void display_spectrum_limit_scroll(int on) */ void display_spectrum(float *samples, int length) { + sender_t *sender; + char print_channel[32], print_frequency[32]; int width, h; int pos, max; double *buffer_I, *buffer_Q; @@ -213,6 +219,34 @@ void display_spectrum(float *samples, int length) } } } + for (sender = sender_head; sender; sender = sender->next) { + j = (int)((sender->empfangsfrequenz - center_frequency) / frequency_range * (double) fft_size + width / 2 + 0.5); + if (j < 0 || j >= width) /* check out-of-range, should not happen */ + continue; + for (k = 0; k < HEIGHT; k++) { + /* skip yellow graph */ + if (screen_color[k][j] == 13) + continue; + screen[k][j] = ':'; + screen_color[k][j] = 12; + } + sprintf(print_channel, "Ch%d", sender->kanal); + for (o = 0; o < (int)strlen(print_channel); o++) { + s = j - strlen(print_channel) + o; + if (s >= 0 && s < width) { + screen[HEIGHT - 1][s] = print_channel[o]; + screen_color[HEIGHT - 1][s] = 7; + } + } + sprintf(print_frequency, "%.4f", sender->empfangsfrequenz / 1e6); + for (o = 0; o < (int)strlen(print_frequency); o++) { + s = j + o + 1; + if (s >= 0 && s < width) { + screen[HEIGHT - 1][s] = print_frequency[o]; + screen_color[HEIGHT - 1][s] = 7; + } + } + } printf("\0337\033[H"); for (j = 0; j < HEIGHT; j++) { for (k = 0; k < width; k++) { diff --git a/src/common/sdr.c b/src/common/sdr.c index a8459c4..3b768a2 100644 --- a/src/common/sdr.c +++ b/src/common/sdr.c @@ -114,9 +114,6 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq threads = 1; } - display_iq_init(samplerate); - display_spectrum_init(samplerate); - bandwidth = 2.0 * (max_deviation + max_modulation); PDEBUG(DSDR, DEBUG_INFO, "Require bandwidth of 2 * (%.1f + %.1f) = %.1f\n", max_deviation / 1000, max_modulation / 1000, bandwidth / 1000); @@ -340,6 +337,9 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq tx_center_frequency = temp; } + display_iq_init(samplerate); + display_spectrum_init(samplerate, rx_center_frequency); + #ifdef HAVE_UHD if (sdr_config->uhd) { rc = uhd_open(sdr_config->channel, sdr_config->device_args, sdr_config->stream_args, sdr_config->tune_args, sdr_config->tx_antenna, sdr_config->rx_antenna, tx_center_frequency, rx_center_frequency, sdr_config->samplerate, sdr_config->tx_gain, sdr_config->rx_gain, sdr_config->bandwidth, sdr_config->uhd_tx_timestamps); diff --git a/src/tv/main.c b/src/tv/main.c index c8a3e78..f7f5a35 100644 --- a/src/tv/main.c +++ b/src/tv/main.c @@ -41,6 +41,7 @@ enum paging_signal; #include "tv_modulate.h" #include "channels.h" +void *sender_head = NULL; int use_sdr = 0; int num_kanal = 1; /* only one channel used for debugging */ -- cgit v1.2.3