Add '--console' command line parameter to enable console thread. Replaces previous IFDEF

This commit is contained in:
Ed Gonzalez 2015-01-15 10:43:42 -06:00
parent d7a84b9ded
commit a05e965db2
4 changed files with 31 additions and 18 deletions

View file

@ -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();
}
/* *****************************************************************************

View file

@ -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);

View file

@ -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);

View file

@ -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);