FreeCalypso > hg > freecalypso-tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
116:3eb75280b38b | 117:c91500530216 |
---|---|
3 * TM3 command packets to the L1TM firmware component: RF calibration | 3 * TM3 command packets to the L1TM firmware component: RF calibration |
4 * and test modes. | 4 * and test modes. |
5 */ | 5 */ |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <ctype.h> | |
8 #include <stdio.h> | 9 #include <stdio.h> |
9 #include <string.h> | 10 #include <string.h> |
10 #include <strings.h> | 11 #include <strings.h> |
11 #include <stdlib.h> | 12 #include <stdlib.h> |
12 #include "pktmux.h" | 13 #include "pktmux.h" |
13 #include "limits.h" | 14 #include "limits.h" |
14 #include "localtypes.h" | 15 #include "localtypes.h" |
15 #include "tm3.h" | 16 #include "tm3.h" |
17 #include "l1tm.h" | |
16 #include "exitcodes.h" | 18 #include "exitcodes.h" |
17 | 19 |
18 cmd_tminit(argc, argv) | 20 cmd_tminit(argc, argv) |
19 char **argv; | 21 char **argv; |
20 { | 22 { |
51 cmdpkt[3] = arg >> 8; | 53 cmdpkt[3] = arg >> 8; |
52 send_etm_cmd(cmdpkt, 3); | 54 send_etm_cmd(cmdpkt, 3); |
53 return(0); | 55 return(0); |
54 } | 56 } |
55 | 57 |
58 static | |
59 is_num_string(argstr) | |
60 char *argstr; | |
61 { | |
62 char *cp = argstr; | |
63 | |
64 if (!isdigit(*cp++)) | |
65 return(0); | |
66 while (*cp) { | |
67 if (!isdigit(*cp++)) | |
68 return(0); | |
69 } | |
70 return(1); | |
71 } | |
72 | |
73 struct kwtab { | |
74 char *kw; | |
75 int val; | |
76 }; | |
77 | |
78 static | |
79 keyword_or_num(argstr, kwtab, valp) | |
80 char *argstr; | |
81 struct kwtab *kwtab; | |
82 u16 *valp; | |
83 { | |
84 struct kwtab *tp; | |
85 | |
86 if (is_num_string(argstr)) { | |
87 *valp = atoi(argstr); | |
88 return(0); | |
89 } | |
90 for (tp = kwtab; tp->kw; tp++) { | |
91 if (!strcmp(tp->kw, argstr)) { | |
92 *valp = tp->val; | |
93 return(0); | |
94 } | |
95 } | |
96 printf("error: non-numeric argument not understood\n"); | |
97 return(ERROR_USAGE); | |
98 } | |
99 | |
100 static struct kwtab rfe_arg[] = { | |
101 {"stop-all", STOP_ALL}, | |
102 {"rx-tch", RX_TCH}, | |
103 {"tx-tch", TX_TCH}, | |
104 {"rx-tx-tch", RX_TX_TCH}, | |
105 {"rx-tx-pdtch", RX_TX_PDTCH}, | |
106 {"rx-tch-cont", RX_TCH_CONT}, | |
107 {"tx-tch-cont", TX_TCH_CONT}, | |
108 {"bcch-loop", BCCH_LOOP}, | |
109 {"sb-loop", SB_LOOP}, | |
110 {"fb1-loop", FB1_LOOP}, | |
111 {"fb0-loop", FB0_LOOP}, | |
112 {"single-pm", SINGLE_PM}, | |
113 {"rx-tx-pdtch-mon", RX_TX_PDTCH_MON}, | |
114 {"rx-tx-mon-tch", RX_TX_MON_TCH}, | |
115 {"rx-tx-mon", RX_TX_MON}, | |
116 {0, 0} | |
117 }; | |
118 | |
56 cmd_rfe(argc, argv) | 119 cmd_rfe(argc, argv) |
57 char **argv; | 120 char **argv; |
58 { | 121 { |
59 u16 arg; | 122 u16 arg; |
60 u_char cmdpkt[5]; | 123 u_char cmdpkt[5]; |
61 | 124 |
62 arg = strtoul(argv[1], 0, 0); | 125 if (keyword_or_num(argv[1], rfe_arg, &arg)) |
126 return(ERROR_USAGE); | |
63 cmdpkt[1] = RF_ENABLE; | 127 cmdpkt[1] = RF_ENABLE; |
64 cmdpkt[2] = arg; | 128 cmdpkt[2] = arg; |
65 cmdpkt[3] = arg >> 8; | 129 cmdpkt[3] = arg >> 8; |
66 send_etm_cmd(cmdpkt, 3); | 130 send_etm_cmd(cmdpkt, 3); |
67 return(0); | 131 return(0); |