begin work on RSS feed, better startup checks

This commit is contained in:
hornet 2025-01-01 20:11:41 +05:00
parent b212def173
commit 720ac7950f
2 changed files with 112 additions and 20 deletions

3
.gitignore vendored
View file

@ -55,4 +55,7 @@ dkms.conf
# Custom # Custom
sentinel sentinel
.vscode .vscode
.rss_feed_list
.last_known_defcon
test.c

95
main.c
View file

@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <ncurses.h> #include <ncurses.h>
#include <rtl-sdr.h> #include <rtl-sdr.h>
#include <curl/curl.h>
/* define ANSI escape chars and math */ /* define ANSI escape chars and math */
#define RESET "\033[0m" #define RESET "\033[0m"
@ -41,6 +42,10 @@ uint32_t MHz = 1000000;
uint32_t kHz = 1000; uint32_t kHz = 1000;
uint32_t bandwidth; uint32_t bandwidth;
uint32_t center_freq; uint32_t center_freq;
bool SDR_PRESENT = false;
bool RSS_LIST_PRESENT = false;
bool COMMS_AVAILABLE = false;
bool CURL_AVAILABLE = false;
/* declare reusable functions */ /* declare reusable functions */
@ -80,19 +85,22 @@ void util_check() {
printf("curl: "); printf("curl: ");
if (system("curl --version > /dev/null 2>&1") == 0) { if (system("curl --version > /dev/null 2>&1") == 0) {
printf(GREEN"OK\n"RESET); printf(GREEN"OK\n"RESET);
CURL_AVAILABLE = true;
} else { } else {
printf(RED"FAIL\n"RESET); printf(RED"FAIL\n"RESET);
} }
printf("rtl-sdr: "); printf("rtl-sdr: ");
if (system("ls /usr/bin/rtl_sdr > /dev/null 2>&1") == 0) { if (system("ls /usr/bin/rtl_sdr > /dev/null 2>&1") == 0) {
printf(GREEN"OK\n"RESET); printf(GREEN"OK\n"RESET);
SDR_PRESENT = true;
} else { } else {
printf(RED"FAIL\n"RESET); printf(RED"FAIL\n"RESET);
} }
} }
void rtl_sdr_check() { void rtl_sdr_check() {
rtlsdr_open;
if (rtlsdr_open != NULL && SDR_PRESENT == true) {
int index; int index;
const char* device_name; const char* device_name;
char serial[256], product[256], manufact[256]; char serial[256], product[256], manufact[256];
@ -106,6 +114,52 @@ void rtl_sdr_check() {
printf("manufacturer: %s\n", manufact); printf("manufacturer: %s\n", manufact);
printf(RESET); printf(RESET);
rtlsdr_close; rtlsdr_close;
} else {
printf(RED"SDR not detected! skipping...\n"RESET);
}
}
void defcon_level_check() {
FILE *fp = fopen(".last_known_defcon", "r");
if ( fp == NULL) {
printf(YELLOW"DEFCON level cache file not found or corrupted, creating new...\n"RESET);
FILE *fp = fopen(".last_known_defcon", "w");
fputc(5, fp);
fclose(fp);
} else {
int last_known = fgetc(fp);
printf("DEFCON level cache file found! last known level: %d\n", last_known);
fclose(fp);
}
}
void rss_sources_check() {
if (COMMS_AVAILABLE == true) {
FILE *fp = fopen(".rss_feed_list", "r");
if ( fp == NULL) {
printf(RED"RSS feed source list not found!\n"RESET);
fclose(fp);
} else {
printf(GREEN"RSS feed source list found! sources:\n\n"RESET);
RSS_LIST_PRESENT = true;
int line_count = 0;
char buffer[256];
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
line_count++;
}
char feed_source[line_count][256];
fseek(fp, 0, SEEK_SET);
for (int i = 0; i < line_count; i++) {
fgets(feed_source[i], sizeof(feed_source[i]), fp);
printf(GREEN"%s\n"RESET, feed_source[i]);
}
fclose(fp);
}
} else {
printf(RED"internet not available! skipping..."RESET);
}
} }
@ -122,10 +176,12 @@ void startup_checks() {
if (status == 0) { if (status == 0) {
printf("internet connectivity status: "); printf("internet connectivity status: ");
printf(GREEN"online\n"RESET); printf(GREEN"online\n"RESET);
COMMS_AVAILABLE = true;
} else { } else {
printf("internet connectivity status: "); printf("internet connectivity status: ");
printf(RED"offline\n"RESET); printf(RED"offline\n"RESET);
printf(RED"internet-dependent capabilities will be unavailable!"RESET); printf(RED"internet-dependent capabilities will be unavailable!"RESET);
COMMS_AVAILABLE = false;
} }
printf("----------------------------------------------------------------------\n"); printf("----------------------------------------------------------------------\n");
/* utilities presence check */ /* utilities presence check */
@ -135,10 +191,25 @@ void startup_checks() {
printf(MAGENTA"SOFTWARE-DEFINED RADIO\n\n"RESET); printf(MAGENTA"SOFTWARE-DEFINED RADIO\n\n"RESET);
rtl_sdr_check(); rtl_sdr_check();
printf("----------------------------------------------------------------------\n"); printf("----------------------------------------------------------------------\n");
printf(MAGENTA"DEFCON LEVEL STATUS\n\n"RESET);
defcon_level_check();
printf("----------------------------------------------------------------------\n");
printf(MAGENTA"RSS AGGREGATOR CHECK\n\n"RESET);
rss_sources_check();
printf("----------------------------------------------------------------------\n");
printf(MAGENTA"all checks finished!\n"RESET); printf(MAGENTA"all checks finished!\n"RESET);
printf("######################################################################\n"); printf("######################################################################\n");
printf(BLUE"initializing in 5 seconds...\n\n"RESET);
usleep(5000000);
if (SDR_PRESENT == true)
{
printf(GREEN"initializing RTL-SDR...\n"RESET); printf(GREEN"initializing RTL-SDR...\n"RESET);
rtlsdr_open(&dev, device_index); rtlsdr_open(&dev, device_index);
}
if (RSS_LIST_PRESENT == true && COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
printf(GREEN"initializing RSS aggregator...\n"RESET);
}
} }
/* signal analysis function */ /* signal analysis function */
@ -219,6 +290,18 @@ void rtl_sdr_waterfall() {
usleep(500000); 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 */
/* main dashboard function */ /* main dashboard function */
void start_dashboard() { void start_dashboard() {
@ -226,10 +309,16 @@ void start_dashboard() {
cbreak(); cbreak();
noecho(); noecho();
init_colors(); init_colors();
do if (SDR_PRESENT == true) {
{ do{
rtl_sdr_waterfall(); rtl_sdr_waterfall();
} while (true); } while (true);
}
else {
do{
sdr_not_available();
} while (true);
}
rtlsdr_close(dev); rtlsdr_close(dev);
endwin(); endwin();
} }