mirror of
https://github.com/n5ac/smartsdr-dsp.git
synced 2026-01-20 07:10:17 +01: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
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue