FreeCalypso > hg > fc-rfcal-tools
changeset 68:3ec82dc1dbda
fc-cmu200d: implemented reading and parsing of cable config files (-c arg)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 14 Jul 2017 04:34:15 +0000 |
parents | 3f92d88fbb1c |
children | 4e263849b064 |
files | cmu200/Makefile cmu200/band.h cmu200/cableconf.c cmu200/main.c |
diffstat | 4 files changed, 150 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/cmu200/Makefile Sun May 28 07:22:09 2017 +0000 +++ b/cmu200/Makefile Fri Jul 14 04:34:15 2017 +0000 @@ -3,8 +3,8 @@ PROGS= fc-cmu200d fc-serscpi INSTBIN=/opt/freecalypso/bin -CMU200D_OBJS= band.o dispatch.o init.o main.o mode.o openport.o rfanalyzer.o \ - sercmd.o session.o signalgen.o socket.o +CMU200D_OBJS= band.o cableconf.o dispatch.o init.o main.o mode.o openport.o \ + rfanalyzer.o sercmd.o session.o signalgen.o socket.o SERSCPI_OBJS= openport.o sertool.o
--- a/cmu200/band.h Sun May 28 07:22:09 2017 +0000 +++ b/cmu200/band.h Fri Jul 14 04:34:15 2017 +0000 @@ -15,4 +15,6 @@ int secaddr; struct arfcn_range *arfcn_range; struct arfcn_range *arfcn_range_ext; + unsigned ul_cable_loss; + unsigned dl_cable_loss; };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmu200/cableconf.c Fri Jul 14 04:34:15 2017 +0000 @@ -0,0 +1,139 @@ +/* + * The code that reads and parses cable config files lives here. + */ + +#include <sys/param.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "band.h" + +char cableconf_directory[] = "/opt/freecalypso/rfcal/cableconf/"; + +extern struct band supported_bands[]; +extern int cmu200_rf_port; + +static void +cable_loss_line(cp, filename_for_errs, lineno) + char *cp, *filename_for_errs; +{ + char *np; + struct band *band; + int dir; + unsigned num; + + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) { +inv: fprintf(stderr, "%s line %d: invalid syntax for cable-loss\n", + filename_for_errs, lineno); + exit(1); + } + for (np = cp; isdigit(*cp); cp++) + ; + if (cp[0] != 'd' && cp[0] != 'u' || cp[1] != 'l') + goto inv; + dir = *cp; + *cp = '\0'; + cp += 2; + for (band = supported_bands; band->name; band++) + if (!strcmp(band->name, np)) + break; + if (!band->name) { + fprintf(stderr, "%s line %d: frequency band \"%s\" not known\n", + filename_for_errs, lineno, np); + exit(1); + } + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) + goto inv; + for (np = cp; isdigit(*cp); cp++) + ; + if (cp[0] != '.' || !isdigit(cp[1])) + goto inv; + num = atoi(np) * 10 + (cp[1] - '0'); + cp += 2; + while (isspace(*cp)) + cp++; + if (*cp != '\0' && *cp != '#') + goto inv; + switch (dir) { + case 'd': + band->dl_cable_loss = num; + break; + case 'u': + band->ul_cable_loss = num; + break; + } +} + +static void +rf_port_line(cp, filename_for_errs, lineno) + char *cp, *filename_for_errs; +{ + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) { +inv: fprintf(stderr, "%s line %d: invalid syntax for rf-port\n", + filename_for_errs, lineno); + exit(1); + } + if (cp[0] != '1' && cp[0] != '2' || isdigit(cp[1])) { + fprintf(stderr, "%s line %d: invalid RF port number\n", + filename_for_errs, lineno); + exit(1); + } + cmu200_rf_port = *cp++ - '0'; + while (isspace(*cp)) + cp++; + if (*cp != '\0' && *cp != '#') + goto inv; +} + +static void +process_line(linebuf, filename_for_errs, lineno) + char *linebuf, *filename_for_errs; +{ + char *cp, *np; + + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + return; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (!strcmp(np, "cable-loss")) + cable_loss_line(cp, filename_for_errs, lineno); + else if (!strcmp(np, "rf-port")) + rf_port_line(cp, filename_for_errs, lineno); + else { + fprintf(stderr, "%s line %d: unknown keyword \"%s\"\n", + filename_for_errs, lineno, np); + exit(1); + } +} + +read_cable_conf_file(cable_conf_name) + char *cable_conf_name; +{ + char pathname[MAXPATHLEN]; + FILE *inf; + int lineno; + char linebuf[512]; + + strcpy(pathname, cableconf_directory); + strcat(pathname, cable_conf_name); + inf = fopen(pathname, "r"); + if (!inf) { + perror(pathname); + exit(1); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) + process_line(linebuf, pathname, lineno); + fclose(inf); +}
--- a/cmu200/main.c Sun May 28 07:22:09 2017 +0000 +++ b/cmu200/main.c Fri Jul 14 04:34:15 2017 +0000 @@ -19,14 +19,20 @@ extern int optind; int c; - while ((c = getopt(argc, argv, "1at:")) != EOF) + while ((c = getopt(argc, argv, "12ac:t:")) != EOF) switch (c) { case '1': cmu200_rf_port = 1; continue; + case '2': + cmu200_rf_port = 2; + continue; case 'a': cmu200_tx_name = "AUXT"; continue; + case 'c': + read_cable_conf_file(optarg); + continue; case 't': bind_socket_pathname = optarg; continue;