add makefile, create ncurses windows
This commit is contained in:
parent
720ac7950f
commit
807e3d0465
2 changed files with 41 additions and 12 deletions
4
Makefile
Normal file
4
Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
all: sentinel
|
||||
|
||||
sentinel: main.c
|
||||
gcc -lncurses -lcurl -lrtlsdr -lm main.c -o sentinel
|
||||
49
main.c
49
main.c
|
|
@ -5,6 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ncurses.h>
|
||||
#include <rtl-sdr.h>
|
||||
#include <curl/curl.h>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue