annotate pathloss/main.c @ 70:47947e25f922

tmo/CSD-tests: document experimental findings
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Nov 2024 07:22:43 +0000
parents 0cfea66a15f3
children
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>
66
599fac1b882d pathloss: implement FSL
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
11 #include "range_func.h"
65
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #define MAX_FIELDS 5
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char linebuf[256], *fields[MAX_FIELDS];
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static unsigned nfields;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static float freq_dl, freq_ul;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 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
19 static float ms_power, ms_rxs;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 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
21
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static float bts_height, ms_height;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static int bts_height_set, ms_height_set;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static float misc_loss;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 parse_into_fields(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char *cp;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 nfields = 0;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (cp = linebuf; ; ) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 while (isspace(*cp))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 cp++;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (*cp == '\0' || *cp == '#')
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 break;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (nfields >= MAX_FIELDS) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 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
41 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fields[nfields++] = cp;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 while (*cp && !isspace(*cp))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 cp++;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (*cp)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *cp++ = '\0';
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 set_band(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (nfields != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 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
58 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!strcasecmp(fields[1], "PCS")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 freq_dl = 1990.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 freq_ul = 1910.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 } else if (!strcasecmp(fields[1], "B5")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 freq_dl = 894.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 freq_ul = 849.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 } else if (!strcasecmp(fields[1], "ISM")) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 freq_dl = 925.2f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 freq_ul = 880.2f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 } else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 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
72 filename, lineno, fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 band_set = 1;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 set_bts_param(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (nfields != 4) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 "%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
85 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 bts_power = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 bts_rxs = atof(fields[2]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 bts_ant_gain = atof(fields[3]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 bts_param_set = 1;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 set_bts_height(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 float val, mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 "%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
103 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (!strcmp(fields[2], "m"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 mult = 1.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 else if (!strcmp(fields[2], "ft"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 mult = 0.3048f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 "%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
114 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 bts_height = val * mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 bts_height_set = 1;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 set_ms_param(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 "%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
128 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 ms_power = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 ms_rxs = atof(fields[2]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 ms_param_set = 1;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 set_ms_height(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 float val, mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (nfields != 3) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 "%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
145 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (!strcmp(fields[2], "m"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 mult = 1.0f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 else if (!strcmp(fields[2], "ft"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 mult = 0.3048f;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 "%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
156 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 ms_height = val * mult;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 ms_height_set = 1;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 add_loss_line(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 float val;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 if (nfields != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 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
171 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 val = atof(fields[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 misc_loss += val;
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 process_line(filename, lineno)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 if (!strcmp(fields[0], "band"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 set_band(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 else if (!strcmp(fields[0], "bts-param"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 set_bts_param(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 else if (!strcmp(fields[0], "bts-height"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 set_bts_height(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 else if (!strcmp(fields[0], "ms-param"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 set_ms_param(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 else if (!strcmp(fields[0], "ms-height"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 set_ms_height(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 else if (!strcmp(fields[0], "loss"))
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 add_loss_line(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 else {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 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
196 filename, lineno, fields[0]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 exit(1);
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 check_required_params(filename)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 if (!band_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 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
207 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 if (!bts_param_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 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
211 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 if (!bts_height_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 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
216 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 if (!ms_param_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 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
221 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 if (!ms_height_set) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 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
225 filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 exit(1);
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 static void
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 read_param_file(filename)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 char *filename;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 FILE *inf;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 int lineno;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 inf = fopen(filename, "r");
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 if (!inf) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 perror(filename);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 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
243 if (!index(linebuf, '\n')) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 fprintf(stderr,
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 "%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
246 filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 parse_into_fields(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 if (nfields == 0)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 continue;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 process_line(filename, lineno);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 fclose(inf);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 check_required_params(filename);
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
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 main(argc, argv)
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 char **argv;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 float path_loss_dl, path_loss_ul;
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 if (argc != 2) {
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 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
265 exit(1);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 }
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 read_param_file(argv[1]);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 /* do the math */
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 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
270 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
271 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
272 path_loss_ul);
66
599fac1b882d pathloss: implement FSL
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
273 /* distance per various models */
599fac1b882d pathloss: implement FSL
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
274 printf("FSL: %.2f m DL, %.2f m UL\n",
599fac1b882d pathloss: implement FSL
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
275 rf_range_freespace(freq_dl, path_loss_dl),
599fac1b882d pathloss: implement FSL
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
276 rf_range_freespace(freq_ul, path_loss_ul));
68
0cfea66a15f3 pathloss: implement Egli model
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
277 printf("Egli: %.2f m DL, %.2f m UL\n",
0cfea66a15f3 pathloss: implement Egli model
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
278 rf_range_egli(freq_dl, path_loss_dl, bts_height, ms_height),
0cfea66a15f3 pathloss: implement Egli model
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
279 rf_range_egli(freq_ul, path_loss_ul, bts_height, ms_height));
0cfea66a15f3 pathloss: implement Egli model
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
280 /* Hata model coming next */
65
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 exit(0);
b3f04535eb14 pathloss: initial code, no distance calculation yet
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 }