Skip to content

Commit

Permalink
Merge pull request #20 from blevic/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
blevic authored Jul 24, 2022
2 parents 16c7da8 + b0a965d commit b4d7e35
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nrarfcn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
from nrarfcn.api.get_duplex_mode import get_duplex_mode
from nrarfcn.api.get_nrarfcn_range import get_nrarfcn_range
from nrarfcn.api.get_frequency_range import get_frequency_range
from nrarfcn.api.get_gscn_by_frequency import get_gscn_by_frequency
from nrarfcn.api.get_frequency_by_gscn import get_frequency_by_gscn
from nrarfcn.api.get_gscn_range import get_gscn_range
42 changes: 42 additions & 0 deletions nrarfcn/api/get_frequency_by_gscn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from nrarfcn.tables.gscn_parameters import table_gscn_parameters


def get_frequency_by_gscn(gscn: int) -> float:
"""Gets the frequency of a given GSCN (Global Synchronization Channel Number), in MHz.
Args:
gscn: The GSCN to get the frequency of.
Returns:
The frequency of the given GSCN, in MHz.
Raises:
ValueError: If the given GSCN is invalid
"""
if not isinstance(gscn, int):
raise ValueError("GSCN must be an integer")

if gscn < 2 or gscn > 26639:
raise ValueError("GSCN must be between 2 and 26639")

table = table_gscn_parameters()

for row in table.data:
if table.get_cell(row, 'gscn_min') <= gscn <= table.get_cell(row, 'gscn_max'):
if table.get_cell(row, 'm_set') == {}:
n = gscn - table.get_cell(row, 'g_offs')
return table.get_cell(row, 'f_offs') + table.get_cell(row, 'n_coeff') * n
else:
if gscn % 3 == 0:
n = gscn // table.get_cell(row, 'g_n_coeff')
m = 3
elif gscn % 3 == 1:
n = gscn // table.get_cell(row, 'g_n_coeff')
m = 5
elif gscn % 3 == 2:
n = (gscn + 1) // table.get_cell(row, 'g_n_coeff')
m = 1

return table.get_cell(row, 'f_offs') + table.get_cell(row, 'n_coeff') * n + table.get_cell(row, 'm_coeff') * m

raise ValueError("Expected to have found a GSCN in the table, but didn't")
6 changes: 6 additions & 0 deletions nrarfcn/api/get_gscn_by_frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from nrarfcn.tables.gscn_parameters import table_gscn_parameters


def get_gscn_by_frequency(freq: float) -> int:
table = table_gscn_parameters()
return 0
10 changes: 10 additions & 0 deletions nrarfcn/api/get_gscn_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Union
from nrarfcn.tables.applicable_ss_raster_fr1 import table_applicable_ss_raster_fr1
from nrarfcn.tables.applicable_ss_raster_fr2 import table_applicable_ss_raster_fr2


def get_gscn_range(band: Union[str, int]) -> tuple:
table_fr1 = table_applicable_ss_raster_fr1()
table_fr2 = table_applicable_ss_raster_fr2()

return 0, 0
47 changes: 47 additions & 0 deletions tests/test_get_frequency_by_gscn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest
from nrarfcn import get_frequency_by_gscn


class TestGetFrequencyByGscn(unittest.TestCase):
def test_valid_channels(self):
gscn_freq_map = {
2: 1.250,
500: 200.450,
1000: 399.850,
5000: 2000.450,
7498: 2999.050,
7499: 3000.000,
10000: 6601.440,
15000: 13801.440,
20000: 21001.440,
22255: 24248.640,
22256: 24250.080,
23000: 37106.400,
25000: 71666.400,
26639: 99988.320
}

for gscn, freq in gscn_freq_map.items():
self.assertAlmostEqual(get_frequency_by_gscn(gscn), freq, places=3)

def test_different_channels(self):
different_channels = [
(2, 3),
(500, 501),
(1000, 1001),
(7498, 7499),
(22255, 22256),
(22256, 22257),
(23000, 23001),
(25000, 25001)
]

for gscn1, gscn2 in different_channels:
self.assertNotAlmostEqual(get_frequency_by_gscn(gscn1), get_frequency_by_gscn(gscn2), places=3)

def test_invalid_channels(self):
invalid_channels = [-1, 0, 1, 2.0, 23000.5, None, '', '2', 26640]

for channel in invalid_channels:
with self.assertRaises(ValueError):
get_frequency_by_gscn(channel)
13 changes: 13 additions & 0 deletions tests/test_get_gscn_by_frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from nrarfcn import get_gscn_by_frequency


class TestGetGscnByFrequency(unittest.TestCase):
def test_valid_freqs(self):
pass

def test_different_freqs(self):
pass

def test_invalid_freqs(self):
pass
10 changes: 10 additions & 0 deletions tests/test_get_gscn_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest
from nrarfcn import get_gscn_range


class TestGetGscnRange(unittest.TestCase):
def test_valid_bands(self):
pass

def test_invalid_bands(self):
pass

0 comments on commit b4d7e35

Please sign in to comment.