forked from wirelessModem/NgToolset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngltegridui.py
347 lines (305 loc) · 14.7 KB
/
ngltegridui.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
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
'''
File:
ngltegridui.py
Description:
UI for LTE resource grid.
Change History:
2018-1-19 v0.1 created. github/zhenggao2
'''
import os
from PyQt5.QtWidgets import QDialog, QTextEdit, QTabWidget, QLabel, QLineEdit, QComboBox, QPushButton, QTableWidget, QTableWidgetItem, QHeaderView
from PyQt5.QtWidgets import QGridLayout, QHBoxLayout, QVBoxLayout
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt
import ngmainwin
from ngltephy import LteResType
from ngltegrid import NgLteGrid
from ngb36utils import time2str36, freq2str36
class NgLteGridUi(QDialog):
def __init__(self, ngwin):
super().__init__()
self.ngwin = ngwin
self.args = dict()
self.initResGridMapper()
self.initUi()
def onOkBtnClicked(self):
self.args['fs'] = self.fsCombo.currentIndex()
self.args['bw'] = self.bwCombo.currentIndex()
self.args['cp'] = self.cpCombo.currentIndex()
self.args['ap'] = self.apCombo.currentIndex()
try:
_pci = int(self.pciEdit.text())
except ValueError as e:
self.ngwin.logEdit.append("Invalid PCI: '%s'." % self.pciEdit.text())
self.accept()
return
self.args['pci'] = _pci
self.args['cfi'] = int(self.cfiCombo.currentText())
self.args['cfiSsf'] = int(self.cfiSsfCombo.currentText())
self.args['phichDur'] = self.phichDurCombo.currentIndex()
self.args['phichRes'] = self.phichResCombo.currentIndex()
self.args['sa'] = self.saCombo.currentIndex()
self.args['ssp'] = self.sspCombo.currentIndex()
self.args['dsPucch'] = int(self.dsPucchCombo.currentText()[-1])
self.args['nCqiRb'] = int(self.nCqiRbEdit.text())
self.args['nCsAn'] = int(self.nCsAnEdit.text())
self.args['n1PucchAn'] = int(self.n1PucchAnEdit.text())
self.args['tddAckMode'] = self.tddAckModeCombo.currentIndex()
self.args['sfn'] = int(self.sfnEdit.text())
self.args['prachConfInd'] = int(self.prachConfIndEdit.text())
self.args['prachFreqOff'] = int(self.prachFreqOffEdit.text())
self.args['srsSubfConf'] = int(self.srsSfConfEdit.text())
if self.ngwin.enableDebug:
self.ngwin.logEdit.append('contents of NgLteGridUI.args:')
for key, value in self.args.items():
self.ngwin.logEdit.append('-->key=%s, value=%s' % (key, str(value)))
grid = NgLteGrid(self.ngwin, self.args)
if grid.isOk:
grid.fillCrs()
grid.fillPbch()
grid.fillSch()
grid.fillPdcch()
grid.printDl()
grid.fillPucch()
grid.fillPrach()
grid.fillDmrsForPusch()
grid.fillSrs()
grid.printUl()
self.parseLteGrid()
self.accept()
def initUi(self):
self.fsLabel = QLabel('Frame Structure:')
self.fsCombo = QComboBox()
self.fsCombo.addItem('Type 1(FDD)')
self.fsCombo.addItem('Type 2(TDD)')
self.fsCombo.setCurrentIndex(1)
self.bwLabel = QLabel('System Bandwidth:')
self.bwCombo = QComboBox()
self.bwCombo.addItem('1.4MHz')
self.bwCombo.addItem('3MHz')
self.bwCombo.addItem('5MHz')
self.bwCombo.addItem('10MHz')
self.bwCombo.addItem('15MHz')
self.bwCombo.addItem('20MHz')
self.bwCombo.setCurrentIndex(5)
self.cpLabel = QLabel('Cyclic Prefix:')
self.cpCombo = QComboBox()
self.cpCombo.addItem('Normal CP')
self.cpCombo.addItem('Extended CP')
self.cpCombo.setCurrentIndex(0)
self.apLabel = QLabel('Downlink Antenna Port(s):')
self.apCombo = QComboBox()
self.apCombo.addItem('One Antenna Port')
self.apCombo.addItem('Two Antenna Ports')
self.apCombo.addItem('Four Antenna Ports')
self.apCombo.setCurrentIndex(1)
self.pciLabel = QLabel('Physical Cell Identity:')
self.pciEdit = QLineEdit()
self.pciEdit.setText('0')
self.cfiLabel = QLabel('CFI(Normal Downlink Subframe):')
self.cfiCombo = QComboBox()
self.cfiCombo.addItem('1')
self.cfiCombo.addItem('2')
self.cfiCombo.addItem('3')
self.cfiCombo.addItem('4')
self.cfiCombo.setCurrentIndex(2)
self.cfiSsfLabel = QLabel('CFI(Special Subframe, TDD):')
self.cfiSsfCombo = QComboBox()
self.cfiSsfCombo.addItem('1')
self.cfiSsfCombo.addItem('2')
self.cfiSsfCombo.setCurrentIndex(1)
self.phichDurLabel = QLabel('PHICH Duration:')
self.phichDurCombo = QComboBox()
self.phichDurCombo.addItem('Normal')
self.phichDurCombo.addItem('Extended')
self.phichDurCombo.setCurrentIndex(0)
self.phichResLabel = QLabel('PHICH Resource:')
self.phichResCombo = QComboBox()
self.phichResCombo.addItem('OneSixth')
self.phichResCombo.addItem('Half')
self.phichResCombo.addItem('One')
self.phichResCombo.addItem('Two')
self.phichResCombo.setCurrentIndex(0)
self.saLabel = QLabel('Subframe Assignment(TDD):')
self.saCombo = QComboBox()
self.saCombo.addItem('SA0')
self.saCombo.addItem('SA1')
self.saCombo.addItem('SA2')
self.saCombo.addItem('SA3')
self.saCombo.addItem('SA4')
self.saCombo.addItem('SA5')
self.saCombo.addItem('SA6')
self.saCombo.setCurrentIndex(2)
self.sspLabel = QLabel('Special Subframe Pattern(TDD):')
self.sspCombo = QComboBox()
self.sspCombo.addItem('SSP0')
self.sspCombo.addItem('SSP1')
self.sspCombo.addItem('SSP2')
self.sspCombo.addItem('SSP3')
self.sspCombo.addItem('SSP4')
self.sspCombo.addItem('SSP5')
self.sspCombo.addItem('SSP6')
self.sspCombo.addItem('SSP7(Normal CP)')
self.sspCombo.addItem('SSP8(Normal CP)')
self.sspCombo.setCurrentIndex(7)
self.dsPucchLabel = QLabel('Delta PUCCH Shift:')
self.dsPucchCombo = QComboBox()
self.dsPucchCombo.addItem('DS1')
self.dsPucchCombo.addItem('DS2')
self.dsPucchCombo.addItem('DS3')
self.dsPucchCombo.setCurrentIndex(0)
self.nCqiRbLabel = QLabel('nRB-CQI:')
self.nCqiRbEdit = QLineEdit()
self.nCqiRbEdit.setText('2')
self.nCsAnLabel = QLabel('nCS-AN:')
self.nCsAnEdit = QLineEdit()
self.nCsAnEdit.setText('0')
self.n1PucchAnLabel = QLabel('n1PUCCH-AN:')
self.n1PucchAnEdit = QLineEdit()
self.n1PucchAnEdit.setText('36')
self.tddAckModeLabel = QLabel('ACK/NACK Feedback Mode(TDD):')
self.tddAckModeCombo = QComboBox()
self.tddAckModeCombo.addItem('ACK/NACK Bundling')
self.tddAckModeCombo.addItem('ACK/NACK Multiplexing')
self.tddAckModeCombo.setCurrentIndex(0)
self.sfnLabel = QLabel('System Frame Number(SFN):')
self.sfnEdit = QLineEdit()
self.sfnEdit.setText('0')
self.prachConfIndLabel = QLabel('PRACH Configuration Index:')
self.prachConfIndEdit = QLineEdit()
self.prachConfIndEdit.setText('3')
self.prachFreqOffLabel = QLabel('PRACH Frequency Offset:')
self.prachFreqOffEdit = QLineEdit()
self.prachFreqOffEdit.setText('0')
self.srsSfConfLabel = QLabel('srs-SubframeConfig:')
self.srsSfConfEdit = QLineEdit()
self.srsSfConfEdit.setText('0')
self.okBtn = QPushButton('OK')
self.cancelBtn = QPushButton('Cancel')
self.okBtn.clicked.connect(self.onOkBtnClicked)
self.cancelBtn.clicked.connect(self.reject)
self.layout1 = QGridLayout()
self.layout1.addWidget(self.fsLabel, 0, 0)
self.layout1.addWidget(self.fsCombo, 0, 1)
self.layout1.addWidget(self.bwLabel, 1, 0)
self.layout1.addWidget(self.bwCombo, 1, 1)
self.layout1.addWidget(self.cpLabel, 2, 0)
self.layout1.addWidget(self.cpCombo, 2, 1)
self.layout1.addWidget(self.apLabel, 3, 0)
self.layout1.addWidget(self.apCombo, 3, 1)
self.layout1.addWidget(self.pciLabel, 4, 0)
self.layout1.addWidget(self.pciEdit, 4, 1)
self.layout1.addWidget(self.cfiLabel, 5, 0)
self.layout1.addWidget(self.cfiCombo, 5, 1)
self.layout1.addWidget(self.cfiSsfLabel, 6, 0)
self.layout1.addWidget(self.cfiSsfCombo, 6, 1)
self.layout1.addWidget(self.phichDurLabel, 7, 0)
self.layout1.addWidget(self.phichDurCombo, 7, 1)
self.layout1.addWidget(self.phichResLabel, 8, 0)
self.layout1.addWidget(self.phichResCombo, 8, 1)
self.layout1.addWidget(self.saLabel, 9, 0)
self.layout1.addWidget(self.saCombo, 9, 1)
self.layout1.addWidget(self.sspLabel, 10, 0)
self.layout1.addWidget(self.sspCombo, 10, 1)
self.layout1.addWidget(self.dsPucchLabel, 11, 0)
self.layout1.addWidget(self.dsPucchCombo, 11, 1)
self.layout1.addWidget(self.nCqiRbLabel, 12, 0)
self.layout1.addWidget(self.nCqiRbEdit, 12, 1)
self.layout1.addWidget(self.nCsAnLabel, 13, 0)
self.layout1.addWidget(self.nCsAnEdit, 13, 1)
self.layout1.addWidget(self.n1PucchAnLabel, 14, 0)
self.layout1.addWidget(self.n1PucchAnEdit, 14, 1)
self.layout1.addWidget(self.tddAckModeLabel, 15, 0)
self.layout1.addWidget(self.tddAckModeCombo, 15, 1)
self.layout1.addWidget(self.sfnLabel, 16, 0)
self.layout1.addWidget(self.sfnEdit, 16, 1)
self.layout1.addWidget(self.prachConfIndLabel, 17, 0)
self.layout1.addWidget(self.prachConfIndEdit, 17, 1)
self.layout1.addWidget(self.prachFreqOffLabel, 18, 0)
self.layout1.addWidget(self.prachFreqOffEdit, 18, 1)
self.layout1.addWidget(self.srsSfConfLabel, 19, 0)
self.layout1.addWidget(self.srsSfConfEdit, 19, 1)
self.layout2 = QHBoxLayout()
self.layout2.addStretch()
self.layout2.addWidget(self.okBtn)
self.layout2.addWidget(self.cancelBtn)
self.layout = QVBoxLayout()
self.layout.addLayout(self.layout1)
self.layout.addLayout(self.layout2)
self.setLayout(self.layout)
self.setWindowTitle('LTE Resource Grid Tool')
def initResGridMapper(self):
self.dlMap = dict()
self.dlMap[LteResType.LTE_RES_PDSCH.value] = ('PDSCH', QColor(0, 0, 0), QColor(255, 255, 255))
self.dlMap[LteResType.LTE_RES_PDCCH.value] = ('PDCCH', QColor(0, 0, 0), QColor(0, 255, 255))
self.dlMap[LteResType.LTE_RES_PHICH.value] = ('PHICH', QColor(0, 0, 0), QColor(255, 0, 255))
self.dlMap[LteResType.LTE_RES_PCFICH.value] = ('PCFICH', QColor(0, 0, 255), QColor(255, 255, 255))
self.dlMap[LteResType.LTE_RES_PBCH.value] = ('PBCH', QColor(0, 0, 0), QColor(128, 255, 255))
self.dlMap[LteResType.LTE_RES_PSCH.value] = ('PSCH', QColor(0, 0, 0), QColor(0, 255, 0))
self.dlMap[LteResType.LTE_RES_SSCH.value] = ('SSCH', QColor(0, 0, 0), QColor(255, 255, 0))
self.dlMap[LteResType.LTE_RES_CRS.value] = ('CRS', QColor(0, 0, 0), QColor(255, 0, 0))
self.dlMap[LteResType.LTE_RES_DTX.value] = ('DTX', QColor(255, 255, 255), QColor(0, 0, 0))
self.dlMap[LteResType.LTE_RES_GP.value] = ('GP', QColor(255, 255, 255), QColor(0, 0, 0))
self.dlMap[LteResType.LTE_RES_UL.value] = ('UL', QColor(255, 255, 255), QColor(0, 0, 0))
self.dlMap[LteResType.LTE_RES_NB_INBAND.value] = ('NB DL', QColor(128, 128, 128), QColor(0, 0, 0))
self.ulMap = dict()
self.ulMap[LteResType.LTE_RES_GP.value] = ('GP', QColor(0, 0, 0), QColor(0, 255, 0))
self.ulMap[LteResType.LTE_RES_DL.value] = ('DL', QColor(255, 255, 255), QColor(0, 0, 0))
self.ulMap[LteResType.LTE_RES_PUSCH.value] = ('PUSCH', QColor(0, 0, 0), QColor(255, 255, 255))
self.ulMap[LteResType.LTE_RES_PUCCH_AN.value] = ('AN', QColor(0, 0, 0), QColor(0, 255, 255))
self.ulMap[LteResType.LTE_RES_PUCCH_MIXED.value] = ('MIXED', QColor(0, 0, 0), QColor(255, 0, 255))
self.ulMap[LteResType.LTE_RES_PUCCH_CQI.value] = ('CQI', QColor(255, 255, 255), QColor(0, 0, 255))
self.ulMap[LteResType.LTE_RES_PRACH.value] = ('PRACH', QColor(0, 0, 0), QColor(128, 255, 255))
self.ulMap[LteResType.LTE_RES_DMRS.value] = ('DMRS', QColor(0, 0, 0), QColor(255, 0, 0))
self.ulMap[LteResType.LTE_RES_SRS.value] = ('SRS', QColor(0, 0, 0), QColor(255, 255, 0))
self.ulMap[LteResType.LTE_RES_NB_INBAND.value] = ('NB UL', QColor(128, 128, 128), QColor(0, 0, 0))
def parseLteGrid(self):
scPerPrb = 12
_prbs = (6, 15, 25, 50, 75, 100)
prbNum = _prbs[self.args['bw']]
outDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'output')
files = []
files.append('LTE_UL_RES_GRID.csv')
_aps = (1, 2, 4)
apNum = _aps[self.args['ap']]
for i in range(apNum):
files.append('LTE_DL_RES_GRID_AP%d.csv' % i)
for fn in files:
with open(os.path.join(outDir, fn), 'r') as f:
line = f.readline()
colLabels = line.split(',')[1:]
rowLabels = []
numRows = prbNum * scPerPrb
numCols = len(colLabels)
tab = QTableWidget()
tab.setRowCount(numRows)
tab.setColumnCount(numCols)
tab.setHorizontalHeaderLabels(colLabels)
#tab.setVerticalHeaderLabels(rowLabels)
tab.horizontalHeader().setDefaultSectionSize(8 * self.fontMetrics().width('X'))
tab.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
ire = 0
while True:
line = f.readline()
if not line:
break
tokens = line.split(',')
rowLabels.append(tokens[0])
for isym in range(numCols):
item = QTableWidgetItem()
imap = int(tokens[isym+1])
if 'UL_RES_GRID' in fn:
_str, _fg, _bg = self.ulMap[imap]
else:
_str, _fg, _bg = self.dlMap[imap]
item.setText(_str)
item.setForeground(_fg)
item.setBackground(_bg)
item.setTextAlignment(Qt.AlignCenter)
item.setFlags(item.flags() & (~Qt.ItemIsEditable));
tab.setItem(ire, isym, item);
ire = ire + 1
tab.setVerticalHeaderLabels(rowLabels)
self.ngwin.tabWidget.addTab(tab, fn)