begin work on RSS feed, better startup checks
This commit is contained in:
parent
b212def173
commit
720ac7950f
2 changed files with 112 additions and 20 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -55,4 +55,7 @@ dkms.conf
|
|||
# Custom
|
||||
sentinel
|
||||
.vscode
|
||||
.rss_feed_list
|
||||
.last_known_defcon
|
||||
test.c
|
||||
|
||||
|
|
129
main.c
129
main.c
|
@ -7,6 +7,7 @@
|
|||
#include <unistd.h>
|
||||
#include <ncurses.h>
|
||||
#include <rtl-sdr.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
/* define ANSI escape chars and math */
|
||||
#define RESET "\033[0m"
|
||||
|
@ -41,6 +42,10 @@ uint32_t MHz = 1000000;
|
|||
uint32_t kHz = 1000;
|
||||
uint32_t bandwidth;
|
||||
uint32_t center_freq;
|
||||
bool SDR_PRESENT = false;
|
||||
bool RSS_LIST_PRESENT = false;
|
||||
bool COMMS_AVAILABLE = false;
|
||||
bool CURL_AVAILABLE = false;
|
||||
|
||||
/* declare reusable functions */
|
||||
|
||||
|
@ -80,32 +85,81 @@ void util_check() {
|
|||
printf("curl: ");
|
||||
if (system("curl --version > /dev/null 2>&1") == 0) {
|
||||
printf(GREEN"OK\n"RESET);
|
||||
CURL_AVAILABLE = true;
|
||||
} else {
|
||||
printf(RED"FAIL\n"RESET);
|
||||
}
|
||||
printf("rtl-sdr: ");
|
||||
if (system("ls /usr/bin/rtl_sdr > /dev/null 2>&1") == 0) {
|
||||
printf(GREEN"OK\n"RESET);
|
||||
SDR_PRESENT = true;
|
||||
} else {
|
||||
printf(RED"FAIL\n"RESET);
|
||||
}
|
||||
}
|
||||
|
||||
void rtl_sdr_check() {
|
||||
rtlsdr_open;
|
||||
int index;
|
||||
const char* device_name;
|
||||
char serial[256], product[256], manufact[256];
|
||||
device_name = rtlsdr_get_device_name(device_index);
|
||||
rtlsdr_get_device_usb_strings(index, manufact, product, serial);
|
||||
printf("device name: " GREEN);
|
||||
printf(device_name);
|
||||
printf("\n" RESET);
|
||||
printf(YELLOW"serial: %s\n", serial);
|
||||
printf("product: %s\n", product);
|
||||
printf("manufacturer: %s\n", manufact);
|
||||
printf(RESET);
|
||||
rtlsdr_close;
|
||||
|
||||
if (rtlsdr_open != NULL && SDR_PRESENT == true) {
|
||||
int index;
|
||||
const char* device_name;
|
||||
char serial[256], product[256], manufact[256];
|
||||
device_name = rtlsdr_get_device_name(device_index);
|
||||
rtlsdr_get_device_usb_strings(index, manufact, product, serial);
|
||||
printf("device name: " GREEN);
|
||||
printf(device_name);
|
||||
printf("\n" RESET);
|
||||
printf(YELLOW"serial: %s\n", serial);
|
||||
printf("product: %s\n", product);
|
||||
printf("manufacturer: %s\n", manufact);
|
||||
printf(RESET);
|
||||
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) {
|
||||
printf("internet connectivity status: ");
|
||||
printf(GREEN"online\n"RESET);
|
||||
COMMS_AVAILABLE = true;
|
||||
} else {
|
||||
printf("internet connectivity status: ");
|
||||
printf(RED"offline\n"RESET);
|
||||
printf(RED"internet-dependent capabilities will be unavailable!"RESET);
|
||||
COMMS_AVAILABLE = false;
|
||||
}
|
||||
printf("----------------------------------------------------------------------\n");
|
||||
/* utilities presence check */
|
||||
|
@ -135,10 +191,25 @@ void startup_checks() {
|
|||
printf(MAGENTA"SOFTWARE-DEFINED RADIO\n\n"RESET);
|
||||
rtl_sdr_check();
|
||||
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("######################################################################\n");
|
||||
printf(GREEN"initializing RTL-SDR...\n"RESET);
|
||||
rtlsdr_open(&dev, device_index);
|
||||
printf(BLUE"initializing in 5 seconds...\n\n"RESET);
|
||||
usleep(5000000);
|
||||
if (SDR_PRESENT == true)
|
||||
{
|
||||
printf(GREEN"initializing RTL-SDR...\n"RESET);
|
||||
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 */
|
||||
|
@ -219,6 +290,18 @@ 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 */
|
||||
|
||||
|
||||
/* main dashboard function */
|
||||
|
||||
void start_dashboard() {
|
||||
|
@ -226,10 +309,16 @@ void start_dashboard() {
|
|||
cbreak();
|
||||
noecho();
|
||||
init_colors();
|
||||
do
|
||||
{
|
||||
rtl_sdr_waterfall();
|
||||
} while (true);
|
||||
if (SDR_PRESENT == true) {
|
||||
do{
|
||||
rtl_sdr_waterfall();
|
||||
} while (true);
|
||||
}
|
||||
else {
|
||||
do{
|
||||
sdr_not_available();
|
||||
} while (true);
|
||||
}
|
||||
rtlsdr_close(dev);
|
||||
endwin();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue