-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkplanner.py
357 lines (306 loc) · 10 KB
/
linkplanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/python
#
#
# By brendan Minish ([email protected]) 2014 as a learning excercise
# Licence GPL v3
#
import math
#import sys
from StringIO import StringIO
class LINK(object):
""" This is an instance of a wireless link"""
C = 3e8
def __init__(self):
self._frequency = 5825
self._txpower = 17
self._feedloss = 1
self._rxgain = 23
self._txgain = 23
self._rxsens = -74
self._distance = 10
self._cfactor = 0.5
self._tfactor = 1.0
# Some defaults not exposed in UI yet
# Somewhat safe value for temperate regions
self._kfactor = 1.33
# Atmosperic absorbtion ITU-R p.676
# Over simplified as it's low below 10Ghz
# Later we need a lookup table
# 10Ghz 0.01dB/Km
# 20Ghz 0.1dB/Km
# 24Ghz 0.2dB/Km
# 38Ghz 0.12dB/Km
# 60Ghz ~ 15dB/Km
self._atmatten = 0.01
# Humidity ITU-R p.836
#
# see rain, ITU-R pn.837-1
# Ireland = H
# H .001% = 32mm/h
# Later we should accept region codes
# then use a lookup table
# when we do the below value should be set inside the object
self._rainfall = 32
self._rczone = 'H'
# self._c = 3e8
def getFrequency(self):
return self._frequency
def setFrequency(self, v):
if v:
try:
x = float(v)
self._frequency = x
except:
raise ValueError("Frequency must be in MHz")
elif not v:
pass
frequency = property(getFrequency, setFrequency)
def getTxpower(self):
return self._txpower
def setTxpower(self, v):
if v:
try:
x = float(v)
self._txpower = x
except:
raise ValueError("TX power must be in dBm")
elif not v:
pass
txpower = property(getTxpower, setTxpower)
def getFeedloss(self):
return self._feedloss
def setFeedloss(self, v):
if v:
try:
x = float(v)
self._feedloss = x
except:
raise ValueError("Feeder Loss must be in dB")
elif not v:
pass
feedloss = property(getFeedloss, setFeedloss)
def getRxgain(self):
return self._rxgain
def setRxgain(self, v):
if v:
try:
x = float(v)
self._rxgain = x
except:
raise ValueError("RX antenna Gain must be in dBi")
elif not v:
pass
rxgain = property(getRxgain, setRxgain)
def getTxgain(self):
return self._txgain
def setTxgain(self, v):
if v:
try:
x = float(v)
self._txgain = x
except:
raise ValueError("TX antenna Gain must be in dBi")
elif not v:
pass
txgain = property(getTxgain, setTxgain)
def getRxsens(self):
return self._rxsens
def setRxsens(self, v):
if v:
try:
x = float(v)
self._rxsens = x
except:
raise ValueError("RX Sensitivity must be in dBm")
elif not v:
pass
rxsens = property(getRxsens, setRxsens)
def getDistance(self):
return self._distance
def setDistance(self, v):
if v:
try:
x = float(v)
self._distance = x
except:
raise ValueError("Distance must be In Km")
elif not v:
pass
distance = property(getDistance, setDistance)
def getCfactor(self):
return self._cfactor
def setCfactor(self, v):
if v:
try:
x = float(v)
if x > 0.09 and x < 0.51:
self._cfactor = x
else:
raise ValueError("Climate factor must be between 0.1 (dry) and 0.5 (wet)")
except:
raise ValueError("Climate factor must be between 0.1 (dry) and 0.5 (wet)")
elif not v:
pass
cfactor = property(getCfactor, setCfactor)
def getTfactor(self):
return self._tfactor
def setTfactor(self, v):
if v:
try:
x = float(v)
if x > 0.24 and x < 4.01:
self._tfactor = x
else:
raise ValueError("Terrain factor between 0.25 (Mountains) and 4 (smooth)")
except:
raise ValueError("Terrain factor between 0.25 (Mountains) and 4 (smooth)")
elif not v:
pass
tfactor = property(getTfactor, setTfactor)
def exportLink(self, f):
# free space losses calulation done in MHz
fsl = 32.44 + 20 * math.log10(self.frequency) \
+ 20 * math.log10(self.distance)
# Atmospehric attenuation
aatt = self.distance * self._atmatten
ploss = fsl + aatt
erp = self.txpower + self.txgain - self.feedloss
rxsig = erp - ploss + self.rxgain - self.feedloss
margin = rxsig - self.rxsens
# this is horrible and needs to be rewitten to use ITU-R P.530-15
# but to get to meaningfull results we should be doing terrain profiles
# and extracting data from that.
# below is a badly implemented over-simplifcation of Barnett-Vigants
# basically a placeholder for someting better
avail = (1 - 2.5/1e6 * self.cfactor * self.tfactor * self.frequency
/ 1e3 * (self.distance / 1.6) ** 3 * 10 ** (- margin / 10))
if avail <= 0:
avail = 0
elif avail >= 1:
avail = 1
avail = avail * 100
outage = (525600 - avail * 5256) / 60
f.write("ERP in dBm = %.1f\n" % erp)
f.write("RSSI in dBm = %.0f\n" % rxsig)
f.write("Path loss in dB = %.0f\n" % ploss)
f.write("Link Margin dB = %.0f\n" % margin)
f.write("Link Avalability = %.6f\n" % avail)
f.write("Outage Hours/Yr = %s\n" % outage)
#testing = link()
#f = StringIO()
#testing.exportLink(f)
#print(f.getvalue())
def doInput(link):
""" gets the varous input for a link plan and sanity checks """
gotInput = False
while not gotInput:
while True:
try:
if link.frequency:
prompt = "Frequency [%.0f]Mhz? " % link.frequency
else:
prompt = "Frequency in MHz? "
link.frequency = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.txpower:
prompt = "TX power [%.1f]dBm? " % link.txpower
else:
prompt = "TX power in dBm? "
link.txpower = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.feedloss:
prompt = "Feeder Losses (total) [%.1f]dBm? " % link.feedloss
else:
prompt = "Feeder Losses (total) dBm? "
link.feedloss = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.rxgain:
prompt = "RX Antenna gain [%.1f]dBi? " % link.rxgain
else:
prompt = "RX Antenna gain dBi? "
link.rxgain = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.txgain:
prompt = "TX Antenna gain [%.1f]dBi? " % link.txgain
else:
prompt = "TX Antenna gain dBi? "
link.txgain = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.rxsens:
prompt = "RX Sensitivity [%.1f]dBm? " % link.rxsens
else:
prompt = "RX Sensitivity dBm? "
link.rxsens = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.distance:
prompt = "Link Distance [%.3f]Km? " % link.distance
else:
prompt = "Link Distance in Km? "
link.distance = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.cfactor:
prompt = "Climate factor (0.1 dry) to (0.5 Humid) [%.2f]? " % link.cfactor
else:
prompt = "Climate factor (0.1 dry) to (0.5 Humid) ? "
link.cfactor = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
while True:
try:
if link.tfactor:
prompt = "Terrain factor (0.25 Mountains, 1 Average, 4 Smooth) [%.2f]? " % link.tfactor
else:
prompt = "Terrain factor (0.25 Mountains, 1 Average, 4 Smooth) ? "
link.tfactor = raw_input(prompt)
except ValueError as strerror:
print strerror
continue
break
gotInput = True
f = StringIO()
link.exportLink(f)
print
print "Based in input values, link calulation is"
print(f.getvalue())
def main():
link = LINK()
doInput(link)
if __name__ == "__main__":
main()