mirror of
https://github.com/n5ac/smartsdr-dsp.git
synced 2026-04-05 14:25:30 +00:00
Add '--ip=' command line param to restrict which radio the waveform connects to in a multi-radio environment
This commit is contained in:
parent
17bf4b036a
commit
504ef71d99
5 changed files with 56 additions and 9 deletions
|
|
@ -33,6 +33,7 @@
|
|||
#include <string.h> // for memset
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h> // for htonl, htons, IPPROTO_UDP
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h> // for errno
|
||||
#include <unistd.h>
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/* *****************************************************************************
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue