Discovery now starts the Traffic Cop when a radio is found. The TC is passed the hostname and port from discovery

This commit is contained in:
Ed Gonzalez 2015-01-15 11:45:36 -06:00
parent a05e965db2
commit b7707136bf
4 changed files with 20 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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