-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarrierrow4g.cpp
More file actions
533 lines (453 loc) · 19.8 KB
/
Copy pathcarrierrow4g.cpp
File metadata and controls
533 lines (453 loc) · 19.8 KB
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
#include "carrierrow4g.h"
#include "ui_carrierrow4g.h"
#include "appconfig.h"
#include <QJsonArray>
CarrierRow4G::CarrierRow4G(int carrierId, bool isPrimary, QWidget *parent) :
QWidget(parent),
ui(new Ui::CarrierRow4G),
m_carrierId(carrierId),
m_isPrimary(isPrimary)
{
ui->setupUi(this);
populateBands();
populateSelectors();
setupInitialState();
connectSignals();
}
CarrierRow4G::~CarrierRow4G()
{
delete ui;
}
int CarrierRow4G::id() const
{
return m_carrierId;
}
void CarrierRow4G::setId(int newId)
{
m_carrierId = newId;
}
void CarrierRow4G::updateTitle(const QString &newTitle)
{
ui->headerButton->setText(newTitle);
}
void CarrierRow4G::onHeaderClicked()
{
ui->contentWidget->setVisible(!ui->contentWidget->isVisible());
}
void CarrierRow4G::onRemoveClicked()
{
emit removeClicked(m_carrierId);
}
void CarrierRow4G::onUplinkAggClicked()
{
m_isUplinkAggregated = !m_isUplinkAggregated;
ui->uplinkAggButton->setText(m_isUplinkAggregated ? "Deaggregate Uplink" : "Aggregate Uplink");
emit uplinkAggClicked(m_carrierId);
}
void CarrierRow4G::setupInitialState()
{
updateTitle(QString("Carrier #%1 - Select a band").arg(m_carrierId + 1));
ui->removeButton->setVisible(!m_isPrimary);
ui->uplinkAggButton->setVisible(!m_isPrimary);
ui->contentWidget->setVisible(m_isPrimary); // Show first carrier by default
reset4GSelectors();
ui->mimoNoteLabel->setVisible(false);
}
void CarrierRow4G::populateBands()
{
const auto& lteBands = AppConfig::instance().lteBandData;
QList<int> bandKeys;
for(auto it = lteBands.constBegin(); it != lteBands.constEnd(); ++it) {
bandKeys.append(it.key().toInt());
}
std::sort(bandKeys.begin(), bandKeys.end());
QVariantMap bandMap;
for (int key : bandKeys) {
QString bandNum = QString::number(key);
QJsonObject data = lteBands[bandNum].toObject();
if (data.contains("frequency")) {
QString text = QString("Band %1 | %2 (%3MHz)")
.arg(bandNum)
.arg(data["type"].toString())
.arg(data["frequency"].toString());
bandMap.insert(text, bandNum);
}
}
populateGenericSelector(ui->bandComboBox, bandMap, QVariant(), "Select a band", "0");
}
void CarrierRow4G::populateSelectors()
{
// For data direction (SDL/SUL)
populateGenericSelector(ui->lbandDirComboBox, { {"Downlink (SDL)", 0},
{"Uplink (SUL)", 1} });
// For TDD Cyclic Prefix Length
populateGenericSelector(ui->tddCplComboBox, { {"Normal CP [6]", "normal"},
{"Extended CP [7]", "extended"} });
// For TDD Configuration
QVariantMap tddCnfMap;
for (int i = 0; i <= 6; ++i) {
tddCnfMap.insert(QString("TDD Config %1").arg(i), i);
}
populateGenericSelector(ui->tddCnfComboBox, tddCnfMap);
// For TDD Special Subframe Configuration
QVariantMap tddSsfMap;
for (int i = 0; i <= 8; ++i) {
tddSsfMap.insert(QString("Special Config %1").arg(i), i);
}
populateGenericSelector(ui->tddSsfComboBox, tddSsfMap);
}
void CarrierRow4G::connectSignals()
{
connect(ui->headerButton, &QPushButton::clicked, this, &CarrierRow4G::onHeaderClicked);
connect(ui->removeButton, &QPushButton::clicked, this, &CarrierRow4G::onRemoveClicked);
connect(ui->uplinkAggButton, &QPushButton::clicked, this, &CarrierRow4G::onUplinkAggClicked);
connect(ui->earfcnLineEdit, &QLineEdit::editingFinished, this, &CarrierRow4G::onEarfcnUpdated);
connect(ui->rbLineEdit, &QLineEdit::editingFinished, this, &CarrierRow4G::onRbUpdated);
connect(ui->bandComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::onBandChanged);
connect(ui->widthComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::onWidthChanged);
connect(ui->lbandDirComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::onLbandDirChanged);
connect(ui->dlModComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
connect(ui->ulModComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
connect(ui->mimoComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
connect(ui->tddCplComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
connect(ui->tddCnfComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
connect(ui->tddSsfComboBox, QOverload<int>::of(&QComboBox::activated), this, &CarrierRow4G::dataChanged);
}
void CarrierRow4G::onBandChanged(int index)
{
QString band = ui->bandComboBox->itemData(index).toString();
if (band == "0") {
reset4GSelectors();
setCarrierTitle("0", {});
} else {
populateSelectorsForBand(band);
handleBandOptions(band);
}
emit dataChanged();
}
void CarrierRow4G::onEarfcnUpdated()
{
QString earfcnStr = ui->earfcnLineEdit->text();
if (earfcnStr.isEmpty()) return;
int earfcn = earfcnStr.toInt();
QString foundBand = "0";
const auto& lteBands = AppConfig::instance().lteBandData;
for(auto it = lteBands.constBegin(); it != lteBands.constEnd(); ++it) {
QJsonObject bandData = it.value().toObject();
QJsonArray earfcnRange = bandData["earfcn"].toArray();
if (earfcn >= earfcnRange[0].toInt() && earfcn <= earfcnRange[1].toInt()) {
foundBand = it.key();
break;
}
}
int index = ui->bandComboBox->findData(foundBand);
if (index != -1) {
ui->bandComboBox->setCurrentIndex(index);
}
}
void CarrierRow4G::reset4GSelectors()
{
QList<QComboBox*> selectors = {ui->widthComboBox, ui->dlModComboBox, ui->ulModComboBox, ui->mimoComboBox};
for(QComboBox* cb : selectors) {
cb->blockSignals(true);
cb->clear();
cb->addItem("Select a band first");
cb->blockSignals(false);
}
ui->extraOptionsStack->setCurrentWidget(ui->page_empty);
ui->uplinkAggButton->setVisible(!m_isPrimary);
}
void CarrierRow4G::populateSelectorsForBand(const QString &band)
{
const auto& bandData = AppConfig::instance().lteBandData[band].toObject();
QJsonArray bandwidths = bandData["bandwidths"].toArray();
// Width Selector
QVariantMap widthMap;
ui->widthComboBox->blockSignals(true);
ui->widthComboBox->clear();
for (const QJsonValue& bwValue : bandwidths) {
double bw = bwValue.toDouble();
// ( Bandwidth (Hz) - Guard % of Bandwidth (Hz) ) / Resource block size in frequency domain (Hz)
double guard = (bw == 1.4) ? 0.23 : 0.1;
int rbs = qRound((bw * 1000 * (1 - guard)) / 180.0);
QVariantMap userData;
userData["rbs"] = rbs;
QString text = QString("%1MHz (%2 RBs)").arg(bw).arg(rbs);
ui->widthComboBox->addItem(text, QVariant(userData));
}
if (ui->widthComboBox->count() > 0) {
ui->widthComboBox->setCurrentIndex(ui->widthComboBox->count() - 1);
}
ui->widthComboBox->blockSignals(false);
// Modulation and MIMO Selectors
const QVariantMap modMap = {
{"QPSK", 0}, {"16QAM", 1}, {"64QAM", 2}, {"256QAM", 3}
};
populateGenericSelector(ui->dlModComboBox, modMap, 2); // Default 64QAM
populateGenericSelector(ui->ulModComboBox, modMap, 1); // Default 16QAM
const QVariantMap mimoMap = {
{"1x1 SiSo", 0}, {"2x2 MiMo", 1}, {"4x4 MiMo", 2}
};
populateGenericSelector(ui->mimoComboBox, mimoMap, 1); // Default 2x2
// Trigger width change to set RB
onWidthChanged();
}
void CarrierRow4G::handleBandOptions(const QString &band)
{
// Reset UI visibility to default (FDD/TDD) state ---
ui->dlModComboBox->setVisible(true);
ui->label_dlMod->setVisible(true);
ui->ulModComboBox->setVisible(true);
ui->label_ulMod->setVisible(true);
ui->mimoComboBox->setVisible(true);
ui->label_mimo->setVisible(true);
ui->mimoNoteLabel->setVisible(false); // Hide the SUL-specific note
const auto& bandData = AppConfig::instance().lteBandData[band].toObject();
QString type = bandData["type"].toString();
ui->uplinkAggButton->setVisible(type != "SDL");
if (type == "TDD") {
ui->extraOptionsStack->setCurrentWidget(ui->page_tdd);
} else if (type == "SDL") {
ui->extraOptionsStack->setCurrentWidget(ui->page_sdl);
onLbandDirChanged(); // Trigger initial UI state
} else { // FDD
ui->extraOptionsStack->setCurrentWidget(ui->page_fdd);
}
}
void CarrierRow4G::onWidthChanged()
{
QVariantMap userData = ui->widthComboBox->currentData().toMap();
if (userData.contains("rbs")) {
ui->rbLineEdit->setText(QString::number(userData["rbs"].toInt()));
}
ui->widthComboBox->setStyleSheet("");
emit dataChanged();
}
void CarrierRow4G::onRbUpdated()
{
if (!ui->rbLineEdit->text().isEmpty()) {
ui->widthComboBox->setStyleSheet("opacity: 0.5;");
}
emit dataChanged();
}
bool CarrierRow4G::isSUL() const
{
QString currentBand = ui->bandComboBox->currentData().toString();
if (currentBand == "0") {
return false;
}
const auto& bandData = AppConfig::instance().lteBandData[currentBand].toObject();
if (bandData["type"].toString() != "SDL") {
return false;
}
return (ui->lbandDirComboBox->currentData().toInt() == 1);
}
void CarrierRow4G::onLbandDirChanged()
{
bool isSul = (ui->lbandDirComboBox->currentData().toInt() == 1);
ui->dlModComboBox->setVisible(!isSul);
ui->label_dlMod->setVisible(!isSul);
ui->mimoComboBox->setVisible(!isSul);
ui->label_mimo->setVisible(!isSul);
ui->ulModComboBox->setVisible(isSul);
ui->label_ulMod->setVisible(isSul);
ui->mimoNoteLabel->setVisible(isSul);
emit dataChanged();
}
void CarrierRow4G::setCarrierTitle(const QString &band, const Calc4GResult& result)
{
if (band == "0" || band.isEmpty()) {
updateTitle(QString("Carrier #%1 - Select a band").arg(m_carrierId + 1));
return;
}
const auto& bandData = AppConfig::instance().lteBandData[band].toObject();
QString widthText = ui->widthComboBox->currentText().split(" ").first();
int rbCount = getRbsForCarrier();
QString stext;
if (result.downlink > 0) {
stext += QString("%1Mbps ↓").arg(round2(result.downlink));
if (result.uplink > 0) stext += " && "; // Button text needs '&&' escape to be distinguished from shortcut key
}
if (result.uplink > 0) {
stext += QString("%1Mbps ↑").arg(round2(result.uplink));
}
QString freqInf = QString("Band b%1: %2MHz, ").arg(band).arg(bandData["frequency"].toString());
QJsonArray range = bandData["range"].toArray();
freqInf += (range.size() == 2)
? QString("Uplink: %1MHz, Downlink: %2MHz").arg(range[0].toString()).arg(range[1].toString())
: QString("Range: %1MHz").arg(range[0].toString());
QString titleText = QString("Carrier #%1: %2 (%3 RBs), %4\n%5")
.arg(m_carrierId + 1)
.arg(widthText)
.arg(rbCount)
.arg(stext)
.arg(freqInf);
updateTitle(titleText);
}
double CarrierRow4G::getRbsForCarrier() const {
return ui->rbLineEdit->text().toDouble();
}
void CarrierRow4G::populateGenericSelector(QComboBox* comboBox, const QVariantMap& data,
const QVariant& selectedValue,
const QString& placeholderText,
const QVariant& placeholderData)
{
comboBox->blockSignals(true);
comboBox->clear();
if (!placeholderText.isNull()) {
comboBox->addItem(placeholderText, placeholderData);
}
for (auto it = data.constBegin(); it != data.constEnd(); ++it) {
comboBox->addItem(it.key(), it.value());
}
if (selectedValue.isValid()) {
int index = comboBox->findData(selectedValue);
if (index != -1) {
comboBox->setCurrentIndex(index);
}
}
comboBox->blockSignals(false);
}
Calc4GResult CarrierRow4G::calculate() {
Calc4GResult res;
QString band = ui->bandComboBox->currentData().toString();
if (band == "0") {
res.hasUnselectedBands = true;
setCarrierTitle("0", {});
return res;
} else res.hasUnselectedBands = false;
int selDlMod = ui->dlModComboBox->currentData().toInt();
int selUlMod = ui->ulModComboBox->currentData().toInt();
int selMimo = ui->mimoComboBox->currentData().toInt();
const auto& bandData = AppConfig::instance().lteBandData[band].toObject();
QString type = bandData["type"].toString();
if (type == "TDD") {
QString selTddCpl = ui->tddCplComboBox->currentData().toString();
int selTddCnf = ui->tddCnfComboBox->currentData().toInt();
int selTddFrm = ui->tddSsfComboBox->currentData().toInt();
res.downlink = calcTdd(selDlMod, selMimo, selTddCnf, selTddCpl, selTddFrm, "D");
res.uplink = calcTdd(selUlMod, 0, selTddCnf, selTddCpl, selTddFrm, "U");
} else if (type == "FDD") {
res.downlink = calcFdd(selDlMod, selMimo);
res.uplink = calcFdd(selUlMod, 0);
} else if (type == "SDL") {
int selLBDir = ui->lbandDirComboBox->currentData().toInt();
if (selLBDir == 0) { // Downlink
res.downlink = calcFdd(selDlMod, selMimo);
} else { // Uplink
res.uplink = calcFdd(selUlMod, 0);
}
}
setCarrierTitle(band, res);
return res;
}
/**
* @brief Calculates the theoretical throughput for an LTE TDD (Time Division Duplex) carrier.
* @note This calculation appears to be a custom model that reverse-engineers the throughput from key TDD parameters.
* It correctly calculates the total number of available symbols in a radio frame and then derives the data rate.
* @param selModulation The selected modulation index (0-3 for QPSK-256QAM).
* @param selMimo The selected MIMO layers index (0-2 for 1x1-4x4).
* @param selTddCnf The selected TDD UL/DL Configuration (0-6).
* @param selTddCpl The selected Cyclic Prefix Length ("normal" or "extended").
* @param selTddFrm The selected Special Subframe Configuration (0-8).
* @param link The direction of calculation, "D" for Downlink or "U" for Uplink.
* @return The calculated theoretical throughput in Mbps.
*/
double CarrierRow4G::calcTdd(int selModulation, int selMimo, int selTddCnf, const QString& selTddCpl, int selTddFrm, const QString& link)
{
// --- Constants for LTE TDD Calculation ---
// Modulation order (Q_m), bits per symbol. {QPSK, 16QAM, 64QAM, 256QAM}.
const double tddmod[] = {2, 4, 6, 8};
// MIMO multiplier for spatial multiplexing. {1x1 SISO, 2x2 MIMO, 4x4 MIMO}.
const double mimo[] = {1, 2, 4};
// Maps Cyclic Prefix type to the number of OFDM symbols per slot.
const QMap<QString, int> tcpl = {{"normal", 7}, {"extended", 6}};
// Number of subcarriers per Resource Block (RB). Standard for LTE.
const int tscprb = 12;
// Duration of a single LTE slot in seconds (0.5 ms).
const double defaultTddBase = 0.0005;
/**
* @brief Maps TDD UL/DL Configuration index to the number of subframes in a 10ms radio frame.
* Based on 3GPP TS 36.211, Table 4.2-2.
* The format is { Downlink subframes, Special subframes, Uplink subframes }.
*/
const QJsonObject tconfData = {
{"0", QJsonArray{2, 2, 6}}, {"1", QJsonArray{4, 2, 4}},
{"2", QJsonArray{6, 2, 2}}, {"3", QJsonArray{6, 1, 3}},
{"4", QJsonArray{7, 1, 2}}, {"5", QJsonArray{8, 1, 1}},
{"6", QJsonArray{3, 2, 5}}
};
// --- Step 1: Calculate total available symbols in a 10ms radio frame for the given link direction ---
// Get number of symbols per slot (7 for normal CP, 6 for extended CP).
int symps = tcpl.value(selTddCpl);
// Calculate number of symbols per subframe (1ms). Since a subframe has 2 slots, this is `symps * 2`.
// The formula `symps / 0.0005 / 1000` is a convoluted way of writing `symps * 2`.
double sympsfo = symps / defaultTddBase / 1000.0;
// Determine the array index for accessing subframe counts (0 for Downlink 'D', 2 for Uplink 'U').
int linkoff = (link == "D" ? 0 : 2);
// --- Contribution from REGULAR (Downlink or Uplink) subframes ---
QJsonArray tddsconf = tconfData[QString::number(selTddCnf)].toArray();
// Get the number of regular D or U subframes in a 10ms frame.
double frames = tddsconf[linkoff].toDouble();
// Calculate total symbols from these regular subframes.
double sect1t = frames * sympsfo;
// --- Contribution from SPECIAL subframes ---
const auto& ssubConf = AppConfig::instance().lteSsubConf;
// Get the [DL symbols, GP symbols, UL symbols] array for the selected Special Subframe Configuration.
QJsonArray ssubsconf = ssubConf[selTddCpl].toObject()[QString::number(selTddFrm)].toArray();
// Get the number of D or U symbols within ONE special subframe.
double sframes = ssubsconf[linkoff].toDouble();
// Calculate total symbols contributed by all special subframes in the 10ms frame.
double sect2t = sframes * tddsconf[1].toDouble();
// Total number of available symbols for the link direction in a 10ms radio frame.
double totalc = sect1t + sect2t;
// --- Step 2: Calculate throughput based on total symbols and other parameters ---
/**
* @brief The final formula is derived as follows:
* 1. Total symbols per second = `totalc` (symbols per 10ms) * 100 (10ms frames in 1s).
* 2. Total bits per second per subcarrier = (Total symbols per second) * (bits per symbol).
* 3. Total bits per second = (bits per second per subcarrier) * (total subcarriers).
* Total subcarriers = (Number of RBs) * 12.
* 4. Apply MIMO multiplier.
* 5. Convert from bps to Mbps by dividing by 1,000,000.
*
* Simplified Formula:
* Mbps = (RBs * 12 * totalc * bits_per_symbol * MIMO) / 10000
*
* The code breaks this down into several confusingly named intermediate steps.
*/
// `dltpsc` is an intermediate value: (bits per second per subcarrier) / 1000 -> kbps per subcarrier.
double dltpsc = (totalc * 100.0 * tddmod[selModulation] / 1000.0);
// `scprb_val` is another intermediate value. Note: the comment "Sub carriers per RB" is incorrect.
// It should be throughput per RB in some unit.
double scprb_val = dltpsc * (tscprb / 1000.0);
// `tpea`: Total throughput before MIMO, combining all RBs.
double tpea = getRbsForCarrier() * scprb_val;
// `atm`: Total throughput after applying the MIMO multiplier. This is the peak theoretical rate in Mbps.
double atm = tpea * mimo[selMimo];
// --- Step 3: Apply overhead reduction ---
// A common rule of thumb for LTE is to reduce peak throughput by ~25% to account for signaling overhead
// from control channels like PDCCH, PHICH, PCFICH, and reference signals.
double ctrl = atm * 0.25;
return atm - ctrl;
}
/**
* @brief Calculates the theoretical throughput for an LTE FDD (Frequency Division Duplex) carrier.
* @note This function uses a simplified empirical formula, not a detailed 3GPP-based calculation.
* It provides a reasonable estimate based on key input parameters.
* The formula is essentially: Throughput (Mbps) ≈ 0.5 * RBs * Modulation_Factor * MIMO_Layers
* @param selMod The selected modulation index (0-3).
* @param selMimo The selected MIMO layers index (0-2).
* @return The calculated theoretical throughput in Mbps.
*/
double CarrierRow4G::calcFdd(int selMod, int selMimo)
{
// An empirical base value for the simplified formula.
const double base = 0.5;
// Empirical multipliers for each modulation scheme.
// Corresponds to {QPSK, 16QAM, 64QAM, 256QAM}.
const double mod[] = {0.5, 1, 1.5, 1.958};
// Standard MIMO layer multipliers. {1 layer (SISO), 2 layers, 4 layers}.
const double mimo[] = {1, 2, 4};
return base * getRbsForCarrier() * mod[selMod] * mimo[selMimo];
}