Skip to content

Commit 6502067

Browse files
authored
Merge pull request #1591 from agessaman/fix-kiss-noise-floor
fix(kiss): periodic noise floor calibration and AGC reset
2 parents f7e92a7 + c0b81b9 commit 6502067

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

docs/kiss_modem_protocol.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Maximum unescaped frame size: 512 bytes.
4343
| `CMD_HASH` | `0x08` | Data to hash |
4444
| `CMD_SET_RADIO` | `0x09` | Freq (4) + BW (4) + SF (1) + CR (1) |
4545
| `CMD_SET_TX_POWER` | `0x0A` | Power dBm (1) |
46-
| `CMD_SET_SYNC_WORD` | `0x0B` | Sync word (1) |
46+
| *reserved* | `0x0B` | *(not implemented)* |
4747
| `CMD_GET_RADIO` | `0x0C` | - |
4848
| `CMD_GET_TX_POWER` | `0x0D` | - |
49-
| `CMD_GET_SYNC_WORD` | `0x0E` | - |
49+
| *reserved* | `0x0E` | *(not implemented)* |
5050
| `CMD_GET_VERSION` | `0x0F` | - |
5151
| `CMD_GET_CURRENT_RSSI` | `0x10` | - |
5252
| `CMD_IS_CHANNEL_BUSY` | `0x11` | - |
@@ -73,7 +73,7 @@ Maximum unescaped frame size: 512 bytes.
7373
| `RESP_OK` | `0x29` | - |
7474
| `RESP_RADIO` | `0x2A` | Freq (4) + BW (4) + SF (1) + CR (1) |
7575
| `RESP_TX_POWER` | `0x2B` | Power dBm (1) |
76-
| `RESP_SYNC_WORD` | `0x2C` | Sync word (1) |
76+
| *reserved* | `0x2C` | *(not implemented)* |
7777
| `RESP_VERSION` | `0x2D` | Version (1) + Reserved (1) |
7878
| `RESP_ERROR` | `0x2E` | Error code (1) |
7979
| `RESP_TX_DONE` | `0x2F` | Result (1): 0x00=failed, 0x01=success |
@@ -119,9 +119,19 @@ All values little-endian.
119119
| RSSI | 1 byte | Signal strength dBm, signed |
120120
| Packet | variable | Raw MeshCore packet |
121121

122+
### Noise Floor (RESP_NOISE_FLOOR)
123+
124+
Response to `CMD_GET_NOISE_FLOOR` (0x13). Little-endian.
125+
126+
| Field | Size | Description |
127+
|--------------|------|--------------------------------|
128+
| Noise floor | 2 | int16_t, dBm (signed), e.g. -120 |
129+
130+
The modem recalibrates the noise floor every two seconds with an AGC reset every 30 seconds.
131+
122132
### Stats (RESP_STATS)
123133

124-
All values little-endian.
134+
Response to `CMD_GET_STATS` (0x14). All values little-endian.
125135

126136
| Field | Size | Description |
127137
|-------|------|-------------|

examples/kiss_modem/main.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
#include <SPIFFS.h>
1313
#endif
1414

15+
#define NOISE_FLOOR_CALIB_INTERVAL_MS 2000
16+
#define AGC_RESET_INTERVAL_MS 30000
17+
1518
StdRNG rng;
1619
mesh::LocalIdentity identity;
1720
KissModem* modem;
21+
static uint32_t next_noise_floor_calib_ms = 0;
22+
static uint32_t next_agc_reset_ms = 0;
1823

1924
void halt() {
2025
while (1) ;
@@ -94,7 +99,14 @@ void loop() {
9499

95100
uint8_t packet[KISS_MAX_PACKET_SIZE];
96101
uint16_t len;
97-
102+
103+
// trigger noise floor calibration
104+
if ((uint32_t)(millis() - next_noise_floor_calib_ms) >= NOISE_FLOOR_CALIB_INTERVAL_MS) {
105+
radio_driver.triggerNoiseFloorCalibrate(0);
106+
next_noise_floor_calib_ms = millis();
107+
}
108+
radio_driver.loop();
109+
98110
if (modem->getPacketToSend(packet, &len)) {
99111
radio_driver.startSendRaw(packet, len);
100112
while (!radio_driver.isSendComplete()) {
@@ -104,14 +116,15 @@ void loop() {
104116
modem->onTxComplete(true);
105117
}
106118

119+
if ((uint32_t)(millis() - next_agc_reset_ms) >= AGC_RESET_INTERVAL_MS) {
120+
radio_driver.resetAGC();
121+
next_agc_reset_ms = millis();
122+
}
107123
uint8_t rx_buf[256];
108124
int rx_len = radio_driver.recvRaw(rx_buf, sizeof(rx_buf));
109-
110125
if (rx_len > 0) {
111126
int8_t snr = (int8_t)(radio_driver.getLastSNR() * 4);
112127
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
113128
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
114129
}
115-
116-
radio_driver.loop();
117130
}

variants/heltec_v3/platformio.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,12 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
367367
lib_deps =
368368
${Heltec_lora32_v3.lib_deps}
369369
${esp32_ota.lib_deps}
370+
371+
[env:Heltec_v3_kiss_modem]
372+
extends = Heltec_lora32_v3
373+
build_flags =
374+
${Heltec_lora32_v3.build_flags}
375+
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
376+
+<../examples/kiss_modem/>
377+
lib_deps =
378+
${Heltec_lora32_v3.lib_deps}

variants/rak4631/platformio.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,13 @@ build_flags =
183183
-D MESH_DEBUG=1
184184
build_src_filter = ${rak4631.build_src_filter}
185185
+<helpers/ui/SSD1306Display.cpp>
186-
+<../examples/simple_sensor>
186+
+<../examples/simple_sensor>
187+
188+
[env:RAK_4631_kiss_modem]
189+
extends = rak4631
190+
build_flags =
191+
${rak4631.build_flags}
192+
build_src_filter = ${rak4631.build_src_filter}
193+
+<../examples/kiss_modem/>
194+
lib_deps =
195+
${rak4631.lib_deps}

0 commit comments

Comments
 (0)