Commit 8a90ecce authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fd9ee604
...@@ -17,7 +17,12 @@ ...@@ -17,7 +17,12 @@
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
"""Package earfcn ...""" """Package earfcn helps to do computations with LTE bands, frequencies and EARFCN numbers.
- frequency converts EARFCN to frequency.
- dl2ul converts DL EARFCN to corresponding UL EARFCN.
- band returns information about band to which EARFCN belongs.
"""
import collections import collections
...@@ -25,63 +30,63 @@ import collections ...@@ -25,63 +30,63 @@ import collections
# TS 36.101 v16.18.0 Table 5.7.3-1 # TS 36.101 v16.18.0 Table 5.7.3-1
# band fdl_lo Noffs_dl NDL range ful_lo Noffs_ul NUL range # band fdl_lo Noffs_dl NDL range ful_lo Noffs_ul NUL range
_tab573_1 = """\ _tab573_1 = """\
1 2110 0 0 – 599 1920 18000 18000 – 18599 1 2110 0 0 - 599 1920 18000 18000 - 18599
2 1930 600 600 − 1199 1850 18600 18600 – 19199 2 1930 600 600 - 1199 1850 18600 18600 - 19199
3 1805 1200 1200 – 1949 1710 19200 19200 – 19949 3 1805 1200 1200 - 1949 1710 19200 19200 - 19949
4 2110 1950 1950 – 2399 1710 19950 19950 – 20399 4 2110 1950 1950 - 2399 1710 19950 19950 - 20399
5 869 2400 2400 – 2649 824 20400 20400 – 20649 5 869 2400 2400 - 2649 824 20400 20400 - 20649
6 875 2650 2650 – 2749 830 20650 20650 – 20749 6 875 2650 2650 - 2749 830 20650 20650 - 20749
7 2620 2750 2750 – 3449 2500 20750 20750 – 21449 7 2620 2750 2750 - 3449 2500 20750 20750 - 21449
8 925 3450 3450 – 3799 880 21450 21450 – 21799 8 925 3450 3450 - 3799 880 21450 21450 - 21799
9 1844.9 3800 3800 – 4149 1749.9 21800 21800 – 22149 9 1844.9 3800 3800 - 4149 1749.9 21800 21800 - 22149
10 2110 4150 4150 – 4749 1710 22150 22150 – 22749 10 2110 4150 4150 - 4749 1710 22150 22150 - 22749
11 1475.9 4750 4750 – 4949 1427.9 22750 22750 – 22949 11 1475.9 4750 4750 - 4949 1427.9 22750 22750 - 22949
12 729 5010 5010 – 5179 699 23010 23010 – 23179 12 729 5010 5010 - 5179 699 23010 23010 - 23179
13 746 5180 5180 – 5279 777 23180 23180 – 23279 13 746 5180 5180 - 5279 777 23180 23180 - 23279
14 758 5280 5280 – 5379 788 23280 23280 – 23379 14 758 5280 5280 - 5379 788 23280 23280 - 23379
17 734 5730 5730 – 5849 704 23730 23730 – 23849 17 734 5730 5730 - 5849 704 23730 23730 - 23849
18 860 5850 5850 – 5999 815 23850 23850 – 23999 18 860 5850 5850 - 5999 815 23850 23850 - 23999
19 875 6000 6000 – 6149 830 24000 24000 – 24149 19 875 6000 6000 - 6149 830 24000 24000 - 24149
20 791 6150 6150 – 6449 832 24150 24150 – 24449 20 791 6150 6150 - 6449 832 24150 24150 - 24449
21 1495.9 6450 6450 – 6599 1447.9 24450 24450 – 24599 21 1495.9 6450 6450 - 6599 1447.9 24450 24450 - 24599
22 3510 6600 6600 – 7399 3410 24600 24600 – 25399 22 3510 6600 6600 - 7399 3410 24600 24600 - 25399
23 2180 7500 7500 – 7699 2000 25500 25500 – 25699 23 2180 7500 7500 - 7699 2000 25500 25500 - 25699
24 1525 7700 7700 – 8039 1626.5 25700 25700 – 26039 24 1525 7700 7700 - 8039 1626.5 25700 25700 - 26039
25 1930 8040 8040 – 8689 1850 26040 26040 – 26689 25 1930 8040 8040 - 8689 1850 26040 26040 - 26689
26 859 8690 8690 – 9039 814 26690 26690 – 27039 26 859 8690 8690 - 9039 814 26690 26690 - 27039
27 852 9040 9040 – 9209 807 27040 27040 – 27209 27 852 9040 9040 - 9209 807 27040 27040 - 27209
28 758 9210 9210 – 9659 703 27210 27210 – 27659 28 758 9210 9210 - 9659 703 27210 27210 - 27659
29 717 9660 9660 9769 N/A 29 717 9660 9660 - 9769 N/A
30 2350 9770 9770 – 9869 2305 27660 27660 – 27759 30 2350 9770 9770 - 9869 2305 27660 27660 - 27759
31 462.5 9870 9870 – 9919 452.5 27760 27760 – 27809 31 462.5 9870 9870 - 9919 452.5 27760 27760 - 27809
32 1452 9920 9920 10359 N/A 32 1452 9920 9920 - 10359 N/A
33 1900 36000 36000 – 36199 1900 36000 36000 – 36199 33 1900 36000 36000 - 36199 1900 36000 36000 - 36199
34 2010 36200 36200 – 36349 2010 36200 36200 – 36349 34 2010 36200 36200 - 36349 2010 36200 36200 - 36349
35 1850 36350 36350 – 36949 1850 36350 36350 – 36949 35 1850 36350 36350 - 36949 1850 36350 36350 - 36949
36 1930 36950 36950 – 37549 1930 36950 36950 – 37549 36 1930 36950 36950 - 37549 1930 36950 36950 - 37549
37 1910 37550 37550 – 37749 1910 37550 37550 – 37749 37 1910 37550 37550 - 37749 1910 37550 37550 - 37749
38 2570 37750 37750 – 38249 2570 37750 37750 – 38249 38 2570 37750 37750 - 38249 2570 37750 37750 - 38249
39 1880 38250 38250 – 38649 1880 38250 38250 – 38649 39 1880 38250 38250 - 38649 1880 38250 38250 - 38649
40 2300 38650 38650 – 39649 2300 38650 38650 – 39649 40 2300 38650 38650 - 39649 2300 38650 38650 - 39649
41 2496 39650 39650 – 41589 2496 39650 39650 – 41589 41 2496 39650 39650 - 41589 2496 39650 39650 - 41589
42 3400 41590 41590 – 43589 3400 41590 41590 – 43589 42 3400 41590 41590 - 43589 3400 41590 41590 - 43589
43 3600 43590 43590 – 45589 3600 43590 43590 – 45589 43 3600 43590 43590 - 45589 3600 43590 43590 - 45589
44 703 45590 45590 – 46589 703 45590 45590 – 46589 44 703 45590 45590 - 46589 703 45590 45590 - 46589
45 1447 46590 46590 – 46789 1447 46590 46590 – 46789 45 1447 46590 46590 - 46789 1447 46590 46590 - 46789
46 5150 46790 46790 – 54539 5150 46790 46790 – 54539 46 5150 46790 46790 - 54539 5150 46790 46790 - 54539
47 5855 54540 54540 - 55239 5855 54540 54540 55239 47 5855 54540 54540 - 55239 5855 54540 54540 - 55239
48 3550 55240 55240 – 56739 3550 55240 55240 – 56739 48 3550 55240 55240 - 56739 3550 55240 55240 - 56739
49 3550 56740 56740 – 58239 3550 56740 56740 – 58239 49 3550 56740 56740 - 58239 3550 56740 56740 - 58239
50 1432 58240 58240 - 59089 1432 58240 58240 - 59089 50 1432 58240 58240 - 59089 1432 58240 58240 - 59089
51 1427 59090 59090 - 59139 1427 59090 59090 - 59139 51 1427 59090 59090 - 59139 1427 59090 59090 - 59139
52 3300 59140 59140 - 60139 3300 59140 59140 - 60139 52 3300 59140 59140 - 60139 3300 59140 59140 - 60139
53 2483.5 60140 60140 - 60254 2483.5 60140 60140 - 60254 53 2483.5 60140 60140 - 60254 2483.5 60140 60140 - 60254
64 Reserved 64 Reserved
65 2110 65536 65536 – 66435 1920 131072 131072 – 131971 65 2110 65536 65536 - 66435 1920 131072 131072 - 131971
66 2110 66436 66436 – 67335 1710 131972 131972 – 132671 66 2110 66436 66436 - 67335 1710 131972 131972 - 132671
67 738 67336 67336 67535 N/A 67 738 67336 67336 - 67535 N/A
68 753 67536 67536 - 67835 698 132672 132672 - 132971 68 753 67536 67536 - 67835 698 132672 132672 - 132971
69 2570 67836 67836 - 68335 N/A 69 2570 67836 67836 - 68335 N/A
70 1995 68336 68336 - 68585 1695 132972 132972 - 133121 70 1995 68336 68336 - 68585 1695 132972 132972 - 133121
...@@ -98,7 +103,7 @@ _tab573_1 = """\ ...@@ -98,7 +103,7 @@ _tab573_1 = """\
# EBand represents information about one LTE band. # EBand represents information about one LTE band.
EBand = collections.namedtuple('EBand', EBand = collections.namedtuple('EBand',
'band', 'fdl_lo', 'ndl_lo', 'ndl_hi', 'ful_lo', 'nul_lo', 'nul_hi') ['band', 'fdl_lo', 'ndl_lo', 'ndl_hi', 'ful_lo', 'nul_lo', 'nul_hi'])
# _eband_tab is table with all LTE bands. # _eband_tab is table with all LTE bands.
_eband_tab = [] # of EBand _eband_tab = [] # of EBand
...@@ -132,13 +137,13 @@ def _(): ...@@ -132,13 +137,13 @@ def _():
nul_lo = None nul_lo = None
nul_hi = None nul_hi = None
else: else:
assert len(v) == 12, v assert len(v) == 11, v
ful_lo = float(v[7]) ful_lo = float(v[6])
noff_ul = int (v[8]) noff_ul = int (v[7])
nul_lo = int (v[9]) nul_lo = int (v[8])
assert v[10] == '-', v assert v[9] == '-', v
nul_hi = int (v[11]) nul_hi = int (v[10])
assert noff_ul = nul_lo, v assert noff_ul == nul_lo, v
assert nul_lo < nul_hi, v assert nul_lo < nul_hi, v
eband = EBand(band, fdl_lo, ndl_lo, ndl_hi, ful_lo, nul_lo, nul_hi) eband = EBand(band, fdl_lo, ndl_lo, ndl_hi, ful_lo, nul_lo, nul_hi)
...@@ -147,10 +152,30 @@ def _(): ...@@ -147,10 +152,30 @@ def _():
p = eprev p = eprev
assert p.band < n.band assert p.band < n.band
assert p.ndl_hi < n.ndl_lo assert p.ndl_hi < n.ndl_lo
assert p.nul_hi < n.nul_hi if p.ful_lo is not None and n.ful_lo is not None:
assert p.nul_hi < n.nul_hi
_eband_tab.append(eband) _eband_tab.append(eband)
eprev = eband eprev = eband
_()
# band returns information about band covering earfcn.
def band(earfcn): # -> (EBand, is_dl) | KeyError
try:
b = _eband_lookup_dl(earfcn)
except KeyError:
pass
else:
return b, True
try:
b = _eband_lookup_ul(earfcn)
except KeyError:
pass
else:
return b, False
raise KeyError('no band that corresponds to EARFCN=%r' % earfcn)
# _eband_lookup_{dl,ul} look up EBand by DL/UL EARFCN. # _eband_lookup_{dl,ul} look up EBand by DL/UL EARFCN.
def _eband_lookup_dl(dl_earfcn): # -> EBand | KeyError def _eband_lookup_dl(dl_earfcn): # -> EBand | KeyError
...@@ -168,33 +193,30 @@ def _eband_lookup_ul(ul_earfcn): # -> EBand | KeyError ...@@ -168,33 +193,30 @@ def _eband_lookup_ul(ul_earfcn): # -> EBand | KeyError
raise KeyError('no band that corresponds to UL EARFCN=%r' % ul_earfcn) raise KeyError('no band that corresponds to UL EARFCN=%r' % ul_earfcn)
# dl2ul returns UL EARFCN that corresponds to DL EARFCN.
# earfcn_dl2ul returns UL EARFCN that corresponds to DL EARFCN. def dl2ul(dl_earfcn): # -> ul_earfcn
def earfcn_dl2ul(dl_earfcn): # -> ul_earfcn
b = _eband_lookup_dl(dl_earfcn) b = _eband_lookup_dl(dl_earfcn)
assert b.ndl_lo <= dl_earfcn <= b.ndl_hi assert b.ndl_lo <= dl_earfcn <= b.ndl_hi
ul_earfcn = b.nul_lo + (dl_earfcn - b.ndl_lo) ul_earfcn = b.nul_lo + (dl_earfcn - b.ndl_lo)
assert b.nul_lo <= ul_earfcn <= b.nul_hi assert b.nul_lo <= ul_earfcn <= b.nul_hi
return ul_earfcn return ul_earfcn
# earfcn_to_freq returns frequency corresponding to DL or UL EARFCN
def earfcn_to_freq(earfcn): # -> freq (MHz) # frequency returns frequency corresponding to DL or UL EARFCN.
try: def frequency(earfcn): # -> freq (MHz)
b = _eband_lookup_dl(earfcn) b, dl = band(earfcn)
except KeyError: if dl:
pass
else:
assert b.ndl_lo <= earfcn <= b.ndl_hi assert b.ndl_lo <= earfcn <= b.ndl_hi
fdl = b.fdl_lo + 0.1*(earfcn - b.ndl_lo) # TS 36.101 5.7.3 fdl = b.fdl_lo + 0.1*(earfcn - b.ndl_lo) # TS 36.101 5.7.3
return fdl return fdl
try:
b = _eband_lookup_ul(earfcn)
except KeyError:
pass
else: else:
assert b.nul_lo <= earfcn <= b.nul_hi assert b.nul_lo <= earfcn <= b.nul_hi
ful = b.ful_lo + 0.1*(earfcn - b.nul_lo) # TS 36.101 5.7.3 ful = b.ful_lo + 0.1*(earfcn - b.nul_lo) # TS 36.101 5.7.3
return ful return ful
raise KeyError('no band that corresponds to EARFCN=%r' % earfcn)
# XXX _testme
def _testme():
assert dl2ul(300) == 18300
assert frequency(300) == 2140
# XXX ...
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