FreeCalypso > hg > freecalypso-tools
diff rvinterf/tmsh/l1cmd.c @ 117:c91500530216
fc-tmsh: l1tm keyword argument framework implemented, used in rfe command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 18 Feb 2017 07:44:12 +0000 |
parents | c41511b79b1d |
children | 9aeabcbe6a3d |
line wrap: on
line diff
--- a/rvinterf/tmsh/l1cmd.c Sat Feb 18 06:54:06 2017 +0000 +++ b/rvinterf/tmsh/l1cmd.c Sat Feb 18 07:44:12 2017 +0000 @@ -5,6 +5,7 @@ */ #include <sys/types.h> +#include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> @@ -13,6 +14,7 @@ #include "limits.h" #include "localtypes.h" #include "tm3.h" +#include "l1tm.h" #include "exitcodes.h" cmd_tminit(argc, argv) @@ -53,13 +55,75 @@ return(0); } +static +is_num_string(argstr) + char *argstr; +{ + char *cp = argstr; + + if (!isdigit(*cp++)) + return(0); + while (*cp) { + if (!isdigit(*cp++)) + return(0); + } + return(1); +} + +struct kwtab { + char *kw; + int val; +}; + +static +keyword_or_num(argstr, kwtab, valp) + char *argstr; + struct kwtab *kwtab; + u16 *valp; +{ + struct kwtab *tp; + + if (is_num_string(argstr)) { + *valp = atoi(argstr); + return(0); + } + for (tp = kwtab; tp->kw; tp++) { + if (!strcmp(tp->kw, argstr)) { + *valp = tp->val; + return(0); + } + } + printf("error: non-numeric argument not understood\n"); + return(ERROR_USAGE); +} + +static struct kwtab rfe_arg[] = { + {"stop-all", STOP_ALL}, + {"rx-tch", RX_TCH}, + {"tx-tch", TX_TCH}, + {"rx-tx-tch", RX_TX_TCH}, + {"rx-tx-pdtch", RX_TX_PDTCH}, + {"rx-tch-cont", RX_TCH_CONT}, + {"tx-tch-cont", TX_TCH_CONT}, + {"bcch-loop", BCCH_LOOP}, + {"sb-loop", SB_LOOP}, + {"fb1-loop", FB1_LOOP}, + {"fb0-loop", FB0_LOOP}, + {"single-pm", SINGLE_PM}, + {"rx-tx-pdtch-mon", RX_TX_PDTCH_MON}, + {"rx-tx-mon-tch", RX_TX_MON_TCH}, + {"rx-tx-mon", RX_TX_MON}, + {0, 0} +}; + cmd_rfe(argc, argv) char **argv; { u16 arg; u_char cmdpkt[5]; - arg = strtoul(argv[1], 0, 0); + if (keyword_or_num(argv[1], rfe_arg, &arg)) + return(ERROR_USAGE); cmdpkt[1] = RF_ENABLE; cmdpkt[2] = arg; cmdpkt[3] = arg >> 8;