Commit 5a278f03 authored by Joanne Hugé's avatar Joanne Hugé

tx power dbm

parent f09fa586
......@@ -20,7 +20,7 @@ md5sum = 1bd4ed3240f81ce5ff5a55e79366a3f4
[template-ors]
filename = instance-ors.cfg
md5sum = 2cf97b9e8db9cd77e806ae856ba23c0d
md5sum = ea7c0410567526c7ad5454aad5b77e7b
[slaplte.jinja2]
_update_hash_filename_ = slaplte.jinja2
......
......@@ -49,7 +49,7 @@ recipe = slapos.recipe.build
configuration = $${slap-configuration:configuration}
sdr-dir = $${sdr:dir}
init =
import subprocess
import math, subprocess
DEFAULTS = {
"*": {
"tx_power_dbm": 20,
......@@ -61,8 +61,8 @@ init =
"dl_nr_arfcn": 158400,
"nr_band": 28,
"rf_mode": "fdd",
"power_estimation": (
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
[-0.004711416231164319, 1.5976906979683085, -67.71316951508676],
),
},
......@@ -72,7 +72,7 @@ init =
"dl_nr_arfcn": 519000,
"nr_band": 41,
"rf_mode": "tdd",
"power_estimation": (
"tx_interpolation_coefficients": (
[-0.008712931375092506, 2.1973585140044642, -94.29420762479742],
[-0.004472751640641793, 1.6308290630103919, -81.84549245154561],
),
......@@ -83,7 +83,7 @@ init =
"dl_nr_arfcn": 378000,
"nr_band": 39,
"rf_mode": "tdd",
"power_estimation": (
"tx_interpolation_coefficients": (
[-0.008712931375092506, 2.1973585140044642, -94.29420762479742],
[-0.0022523817802900985, 1.2674016231310092, -66.57165215468584],
),
......@@ -94,8 +94,8 @@ init =
"dl_nr_arfcn": 470000,
"nr_band": 40,
"rf_mode": "tdd",
"power_estimation": (
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
[-0.0016475305254340404, 1.1580162105112186, -62.10679297527826],
),
},
......@@ -105,9 +105,9 @@ init =
"dl_nr_arfcn": 518600,
"nr_band": 41,
"rf_mode": "tdd",
"power_estimation": (
lambda x: "UNKNOWN",
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
None,
),
},
"B42": {
......@@ -116,7 +116,7 @@ init =
"dl_nr_arfcn": 632628,
"nr_band": 78,
"rf_mode": "tdd",
"power_estimation": (
"tx_interpolation_coefficients": (
[-0.014198126839751619, 2.980758813262773, -125.25800492285738],
[0.003977721774394756, 0.527208191717173, -42.761142655285376],
),
......@@ -127,7 +127,7 @@ init =
"dl_nr_arfcn": 646666,
"nr_band": 78,
"rf_mode": "tdd",
"power_estimation": (
"tx_interpolation_coefficients": (
[-0.014198126839751619, 2.980758813262773, -125.25800492285738],
[-0.0036530114002551943, 1.510856844601873, -74.58790185136355],
),
......@@ -138,8 +138,8 @@ init =
"dl_nr_arfcn": 660000,
"nr_band": 77,
"rf_mode": "tdd",
"power_estimation": (
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
[-0.003358281211508112, 1.4533760798172672, -70.18774498873421],
),
},
......@@ -149,8 +149,8 @@ init =
"dl_nr_arfcn": 720000,
"nr_band": 79,
"rf_mode": "tdd",
"power_estimation": (
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
[-0.004745509248998074, 1.659474968728413, -76.46937551110834],
),
},
......@@ -160,34 +160,35 @@ init =
"dl_nr_arfcn": 0,
"nr_band": 0,
"rf_mode": "tdd",
"power_estimation": (
lambda x: "UNKNOWN",
lambda x: "UNKNOWN",
"tx_interpolation_coefficients": (
None,
None,
),
},
}
def get_sdr_info(cmd):
if options['configuration'].get('testing', False):
return {'t': 'TDD', 'b': 'B39', 'v': '4.2', 's': 'B53'}[cmd]
return {'t': 'TDD', 'b': 'UNKNOWN', 'v': '4.2', 's': 'B53'}[cmd]
return subprocess.check_output(
["sudo", "-n", options['sdr-dir'] + "/get-sdr-info", "-" + cmd]
).decode()
version = get_sdr_info('v')
tdd = get_sdr_info('t')
band = get_sdr_info('b')
version = float(version) if version != 'UNKNOWN' else 0
options.update({
'version' : float(version) if version != 'UNKNOWN' else 0,
'band' : get_sdr_info('b'),
'tdd' : get_sdr_info('t'),
'one-watt': bool(options['version'] >= 4),
'ors-version': = "{} {} {}".format(
options['tdd'],
options['band'],
"2x1W" if options['one-watt'] else "2x0.5W",
'version' : version,
'band' : band,
'tdd' : tdd,
'one-watt': bool(version >= 4),
'ors-version': "{} {} {}".format(
tdd,
band,
"2x1W" if version >= 4 else "2x0.5W",
),
})
band = options['band']
ors_version = int(options['one-watt'])
default_tx_gain = DEFAULTS[band]['tx_gain' ][ors_version]
default_rx_gain = DEFAULTS[band]['rx_gain' ][ors_version]
default_earfcn = DEFAULTS[band]['dl_earfcn' ]
default_nr_arfcn = DEFAULTS[band]['dl_nr_arfcn']
default_nr_band = DEFAULTS[band]['nr_band' ]
......@@ -197,27 +198,33 @@ init =
def dbm_to_gain(coefficients, x):
if not coefficients:
return None
a, b, c = *coefficients
a, b, c = coefficients
return (2 * (x - c)) / (math.sqrt(b**2 - 4 * a * (c - x)) + b)
default_rx_gain = DEFAULTS['*']['rx_gain'] + 20
tx_power_dbm = options['configuration'].get('tx_dbm_power' , DEFAULTS['*']['tx_power_dbm'])
tx_gain = dbm_to_gain(DEFAULTS[band]['tx_interpolation_coefficients'][ors_version], tx_power_dbm)
def print_dbm(tx_power_dbm):
tx_power_mw = 10 ** ( tx_power_dbm / 10 )
if tx_power_mw < 0.01:
tx_power_w_s = "{:0.2f} µW".format(tx_power_mw * 1000)
else:
tx_power_w_s = "{:0.2f} mW".format(tx_power_mw)
return "{:0.2f} dBm ({})".format(tx_power_dbm, tx_power_w_s)
if tx_gain == None:
tx_gain = options['configuration'].get('tx_gain', -1)
tx_power_s = "Radio board unknown, please set tx_gain manually"
else:
tx_power_s = print_dbm(tx_power_dbm)
options.update({
'tx-gain' : dbm_to_gain(DEFAULTS[band]['power_estimation'][ors_version], tx_power_dbm),
'tx-power' : dbm_to_gain(DEFAULTS[band]['power_estimation'][ors_version], tx_power_dbm),
'tx-gain' : tx_gain,
'tx-power' : tx_power_s,
'rx-gain' : options['configuration'].get('rx_gain' , default_rx_gain ),
'earfcn' : options['configuration'].get('dl_earfcn' , default_earfcn ),
'nr-arfcn': options['configuration'].get('dl_nr_arfcn', default_nr_arfcn),
'nr-band' : options['configuration'].get('nr_band' , default_nr_band ),
'rf-mode' : options['configuration'].get('rf_mode' , default_rf_mode ),
})
power_estimate_dbm = DEFAULTS[options['band']]['power_estimation'][int(options['one-watt'])](float(options['current-tx-gain']))
if power_estimate_dbm == "UNKNOWN":
power_estimate = "Information not available for this band"
else:
power_estimate_mw = 10 ** ( power_estimate_dbm / 10 )
if power_estimate_mw < 0.01:
power_estimate_s = "{:0.2f} µW".format(power_estimate_mw * 1000)
else:
power_estimate_s = "{:0.2f} mW".format(power_estimate_mw)
power_estimate = "{:0.2f} dBm ({})".format(power_estimate_dbm, power_estimate_s)
options['power-estimate'] = power_estimate
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment