FreeCalypso > hg > freecalypso-tools
view rvinterf/tmsh/l1cmd.c @ 118:9aeabcbe6a3d
fc-tmsh: scw and scr accept keyword arguments
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 18 Feb 2017 07:49:29 +0000 |
parents | c91500530216 |
children | 6ce20d48e9ee |
line wrap: on
line source
/* * In this module we are going to implement commands which send * TM3 command packets to the L1TM firmware component: RF calibration * and test modes. */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "pktmux.h" #include "limits.h" #include "localtypes.h" #include "tm3.h" #include "l1tm.h" #include "exitcodes.h" cmd_tminit(argc, argv) char **argv; { u_char cmdpkt[3]; cmdpkt[1] = TM_INIT; send_etm_cmd(cmdpkt, 1); return(0); } cmd_tms(argc, argv) char **argv; { u16 arg; u_char cmdpkt[5]; arg = strtoul(argv[1], 0, 0); cmdpkt[1] = TM_MODE_SET; cmdpkt[2] = arg; cmdpkt[3] = arg >> 8; send_etm_cmd(cmdpkt, 3); return(0); } cmd_tm3ver(argc, argv) char **argv; { u16 arg; u_char cmdpkt[5]; arg = strtoul(argv[1], 0, 16); cmdpkt[1] = VERSION_GET; cmdpkt[2] = arg; cmdpkt[3] = arg >> 8; send_etm_cmd(cmdpkt, 3); 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]; if (keyword_or_num(argv[1], rfe_arg, &arg)) return(ERROR_USAGE); cmdpkt[1] = RF_ENABLE; cmdpkt[2] = arg; cmdpkt[3] = arg >> 8; send_etm_cmd(cmdpkt, 3); return(0); } static struct kwtab stats_config_arg[] = { {"loops", LOOPS}, {"auto-result-loops", AUTO_RESULT_LOOPS}, {"auto-reset-loops", AUTO_RESET_LOOPS}, {"stat-gprs-slots", STAT_GPRS_SLOTS}, {"stat-type", STAT_TYPE}, {"stat-bitmask", STAT_BITMASK}, {0, 0} }; cmd_scw(argc, argv) char **argv; { u16 index, value; u_char cmdpkt[7]; if (keyword_or_num(argv[1], stats_config_arg, &index)) return(ERROR_USAGE); value = strtoul(argv[2], 0, 0); cmdpkt[1] = STATS_CONFIG_WRITE; cmdpkt[2] = index; cmdpkt[3] = index >> 8; cmdpkt[4] = value; cmdpkt[5] = value >> 8; send_etm_cmd(cmdpkt, 5); return(0); } cmd_scr(argc, argv) char **argv; { u16 index; u_char cmdpkt[5]; if (keyword_or_num(argv[1], stats_config_arg, &index)) return(ERROR_USAGE); cmdpkt[1] = STATS_CONFIG_READ; cmdpkt[2] = index; cmdpkt[3] = index >> 8; send_etm_cmd(cmdpkt, 3); return(0); } cmd_sr(argc, argv) char **argv; { u16 type, bitmask; u_char cmdpkt[7]; type = strtoul(argv[1], 0, 0); bitmask = strtoul(argv[2], 0, 16); cmdpkt[1] = STATS_READ; cmdpkt[2] = type; cmdpkt[3] = type >> 8; cmdpkt[4] = bitmask; cmdpkt[5] = bitmask >> 8; send_etm_cmd(cmdpkt, 5); return(0); } cmd_rfpw2(argc, argv) char **argv; { u16 index, value; u_char cmdpkt[7]; index = strtoul(argv[1], 0, 0); value = strtol(argv[2], 0, 0); cmdpkt[1] = RF_PARAM_WRITE; cmdpkt[2] = index; cmdpkt[3] = index >> 8; cmdpkt[4] = value; cmdpkt[5] = value >> 8; send_etm_cmd(cmdpkt, 5); return(0); } cmd_rfpw3(argc, argv) char **argv; { u16 index; u8 val1, val2; u_char cmdpkt[7]; index = strtoul(argv[1], 0, 0); val1 = strtoul(argv[2], 0, 0); val2 = strtoul(argv[3], 0, 0); cmdpkt[1] = RF_PARAM_WRITE; cmdpkt[2] = index; cmdpkt[3] = index >> 8; cmdpkt[4] = val1; cmdpkt[5] = val2; send_etm_cmd(cmdpkt, 5); return(0); } cmd_rfpw(argc, argv) char **argv; { switch (argc) { case 3: return cmd_rfpw2(argc, argv); case 4: return cmd_rfpw3(argc, argv); default: fprintf(stderr, "BUG: wrong argc in cmd_rfpw()\n"); return(ERROR_BUG); } } cmd_rfpr(argc, argv) char **argv; { u16 index; u_char cmdpkt[5]; index = strtoul(argv[1], 0, 0); cmdpkt[1] = RF_PARAM_READ; cmdpkt[2] = index; cmdpkt[3] = index >> 8; send_etm_cmd(cmdpkt, 3); return(0); }