1 # -*- coding: utf-8 -*-
4 # Power measurement emulation
6 # (C) 2017-2018 by Vadim Yanitskiy <axilirator@gmail.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 from random
import randint
23 """ Power measurement emulation for fake transceivers.
25 There is no such thing like RF signal level in fake Um-interface,
26 so we need to emulate this. The main idea is to have a list of
27 all running and idle transceivers. As soon as a measurement
28 request is received, FakePM will attempt to find a running
29 transceiver on a given frequency.
31 The result of such "measurement" is a random RSSI value
32 in one of the following ranges:
34 - trx_min ... trx_max - if at least one TRX was found,
35 - noise_min ... noise_max - no TRX instances were found.
37 FIXME: it would be great to average the rate of bursts
38 and indicated power / attenuation values for all
39 matching transceivers, so "pure traffic" ARFCNs
40 would be handled properly.
44 def __init__(self
, noise_min
, noise_max
, trx_min
, trx_max
):
45 # Init list of transceivers
48 # RSSI randomization ranges
49 self
.noise_min
= noise_min
50 self
.noise_max
= noise_max
51 self
.trx_min
= trx_min
52 self
.trx_max
= trx_max
56 return randint(self
.noise_min
, self
.noise_max
)
60 return randint(self
.trx_min
, self
.trx_max
)
62 def measure(self
, freq
, fn
= None):
63 # Iterate over all known transceivers
64 for trx
in self
.trx_list
:
68 # FIXME: we need to know current TDMA frame number here,
69 # because some transceivers may use frequency hopping
70 if trx
.fh
is not None and fn
is None:
73 # Match by given frequency
74 if trx
.get_tx_freq(fn
) == freq
:
77 return self
.rssi_noise