From 807e3d04650596872f002de46558ab912de9d625 Mon Sep 17 00:00:00 2001 From: hornet Date: Wed, 1 Jan 2025 22:16:44 +0500 Subject: [PATCH] add makefile, create ncurses windows --- Makefile | 4 ++++ main.c | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ca46060 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: sentinel + +sentinel: main.c + gcc -lncurses -lcurl -lrtlsdr -lm main.c -o sentinel \ No newline at end of file diff --git a/main.c b/main.c index f1077cd..92be0d4 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -46,9 +47,24 @@ bool SDR_PRESENT = false; bool RSS_LIST_PRESENT = false; bool COMMS_AVAILABLE = false; bool CURL_AVAILABLE = false; +int term_rows, term_cols; + +/* declare ncurses windows */ + +WINDOW * sdr; +WINDOW * rss; +WINDOW * defcon; + /* declare reusable functions */ +void get_terminal_size(int *rows, int *cols) { + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + *rows = w.ws_row; + *cols = w.ws_col; +} + /* read out shell command output */ char* readout(const char* command, char* buffer, size_t size) { FILE *fp = popen(command, "r"); @@ -180,9 +196,13 @@ void startup_checks() { } else { printf("internet connectivity status: "); printf(RED"offline\n"RESET); - printf(RED"internet-dependent capabilities will be unavailable!"RESET); + printf(RED"internet-dependent capabilities will be unavailable!\n"RESET); COMMS_AVAILABLE = false; } + /* get terminal size */ + get_terminal_size(&term_rows, &term_cols); + printf("terminal size: "); + printf(YELLOW"%dx%d\n"RESET, term_rows, term_cols); printf("----------------------------------------------------------------------\n"); /* utilities presence check */ printf(MAGENTA"UTILITIES\n\n"RESET); @@ -200,7 +220,7 @@ void startup_checks() { printf(MAGENTA"all checks finished!\n"RESET); printf("######################################################################\n"); printf(BLUE"initializing in 5 seconds...\n\n"RESET); - usleep(5000000); + //usleep(5000000); if (SDR_PRESENT == true) { printf(GREEN"initializing RTL-SDR...\n"RESET); @@ -237,13 +257,14 @@ void init_colors() { init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK); + init_pair(8, COLOR_WHITE, COLOR_RED); } void draw_bar_graph(double *data, int size) { clear(); double max_value = 0.0; attron(COLOR_PAIR(6)); - printw("center frequency: %.3f MHz gain: %d bandwidth: %.3f MHz", center_freq / (double)MHz, rtlsdr_get_tuner_gain(dev), bandwidth / (double)MHz); + wprintw(sdr, "center frequency: %.3f MHz gain: %d bandwidth: %.3f MHz", center_freq / (double)MHz, rtlsdr_get_tuner_gain(dev), bandwidth / (double)MHz); attroff(COLOR_PAIR(6)); double bottom = center_freq - bandwidth / 2.0; double step = bandwidth / (double)size; @@ -290,14 +311,6 @@ void rtl_sdr_waterfall() { usleep(500000); } -void sdr_not_available() { - clear(); - attron(COLOR_PAIR(1)); - printw("SDR NOT AVAILABLE"); - attroff(COLOR_PAIR(1)); - refresh(); - usleep(5000000); -} /* DEFCON level functions */ @@ -309,6 +322,14 @@ void start_dashboard() { cbreak(); noecho(); init_colors(); + refresh(); + WINDOW * sdr = newwin(term_rows/2, term_cols/2, 1, 1); + WINDOW * rss = newwin(term_rows/2, term_cols/2-2, 1, term_cols/2+2); + box(sdr, 0, 0); + box(rss, 0, 0); + wrefresh(sdr); + wrefresh(rss); + if (SDR_PRESENT == true) { do{ rtl_sdr_waterfall(); @@ -316,7 +337,11 @@ void start_dashboard() { } else { do{ - sdr_not_available(); + wmove(sdr, 14, 47); + wbkgd(sdr, COLOR_PAIR(8)); + wprintw(sdr, " SDR NOT AVAILABLE "); + wrefresh(sdr); + usleep(5000000); } while (true); } rtlsdr_close(dev);