From a05e965db203ae9b35b5bd80e0a315c4432222ce Mon Sep 17 00:00:00 2001 From: Ed Gonzalez Date: Thu, 15 Jan 2015 10:43:42 -0600 Subject: [PATCH] Add '--console' command line parameter to enable console thread. Replaces previous IFDEF --- DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c | 23 ++++++++++--------- DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h | 2 +- DSP_API/SmartSDR_Interface/traffic_cop.h | 1 - DSP_API/main.c | 23 +++++++++++++++---- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c index bf20d2c..d7c3349 100644 --- a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c +++ b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c @@ -49,9 +49,8 @@ static uint32 _api_version; static uint32 _handle; -#ifdef CONSOLE_THREAD static pthread_t _console_thread_ID; -#endif + static BOOL console_thread_abort = FALSE; #define PROMPT "\n\033[92mWaveform -->\033[33m" static sem_t _startup_sem, _communications_sem; @@ -94,10 +93,10 @@ void SmartSDR_API_Shutdown(void) void* _console_thread(void* param) { cmd_banner(); + output(PROMPT); // let everybody know we're through printing sem_post(&_startup_sem); sem_wait(&_communications_sem); - output(PROMPT); while (!console_thread_abort) { command(); @@ -108,7 +107,7 @@ void* _console_thread(void* param) return NULL; } -void SmartSDR_API_Init(void) +void SmartSDR_API_Init(BOOL enable_console) { sem_init(&_startup_sem,0,0); sem_init(&_communications_sem,0,0); @@ -116,20 +115,22 @@ void SmartSDR_API_Init(void) // initialize printed output lock_printf_init(); lock_malloc_init(); + /* Initialize UDP connections for TX */ vita_output_Init(); sched_waveform_Init(); // Start the console thread -#ifdef CONSOLE_THREAD - pthread_create(&_console_thread_ID, NULL, &_console_thread, NULL); -#endif - + if ( enable_console ) { + pthread_create(&_console_thread_ID, NULL, &_console_thread, NULL); // wait for the console to print out all it's stuff - sem_wait(&_startup_sem); - // initialize the traffic cop - tc_Init(); + sem_wait(&_startup_sem); + } + // initialize the discovery client dc_Init(); + + /* Initialize Traffic Cop for TCP RX/TX */ + tc_Init(); } /* ***************************************************************************** diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h index 56468a1..f527c58 100644 --- a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h +++ b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h @@ -45,7 +45,7 @@ uint32 api_getVersion(void); void api_setHandle(uint32 handle); uint32 api_getHandle(void); void SmartSDR_API_Shutdown(void); -void SmartSDR_API_Init(void); +void SmartSDR_API_Init(BOOL enable_console); uint32 register_mode(void); diff --git a/DSP_API/SmartSDR_Interface/traffic_cop.h b/DSP_API/SmartSDR_Interface/traffic_cop.h index 49470ac..3017ba3 100644 --- a/DSP_API/SmartSDR_Interface/traffic_cop.h +++ b/DSP_API/SmartSDR_Interface/traffic_cop.h @@ -61,7 +61,6 @@ void tc_Abort(void); void tc_startKeepalive(void); void tc_abort(void); void tc_Init(void); -void SmartSDR_API_Init(void); uint32 tc_sendSmartSDRcommand(char* command, BOOL block, char** response); Command tc_commandList_respond(uint32 sequence, char* response); diff --git a/DSP_API/main.c b/DSP_API/main.c index 74120c7..c5ca076 100644 --- a/DSP_API/main.c +++ b/DSP_API/main.c @@ -121,20 +121,33 @@ void setup_segfault_handler(void) signal(SIGPIPE, SIG_IGN); } - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // main() -int main(void) +int main( int argc, char * argv[]) { + const char * console_param = "--console"; + BOOL enable_console = FALSE; /* Semaphore will be used to signal end of execution */ sem_init(&shutdown_sem, 0, 0); - + /* If compiled in DEBUG then seg-faults will include a stack trace */ setup_segfault_handler(); - SmartSDR_API_Init(); + int i = 0; + for ( i = 1 ; i < argc; i++ ) { + if (strncmp(argv[i], console_param, strlen(console_param)) == 0 ) { + /* We will run with a console for input. + * This is normally disabled so that the waveform can run as a + * service or as a subprocess. + */ + enable_console = TRUE; + } else { + output("Unknown console parameter - '%s'\n", argv[i]); + } + } + + SmartSDR_API_Init(enable_console); /* Wait to be notified of shutdown */ sem_wait(&shutdown_sem);