implement queued commands in telnet server
This commit is contained in:
@@ -53,6 +53,7 @@
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include "common/utils/load_module_shlib.h"
|
#include "common/utils/load_module_shlib.h"
|
||||||
#include "common/config/config_userapi.h"
|
#include "common/config/config_userapi.h"
|
||||||
|
#include "common/utils/threadPool/thread-pool.h"
|
||||||
#include "executables/softmodem-common.h"
|
#include "executables/softmodem-common.h"
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
|
||||||
@@ -512,7 +513,17 @@ int process_command(char *buf) {
|
|||||||
} else {
|
} else {
|
||||||
for (k=0 ; telnetparams.CmdParsers[i].cmd[k].cmdfunc != NULL ; k++) {
|
for (k=0 ; telnetparams.CmdParsers[i].cmd[k].cmdfunc != NULL ; k++) {
|
||||||
if (strncasecmp(cmd, telnetparams.CmdParsers[i].cmd[k].cmdname,sizeof(telnetparams.CmdParsers[i].cmd[k].cmdname)) == 0) {
|
if (strncasecmp(cmd, telnetparams.CmdParsers[i].cmd[k].cmdname,sizeof(telnetparams.CmdParsers[i].cmd[k].cmdname)) == 0) {
|
||||||
telnetparams.CmdParsers[i].cmd[k].cmdfunc(cmdb, telnetparams.telnetdbg, client_printf);
|
if (telnetparams.CmdParsers[i].cmd[k].qptr != NULL) {
|
||||||
|
notifiedFIFO_elt_t *msg =newNotifiedFIFO_elt(sizeof(telnetsrv_qmsg_t),0,NULL,NULL);
|
||||||
|
telnetsrv_qmsg_t *cmddata=NotifiedFifoData(msg);
|
||||||
|
cmddata->cmdfunc=telnetparams.CmdParsers[i].cmd[k].cmdfunc;
|
||||||
|
cmddata->prnt=client_printf;
|
||||||
|
cmddata->debug=telnetparams.telnetdbg;
|
||||||
|
cmddata->cmdbuff=strdup(cmdb);
|
||||||
|
pushNotifiedFIFO(telnetparams.CmdParsers[i].cmd[k].qptr, msg);
|
||||||
|
} else {
|
||||||
|
telnetparams.CmdParsers[i].cmd[k].cmdfunc(cmdb, telnetparams.telnetdbg, client_printf);
|
||||||
|
}
|
||||||
rt= CMDSTATUS_FOUND;
|
rt= CMDSTATUS_FOUND;
|
||||||
}
|
}
|
||||||
} /* for k */
|
} /* for k */
|
||||||
@@ -758,6 +769,7 @@ int telnetsrv_autoinit(void) {
|
|||||||
*/
|
*/
|
||||||
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd) {
|
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd) {
|
||||||
int i;
|
int i;
|
||||||
|
notifiedFIFO_t *afifo=NULL;
|
||||||
|
|
||||||
if( modulename == NULL || var == NULL || cmd == NULL) {
|
if( modulename == NULL || var == NULL || cmd == NULL) {
|
||||||
fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
|
fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
|
||||||
@@ -769,6 +781,13 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde
|
|||||||
strncpy(telnetparams.CmdParsers[i].module,modulename,sizeof(telnetparams.CmdParsers[i].module)-1);
|
strncpy(telnetparams.CmdParsers[i].module,modulename,sizeof(telnetparams.CmdParsers[i].module)-1);
|
||||||
telnetparams.CmdParsers[i].cmd = cmd;
|
telnetparams.CmdParsers[i].cmd = cmd;
|
||||||
telnetparams.CmdParsers[i].var = var;
|
telnetparams.CmdParsers[i].var = var;
|
||||||
|
if (cmd->cmdflags & TELNETSRV_CMDFLAG_PUSHINTPOOLQ) {
|
||||||
|
if (afifo == NULL) {
|
||||||
|
afifo = malloc(sizeof(notifiedFIFO_t));
|
||||||
|
initNotifiedFIFO(afifo);
|
||||||
|
}
|
||||||
|
cmd->qptr = afifo;
|
||||||
|
}
|
||||||
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
|
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
|
||||||
i,telnetparams.CmdParsers[i].module);
|
i,telnetparams.CmdParsers[i].module);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -54,12 +54,24 @@
|
|||||||
typedef void(*telnet_printfunc_t)(const char* format, ...);
|
typedef void(*telnet_printfunc_t)(const char* format, ...);
|
||||||
typedef int(*cmdfunc_t)(char*, int, telnet_printfunc_t prnt);
|
typedef int(*cmdfunc_t)(char*, int, telnet_printfunc_t prnt);
|
||||||
|
|
||||||
|
#define TELNETSRV_CMDFLAG_PUSHINTPOOLQ (1<<0) // ask the telnet server to push the command in a thread pool queue
|
||||||
typedef struct cmddef {
|
typedef struct cmddef {
|
||||||
char cmdname[TELNET_CMD_MAXSIZE];
|
char cmdname[TELNET_CMD_MAXSIZE];
|
||||||
char helpstr[TELNET_HELPSTR_SIZE];
|
char helpstr[TELNET_HELPSTR_SIZE];
|
||||||
cmdfunc_t cmdfunc;
|
cmdfunc_t cmdfunc;
|
||||||
|
unsigned int cmdflags;
|
||||||
|
void *qptr;
|
||||||
} telnetshell_cmddef_t;
|
} telnetshell_cmddef_t;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* structure used to send a command via a message queue to enable */
|
||||||
|
/* executing a command in a thread different from the telnet server thread */
|
||||||
|
typedef struct telnetsrv_qmsg {
|
||||||
|
cmdfunc_t cmdfunc;
|
||||||
|
telnet_printfunc_t prnt;
|
||||||
|
int debug;
|
||||||
|
char *cmdbuff;
|
||||||
|
} telnetsrv_qmsg_t;
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/*structure to be used when adding a module to the telnet server */
|
/*structure to be used when adding a module to the telnet server */
|
||||||
/* This is the first parameter of the add_telnetcmd function, which can be used */
|
/* This is the first parameter of the add_telnetcmd function, which can be used */
|
||||||
@@ -111,9 +123,6 @@ typedef struct {
|
|||||||
} telnetsrv_params_t;
|
} telnetsrv_params_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef int(*addcmdfunc_t)(char*, telnetshell_vardef_t*, telnetshell_cmddef_t*);
|
|
||||||
|
|
||||||
typedef void(*settelnetmodule_t)(char *name, void *ptr);
|
typedef void(*settelnetmodule_t)(char *name, void *ptr);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
@@ -133,6 +142,7 @@ VT escape sequence definition, for smarter display....
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------------------*/
|
||||||
#define TELNET_ADDCMD_FNAME "add_telnetcmd"
|
#define TELNET_ADDCMD_FNAME "add_telnetcmd"
|
||||||
|
#define TELNET_ADDQUEUEDCMD_FNAME "add_telnetqueuedcmd"
|
||||||
typedef int(*add_telnetcmd_func_t)(char *, telnetshell_vardef_t *, telnetshell_cmddef_t *);
|
typedef int(*add_telnetcmd_func_t)(char *, telnetshell_vardef_t *, telnetshell_cmddef_t *);
|
||||||
#ifdef TELNETSERVERCODE
|
#ifdef TELNETSERVERCODE
|
||||||
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd);
|
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd);
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ static mapping channelmod_names[] = {
|
|||||||
|
|
||||||
static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
|
static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
|
||||||
static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt);
|
static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt);
|
||||||
|
static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt);
|
||||||
static telnetshell_cmddef_t channelmod_cmdarray[] = {
|
static telnetshell_cmddef_t channelmod_cmdarray[] = {
|
||||||
|
{"help","",channelmod_print_help},
|
||||||
{"show","<predef,current>",channelmod_show_cmd},
|
{"show","<predef,current>",channelmod_show_cmd},
|
||||||
{"modify","<channelid> <param> <value>",channelmod_modify_cmd},
|
{"modify","<channelid> <param> <value>",channelmod_modify_cmd},
|
||||||
{"","",NULL},
|
{"","",NULL},
|
||||||
@@ -1504,11 +1506,18 @@ double N_RB2channel_bandwidth(uint16_t N_RB) {
|
|||||||
LOG_E(PHY,"Unknown N_PRB\n");
|
LOG_E(PHY,"Unknown N_PRB\n");
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(channel_bandwidth);
|
return(channel_bandwidth);
|
||||||
}
|
}
|
||||||
static void display_channelmodel_help( telnet_printfunc_t prnt) {
|
|
||||||
|
|
||||||
|
|
||||||
|
static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt ) {
|
||||||
|
prnt("channelmod commands can be used to display or modify channel models parameters\n");
|
||||||
|
prnt("channelmod show predef: display predefined model algorithms available in oai\n");
|
||||||
|
prnt("channelmod show current: display the currently used models in the running executable\n");
|
||||||
|
prnt("channelmod modify <model index> <param name> <param value>: set the specified parameters in a current model to the given value\n");
|
||||||
|
prnt(" <model index> specifies the model, the show current model command can be used to list the current models indexes\n");
|
||||||
|
prnt(" <param name> can be one of \"riceanf\", \"aoa\", \"randaoa\", \"ploss\", \"offset\", \"forgetf\"\n");
|
||||||
|
return CMDSTATUS_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1543,7 +1552,7 @@ static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
display_channelmodel_help(prnt);
|
channelmod_print_help(buff, debug, prnt);
|
||||||
}
|
}
|
||||||
free(subcmd);
|
free(subcmd);
|
||||||
}
|
}
|
||||||
@@ -1569,15 +1578,21 @@ static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt)
|
|||||||
if ( strcmp(param,"riceanf") == 0) {
|
if ( strcmp(param,"riceanf") == 0) {
|
||||||
double dbl = atof(value);
|
double dbl = atof(value);
|
||||||
if (dbl <0 || dbl > 1)
|
if (dbl <0 || dbl > 1)
|
||||||
prnt("ricean factor range: 0 to 1, %lf is outof range\n",dbl);
|
prnt("ERROR: ricean factor range: 0 to 1, %lf is outof range\n",dbl);
|
||||||
else
|
else
|
||||||
defined_channels[cd_id]->ricean_factor=dbl;
|
defined_channels[cd_id]->ricean_factor=dbl;
|
||||||
} else if ( strcmp(param,"aoa") == 0) {
|
} else if ( strcmp(param,"aoa") == 0) {
|
||||||
double dbl = atof(value);
|
double dbl = atof(value);
|
||||||
if (dbl <0 || dbl >6.28)
|
if (dbl <0 || dbl >6.28)
|
||||||
prnt("angle of arrival range: 0 to 2*Pi, %lf is outof range\n",dbl);
|
prnt("ERROR: angle of arrival range: 0 to 2*Pi, %lf is outof range\n",dbl);
|
||||||
else
|
else
|
||||||
defined_channels[cd_id]->aoa=dbl;
|
defined_channels[cd_id]->aoa=dbl;
|
||||||
|
} else if ( strcmp(param,"randaoa") == 0) {
|
||||||
|
int i = atoi(value);
|
||||||
|
if (i!=0 && i!=1)
|
||||||
|
prnt("ERROR: randaoa is a boolean, must be 0 or 1\n");
|
||||||
|
else
|
||||||
|
defined_channels[cd_id]->random_aoa=i;
|
||||||
} else if ( strcmp(param,"ploss") == 0) {
|
} else if ( strcmp(param,"ploss") == 0) {
|
||||||
double dbl = atof(value);
|
double dbl = atof(value);
|
||||||
defined_channels[cd_id]->path_loss_dB=dbl;
|
defined_channels[cd_id]->path_loss_dB=dbl;
|
||||||
@@ -1587,18 +1602,18 @@ static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt)
|
|||||||
} else if ( strcmp(param,"forgetf") == 0) {
|
} else if ( strcmp(param,"forgetf") == 0) {
|
||||||
double dbl = atof(value);
|
double dbl = atof(value);
|
||||||
if (dbl <0 || dbl > 1)
|
if (dbl <0 || dbl > 1)
|
||||||
prnt("forgetting factor range: 0 to 1 (disable variation), %lf is outof range\n",dbl);
|
prnt("ERROR: forgetting factor range: 0 to 1 (disable variation), %lf is outof range\n",dbl);
|
||||||
else
|
else
|
||||||
defined_channels[cd_id]->forgetting_factor=dbl;
|
defined_channels[cd_id]->forgetting_factor=dbl;
|
||||||
} else {
|
} else {
|
||||||
|
prnt("ERROR: %s, unknown channel parameter\n",param);
|
||||||
|
return CMDSTATUS_FOUND;
|
||||||
}
|
}
|
||||||
display_channelmodel(defined_channels[cd_id],debug,prnt);
|
display_channelmodel(defined_channels[cd_id],debug,prnt);
|
||||||
free(param);
|
free(param);
|
||||||
free(value);
|
free(value);
|
||||||
|
random_channel(defined_channels[cd_id],false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CMDSTATUS_FOUND;
|
return CMDSTATUS_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ extern RAN_CONTEXT_t RC;
|
|||||||
{"IQfile", "<file path to use when saving IQs>\n", 0, strptr:&(saveF), defstrval:"/tmp/rfsimulator.iqs",TYPE_STRING, 0 },\
|
{"IQfile", "<file path to use when saving IQs>\n", 0, strptr:&(saveF), defstrval:"/tmp/rfsimulator.iqs",TYPE_STRING, 0 },\
|
||||||
{"modelname", "<channel model name>\n", 0, strptr:&(modelname), defstrval:"AWGN", TYPE_STRING, 0 },\
|
{"modelname", "<channel model name>\n", 0, strptr:&(modelname), defstrval:"AWGN", TYPE_STRING, 0 },\
|
||||||
{"ploss", "<channel path loss in dB>\n", 0, dblptr:&(rfsimulator->chan_pathloss), defdblval:0, TYPE_DOUBLE, 0 },\
|
{"ploss", "<channel path loss in dB>\n", 0, dblptr:&(rfsimulator->chan_pathloss), defdblval:0, TYPE_DOUBLE, 0 },\
|
||||||
{"forgetfact", "<channel forget factor ((0 to 1)>\n", 0, dblptr:&(rfsimulator->chan_forgetfact), defdblval:0, TYPE_DOUBLE, 0 }\
|
{"forgetfact", "<channel forget factor ((0 to 1)>\n", 0, dblptr:&(rfsimulator->chan_forgetfact), defdblval:0, TYPE_DOUBLE, 0 },\
|
||||||
|
{"offset", "<channel offset in samps>\n", 0, iptr:&(rfsimulator->chan_offset), defintval:0, TYPE_INT, 0 }\
|
||||||
};
|
};
|
||||||
|
|
||||||
pthread_mutex_t Sockmutex;
|
pthread_mutex_t Sockmutex;
|
||||||
@@ -118,6 +119,7 @@ typedef struct {
|
|||||||
int channelmod;
|
int channelmod;
|
||||||
double chan_pathloss;
|
double chan_pathloss;
|
||||||
double chan_forgetfact;
|
double chan_forgetfact;
|
||||||
|
int chan_offset;
|
||||||
} rfsimulator_state_t;
|
} rfsimulator_state_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +168,7 @@ void allocCirBuf(rfsimulator_state_t *bridge, int sock) {
|
|||||||
bridge->sample_rate,
|
bridge->sample_rate,
|
||||||
bridge->tx_bw,
|
bridge->tx_bw,
|
||||||
bridge->chan_forgetfact, // forgetting_factor
|
bridge->chan_forgetfact, // forgetting_factor
|
||||||
0, // maybe used for TA
|
bridge->chan_offset, // maybe used for TA
|
||||||
bridge->chan_pathloss); // path_loss in dB
|
bridge->chan_pathloss); // path_loss in dB
|
||||||
random_channel(ptr->channel_model,false);
|
random_channel(ptr->channel_model,false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user