📄 sdlconf.c
字号:
if (cfg->ifalarms & SDL_ALARM_RED) printf(" red"); if (cfg->ifalarms & SDL_ALARM_BLU) printf(" blu"); if (cfg->ifalarms & SDL_ALARM_YEL) printf(" yel"); if (cfg->ifalarms & SDL_ALARM_REC) printf(" rec"); printf("\n"); printf(" ifrxlevel: %u\n", cfg->ifrxlevel); printf(" ifsync: %u\n", cfg->ifsync); printf(" ifbpv: %u\n", cfg->ifbpv); }}voidshow_config(sdl_config_t * cfg, int get){ char *unknown = "unknown"; printf("Configuration:"); printf(" %s card %d, span %d, slot %d\n", devname, card, span, slot); printf(" type: %s(%u)", (cfg->iftype < optnames[CFG_TYPE].size) ? optnames[CFG_TYPE].name[cfg->iftype].key : unknown, cfg->iftype); printf(", rate: %u", cfg->ifrate); printf(", mode: %s(%u)\n", (cfg->ifmode < optnames[CFG_MODE].size) ? optnames[CFG_MODE].name[cfg->ifmode].key : unknown, cfg->ifmode); printf(" gtype: %s(%u)", (cfg->ifgtype < optnames[CFG_GTYPE].size) ? optnames[CFG_GTYPE].name[cfg->ifgtype].key : unknown, cfg->ifgtype); printf(", grate: %u", cfg->ifgrate); printf(", gmode: %s(%u)", (cfg->ifgmode < optnames[CFG_GMODE].size) ? optnames[CFG_GMODE].name[cfg->ifgmode].key : unknown, cfg->ifgmode); printf(", clock: %s(%u)\n", (cfg->ifclock < optnames[CFG_CLOCK].size) ? optnames[CFG_CLOCK].name[cfg->ifclock].key : unknown, cfg->ifclock); printf(" gcrc: %s(%u)", (cfg->ifgcrc < optnames[CFG_GCRC].size) ? optnames[CFG_GCRC].name[cfg->ifgcrc].key : unknown, cfg->ifgcrc); printf(", coding: %s(%u)", (cfg->ifcoding < optnames[CFG_CODING].size) ? optnames[CFG_CODING].name[cfg->ifcoding].key : unknown, cfg->ifcoding); printf(", framing: %s(%u)\n", (cfg->ifframing < optnames[CFG_FRAMING].size) ? optnames[CFG_FRAMING].name[cfg->ifframing].key : unknown, cfg->ifframing); printf(" blksize: %u", cfg->ifblksize); printf(", txlevel: %u", cfg->iftxlevel); printf(", syncsrc: {%u,%u,%u,%u}\n", cfg->ifsyncsrc[0], cfg->ifsyncsrc[1], cfg->ifsyncsrc[2], cfg->ifsyncsrc[3]); if (get) { printf(" leads:"); if (cfg->ifleads & SDL_LEAD_DTR) printf(" dtr"); if (cfg->ifleads & SDL_LEAD_RTS) printf(" rts"); if (cfg->ifleads & SDL_LEAD_DCD) printf(" dcd"); if (cfg->ifleads & SDL_LEAD_CTS) printf(" cts"); if (cfg->ifleads & SDL_LEAD_DSR) printf(" dsr"); printf(", alarms:"); if (cfg->ifalarms & SDL_ALARM_RED) printf(" red"); if (cfg->ifalarms & SDL_ALARM_BLU) printf(" blu"); if (cfg->ifalarms & SDL_ALARM_YEL) printf(" yel"); if (cfg->ifalarms & SDL_ALARM_REC) printf(" rec"); printf(", rxlevel: %u", cfg->ifrxlevel); printf(", sync: %u", cfg->ifsync); printf(", bpv: %u\n", cfg->ifbpv); }}#if 0voidshow_stats(sdl_stats_t * sta){ printf("Statistics:"); printf(" %s card %d, span %d, slot %d\n", devname, card, span, slot); printf(" rx_octets: %12u\n", sta->rx_octets); printf(" tx_octets: %12u\n", sta->tx_octets); printf(" rx_overruns: %12u\n", sta->rx_overruns); printf(" tx_underruns: %12u\n", sta->tx_underruns); printf(" rx_buffer_overflows: %12u\n", sta->rx_buffer_overflows); printf(" rx_buffer_overflows: %12u\n", sta->rx_buffer_overflows); printf(" lead_cts_lost: %12u\n", sta->lead_cts_lost); printf(" lead_dcd_lost: %12u\n", sta->lead_dcd_lost); printf(" carrier_lost: %12u\n", sta->carrier_lost);}#endif#define BUFSIZE 128voidslconf_get(void){ sdl_config_t cfg;#if 0 sdl_stats_t sta;#endif struct strioctl ctl; char cbuf[BUFSIZE]; char dbuf[BUFSIZE]; struct strbuf ctrl = { sizeof(*cbuf), 0, cbuf }; struct strbuf data = { sizeof(*dbuf), 0, dbuf }; union LMI_primitives *p = (union LMI_primitives *) cbuf; unsigned short ppa = (card << 12) | (span << 8) | (slot << 0); int fd, ret, flags = 0; if ((fd = open(devname, O_RDWR)) < 0) { perror(__FUNCTION__); exit(1); } ctrl.maxlen = sizeof(cbuf); ctrl.len = sizeof(p->attach_req) + sizeof(ppa); ctrl.buf = cbuf; p->attach_req.lmi_primitive = LMI_ATTACH_REQ; bcopy(&ppa, p->attach_req.lmi_ppa, sizeof(ppa)); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { perror(__FUNCTION__); exit(1); } flags = 0; ctrl.maxlen = BUFSIZE; ctrl.len = 0; ctrl.buf = cbuf; data.maxlen = BUFSIZE; data.len = 0; data.buf = dbuf; if ((ret = getmsg(fd, &ctrl, &data, &flags)) < 0) { perror(__FUNCTION__); exit(1); } if (p->lmi_primitive != LMI_OK_ACK) { if (p->lmi_primitive == LMI_ERROR_ACK) { fprintf(stderr, "%s: %s: could not attach (LMI_ERROR_ACK)\n", "sdlconf", __FUNCTION__); } else fprintf(stderr, "%s: %s: could not attach\n", "sdlconf", __FUNCTION__); exit(1); } ctl.ic_cmd = SDL_IOCGCONFIG; ctl.ic_timout = 0; ctl.ic_len = sizeof(cfg); ctl.ic_dp = (char *) &cfg; if (ioctl(fd, I_STR, &ctl) < 0) { perror(__FUNCTION__); exit(1); }#if 0 ctl.ic_cmd = SDL_IOCGSTATS; ctl.ic_timout = 0; ctl.ic_len = sizeof(sta); ctl.ic_dp = (char *) &sta; if (ioctl(fd, I_STR, &ctl) < 0) { perror(__FUNCTION__); exit(1); }#endif ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->detach_req); ctrl.buf = cbuf; p->detach_req.lmi_primitive = LMI_DETACH_REQ; if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { perror(__FUNCTION__); exit(1); } if (output) { show_config(&cfg, 1);#if 0 show_stats(&sta);#endif }}voidslconf_set(void){ sdl_config_t cfg; struct strioctl ctl; char cbuf[BUFSIZE]; char dbuf[BUFSIZE]; struct strbuf ctrl = { sizeof(*cbuf), 0, cbuf }; struct strbuf data = { sizeof(*dbuf), 0, dbuf }; union LMI_primitives *p = (union LMI_primitives *) cbuf; unsigned short ppa = (card << 12) | (span << 8) | (slot << 0); int fd, ret, flags = 0; cfg = config; if (output > 2) show_config(&cfg, 0); if ((fd = open(devname, O_RDWR)) < 0) { perror(__FUNCTION__); exit(1); } ctrl.maxlen = sizeof(cbuf); ctrl.len = sizeof(p->attach_req) + sizeof(ppa); ctrl.buf = cbuf; p->attach_req.lmi_primitive = LMI_ATTACH_REQ; bcopy(&ppa, p->attach_req.lmi_ppa, sizeof(ppa)); if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { perror(__FUNCTION__); exit(1); } flags = 0; ctrl.maxlen = BUFSIZE; ctrl.len = 0; ctrl.buf = cbuf; data.maxlen = BUFSIZE; data.len = 0; data.buf = dbuf; if ((ret = getmsg(fd, &ctrl, &data, &flags)) < 0) { perror(__FUNCTION__); exit(1); } if (p->lmi_primitive != LMI_OK_ACK) { if (p->lmi_primitive == LMI_ERROR_ACK) { fprintf(stderr, "%s: %s: could not attach (LMI_ERROR_ACK)\n", "sdlconf", __FUNCTION__); } else fprintf(stderr, "%s: %s: could not attach\n", "sdlconf", __FUNCTION__); exit(1); } if (output > 1) show_config(&cfg, 0); ctl.ic_cmd = SDL_IOCSCONFIG; ctl.ic_timout = 0; ctl.ic_len = sizeof(cfg); ctl.ic_dp = (char *) &cfg; if (ioctl(fd, I_STR, &ctl) < 0) { perror(__FUNCTION__); exit(1); } ctl.ic_cmd = SDL_IOCGCONFIG; ctl.ic_timout = 0; ctl.ic_len = sizeof(cfg); ctl.ic_dp = (char *) &cfg; if (ioctl(fd, I_STR, &ctl) < 0) { perror(__FUNCTION__); exit(1); } ctrl.maxlen = BUFSIZE; ctrl.len = sizeof(p->detach_req); ctrl.buf = cbuf; p->detach_req.lmi_primitive = LMI_DETACH_REQ; if ((ret = putmsg(fd, &ctrl, NULL, RS_HIPRI)) < 0) { perror(__FUNCTION__); exit(1); } if (output) show_config(&cfg, 1);}voidslconf_cfg(void){ fprintf(stderr, "%s: %s: file option not currently available\n", "sdlconf", __FUNCTION__); exit(1);}intmain(int argc, char **argv){ int c; int val; enum { CMD_NONE = 0, CMD_GET, /* get device */ CMD_SET, /* set device */ CMD_CFG, /* configure from file */ } cmd = CMD_NONE; while (1) { int option_index = 0; /* *INDENT-OFF* */ static struct option long_options[] = { {"get", no_argument, NULL, 'g'}, {"set", no_argument, NULL, 's'}, {"file", required_argument, NULL, 'f'}, {"device", required_argument, NULL, 'd'}, {"card", required_argument, NULL, 'c'}, {"span", required_argument, NULL, 'p'}, {"slot", required_argument, NULL, 't'}, {"type", required_argument, NULL, CFG_TYPE + 1}, {"gtype", required_argument, NULL, CFG_GTYPE + 1}, {"mode", required_argument, NULL, CFG_MODE + 1}, {"gmode", required_argument, NULL, CFG_GMODE + 1}, {"gcrc", required_argument, NULL, CFG_GCRC + 1}, {"clock", required_argument, NULL, CFG_CLOCK + 1}, {"coding", required_argument, NULL, CFG_CODING + 1}, {"framing", required_argument, NULL, CFG_FRAMING + 1}, {"rate", required_argument, NULL, CFG_RATE + 1}, {"grate", required_argument, NULL, CFG_GRATE + 1}, {"txlevel", required_argument, NULL, CFG_TXLEVEL + 1}, {"syncsrc", required_argument, NULL, CFG_SYNCSRC + 1}, {"quiet", no_argument, NULL, 'q'}, {"verbose", optional_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"copying", no_argument, NULL, 'C'}, {"?", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0 } }; /* *INDENT-ON* */ c = getopt_long(argc, argv, "gsf:c:p:t:qvhVC?", long_options, &option_index); if (c == -1) break; switch (c) { case 0: usage(argc, argv); exit(2); case 'g': /* -g, --get */ if (cmd != CMD_NONE) goto bad_option; cmd = CMD_GET; break; case 's': /* -s, --set */ if (cmd != CMD_NONE) goto bad_option; cmd = CMD_SET; break; case 'f': /* -f, --file file */ if (cmd != CMD_NONE) goto bad_option; cmd = CMD_CFG; strncpy(cfgfile, optarg, sizeof(cfgfile) - 1); break; case 'd': /* -d, --device */ if (cmd != CMD_SET && cmd != CMD_GET) goto bad_option; strncpy(devname, optarg, sizeof(devname) - 1); break; case 'c': /* -c, --card */ if (cmd != CMD_SET && cmd != CMD_GET) goto bad_option; card = atoi(optarg); break; case 'p': /* -p, --span */ if (cmd != CMD_SET && cmd != CMD_GET) goto bad_option; span = atoi(optarg); break; case 't': /* -t, --slot */ if (cmd != CMD_SET && cmd != CMD_GET) goto bad_option; slot = atoi(optarg); break; case CFG_TYPE + 1: /* --type */ case CFG_GTYPE + 1: /* --gtype */ case CFG_MODE + 1: /* --mode */ case CFG_GMODE + 1: /* --gmode */ case CFG_GCRC + 1: /* --gcrc */ case CFG_CLOCK + 1: /* --clock */ case CFG_CODING + 1: /* --coding */ case CFG_FRAMING + 1: /* --framing */ case CFG_RATE + 1: /* --rate */ case CFG_GRATE + 1: /* --grate */ case CFG_TXLEVEL + 1: /* --txlevel */ { int i; if (cmd != CMD_SET) goto bad_option; if ('0' <= optarg[0] && optarg[0] <= '9') { *(optnames[c - 1].valp) = atoi(optarg); break; } for (i = 0; i < optnames[c - 1].size; i++) if (!strcmp(optarg, optnames[c - 1].name[i].key)) break; if (i < optnames[c - 1].size) { *(optnames[c - 1].valp) = optnames[c - 1].name[i].val; break; } fprintf(stderr, "%s: illegal parm -- %s\n", argv[0], argv[optind - 1]); fprintf(stderr, "%s: valid labels --", argv[0]); for (i = 0; i < optnames[c - 1].size; i++) fprintf(stderr, " %s", optnames[c - 1].name[i].key); fprintf(stderr, "\n"); usage(argc, argv); exit(2); } case CFG_SYNCSRC + 1: /* --syncsrc */ { ulong syncs[4] = { 0, 0, 0, 0 }; int i, j, p, len; if (cmd != CMD_SET) goto bad_option; len = strlen(optarg); for (p = 0, j = 0, i = 0; i < 4; i++) { for (; j <= len; j++) if (optarg[j] == ',' || optarg[j] == '\0') goto gotone; if (j > p) { gotone: syncs[i] = atoi(&optarg[p]); if (output > 3) fprintf(stderr, "got one: %d : %lu\n", i, syncs[i]); j++; p = j; if (j >= len) break; } } if (i == 0) goto bad_option; for (j = 0; j <= i; j++) config.ifsyncsrc[j] = syncs[j]; break; } case 'q': /* -q, --quiet */ output -= output > 0 ? 1 : output; break; case 'v': /* -v, --verbose */ if (optarg == NULL) { output += 1; break; } if ((val = strtol(optarg, NULL, 0)) < 0) goto bad_option; output = val; break; case 'h': /* -h, --help */ if (cmd != CMD_NONE) goto bad_option; help(argc, argv); exit(0); case 'V': /* -V, --version */ if (cmd != CMD_NONE) goto bad_option; version(argc, argv); exit(0); case 'C': if (cmd != CMD_NONE) goto bad_option; copying(argc, argv); exit(0); case ':': fprintf(stderr, "%s: missing parm -- %s\n", argv[0], argv[optind - 1]); usage(argc, argv); exit(2); case '?': default: bad_option: optind--; // syntax_error: if (optind < argc) { fprintf(stderr, "%s: illegal syntax -- ", argv[0]); for (; optind < argc; optind++) fprintf(stderr, "%s ", argv[optind]); fprintf(stderr, "\n"); } usage(argc, argv); exit(2); } } switch (cmd) { default: case CMD_NONE: help(argc, argv); exit(0); case CMD_GET: slconf_get(); exit(0); case CMD_SET: slconf_set(); exit(0); case CMD_CFG: slconf_cfg(); exit(0); } exit(4);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -