mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 21:25:46 +00:00
Merge pull request #1591 from agessaman/fix-kiss-noise-floor
fix(kiss): periodic noise floor calibration and AGC reset
This commit is contained in:
@@ -43,10 +43,10 @@ Maximum unescaped frame size: 512 bytes.
|
||||
| `CMD_HASH` | `0x08` | Data to hash |
|
||||
| `CMD_SET_RADIO` | `0x09` | Freq (4) + BW (4) + SF (1) + CR (1) |
|
||||
| `CMD_SET_TX_POWER` | `0x0A` | Power dBm (1) |
|
||||
| `CMD_SET_SYNC_WORD` | `0x0B` | Sync word (1) |
|
||||
| *reserved* | `0x0B` | *(not implemented)* |
|
||||
| `CMD_GET_RADIO` | `0x0C` | - |
|
||||
| `CMD_GET_TX_POWER` | `0x0D` | - |
|
||||
| `CMD_GET_SYNC_WORD` | `0x0E` | - |
|
||||
| *reserved* | `0x0E` | *(not implemented)* |
|
||||
| `CMD_GET_VERSION` | `0x0F` | - |
|
||||
| `CMD_GET_CURRENT_RSSI` | `0x10` | - |
|
||||
| `CMD_IS_CHANNEL_BUSY` | `0x11` | - |
|
||||
@@ -73,7 +73,7 @@ Maximum unescaped frame size: 512 bytes.
|
||||
| `RESP_OK` | `0x29` | - |
|
||||
| `RESP_RADIO` | `0x2A` | Freq (4) + BW (4) + SF (1) + CR (1) |
|
||||
| `RESP_TX_POWER` | `0x2B` | Power dBm (1) |
|
||||
| `RESP_SYNC_WORD` | `0x2C` | Sync word (1) |
|
||||
| *reserved* | `0x2C` | *(not implemented)* |
|
||||
| `RESP_VERSION` | `0x2D` | Version (1) + Reserved (1) |
|
||||
| `RESP_ERROR` | `0x2E` | Error code (1) |
|
||||
| `RESP_TX_DONE` | `0x2F` | Result (1): 0x00=failed, 0x01=success |
|
||||
@@ -119,9 +119,19 @@ All values little-endian.
|
||||
| RSSI | 1 byte | Signal strength dBm, signed |
|
||||
| Packet | variable | Raw MeshCore packet |
|
||||
|
||||
### Noise Floor (RESP_NOISE_FLOOR)
|
||||
|
||||
Response to `CMD_GET_NOISE_FLOOR` (0x13). Little-endian.
|
||||
|
||||
| Field | Size | Description |
|
||||
|--------------|------|--------------------------------|
|
||||
| Noise floor | 2 | int16_t, dBm (signed), e.g. -120 |
|
||||
|
||||
The modem recalibrates the noise floor every two seconds with an AGC reset every 30 seconds.
|
||||
|
||||
### Stats (RESP_STATS)
|
||||
|
||||
All values little-endian.
|
||||
Response to `CMD_GET_STATS` (0x14). All values little-endian.
|
||||
|
||||
| Field | Size | Description |
|
||||
|-------|------|-------------|
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#define NOISE_FLOOR_CALIB_INTERVAL_MS 2000
|
||||
#define AGC_RESET_INTERVAL_MS 30000
|
||||
|
||||
StdRNG rng;
|
||||
mesh::LocalIdentity identity;
|
||||
KissModem* modem;
|
||||
static uint32_t next_noise_floor_calib_ms = 0;
|
||||
static uint32_t next_agc_reset_ms = 0;
|
||||
|
||||
void halt() {
|
||||
while (1) ;
|
||||
@@ -94,7 +99,14 @@ void loop() {
|
||||
|
||||
uint8_t packet[KISS_MAX_PACKET_SIZE];
|
||||
uint16_t len;
|
||||
|
||||
|
||||
// trigger noise floor calibration
|
||||
if ((uint32_t)(millis() - next_noise_floor_calib_ms) >= NOISE_FLOOR_CALIB_INTERVAL_MS) {
|
||||
radio_driver.triggerNoiseFloorCalibrate(0);
|
||||
next_noise_floor_calib_ms = millis();
|
||||
}
|
||||
radio_driver.loop();
|
||||
|
||||
if (modem->getPacketToSend(packet, &len)) {
|
||||
radio_driver.startSendRaw(packet, len);
|
||||
while (!radio_driver.isSendComplete()) {
|
||||
@@ -104,14 +116,15 @@ void loop() {
|
||||
modem->onTxComplete(true);
|
||||
}
|
||||
|
||||
if ((uint32_t)(millis() - next_agc_reset_ms) >= AGC_RESET_INTERVAL_MS) {
|
||||
radio_driver.resetAGC();
|
||||
next_agc_reset_ms = millis();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
radio_driver.loop();
|
||||
}
|
||||
|
||||
@@ -367,3 +367,12 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
|
||||
lib_deps =
|
||||
${Heltec_lora32_v3.lib_deps}
|
||||
${esp32_ota.lib_deps}
|
||||
|
||||
[env:Heltec_v3_kiss_modem]
|
||||
extends = Heltec_lora32_v3
|
||||
build_flags =
|
||||
${Heltec_lora32_v3.build_flags}
|
||||
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
|
||||
+<../examples/kiss_modem/>
|
||||
lib_deps =
|
||||
${Heltec_lora32_v3.lib_deps}
|
||||
@@ -183,4 +183,13 @@ build_flags =
|
||||
-D MESH_DEBUG=1
|
||||
build_src_filter = ${rak4631.build_src_filter}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<../examples/simple_sensor>
|
||||
+<../examples/simple_sensor>
|
||||
|
||||
[env:RAK_4631_kiss_modem]
|
||||
extends = rak4631
|
||||
build_flags =
|
||||
${rak4631.build_flags}
|
||||
build_src_filter = ${rak4631.build_src_filter}
|
||||
+<../examples/kiss_modem/>
|
||||
lib_deps =
|
||||
${rak4631.lib_deps}
|
||||
Reference in New Issue
Block a user