From 985939ea80912726d0f418f8ee6bea29f7c6a7c3 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Thu, 9 Dec 2021 22:13:50 -0800 Subject: [PATCH] add get packet RSSI and current RSSI --- include/esp32-lora.h | 4 +++- main/esp32-lora.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/esp32-lora.h b/include/esp32-lora.h index d281cd9..a270de6 100644 --- a/include/esp32-lora.h +++ b/include/esp32-lora.h @@ -23,7 +23,7 @@ #define REG_IRQ_FLAGS 0x12 #define REG_RX_NB_BYTES 0x13 #define REG_PKT_RSSI_VALUE 0x1a -#define REG_PKT_SNR_VALUE 0x1b +#define REG_RSSI_VALUE 0x1b #define REG_MODEM_CONFIG_1 0x1d #define REG_MODEM_CONFIG_2 0x1e #define REG_PREAMBLE_MSB 0x20 @@ -142,6 +142,8 @@ typedef struct lora32_cfg_t { uint8_t lora32_spi_init(lora32_cfg_t *config); uint8_t lora32_init(lora32_cfg_t *config); uint8_t lora32_data_available(lora32_cfg_t *lora); +int16_t lora32_get_packet_rssi(lora32_cfg_t *lora); +int16_t lora32_get_rssi(lora32_cfg_t *lora); double lora32_calc_datarate(lora32_cfg_t *lora); void lora32_dump_regs(lora32_cfg_t *lora); diff --git a/main/esp32-lora.c b/main/esp32-lora.c index c7737e8..3da7c7e 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -298,6 +298,16 @@ void lora32_enable_cad(lora32_cfg_t *lora) { lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD_DETECT); } +int16_t lora32_get_rssi(lora32_cfg_t *lora) { + // TODO support LF output constant of -164 + return -157 + lora32_read_reg(lora, REG_RSSI_VALUE); +} + +int16_t lora32_get_packet_rssi(lora32_cfg_t *lora) { + // TODO support LF output constant of -164 + return -157 + lora32_read_reg(lora, REG_PKT_RSSI_VALUE); +} + long lora32_get_bandwidth(lora32_cfg_t *lora) { uint8_t bw = (lora32_read_reg(lora, REG_MODEM_CONFIG_1) >> 4); ESP_LOGI(TAG, "lora32_get_bandwidth: %d", bw);