From 6adfcf74664a30021f12cc84e00a7cd471ee81a1 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Thu, 25 May 2017 18:43:54 +0200 Subject: Status display Alows to show status of current channels and users --- src/common/Makefile.am | 1 + src/common/debug.c | 2 + src/common/display.h | 10 +++ src/common/display_status.c | 147 ++++++++++++++++++++++++++++++++++++++++++++ src/common/main_common.c | 19 +++++- 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/common/display_status.c (limited to 'src/common') diff --git a/src/common/Makefile.am b/src/common/Makefile.am index fa26d21..0b74906 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -27,6 +27,7 @@ libcommon_a_SOURCES = \ ../common/fm_modulation.c \ ../common/sender.c \ ../common/display_wave.c \ + ../common/display_status.c \ ../common/main_common.c if HAVE_SDR diff --git a/src/common/debug.c b/src/common/debug.c index af056d2..bea7bb0 100644 --- a/src/common/debug.c +++ b/src/common/debug.c @@ -97,12 +97,14 @@ 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_wave_limit_scroll(1); + display_status_limit_scroll(1); #ifdef HAVE_SDR display_iq_limit_scroll(1); display_spectrum_limit_scroll(1); #endif printf("%s%s:%d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer); display_wave_limit_scroll(0); + display_status_limit_scroll(0); #ifdef HAVE_SDR display_iq_limit_scroll(0); display_spectrum_limit_scroll(0); diff --git a/src/common/display.h b/src/common/display.h index 9f476de..6f75662 100644 --- a/src/common/display.h +++ b/src/common/display.h @@ -28,6 +28,8 @@ typedef struct display_spectrum { double buffer_Q[MAX_DISPLAY_SPECTRUM]; } dispspectrum_t; +#define MAX_HEIGHT_STATUS 32 + void get_win_size(int *w, int *h); void display_wave_init(sender_t *sender, int samplerate); @@ -35,6 +37,13 @@ void display_wave_on(int on); void display_wave_limit_scroll(int on); void display_wave(sender_t *sender, sample_t *samples, int length, double range); +void display_status_on(int on); +void display_status_limit_scroll(int on); +void display_status_start(void); +void display_status_channel(int channel, const char *type, const char *state); +void display_status_subscriber(const char *number, const char *state); +void display_status_end(void); + void display_iq_init(int samplerate); void display_iq_on(int on); void display_iq_limit_scroll(int on); @@ -44,3 +53,4 @@ void display_spectrum_init(int samplerate); 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_status.c b/src/common/display_status.c new file mode 100644 index 0000000..64ec79c --- /dev/null +++ b/src/common/display_status.c @@ -0,0 +1,147 @@ +/* display status functions + * + * (C) 2017 by Andreas Eversberg + * 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 . + */ + +#include +#include +#include +#include +#include +#include "sample.h" +#include "sender.h" + +static int status_on = 0; +static int line_count = 0; +static int lines_total = 0; +static char screen[MAX_HEIGHT_STATUS][MAX_DISPLAY_WIDTH]; + +void print_status(int on) +{ + int i, j; + int w, h; + + get_win_size(&w, &h); + + if (w > MAX_DISPLAY_WIDTH) + w = MAX_DISPLAY_WIDTH; + h--; + if (h > lines_total) + h = lines_total; + + printf("\0337\033[H\033[1;37m"); + for (i = 0; i < h; i++) { + j = 0; + if (on) { + for (j = 0; j < w; j++) + putchar(screen[i][j]); + } else { + for (j = 0; j < w; j++) + putchar(' '); + } + putchar('\n'); + } + printf("\0338"); fflush(stdout); +} + +void display_status_on(int on) +{ + if (status_on) + print_status(0); + + if (on < 0) + status_on = 1 - status_on; + else + status_on = on; + + if (status_on) + print_status(1); +} + +void display_status_limit_scroll(int on) +{ + int w, h; + + if (!status_on) + return; + + get_win_size(&w, &h); + + printf("\0337"); + printf("\033[%d;%dr", (on) ? lines_total + 1 : 1, h); + printf("\0338"); +} + +/* start status display */ +void display_status_start(void) +{ + memset(screen, ' ', sizeof(screen)); + memset(screen[0], '-', sizeof(screen[0])); + strncpy(screen[0] + 4, "Channel Status", 14); + line_count = 1; +} + +void display_status_channel(int channel, const char *type, const char *state) +{ + char line[MAX_DISPLAY_WIDTH]; + + /* add empty line after previous channel+subscriber */ + if (line_count > 1 && line_count < MAX_HEIGHT_STATUS) + line_count++; + + if (line_count == MAX_HEIGHT_STATUS) + return; + + if (type) + snprintf(line, sizeof(line), "Channel: %d Type: %s State: %s", channel, type, state); + else + snprintf(line, sizeof(line), "Channel: %d State: %s", channel, state); + line[sizeof(line) - 1] = '\0'; + strncpy(screen[line_count++], line, strlen(line)); +} + +void display_status_subscriber(const char *number, const char *state) +{ + char line[MAX_DISPLAY_WIDTH]; + + if (line_count == MAX_HEIGHT_STATUS) + return; + + if (state) + snprintf(line, sizeof(line), " Subscriber: %s State: %s", number, state); + else + snprintf(line, sizeof(line), " Subscriber: %s", number); + line[sizeof(line) - 1] = '\0'; + strncpy(screen[line_count++], line, strlen(line)); +} + +void display_status_end(void) +{ + if (line_count < MAX_HEIGHT_STATUS) { + memset(screen[line_count], '-', sizeof(screen[line_count])); + line_count++; + } + /* if last total lines exceed current line count, keep it, so removed lines are overwritten with spaces */ + if (line_count > lines_total) + lines_total = line_count; + if (status_on) + print_status(1); + /* set new total lines */ + lines_total = line_count; +} + + diff --git a/src/common/main_common.c b/src/common/main_common.c index 4eaeaad..32c1a78 100644 --- a/src/common/main_common.c +++ b/src/common/main_common.c @@ -166,7 +166,12 @@ void print_hotkeys_common(void) printf("\n"); printf("Press digits '0'..'9' and then 'd' key to dial towards mobile station\n"); printf("Press 'h' key to hangup.\n"); - printf("Press 'w' key to toggle display of wave form of RX signal.\n"); + printf("Press 'w' key to toggle display of RX wave form.\n"); + printf("Press 'c' key to toggle display of channel status.\n"); +#ifdef HAVE_SDR + printf("Press 'i' key to toggle display of RX I/Q vector.\n"); + printf("Press 's' key to toggle display of RX spectrum.\n"); +#endif } #define OPT_CHANNEL 1000 @@ -567,18 +572,30 @@ next_char: display_iq_on(0); display_spectrum_on(0); #endif + display_status_on(0); display_wave_on(-1); goto next_char; + case 'c': + /* toggle display */ +#ifdef HAVE_SDR + display_iq_on(0); + display_spectrum_on(0); +#endif + display_wave_on(0); + display_status_on(-1); + goto next_char; #ifdef HAVE_SDR case 'q': /* toggle display */ display_wave_on(0); + display_status_on(0); display_spectrum_on(0); display_iq_on(-1); goto next_char; case 's': /* toggle spectrum */ display_wave_on(0); + display_status_on(0); display_iq_on(0); display_spectrum_on(-1); goto next_char; -- cgit v1.2.3