kiss_modem: add radio chip boosted RX gain control
Add SetRxBoostedGain (0x20) / GetRxBoostedGain (0x21, reply 0xA1) and capability bit 3, the KISS equivalent of the radio.rxgain CLI setting. It is separate from FEM RX gain; a board may support either or both. - Support is declared by the driver via a new RadioLibWrapper::supportsRxBoostedGain() (SX1262, SX1268, LLCC68, LR1110, LR1121, LR2021), so nothing is written to the radio at boot. - The set is refused with TxBusy during TX or while host output is backed up. Otherwise any completed RX packet is delivered first, because some drivers (LR2021) drop to standby to apply the gain. - The reply always carries the state read back from the radio. Driver fixes found along the way, which also affect the radio.rxgain CLI in regular firmware: - CustomLR2021 never updated its cached gain state, so the getter always reported off. It now tracks the applied level per RX path and rolls RadioLib's cached level back if a write fails. - CustomLR1110/LR1121 cached the requested state even when the write failed. - lr11x0ResetAGC only reapplied the gain when RX_BOOSTED_GAIN was defined, so a runtime setting was lost on the next AGC reset.
This commit is contained in:
1 parent
0d648e4a18
commit
8cefda9612
16 files changed
+245
-16
No files matched your search
@@ -123,10 +123,12 @@ MeshCore-specific functionality uses the standard KISS SetHardware command. The
|
||||
| GetAgcResetInterval | `0x1D` | - |
|
||||
| SetFemState | `0x1E` | Apply mask (1) + Value mask (1) |
|
||||
| GetFemState | `0x1F` | - |
|
||||
| SetRxBoostedGain | `0x20` | Enable (1): 0x00=disable, nonzero=enable |
|
||||
| GetRxBoostedGain | `0x21` | - |
|
||||
|
||||
### Response Sub-commands (TNC to Host)
|
||||
|
||||
Response codes use the high-bit convention: `response = command | 0x80`. Generic and unsolicited responses use the `0xF0`+ range. Set commands that report state (SetSignalReport, SetAgcResetInterval, SetFemState) reply with the matching Get response, so `0x9C` and `0x9E` are never sent.
|
||||
Response codes use the high-bit convention: `response = command | 0x80`. Generic and unsolicited responses use the `0xF0`+ range. Set commands that report state (SetSignalReport, SetAgcResetInterval, SetFemState, SetRxBoostedGain) reply with the matching Get response, so `0x9C`, `0x9E` and `0xA0` are never sent.
|
||||
|
||||
| Sub-command | Value | Data |
|
||||
|--------------|--------|-----------------------------------------|
|
||||
@@ -155,6 +157,7 @@ Response codes use the high-bit convention: `response = command | 0x80`. Generic
|
||||
| Capabilities | `0x9B` | Feature bits (4) |
|
||||
| AgcResetInterval | `0x9D` | Effective seconds (2) |
|
||||
| FemState | `0x9F` | Capability mask (1) + Value mask (1) |
|
||||
| RxBoostedGain | `0xA1` | Status (1): 0x00=disabled, 0x01=enabled |
|
||||
| OK | `0xF0` | - |
|
||||
| Error | `0xF1` | Error code (1) |
|
||||
| TxDone | `0xF8` | Result (1): 0x00=failed, 0x01=success |
|
||||
@@ -239,6 +242,7 @@ All values little-endian. Hosts should probe capabilities rather than infer them
|
||||
| 0 | `0x01` | AGC reset interval control (always set) |
|
||||
| 1 | `0x02` | External FEM RX (LNA) gain control |
|
||||
| 2 | `0x04` | External FEM TX (PA) gain control |
|
||||
| 3 | `0x08` | Radio chip boosted RX gain control |
|
||||
|
||||
Remaining bits are reserved and sent as 0.
|
||||
|
||||
@@ -283,6 +287,16 @@ If any bit in the apply mask is not in the board's capability mask (including re
|
||||
|
||||
The setting is not persisted; the board's power-on default applies after reboot.
|
||||
|
||||
### RX Boosted Gain (SetRxBoostedGain / RxBoostedGain response)
|
||||
|
||||
Controls the radio chip's own boosted RX gain mode (SX1262, SX1268, LLCC68, LR11x0, LR2021), the equivalent of the MeshCore `radio.rxgain` setting. This is independent of the external FEM RX gain controlled by SetFemState; a board can support either, both or neither.
|
||||
|
||||
| Field | Size | Description |
|
||||
|--------|--------|------------------------------------|
|
||||
| Status | 1 byte | 0x00 = power-saving, 0x01 = boosted |
|
||||
|
||||
SetRxBoostedGain always replies with the RxBoostedGain response carrying the effective state read back from the radio; if it differs from the requested value, the change did not take effect. Some radios must drop to standby to apply it, so the modem replies `TxBusy` and changes nothing while a packet is on air or host output is backed up; retry later. Before applying, any completed received packet is delivered to the host first. A packet still being received at that moment can be lost. Radios whose driver has no boosted RX gain control (for example SX127x and STM32WLx) do not set capability bit 3 and reply `Unsupported` to both commands. The power-on default is the build's `SX126X_RX_BOOSTED_GAIN` setting; the value is not persisted, and periodic AGC resets preserve it.
|
||||
|
||||
### Stats (Stats response)
|
||||
|
||||
All values little-endian.
|
||||
|
||||
@@ -20,6 +20,9 @@ KissModem::KissModem(Stream& serial, mesh::LocalIdentity& identity, mesh::RNG& r
|
||||
_setTxPowerCallback = nullptr;
|
||||
_getCurrentRssiCallback = nullptr;
|
||||
_getStatsCallback = nullptr;
|
||||
_setRxBoostedGainCallback = nullptr;
|
||||
_getRxBoostedGainCallback = nullptr;
|
||||
_pollRxCallback = nullptr;
|
||||
_config = {0, 0, 0, 0, 0};
|
||||
_signal_report_enabled = true;
|
||||
_agc_reset_interval_sec = KISS_AGC_RESET_DEFAULT_SEC;
|
||||
@@ -422,6 +425,12 @@ void KissModem::handleHardwareCommand(uint8_t sub_cmd, const uint8_t* data, uint
|
||||
case HW_CMD_GET_FEM_STATE:
|
||||
handleGetFemState();
|
||||
break;
|
||||
case HW_CMD_SET_RX_BOOSTED_GAIN:
|
||||
handleSetRxBoostedGain(data, len);
|
||||
break;
|
||||
case HW_CMD_GET_RX_BOOSTED_GAIN:
|
||||
handleGetRxBoostedGain();
|
||||
break;
|
||||
default:
|
||||
writeHardwareError(HW_ERR_UNKNOWN_CMD);
|
||||
break;
|
||||
@@ -778,6 +787,7 @@ void KissModem::handleGetCapabilities() {
|
||||
uint32_t caps = HW_CAP_AGC_RESET;
|
||||
if (_board.canControlLoRaFemLna()) caps |= HW_CAP_FEM_RX_GAIN;
|
||||
if (_board.canControlLoRaFemPaGain()) caps |= HW_CAP_FEM_TX_GAIN;
|
||||
if (_setRxBoostedGainCallback && _getRxBoostedGainCallback) caps |= HW_CAP_RX_BOOSTED_GAIN;
|
||||
uint8_t buf[4] = { (uint8_t)caps, (uint8_t)(caps >> 8), (uint8_t)(caps >> 16), (uint8_t)(caps >> 24) };
|
||||
writeHardwareFrame(HW_RESP(HW_CMD_GET_CAPABILITIES), buf, 4);
|
||||
}
|
||||
@@ -894,3 +904,38 @@ void KissModem::handleGetFemState() {
|
||||
}
|
||||
queueFemReply(true, true);
|
||||
}
|
||||
|
||||
void KissModem::handleSetRxBoostedGain(const uint8_t* data, uint16_t len) {
|
||||
if (len < 1) {
|
||||
writeHardwareError(HW_ERR_INVALID_LENGTH);
|
||||
return;
|
||||
}
|
||||
if (!_setRxBoostedGainCallback || !_getRxBoostedGainCallback) {
|
||||
writeHardwareError(HW_ERR_UNSUPPORTED);
|
||||
return;
|
||||
}
|
||||
// some drivers (LR2021) drop to standby to apply the gain, which would abort a TX and
|
||||
// discard a completed RX packet; so never during TX, and only after draining RX
|
||||
if (_tx_state == TX_SENDING || isHostOutputBackedUp()) {
|
||||
writeHardwareError(HW_ERR_TX_BUSY);
|
||||
return;
|
||||
}
|
||||
if (_pollRxCallback) _pollRxCallback();
|
||||
tryFlushFrames();
|
||||
if (_tx_frame_count >= KISS_TX_FRAME_QUEUE_DEPTH) {
|
||||
writeHardwareError(HW_ERR_TX_BUSY); // no room left for the reply; change nothing
|
||||
return;
|
||||
}
|
||||
// always reply with the state read back, so a failed or partial write is never misreported
|
||||
_setRxBoostedGainCallback(data[0] != 0x00);
|
||||
handleGetRxBoostedGain();
|
||||
}
|
||||
|
||||
void KissModem::handleGetRxBoostedGain() {
|
||||
if (!_getRxBoostedGainCallback) {
|
||||
writeHardwareError(HW_ERR_UNSUPPORTED);
|
||||
return;
|
||||
}
|
||||
uint8_t val = _getRxBoostedGainCallback() ? 0x01 : 0x00;
|
||||
writeHardwareFrame(HW_RESP(HW_CMD_GET_RX_BOOSTED_GAIN), &val, 1);
|
||||
}
|
||||
@@ -67,6 +67,8 @@
|
||||
#define HW_CMD_GET_AGC_RESET_INTERVAL 0x1D
|
||||
#define HW_CMD_SET_FEM_STATE 0x1E
|
||||
#define HW_CMD_GET_FEM_STATE 0x1F
|
||||
#define HW_CMD_SET_RX_BOOSTED_GAIN 0x20
|
||||
#define HW_CMD_GET_RX_BOOSTED_GAIN 0x21
|
||||
|
||||
/* Response code = command code | 0x80. Generic / unsolicited use 0xF0+. */
|
||||
#define HW_RESP(cmd) ((cmd) | 0x80)
|
||||
@@ -92,6 +94,7 @@
|
||||
#define HW_CAP_AGC_RESET (1UL << 0)
|
||||
#define HW_CAP_FEM_RX_GAIN (1UL << 1)
|
||||
#define HW_CAP_FEM_TX_GAIN (1UL << 2)
|
||||
#define HW_CAP_RX_BOOSTED_GAIN (1UL << 3)
|
||||
|
||||
/* SetFemState / GetFemState mask bits */
|
||||
#define HW_FEM_RX_GAIN (1 << 0)
|
||||
@@ -107,6 +110,9 @@ typedef void (*SetRadioCallback)(float freq, float bw, uint8_t sf, uint8_t cr);
|
||||
typedef void (*SetTxPowerCallback)(uint8_t power);
|
||||
typedef float (*GetCurrentRssiCallback)();
|
||||
typedef void (*GetStatsCallback)(uint32_t* rx, uint32_t* tx, uint32_t* errors);
|
||||
typedef bool (*SetRxBoostedGainCallback)(bool enable);
|
||||
typedef bool (*GetRxBoostedGainCallback)();
|
||||
typedef void (*PollRxCallback)();
|
||||
|
||||
struct RadioConfig {
|
||||
uint32_t freq_hz;
|
||||
@@ -155,6 +161,9 @@ class KissModem {
|
||||
SetTxPowerCallback _setTxPowerCallback;
|
||||
GetCurrentRssiCallback _getCurrentRssiCallback;
|
||||
GetStatsCallback _getStatsCallback;
|
||||
SetRxBoostedGainCallback _setRxBoostedGainCallback;
|
||||
GetRxBoostedGainCallback _getRxBoostedGainCallback;
|
||||
PollRxCallback _pollRxCallback;
|
||||
|
||||
RadioConfig _config;
|
||||
bool _signal_report_enabled;
|
||||
@@ -231,6 +240,8 @@ class KissModem {
|
||||
void handleGetAgcResetInterval();
|
||||
void handleSetFemState(const uint8_t* data, uint16_t len);
|
||||
void handleGetFemState();
|
||||
void handleSetRxBoostedGain(const uint8_t* data, uint16_t len);
|
||||
void handleGetRxBoostedGain();
|
||||
|
||||
public:
|
||||
KissModem(Stream& serial, mesh::LocalIdentity& identity, mesh::RNG& rng,
|
||||
@@ -243,6 +254,13 @@ public:
|
||||
void setTxPowerCallback(SetTxPowerCallback cb) { _setTxPowerCallback = cb; }
|
||||
void setGetCurrentRssiCallback(GetCurrentRssiCallback cb) { _getCurrentRssiCallback = cb; }
|
||||
void setGetStatsCallback(GetStatsCallback cb) { _getStatsCallback = cb; }
|
||||
// Only register these when the radio supports boosted RX gain; they define the capability.
|
||||
// Delivers any completed RX packet to the host; called before settings that restart the receiver.
|
||||
void setPollRxCallback(PollRxCallback cb) { _pollRxCallback = cb; }
|
||||
void setRxBoostedGainCallbacks(SetRxBoostedGainCallback set_cb, GetRxBoostedGainCallback get_cb) {
|
||||
_setRxBoostedGainCallback = set_cb;
|
||||
_getRxBoostedGainCallback = get_cb;
|
||||
}
|
||||
|
||||
void onPacketReceived(int8_t snr, int8_t rssi, const uint8_t* packet, uint16_t len);
|
||||
bool isTxBusy() const { return _tx_state != TX_IDLE; }
|
||||
|
||||
@@ -73,6 +73,24 @@ void onGetStats(uint32_t* rx, uint32_t* tx, uint32_t* errors) {
|
||||
*errors = radio_driver.getPacketsRecvErrors();
|
||||
}
|
||||
|
||||
void pollRadioRx() {
|
||||
uint8_t rx_buf[256];
|
||||
int rx_len = radio_driver.recvRaw(rx_buf, sizeof(rx_buf));
|
||||
if (rx_len > 0) {
|
||||
int8_t snr = (int8_t)(radio_driver.getLastSNR() * 4);
|
||||
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
|
||||
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
|
||||
}
|
||||
}
|
||||
|
||||
bool onSetRxBoostedGain(bool enable) {
|
||||
return radio_driver.setRxBoostedGainMode(enable);
|
||||
}
|
||||
|
||||
bool onGetRxBoostedGain() {
|
||||
return radio_driver.getRxBoostedGainMode();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
board.begin();
|
||||
|
||||
@@ -125,6 +143,10 @@ void setup() {
|
||||
modem->setTxPowerCallback(onSetTxPower);
|
||||
modem->setGetCurrentRssiCallback(onGetCurrentRssi);
|
||||
modem->setGetStatsCallback(onGetStats);
|
||||
modem->setPollRxCallback(pollRadioRx);
|
||||
if (radio_driver.supportsRxBoostedGain()) {
|
||||
modem->setRxBoostedGainCallbacks(onSetRxBoostedGain, onGetRxBoostedGain);
|
||||
}
|
||||
modem->begin();
|
||||
|
||||
board.onBootComplete();
|
||||
@@ -134,13 +156,7 @@ void loop() {
|
||||
modem->loop();
|
||||
|
||||
if (!modem->isActuallyTransmitting() && !modem->isHostOutputBackedUp()) {
|
||||
uint8_t rx_buf[256];
|
||||
int rx_len = radio_driver.recvRaw(rx_buf, sizeof(rx_buf));
|
||||
if (rx_len > 0) {
|
||||
int8_t snr = (int8_t)(radio_driver.getLastSNR() * 4);
|
||||
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
|
||||
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
|
||||
}
|
||||
pollRadioRx();
|
||||
}
|
||||
|
||||
board.loop();
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
|
||||
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
return ((CustomLLCC68 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@ class CustomLR1110 : public LR1110 {
|
||||
float getFreqMHz() const { return freqMHz; }
|
||||
|
||||
int16_t setRxBoostedGainMode(bool en) {
|
||||
_rx_boosted = en;
|
||||
return LR1110::setRxBoostedGainMode(en);
|
||||
int16_t status = LR1110::setRxBoostedGainMode(en);
|
||||
if (status == RADIOLIB_ERR_NONE) _rx_boosted = en;
|
||||
return status;
|
||||
}
|
||||
|
||||
bool getRxBoostedGainMode() const { return _rx_boosted; }
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomLR1110 *)_radio)->getSpreadingFactor(); }
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
return ((CustomLR1110 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@ class CustomLR1121 : public LR1121 {
|
||||
float getFreqMHz() const { return freqMHz; }
|
||||
|
||||
int16_t setRxBoostedGainMode(bool en) {
|
||||
_rx_boosted = en;
|
||||
return LR1121::setRxBoostedGainMode(en);
|
||||
int16_t status = LR1121::setRxBoostedGainMode(en);
|
||||
if (status == RADIOLIB_ERR_NONE) _rx_boosted = en;
|
||||
return status;
|
||||
}
|
||||
|
||||
bool getRxBoostedGainMode() const { return _rx_boosted; }
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomLR1121 *)_radio)->getSpreadingFactor(); }
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
return ((CustomLR1121 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ class CustomLR2021 : public LR2021 {
|
||||
uint32_t _maxPayloadMillis = 3934;
|
||||
uint32_t _activityAt = 0;
|
||||
bool _headerSeen = false;
|
||||
bool _rx_boosted = false;
|
||||
// last applied gain level per RX path, mirroring RadioLib's gainModeLf/gainModeHf defaults
|
||||
uint8_t _rx_gain_lf = RADIOLIB_LR2021_RX_BOOST_LF;
|
||||
uint8_t _rx_gain_hf = RADIOLIB_LR2021_RX_BOOST_HF;
|
||||
|
||||
public:
|
||||
CustomLR2021(Module *mod) : LR2021(mod) { irqDioNum = LR2021_IRQ_DIO; }
|
||||
@@ -68,7 +70,21 @@ class CustomLR2021 : public LR2021 {
|
||||
|
||||
float getFreqMHz() const { return freqMHz; }
|
||||
|
||||
bool getRxBoostedGainMode() const { return _rx_boosted; }
|
||||
bool isHighFreqPath() const { return freqMHz > RADIOLIB_LR2021_LF_CUTOFF_FREQ; }
|
||||
|
||||
int16_t setRxBoostedGainMode(uint8_t level) {
|
||||
uint8_t& applied = isHighFreqPath() ? _rx_gain_hf : _rx_gain_lf;
|
||||
int16_t status = LR2021::setRxBoostedGainMode(level);
|
||||
if (status == RADIOLIB_ERR_NONE) {
|
||||
applied = level;
|
||||
} else {
|
||||
// RadioLib caches the level before sending it; restore it so the next startReceive keeps the old gain
|
||||
LR2021::setRxBoostedGainMode(applied);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
bool getRxBoostedGainMode() const { return (isHighFreqPath() ? _rx_gain_hf : _rx_gain_lf) != 0; }
|
||||
|
||||
int16_t startReceive() override {
|
||||
// include the PREAMBLE_DETECTED irq bit in reported flags
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomLR2021 *)_radio)->getSpreadingFactor(); }
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
((CustomLR2021 *)_radio)->standby(); // LR2021 must be in standby to accept setRxBoostedGainMode
|
||||
int16_t status = ((CustomLR2021 *)_radio)->setRxBoostedGainMode(en ? LR2021_RX_BOOST_LEVEL: 0);
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
((CustomSX1262 *)_radio)->sleep(false);
|
||||
}
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
return ((CustomSX1262 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
}
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomSX1268 *)_radio)->spreadingFactor; }
|
||||
|
||||
bool supportsRxBoostedGain() const override { return true; }
|
||||
bool setRxBoostedGainMode(bool en) override {
|
||||
return ((CustomSX1268 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ inline void lr11x0ResetAGC(LR11x0* radio, float freqMHz, bool rx_boost_gain) {
|
||||
// Re-calibrate for the actual operating frequency (band=4MHz matches RadioLib default).
|
||||
radio->calibrateImageRejection(freqMHz - 4.0f, freqMHz + 4.0f);
|
||||
|
||||
#ifdef RX_BOOSTED_GAIN
|
||||
// always reapply: the gain may have been changed at runtime even when no build default is set
|
||||
radio->setRxBoostedGainMode(rx_boost_gain);
|
||||
#endif
|
||||
}
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
|
||||
float packetScore(float snr, int packet_len) override { return packetScoreInt(snr, 10, packet_len); } // assume sf=10
|
||||
|
||||
virtual bool supportsRxBoostedGain() const { return false; }
|
||||
virtual bool setRxBoostedGainMode(bool) { return false; }
|
||||
virtual bool getRxBoostedGainMode() const { return false; }
|
||||
|
||||
|
||||
@@ -149,6 +149,29 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
bool g_rx_boost = false;
|
||||
bool g_rx_boost_set_ok = true;
|
||||
int g_rx_boost_sets = 0;
|
||||
bool fakeSetRxBoost(bool en) {
|
||||
g_rx_boost_sets++;
|
||||
if (!g_rx_boost_set_ok) return false;
|
||||
g_rx_boost = en;
|
||||
return true;
|
||||
}
|
||||
bool fakeGetRxBoost() { return g_rx_boost; }
|
||||
|
||||
KissModem* g_poll_modem = nullptr;
|
||||
bool g_poll_has_packet = false;
|
||||
int g_polls = 0;
|
||||
void fakePollRx() {
|
||||
g_polls++;
|
||||
if (g_poll_has_packet && g_poll_modem) {
|
||||
static constexpr uint8_t PKT[] = {0x55};
|
||||
g_poll_has_packet = false;
|
||||
g_poll_modem->onPacketReceived(4, -80, PKT, sizeof(PKT));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> ERR_UNSUPPORTED = {HW_RESP_ERROR, HW_ERR_UNSUPPORTED};
|
||||
|
||||
TEST_F(KissHwControlTest, VersionIsTwo) {
|
||||
@@ -342,4 +365,93 @@ TEST_F(KissHwControlTest, ImmediateFemReplySurvivesHostBackpressure) {
|
||||
EXPECT_EQ(board.lna_sets, 1);
|
||||
}
|
||||
|
||||
class KissRxBoostTest : public KissHwControlTest {
|
||||
protected:
|
||||
KissRxBoostTest() {
|
||||
g_rx_boost = true;
|
||||
g_rx_boost_set_ok = true;
|
||||
g_rx_boost_sets = 0;
|
||||
modem.setRxBoostedGainCallbacks(fakeSetRxBoost, fakeGetRxBoost);
|
||||
g_poll_modem = &modem;
|
||||
g_poll_has_packet = false;
|
||||
g_polls = 0;
|
||||
modem.setPollRxCallback(fakePollRx);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(KissHwControlTest, RxBoostedGainUnsupportedWithoutCallbacks) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), ERR_UNSUPPORTED);
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 1}), ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, CapabilityAdvertised) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_CAPABILITIES}), (std::vector<uint8_t>{0x9B, 0x09, 0x00, 0x00, 0x00}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, GetReportsCurrentState) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetRepliesWithEffectiveState) {
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{0xA1, 0x00}));
|
||||
EXPECT_FALSE(g_rx_boost);
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0x7F}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetFailureRepliesWithUnchangedState) {
|
||||
g_rx_boost_set_ok = false;
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetDuringTxIsRejectedWithoutTouchingRadio) {
|
||||
startTxAndHold();
|
||||
serial.takeHardwareFrames();
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_TX_BUSY}));
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetShortPayloadIsInvalidLength) {
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_INVALID_LENGTH}));
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, CompletedRxPacketIsDeliveredBeforeGainChange) {
|
||||
g_poll_has_packet = true;
|
||||
auto frames = hw({HW_CMD_SET_RX_BOOSTED_GAIN, 0});
|
||||
EXPECT_EQ(g_polls, 1);
|
||||
EXPECT_FALSE(g_rx_boost);
|
||||
ASSERT_EQ(frames.size(), 2U); // RxMeta for the drained packet, then the gain reply
|
||||
EXPECT_EQ(frames[0][0], HW_RESP_RX_META);
|
||||
EXPECT_EQ(frames[1], (std::vector<uint8_t>{0xA1, 0x00}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, NoRoomForReplyAfterDrainChangesNothing) {
|
||||
serial.blocked = true;
|
||||
g_poll_has_packet = true; // data + meta fill both output slots
|
||||
serial.pushRx({KISS_FEND, KISS_CMD_SETHARDWARE, HW_CMD_SET_RX_BOOSTED_GAIN, 0, KISS_FEND});
|
||||
modem.loop();
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
|
||||
serial.blocked = false;
|
||||
for (int i = 0; i < 5; i++) modem.loop();
|
||||
auto frames = serial.takeHardwareFrames();
|
||||
ASSERT_EQ(frames.size(), 2U);
|
||||
EXPECT_EQ(frames[0][0], HW_RESP_RX_META);
|
||||
EXPECT_EQ(frames[1], (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_TX_BUSY}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetWhileHostOutputBackedUpIsRejected) {
|
||||
serial.blocked = true;
|
||||
static constexpr uint8_t PKT[] = {0x01};
|
||||
modem.onPacketReceived(0, 0, PKT, sizeof(PKT));
|
||||
serial.pushRx({KISS_FEND, KISS_CMD_SETHARDWARE, HW_CMD_SET_RX_BOOSTED_GAIN, 0, KISS_FEND});
|
||||
modem.loop();
|
||||
EXPECT_EQ(g_polls, 0);
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in new issue
Block a user