FreeCalypso > hg > fc-rfcal-tools
view cmu200/cableconf.c @ 132:94e8a410d6bd
fc-rfcal-txcheck: pass PCL to tester (txpwr-cal-pcl)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 20 Dec 2021 03:52:01 +0000 |
parents | 3ec82dc1dbda |
children |
line wrap: on
line source
/* * 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); }