Skip to content

Commit

Permalink
Use ncurses for interactive mode (reduces flicker on slow connections…
Browse files Browse the repository at this point in the history
… a lot!)
  • Loading branch information
mutability committed Oct 11, 2016
1 parent 25ea6d3 commit f6b1b94
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 143 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ all: dump1090 view1090
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

dump1090: dump1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o crc.o demod_2400.o stats.o cpr.o icao_filter.o track.o util.o convert.o $(COMPAT)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_RTLSDR)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_RTLSDR) -lncurses

view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o $(COMPAT)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) -lncurses

faup1090: faup1090.o anet.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o $(COMPAT)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: dump1090-fa
Section: embedded
Priority: extra
Maintainer: Oliver Jowett <oliver@mutability.co.uk>
Build-Depends: debhelper(>=9), librtlsdr-dev, libusb-1.0-0-dev, pkg-config, dh-systemd
Build-Depends: debhelper(>=9), librtlsdr-dev, libusb-1.0-0-dev, pkg-config, dh-systemd, libncurses5-dev
Standards-Version: 3.9.3
Homepage: https://github.com/mutability/dump1090
Vcs-Git: https://github.com/mutability/dump1090.git
Expand Down
37 changes: 3 additions & 34 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,6 @@ static void sigtermHandler(int dummy) {
Modes.exit = 1; // Signal to threads that we are done
log_with_timestamp("Caught SIGTERM, shutting down..\n");
}
//
// =============================== Terminal handling ========================
//
#ifndef _WIN32
// Get the number of rows after the terminal changes size.
int getTermRows() {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return (w.ws_row);
}

// Handle resizing terminal
void sigWinchCallback() {
signal(SIGWINCH, SIG_IGN);
Modes.interactive_rows = getTermRows();
interactiveShowData();
signal(SIGWINCH, sigWinchCallback);
}
#else
int getTermRows() { return MODES_INTERACTIVE_ROWS;}
#endif

