From c95ebb63b4c42a09ab7e6357f6799fbea662054d Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 31 Mar 2020 07:29:01 +0200 Subject: [PATCH] sys/net: add NETOPT_RSSI for wireless channels --- sys/include/net/netopt.h | 11 +++++++++++ sys/net/crosslayer/netopt/netopt.c | 1 + sys/shell/commands/sc_gnrc_netif.c | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index 0962f1d194..b3644029d3 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -729,6 +729,17 @@ typedef enum { */ NETOPT_LINK_CHECK, + /** + * @brief (int8_t) Received Signal Strength Indicator (RSSI) + * + * The RSSI is an indicator for the received field strength in wireless + * channels. It is often represented as the ratio of received power to + * a given unit, for example milliwatts. With a device-dependent scaling + * factor, the RSSI value can be expressed as power level in the unit + * dBm or ASU (Arbitrary Strength Unit). + */ + NETOPT_RSSI, + /** * @brief maximum number of options defined here. * diff --git a/sys/net/crosslayer/netopt/netopt.c b/sys/net/crosslayer/netopt/netopt.c index 99b9eed605..d2ef4e9a9c 100644 --- a/sys/net/crosslayer/netopt/netopt.c +++ b/sys/net/crosslayer/netopt/netopt.c @@ -120,6 +120,7 @@ static const char *_netopt_strmap[] = { [NETOPT_DEMOD_MARGIN] = "NETOPT_DEMOD_MARGIN", [NETOPT_NUM_GATEWAYS] = "NETOPT_NUM_GATEWAYS", [NETOPT_LINK_CHECK] = "NETOPT_LINK_CHECK", + [NETOPT_RSSI] = "NETOPT_RSSI", [NETOPT_NUMOF] = "NETOPT_NUMOF", }; diff --git a/sys/shell/commands/sc_gnrc_netif.c b/sys/shell/commands/sc_gnrc_netif.c index 32e14025f9..01be524b98 100644 --- a/sys/shell/commands/sc_gnrc_netif.c +++ b/sys/shell/commands/sc_gnrc_netif.c @@ -531,6 +531,7 @@ static void _netif_list(netif_t *iface) uint16_t u16; int16_t i16; uint8_t u8; + int8_t i8; int res; netopt_state_t state; unsigned line_thresh = 1; @@ -561,6 +562,10 @@ static void _netif_list(netif_t *iface) if (res >= 0) { printf(" NID: 0x%" PRIx16 " ", u16); } + res = netif_get_opt(iface, NETOPT_RSSI, 0, &i8, sizeof(i8)); + if (res >= 0) { + printf(" RSSI: %d ", i8); + } #ifdef MODULE_GNRC_NETIF_CMD_LORA res = netif_get_opt(iface, NETOPT_BANDWIDTH, 0, &u8, sizeof(u8)); if (res >= 0) {