annotate pathloss/main.c @ 65:b3f04535eb14

pathloss: initial code, no distance calculation yet
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Oct 2024 07:42:53 +0000
parents
children 599fac1b882d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a file of input parameters for a GSM radio link
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and computes maximum reach distances per several common models.
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #define MAX_FIELDS 5
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static char linebuf[256], *fields[MAX_FIELDS];
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static unsigned nfields;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static float freq_dl, freq_ul;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static float bts_power, bts_rxs, bts_ant_gain;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static float ms_power, ms_rxs;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static int band_set, bts_param_set, ms_param_set;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static float bts_height, ms_height;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static int bts_height_set, ms_height_set;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static float misc_loss;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 parse_into_fields(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *cp;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 nfields = 0;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (cp = linebuf; ; ) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 while (isspace(*cp))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cp++;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (*cp == '\0' || *cp == '#')
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 break;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (nfields >= MAX_FIELDS) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fprintf(stderr, "%s line %d: too many fields\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fields[nfields++] = cp;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 while (*cp && !isspace(*cp))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 cp++;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (*cp)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *cp++ = '\0';
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 set_band(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (nfields != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 fprintf(stderr, "%s line %d: band setting takes 1 argument\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!strcasecmp(fields[1], "PCS")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 freq_dl = 1990.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 freq_ul = 1910.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 } else if (!strcasecmp(fields[1], "B5")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 freq_dl = 894.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 freq_ul = 849.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 } else if (!strcasecmp(fields[1], "ISM")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 freq_dl = 925.2f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 freq_ul = 880.2f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 } else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 fprintf(stderr, "%s line %d: unknown band name \"%s\"\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 filename, lineno, fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 band_set = 1;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 set_bts_param(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (nfields != 4) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 "%s line %d: bts-param setting takes 3 arguments\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 bts_power = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 bts_rxs = atof(fields[2]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 bts_ant_gain = atof(fields[3]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 bts_param_set = 1;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 set_bts_height(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 float val, mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 "%s line %d: bts-height setting takes 2 arguments\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (!strcmp(fields[2], "m"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 mult = 1.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 else if (!strcmp(fields[2], "ft"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 mult = 0.3048f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 "%s line %d: height unit must be either m or ft\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 bts_height = val * mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 bts_height_set = 1;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 set_ms_param(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 "%s line %d: ms-param setting takes 2 arguments\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 ms_power = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 ms_rxs = atof(fields[2]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 ms_param_set = 1;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 set_ms_height(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 float val, mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 "%s line %d: ms-height setting takes 2 arguments\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (!strcmp(fields[2], "m"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 mult = 1.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 else if (!strcmp(fields[2], "ft"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 mult = 0.3048f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 "%s line %d: height unit must be either m or ft\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 ms_height = val * mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 ms_height_set = 1;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 add_loss_line(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 float val;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 if (nfields != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 fprintf(stderr, "%s line %d: loss setting takes 1 argument\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 misc_loss += val;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 process_line(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (!strcmp(fields[0], "band"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 set_band(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 else if (!strcmp(fields[0], "bts-param"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 set_bts_param(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 else if (!strcmp(fields[0], "bts-height"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 set_bts_height(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 else if (!strcmp(fields[0], "ms-param"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 set_ms_param(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 else if (!strcmp(fields[0], "ms-height"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 set_ms_height(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 else if (!strcmp(fields[0], "loss"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 add_loss_line(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 fprintf(stderr, "%s line %d: non-understood setting \"%s\"\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 filename, lineno, fields[0]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 check_required_params(filename)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 if (!band_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 fprintf(stderr, "error: %s failed to set band\n", filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 if (!bts_param_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 fprintf(stderr, "error: %s failed to set bts-param\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 if (!bts_height_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 fprintf(stderr, "error: %s failed to set bts-height\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 if (!ms_param_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 fprintf(stderr, "error: %s failed to set ms-param\n", filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 if (!ms_height_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 fprintf(stderr, "error: %s failed to set ms-height\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 read_param_file(filename)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 FILE *inf;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 int lineno;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 inf = fopen(filename, "r");
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 if (!inf) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 perror(filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 if (!index(linebuf, '\n')) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 "%s line %d: too long or missing newline\n",
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 parse_into_fields(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 if (nfields == 0)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 continue;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 process_line(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 fclose(inf);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 check_required_params(filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 main(argc, argv)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 char **argv;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 float path_loss_dl, path_loss_ul;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 if (argc != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 fprintf(stderr, "usage: %s param-file\n", argv[0]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 read_param_file(argv[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 /* do the math */
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 path_loss_dl = bts_power + bts_ant_gain - ms_rxs - misc_loss;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 path_loss_ul = ms_power + bts_ant_gain - bts_rxs - misc_loss;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 printf("Path loss budget: %.2f dB DL, %.2f dB UL\n", path_loss_dl,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 path_loss_ul);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 /* distance calculations will go here */
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 exit(0);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 }