diff --git a/DSP_API/SmartSDR_Interface/discovery_client.c b/DSP_API/SmartSDR_Interface/discovery_client.c index 073eade..cb74368 100644 --- a/DSP_API/SmartSDR_Interface/discovery_client.c +++ b/DSP_API/SmartSDR_Interface/discovery_client.c @@ -33,6 +33,7 @@ #include // for memset #include #include // for htonl, htons, IPPROTO_UDP +#include #include #include // for errno #include @@ -46,6 +47,7 @@ static int _dc_sock; static pthread_t _dc_thread; static BOOL _dc_abort = FALSE; +static char * _restrict_ip = NULL; void printRadio(Radio radio) @@ -75,9 +77,28 @@ void printRadio(Radio radio) static void _dc_RadioFound(Radio radio) { - if(getIP(radio->ip) == ntohl(net_get_ip())) - { - output("Radio found"); + BOOL radio_found = FALSE; + + if ( _restrict_ip != NULL ) { + if ( getIP(radio->ip) == getIP(_restrict_ip)) { + /* We have found the radio that we are restricted to */ + output("We found a radio that maches our _restrict_ip - '%s'\n", _restrict_ip); + radio_found = TRUE; + } + } else if ( FALSE ) { /* Are we running within a radio? */ + + if(getIP(radio->ip) == ntohl(net_get_ip())) { + radio_found = TRUE; + output("We found a radio that is running on the same box as us - '%s'\n", radio->ip); + } + + } else { /* Simply connect to first radio we find */ + radio_found = TRUE; + output("We are attaching to the first radio we see"); + } + + if ( radio_found ) { + output("Radio found\n"); // yes -- connect and stop looking for more radios // TODO: connect // start a keepalive to keep the channel open and know when it dies @@ -269,10 +290,15 @@ static void* _dc_ListenerLoop(void* param) } } + if ( _restrict_ip ) { + safe_free(_restrict_ip); + _restrict_ip = NULL; + } + return NULL; } -void dc_Init(void) +void dc_Init(const char * radio_ip) { output("Discovery Client Init: Opening socket"); int true = TRUE; @@ -310,6 +336,16 @@ void dc_Init(void) } output("\n"); + if ( _restrict_ip ) { + safe_free(_restrict_ip ); + _restrict_ip = NULL; + } + + if ( radio_ip != NULL ) { + _restrict_ip = safe_malloc(strlen(radio_ip) + 1 ); + strncpy(_restrict_ip, radio_ip, strlen(radio_ip) + 1); + } + // start the listener thread pthread_create(&_dc_thread, NULL, &_dc_ListenerLoop, NULL); } diff --git a/DSP_API/SmartSDR_Interface/discovery_client.h b/DSP_API/SmartSDR_Interface/discovery_client.h index c574e56..c1b1840 100644 --- a/DSP_API/SmartSDR_Interface/discovery_client.h +++ b/DSP_API/SmartSDR_Interface/discovery_client.h @@ -45,7 +45,7 @@ typedef struct _radio } radioType, *Radio; -void dc_Init(void); +void dc_Init(const char * radio_ip); void dc_Exit(void); void printRadio(Radio radio); diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c index 54e1fb3..06cef1c 100644 --- a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c +++ b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c @@ -107,7 +107,7 @@ void* _console_thread(void* param) return NULL; } -void SmartSDR_API_Init(BOOL enable_console) +void SmartSDR_API_Init(BOOL enable_console, const char * radio_ip) { sem_init(&_startup_sem,0,0); sem_init(&_communications_sem,0,0); @@ -129,7 +129,7 @@ void SmartSDR_API_Init(BOOL enable_console) /* Initialize the discovery client * When a radio is found then the Traffic Cop is Started */ - dc_Init(); + dc_Init(radio_ip); } /* ***************************************************************************** diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.h index f527c58..242b270 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(BOOL enable_console); +void SmartSDR_API_Init(BOOL enable_console, const char * radio_ip); uint32 register_mode(void); diff --git a/DSP_API/main.c b/DSP_API/main.c index c5ca076..39de9a2 100644 --- a/DSP_API/main.c +++ b/DSP_API/main.c @@ -127,7 +127,9 @@ void setup_segfault_handler(void) int main( int argc, char * argv[]) { const char * console_param = "--console"; + const char * restrict_ip_param = "--ip="; BOOL enable_console = FALSE; + char * restrict_ip = NULL; /* Semaphore will be used to signal end of execution */ sem_init(&shutdown_sem, 0, 0); @@ -142,12 +144,21 @@ int main( int argc, char * argv[]) * service or as a subprocess. */ enable_console = TRUE; + } else if ( strncmp(argv[i], restrict_ip_param, strlen(restrict_ip_param)) == 0 ) { + + restrict_ip = safe_malloc(strlen(argv[i])); + strncpy(restrict_ip, argv[i]+strlen(restrict_ip_param), strlen(argv[i])); + output("Restrict IP = '%s'", restrict_ip); } else { output("Unknown console parameter - '%s'\n", argv[i]); } } - SmartSDR_API_Init(enable_console); + SmartSDR_API_Init(enable_console, restrict_ip); + + if ( restrict_ip ) { + safe_free(restrict_ip); + } /* Wait to be notified of shutdown */ sem_wait(&shutdown_sem);