aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-01-07 19:53:43 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-01-08 09:20:58 +0100
commit12a31f1b051e1afd020747448b7583d5f81cd092 (patch)
tree3ba19efc0b052338b7ffe8fde489e0a8f0ac4582 /src
parent8df212f34fe3b69978dfbc79e9fbd619980984c9 (diff)
SDR: Display IQ data as a plot using 'q' key
Diffstat (limited to 'src')
-rw-r--r--src/common/Makefile.am1
-rw-r--r--src/common/debug.c8
-rw-r--r--src/common/display.h32
-rw-r--r--src/common/display_iq.c231
-rw-r--r--src/common/display_wave.c26
-rw-r--r--src/common/display_wave.h16
-rw-r--r--src/common/main_common.c6
-rw-r--r--src/common/sdr.c4
-rw-r--r--src/common/sender.h2
9 files changed, 294 insertions, 32 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 1269e76..8c70533 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -24,6 +24,7 @@ libcommon_a_SOURCES = \
../common/compandor.c \
../common/sender.c \
../common/display_wave.c \
+ ../common/display_iq.c \
../common/main_common.c
if HAVE_SDR
diff --git a/src/common/debug.c b/src/common/debug.c
index 4de9d3f..b1b6e5d 100644
--- a/src/common/debug.c
+++ b/src/common/debug.c
@@ -24,7 +24,7 @@
#include <stdint.h>
#include <errno.h>
#include "debug.h"
-#include "display_wave.h"
+#include "display.h"
#include "call.h"
const char *debug_level[] = {
@@ -94,9 +94,11 @@ void _printdebug(const char *file, const char __attribute__((unused)) *function,
clear_console_text();
// printf("%s%s:%d %s() %s: %s\033[0;39m", debug_cat[cat].color, file, line, function, debug_level[level], buffer);
- display_limit_scroll(1);
+ display_wave_limit_scroll(1);
+ display_iq_limit_scroll(1);
printf("%s%s:%d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer);
- display_limit_scroll(0);
+ display_wave_limit_scroll(0);
+ display_iq_limit_scroll(0);
print_console_text();
fflush(stdout);
}
diff --git a/src/common/display.h b/src/common/display.h
new file mode 100644
index 0000000..2c07bb8
--- /dev/null
+++ b/src/common/display.h
@@ -0,0 +1,32 @@
+#define MAX_DISPLAY_WIDTH 1024
+
+typedef struct sender sender_t;
+
+typedef struct display_wave {
+ int interval_pos;
+ int interval_max;
+ int offset;
+ int16_t buffer[MAX_DISPLAY_WIDTH];
+} dispwav_t;
+
+#define MAX_DISPLAY_IQ 256
+
+typedef struct display_iq {
+ int interval_pos;
+ int interval_max;
+ int offset;
+ float buffer[MAX_DISPLAY_IQ * 2];
+} dispiq_t;
+
+void get_win_size(int *w, int *h);
+
+void display_wave_init(sender_t *sender, int samplerate);
+void display_wave_on(int on);
+void display_wave_limit_scroll(int on);
+void display_wave(sender_t *sender, int16_t *samples, int length);
+
+void display_iq_init(int samplerate);
+void display_iq_on(int on);
+void display_iq_limit_scroll(int on);
+void display_iq(float *samples, int length);
+
diff --git a/src/common/display_iq.c b/src/common/display_iq.c
new file mode 100644
index 0000000..0e5d0af
--- /dev/null
+++ b/src/common/display_iq.c
@@ -0,0 +1,231 @@
+/* display IQ data form functions
+ *
+ * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu>
+ * All Rights Reserved
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <math.h>
+#include "sender.h"
+
+#define DISPLAY_INTERVAL 0.04
+
+/* must be odd value! */
+#define SIZE 23
+
+static char screen[SIZE][MAX_DISPLAY_WIDTH];
+static int iq_on = 0;
+static double db = 40;
+
+static dispiq_t disp;
+
+void display_iq_init(int samplerate)
+{
+ memset(&disp, 0, sizeof(disp));
+ disp.interval_max = (double)samplerate * DISPLAY_INTERVAL + 0.5;
+ /* should not happen due to low interval */
+ if (disp.interval_max < MAX_DISPLAY_IQ + 1)
+ disp.interval_max = MAX_DISPLAY_IQ + 1;
+}
+
+void display_iq_on(int on)
+{
+ int j;
+ int w, h;
+
+ get_win_size(&w, &h);
+
+ if (iq_on) {
+ memset(&screen, ' ', sizeof(screen));
+ printf("\0337\033[H");
+ for (j = 0; j < SIZE; j++) {
+ screen[j][w] = '\0';
+ puts(screen[j]);
+ }
+ printf("\0338"); fflush(stdout);
+ }
+
+ if (on < 0) {
+ if (++iq_on == 3)
+ iq_on = 0;
+ } else
+ iq_on = on;
+}
+
+void display_iq_limit_scroll(int on)
+{
+ int w, h;
+
+ if (!iq_on)
+ return;
+
+ get_win_size(&w, &h);
+
+ printf("\0337");
+ printf("\033[%d;%dr", (on) ? SIZE + 1 : 1, h);
+ printf("\0338");
+}
+
+/*
+ * plot IQ data:
+ *
+ * theoretical example: SIZE = 3 allows 6 steps plotted as dots
+ *
+ * Line 0: :
+ * Line 1: :
+ * Line 2: :
+ *
+ * The level of -1.0 .. 1.0 is scaled to -3 and 3.
+ *
+ * The lowest of the upper 3 dots ranges from 0.0 .. <1.5.
+ * The upper most dot ranges from 2.5 .. <3.5.
+ * The highest of the lower 3 dots ranges from <0.0 .. >-1.5;
+ * The lower most dot ranges from -2.5 .. >-3.5.
+ *
+ * The center column ranges from -0.5 .. <0.5.
+ * The columns about the center from -1.5 .. <1.5.
+ */
+void display_iq(float *samples, int length)
+{
+ int pos, max;
+ float *buffer;
+ int i, j, k;
+ int color = 9; /* default color */
+ int x_center, y_center;
+ double I, Q, l, s;
+ int x, y;
+ int width, h;
+
+ if (!iq_on)
+ return;
+
+ get_win_size(&width, &h);
+
+ /* at what line we draw our zero-line and what character we use */
+ x_center = width >> 1;
+ y_center = (SIZE - 1) >> 1;
+
+ pos = disp.interval_pos;
+ max = disp.interval_max;
+ buffer = disp.buffer;
+
+ for (i = 0; i < length; i++) {
+ if (pos >= MAX_DISPLAY_IQ) {
+ if (++pos == max)
+ pos = 0;
+ continue;
+ }
+ buffer[pos++] = *samples++;
+ buffer[pos++] = *samples++;
+ if (pos == MAX_DISPLAY_IQ) {
+ memset(&screen, ' ', sizeof(screen));
+ for (j = 0; j < MAX_DISPLAY_IQ; j++) {
+ I = buffer[j * 2];
+ Q = buffer[j * 2 + 1];
+ if (iq_on > 1) {
+ /* 40 db logarithmic scale */
+ l = sqrt(I*I + Q*Q);
+ s = log10(l) * 10 + db;
+ if (s < 0)
+ s = 0;
+ I = (I / l) * (s / db);
+ Q = (Q / l) * (s / db);
+ }
+ x = x_center + (int)(I * (double)SIZE + (double)width + 0.5) - width;
+ if (x < 0)
+ continue;
+ if (x > width - 1)
+ continue;
+ if (Q >= 0)
+ y = SIZE - 1 - (int)(Q * (double)SIZE - 0.5);
+ else
+ y = SIZE - (int)(Q * (double)SIZE + 0.5);
+ if (y < 0)
+ continue;
+ if (y > SIZE * 2 - 1)
+ continue;
+ if (screen[y/2][x] == ':')
+ continue;
+ if (screen[y/2][x] == '.') {
+ if ((y & 1) == 0)
+ screen[y/2][x] = ':';
+ continue;
+ }
+ if (screen[y/2][x] == '\'') {
+ if ((y & 1))
+ screen[y/2][x] = ':';
+ continue;
+ }
+ if ((y & 1) == 0)
+ screen[y/2][x] = '\'';
+ else
+ screen[y/2][x] = '.';
+ }
+ if (iq_on == 1)
+ sprintf(screen[0], "(IQ linear");
+ else
+ sprintf(screen[0], "(IQ log %.0f dB", db);
+ *strchr(screen[0], '\0') = ')';
+ printf("\0337\033[H");
+ for (j = 0; j < SIZE; j++) {
+ for (k = 0; k < width; k++) {
+ if ((j == y_center || k == x_center) && screen[j][k] == ' ') {
+ /* blue cross */
+ if (color != 4) {
+ color = 4;
+ printf("\033[0;34m");
+ }
+ if (j == y_center) {
+ if (k == x_center)
+ putchar('o');
+ else if (k == x_center - SIZE)
+ putchar('+');
+ else if (k == x_center + SIZE)
+ putchar('+');
+ else
+ putchar('-');
+ } else
+ putchar('|');
+ } else if (screen[j][k] == ':' || screen[j][k] == '.' || screen[j][k] == '\'') {
+ /* green plot */
+ if (color != 2) {
+ color = 2;
+ printf("\033[1;32m");
+ }
+ putchar(screen[j][k]);
+ } else if (screen[j][k] != ' ') {
+ /* white other characters */
+ if (color != 7) {
+ color = 7;
+ printf("\033[1;37m");
+ }
+ putchar(screen[j][k]);
+ } else
+ putchar(screen[j][k]);
+ }
+ printf("\n");
+ }
+ /* reset color and position */
+ printf("\033[0;39m\0338"); fflush(stdout);
+ }
+ }
+
+ disp.interval_pos = pos;
+}
+
+
diff --git a/src/common/display_wave.c b/src/common/display_wave.c
index 6c87f39..677e119 100644
--- a/src/common/display_wave.c
+++ b/src/common/display_wave.c
@@ -31,7 +31,7 @@ static int num_sender = 0;
static char screen[HEIGHT][MAX_DISPLAY_WIDTH];
static int wave_on = 0;
-static void get_win_size(int *w, int *h)
+void get_win_size(int *w, int *h)
{
struct winsize win;
int rc;
@@ -65,23 +65,25 @@ void display_wave_on(int on)
get_win_size(&w, &h);
+ if (wave_on) {
+ memset(&screen, ' ', sizeof(screen));
+ printf("\0337\033[H");
+ for (i = 0; i < num_sender; i++) {
+ for (j = 0; j < HEIGHT; j++) {
+ screen[j][w] = '\0';
+ puts(screen[j]);
+ }
+ }
+ printf("\0338"); fflush(stdout);
+ }
+
if (on < 0)
wave_on = 1 - wave_on;
else
wave_on = on;
-
- memset(&screen, ' ', sizeof(screen));
- printf("\0337\033[H");
- for (i = 0; i < num_sender; i++) {
- for (j = 0; j < HEIGHT; j++) {
- screen[j][w] = '\0';
- puts(screen[j]);
- }
- }
- printf("\0338"); fflush(stdout);
}
-void display_limit_scroll(int on)
+void display_wave_limit_scroll(int on)
{
int w, h;
diff --git a/src/common/display_wave.h b/src/common/display_wave.h
deleted file mode 100644
index 57a489a..0000000
--- a/src/common/display_wave.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#define MAX_DISPLAY_WIDTH 1024
-
-typedef struct sender sender_t;
-
-typedef struct display_wave {
- int interval_pos;
- int interval_max;
- int offset;
- int16_t buffer[MAX_DISPLAY_WIDTH];
-} dispwav_t;
-
-void display_wave_init(sender_t *sender, int samplerate);
-void display_wave_on(int on);
-void display_limit_scroll(int on);
-void display_wave(sender_t *sender, int16_t *samples, int length);
-
diff --git a/src/common/main_common.c b/src/common/main_common.c
index 4359546..7a38bc4 100644
--- a/src/common/main_common.c
+++ b/src/common/main_common.c
@@ -431,8 +431,14 @@ next_char:
goto next_char;
case 'w':
/* toggle display */
+ display_iq_on(0);
display_wave_on(-1);
goto next_char;
+ case 'q':
+ /* toggle display */
+ display_wave_on(0);
+ display_iq_on(-1);
+ goto next_char;
case 'i':
/* dump info */
dump_info();
diff --git a/src/common/sdr.c b/src/common/sdr.c
index 527c291..93e591d 100644
--- a/src/common/sdr.c
+++ b/src/common/sdr.c
@@ -83,6 +83,8 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq
int rc;
int c;
+ display_iq_init(samplerate);
+
if (channels < 1) {
PDEBUG(DSDR, DEBUG_ERROR, "No channel given, please fix!\n");
abort();
@@ -283,6 +285,8 @@ int sdr_read(void *inst, int16_t **samples, int num, int channels)
if (count <= 0)
return count;
+ display_iq(buff, count);
+
for (c = 0; c < channels; c++) {
rot = sdr->chan[c].rx_rot;
phase = sdr->chan[c].rx_phase;
diff --git a/src/common/sender.h b/src/common/sender.h
index 5dbdf52..61302f1 100644
--- a/src/common/sender.h
+++ b/src/common/sender.h
@@ -7,7 +7,7 @@
#include "jitter.h"
#include "loss.h"
#include "emphasis.h"
-#include "display_wave.h"
+#include "display.h"
#define MAX_SENDER 16