| 657 | // ── Commands ─────────────────────────────────────────────────────────────── |
| 658 | |
| 659 | void AntennaGeniusModel::selectAntenna(int portId, int antennaId) |
| 660 | { |
| 661 | if (!m_connected) return; |
| 662 | |
| 663 | // Prevent selecting an antenna already in use by the other port. |
| 664 | // Antenna 0 (deselect) is always allowed. |
| 665 | // ShackSwitch is a single-radio device — no port B conflict is possible. |
| 666 | const bool isShackSwitch = m_device.name.contains("ShackSwitch", Qt::CaseInsensitive); |
| 667 | if (!isShackSwitch) { |
| 668 | const auto& otherPort = (portId == 1) ? m_portB : m_portA; |
| 669 | if (antennaId > 0 && otherPort.rxAntenna == antennaId) { |
| 670 | qCDebug(lcTuner) << "AntennaGenius: antenna" << antennaName(antennaId) |
| 671 | << "already in use on port" << otherPort.portId << "— blocked"; |
| 672 | return; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | const auto& ps = (portId == 1) ? m_portA : m_portB; |
| 677 | |
| 678 | // Determine the effective band: prefer the AG device's reported band, |
| 679 | // fall back to our client-side radio-frequency-derived band. |
| 680 | int effectiveBand = ps.band; |
| 681 | if (effectiveBand <= 0 && portId == 1) |
| 682 | effectiveBand = m_lastRadioBand; |
| 683 | |
| 684 | // Always set rxant to the selected antenna. |
| 685 | // Deselect (antenna 0) clears both rxant and txant. |
| 686 | // Otherwise set txant only if the antenna has TX permission for the |
| 687 | // current band; keep the existing txant if not. |
| 688 | int txAnt = ps.txAntenna; // keep current TX antenna by default |
| 689 | if (antennaId == 0) { |
| 690 | txAnt = 0; |
| 691 | } else if (canTxOnBand(antennaId, effectiveBand)) { |
| 692 | txAnt = antennaId; |
| 693 | } else if (effectiveBand > 0) { |
| 694 | qCDebug(lcTuner) << "AntennaGenius: antenna" << antennaName(antennaId) |
| 695 | << "has no TX permission on band" << bandName(effectiveBand) |
| 696 | << "— keeping txant=" << txAnt; |
| 697 | } |
| 698 | |
| 699 | QString cmd = QString("port set %1 rxant=%2 txant=%3") |
| 700 | .arg(portId).arg(antennaId).arg(txAnt); |
| 701 | qCDebug(lcTuner) << "AntennaGenius:" << cmd; |
| 702 | sendCommand(cmd); |
| 703 | |
| 704 | // Save band→antenna mapping for the effective band on this port. |
| 705 | if (effectiveBand > 0) { |
| 706 | saveBandAntenna(portId, effectiveBand, antennaId); |
| 707 | } else { |
| 708 | qCDebug(lcTuner) << "AntennaGenius: no band known for port" << portId |
| 709 | << "— cannot save antenna mapping"; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | void AntennaGeniusModel::setAutoMode(int portId, bool on) |
| 714 | { |
no test coverage detected