static void start_cpu_timing(struct timespec *start_time)
{
Expand Down Expand Up @@ -153,7 +132,6 @@ void modesInitConfig(void) {
#ifdef ENABLE_WEBSERVER
Modes.net_http_ports = strdup("8080");
#endif
Modes.interactive_rows = getTermRows();
Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
Modes.html_dir = HTMLPATH;
Modes.json_interval = 1000;
Expand Down Expand Up @@ -244,6 +222,7 @@ void modesInit(void) {
modesChecksumInit(Modes.nfix_crc);
icaoFilterInit();
modeACInit();
interactiveInit();

if (Modes.show_only)
icaoFilterAdd(Modes.show_only);
Expand Down Expand Up @@ -675,9 +654,7 @@ void showHelp(void) {
"--iformat <format> Sample format for --ifile: UC8 (default), SC16, or SC16Q11\n"
"--throttle When reading from a file, play back in realtime, not at max speed\n"
"--interactive Interactive mode refreshing data on screen. Implies --throttle\n"
"--interactive-rows <num> Max number of rows in interactive mode (default: 15)\n"
"--interactive-ttl <sec> Remove from list if idle for <sec> (default: 60)\n"
"--interactive-rtl1090 Display flight table in RTL1090 format\n"
"--raw Show only messages hex values\n"
"--net Enable networking\n"
"--modeac Enable decoding of SSR Modes 3/A & 3/C\n"
Expand Down Expand Up @@ -1031,8 +1008,6 @@ int main(int argc, char **argv) {
Modes.interactive = Modes.throttle = 1;
} else if (!strcmp(argv[j],"--throttle")) {
Modes.throttle = 1;
} else if (!strcmp(argv[j],"--interactive-rows") && more) {
Modes.interactive_rows = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--interactive-ttl") && more) {
Modes.interactive_display_ttl = (uint64_t)(1000 * atof(argv[++j]));
} else if (!strcmp(argv[j],"--lat") && more) {
Expand Down Expand Up @@ -1080,9 +1055,6 @@ int main(int argc, char **argv) {
Modes.show_only = (uint32_t) strtoul(argv[++j], NULL, 16);
} else if (!strcmp(argv[j],"--mlat")) {
Modes.mlat = 1;
} else if (!strcmp(argv[j],"--interactive-rtl1090")) {
Modes.interactive = 1;
Modes.interactive_rtl1090 = 1;
} else if (!strcmp(argv[j],"--oversample")) {
// Ignored
} else if (!strcmp(argv[j], "--html-dir") && more) {
Expand Down Expand Up @@ -1111,11 +1083,6 @@ int main(int argc, char **argv) {
if (!Modes.quiet) {showCopyright();}
#endif

#ifndef _WIN32
// Setup for SIGWINCH for handling lines
if (Modes.interactive) {signal(SIGWINCH, sigWinchCallback);}
#endif

// Initialization
log_with_timestamp("%s %s starting up.", MODES_DUMP1090_VARIANT, MODES_DUMP1090_VERSION);
modesInit();
Expand Down Expand Up @@ -1252,6 +1219,8 @@ int main(int argc, char **argv) {
pthread_mutex_destroy(&Modes.data_mutex);
}

interactiveCleanup();

// If --stats were given, print statistics
if (Modes.stats) {
display_total_stats();
Expand Down
5 changes: 2 additions & 3 deletions dump1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ typedef enum {
#define MODES_DEBUG_NOPREAMBLE_LEVEL 25

#define MODES_INTERACTIVE_REFRESH_TIME 250 // Milliseconds
#define MODES_INTERACTIVE_ROWS 22 // Rows on screen
#define MODES_INTERACTIVE_DISPLAY_TTL 60000 // Delete from display after 60 seconds

#define MODES_NET_HEARTBEAT_INTERVAL 60000 // milliseconds
Expand Down Expand Up @@ -330,15 +329,13 @@ struct { // Internal state
int quiet; // Suppress stdout
uint32_t show_only; // Only show messages from this ICAO
int interactive; // Interactive mode
int interactive_rows; // Interactive mode: max number of rows
uint64_t interactive_display_ttl;// Interactive mode: TTL display
uint64_t stats; // Interval (millis) between stats dumps,
int stats_range_histo; // Collect/show a range histogram?
int onlyaddr; // Print only ICAO addresses
int metric; // Use metric units
int use_gnss; // Use GNSS altitudes with H suffix ("HAE", though it isn't always) when available
int mlat; // Use Beast ascii format for raw data output, i.e. @...; iso *...;
int interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090
char *json_dir; // Path to json base directory, or NULL not to write json.
uint64_t json_interval; // Interval between rewriting the json aircraft file, in milliseconds; also the advertised map refresh interval
char *html_dir; // Path to www base directory.
Expand Down Expand Up @@ -559,7 +556,9 @@ void useModesMessage (struct modesMessage *mm);
//
// Functions exported from interactive.c
//
void interactiveInit(void);
void interactiveShowData(void);
void interactiveCleanup(void);

#ifdef __cplusplus
}
Expand Down
144 changes: 74 additions & 70 deletions interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

#include "dump1090.h"

#include <curses.h>

//
//========================= Interactive mode ===============================

Expand All @@ -74,11 +76,29 @@ static int convert_speed(int kts)
//
// Show the currently captured interactive data on screen.
//

void interactiveInit() {
if (!Modes.interactive)
return;

initscr();
clear();
refresh();

mvprintw(0, 0, " Hex Mode Sqwk Flight Alt Spd Hdg Lat Long RSSI Msgs Ti");
mvhline(1, 0, ACS_HLINE, 80);
}

void interactiveCleanup(void) {
if (Modes.interactive) {
endwin();
}
}

void interactiveShowData(void) {
struct aircraft *a = Modes.aircrafts;
static uint64_t next_update;
uint64_t now = mstime();
int count = 3;
char progress;
char spinner[4] = "|/-\\";

Expand All @@ -89,24 +109,12 @@ void interactiveShowData(void) {
next_update = now + MODES_INTERACTIVE_REFRESH_TIME;

progress = spinner[(now/1000)%4];
mvaddch(0, 79, progress);

#ifndef _WIN32
printf("\x1b[H\x1b[2J"); // Clear the screen
#else
cls();
#endif

if (Modes.interactive_rtl1090 == 0) {
printf (
" Hex Mode Sqwk Flight Alt Spd Hdg Lat Long RSSI Msgs Ti%c\n", progress);
} else {
printf (
" Hex Flight Alt V/S GS TT SSR G*456^ Msgs Seen %c\n", progress);
}
printf(
"-------------------------------------------------------------------------------\n");
int rows = getmaxy(stdscr);
int row = 2;

while(a && (count < Modes.interactive_rows)) {
while (a && row < rows) {

if ((now - a->seen) < Modes.interactive_display_ttl)
{
Expand Down Expand Up @@ -134,51 +142,42 @@ void interactiveShowData(void) {
msgs = 99999;
}

if (Modes.interactive_rtl1090) { // RTL1090 display mode
if (trackDataValid(&a->altitude_valid)) {
snprintf(strFl,6,"F%03d",((a->altitude+50)/100));
}
printf("%06x %-8s %-4s %-3s %-3s %4s %-6d %-2.0f\n",
a->addr, a->callsign, strFl, strGs, strTt, strSquawk, msgs, (now - a->seen)/1000.0);

} else { // Dump1090 display mode
char strMode[5] = " ";
char strLat[8] = " ";
char strLon[9] = " ";
double * pSig = a->signalLevel;
double signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
pSig[4] + pSig[5] + pSig[6] + pSig[7]) / 8.0;

strMode[0] = 'S';
if (a->modeA_hit) {strMode[2] = 'a';}
if (a->modeC_hit) {strMode[3] = 'c';}

if (trackDataValid(&a->position_valid)) {
snprintf(strLat, 8,"%7.03f", a->lat);
snprintf(strLon, 9,"%8.03f", a->lon);
}

if (trackDataValid(&a->airground_valid) && a->airground == AG_GROUND) {
snprintf(strFl, 7," grnd");
} else if (Modes.use_gnss && trackDataValid(&a->altitude_gnss_valid)) {
snprintf(strFl, 7, "%5dH", convert_altitude(a->altitude_gnss));
} else if (trackDataValid(&a->altitude_valid)) {
snprintf(strFl, 7, "%5d ", convert_altitude(a->altitude));
}

printf("%s%06X %-4s %-4s %-8s %6s %3s %3s %7s %8s %5.1f %5d %2.0f\n",
(a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : " ", (a->addr & 0xffffff),
strMode, strSquawk, a->callsign, strFl, strGs, strTt,
strLat, strLon, 10 * log10(signalAverage), msgs, (now - a->seen)/1000.0);
char strMode[5] = " ";
char strLat[8] = " ";
char strLon[9] = " ";
double * pSig = a->signalLevel;
double signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
pSig[4] + pSig[5] + pSig[6] + pSig[7]) / 8.0;

strMode[0] = 'S';
if (a->modeA_hit) {strMode[2] = 'a';}
if (a->modeC_hit) {strMode[3] = 'c';}

if (trackDataValid(&a->position_valid)) {
snprintf(strLat, 8,"%7.03f", a->lat);
snprintf(strLon, 9,"%8.03f", a->lon);
}

if (trackDataValid(&a->airground_valid) && a->airground == AG_GROUND) {
snprintf(strFl, 7," grnd");
} else if (Modes.use_gnss && trackDataValid(&a->altitude_gnss_valid)) {
snprintf(strFl, 7, "%5dH", convert_altitude(a->altitude_gnss));
} else if (trackDataValid(&a->altitude_valid)) {
snprintf(strFl, 7, "%5d ", convert_altitude(a->altitude));
}
count++;

mvprintw(row, 0, "%s%06X %-4s %-4s %-8s %6s %3s %3s %7s %8s %5.1f %5d %2.0f",
(a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : " ", (a->addr & 0xffffff),
strMode, strSquawk, a->callsign, strFl, strGs, strTt,
strLat, strLon, 10 * log10(signalAverage), msgs, (now - a->seen)/1000.0);
++row;
}
}
a = a->next;
}

if (!Modes.interactive_rtl1090 && Modes.mode_ac) {
for (unsigned i = 1; i < 4096 && count < Modes.interactive_rows; ++i) {
if (Modes.mode_ac) {
for (unsigned i = 1; i < 4096 && row < rows; ++i) {
if (modeAC_match[i] || modeAC_count[i] < 100)
continue;

Expand All @@ -191,22 +190,27 @@ void interactiveShowData(void) {
snprintf(strFl, 7, "%5d ", convert_altitude(modeC * 100));
}

printf("%7s %-4s %04x %-8s %6s %3s %3s %7s %8s %5s %5d %2s\n",
"", /* address */
strMode, /* mode */
modeA, /* squawk */
"", /* callsign */
strFl, /* altitude */
"", /* gs */
"", /* heading */
"", /* lat */
"", /* lon */
"", /* signal */
modeAC_count[i], /* messages */
""); /* seen */
count++;
mvprintw(row, 0,
"%7s %-4s %04x %-8s %6s %3s %3s %7s %8s %5s %5d %2s\n",
"", /* address */
strMode, /* mode */
modeA, /* squawk */
"", /* callsign */
strFl, /* altitude */
"", /* gs */
"", /* heading */
"", /* lat */
"", /* lon */
"", /* signal */
modeAC_count[i], /* messages */
""); /* seen */
++row;
}
}

move(row, 0);
clrtobot();
refresh();
}

//
Expand Down
Loading

0 comments on commit f6b1b94

Please sign in to comment.