From b7707136bfffa63e01606b08a4c0b8b013ebbcc7 Mon Sep 17 00:00:00 2001 From: Ed Gonzalez Date: Thu, 15 Jan 2015 11:45:36 -0600 Subject: [PATCH] Discovery now starts the Traffic Cop when a radio is found. The TC is passed the hostname and port from discovery --- DSP_API/SmartSDR_Interface/discovery_client.c | 2 ++ DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c | 7 +++---- DSP_API/SmartSDR_Interface/traffic_cop.c | 15 +++++++++++++-- DSP_API/SmartSDR_Interface/traffic_cop.h | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/DSP_API/SmartSDR_Interface/discovery_client.c b/DSP_API/SmartSDR_Interface/discovery_client.c index 601fd6e..04941ae 100644 --- a/DSP_API/SmartSDR_Interface/discovery_client.c +++ b/DSP_API/SmartSDR_Interface/discovery_client.c @@ -81,6 +81,8 @@ static void _dc_RadioFound(Radio radio) // yes -- connect and stop looking for more radios // TODO: connect // start a keepalive to keep the channel open and know when it dies + tc_Init(radio->ip, radio->port); + uint32 result = register_mode(); // quick and dirty fail for now if (result != SUCCESS) exit(1); diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c index d7c3349..54e1fb3 100644 --- a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c +++ b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c @@ -126,11 +126,10 @@ void SmartSDR_API_Init(BOOL enable_console) sem_wait(&_startup_sem); } - // initialize the discovery client + /* Initialize the discovery client + * When a radio is found then the Traffic Cop is Started + */ dc_Init(); - - /* Initialize Traffic Cop for TCP RX/TX */ - tc_Init(); } /* ***************************************************************************** diff --git a/DSP_API/SmartSDR_Interface/traffic_cop.c b/DSP_API/SmartSDR_Interface/traffic_cop.c index 7548d8c..6b6651d 100644 --- a/DSP_API/SmartSDR_Interface/traffic_cop.c +++ b/DSP_API/SmartSDR_Interface/traffic_cop.c @@ -55,7 +55,9 @@ static pthread_t _keepalive_thread_id; static __thread receive_data __local; //! address of the host to connect to -- defaults to 127.0.0.1 //! but this is generally provided by discovery -static char* _hostname = "127.0.0.1"; +static char _hostname[32] = "127.0.0.1"; +static char _api_port[32] = SMARTSDR_API_PORT; + //const char* gai_strerror(int ecode); static BOOL _abort = FALSE; static int _socket; @@ -602,11 +604,20 @@ void tc_abort(void) exit(1); } -void tc_Init(void) +void tc_Init(const char * hostname, const char * api_port) { _commandList_Init(); output("\033[32mStarting Traffic Cop...\n\033[m"); + if ( hostname == NULL || api_port == NULL) { + output("NULL Hostname - tc_setHostname()\n"); + return; + } + + strncpy(_hostname, hostname, 31); + strncpy(_api_port, api_port, 31); + + uint32 ret_val = pthread_create(&_tc_thread_id, NULL, &_tc_thread, NULL); if (ret_val != 0) output("failed to start Traffic Cop thread\n"); } diff --git a/DSP_API/SmartSDR_Interface/traffic_cop.h b/DSP_API/SmartSDR_Interface/traffic_cop.h index 3017ba3..216c55e 100644 --- a/DSP_API/SmartSDR_Interface/traffic_cop.h +++ b/DSP_API/SmartSDR_Interface/traffic_cop.h @@ -60,7 +60,8 @@ typedef struct _cmd void tc_Abort(void); void tc_startKeepalive(void); void tc_abort(void); -void tc_Init(void); +void tc_Init(const char * hostname, const char * api_port); + uint32 tc_sendSmartSDRcommand(char* command, BOOL block, char** response); Command tc_commandList_respond(uint32 sequence, char* response);