From 78857f123d05e6fb7894b69f693af62145969980 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 14 Feb 2023 11:14:03 +0100 Subject: [PATCH] socket_zep: simulate RSSI --- cpu/native/socket_zep/socket_zep.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cpu/native/socket_zep/socket_zep.c b/cpu/native/socket_zep/socket_zep.c index 280a541a91bf..75ea96bf2173 100644 --- a/cpu/native/socket_zep/socket_zep.c +++ b/cpu/native/socket_zep/socket_zep.c @@ -32,6 +32,7 @@ #include "net/ieee802154/radio.h" #include "socket_zep.h" +#include "random.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -47,6 +48,26 @@ /* dummy packet to register with ZEP dispatcher */ #define SOCKET_ZEP_V2_TYPE_HELLO (255) +/* simulate RSSI by calculating error function of LQI */ +static const uint8_t lqi_to_rssi[256] = { + 74, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, + 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, + 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 83, + 83, 83, 83, 83, 83, 84, 84, 84, 84, 85, 85, 85, 85, 85, 86, 86, + 86, 86, 87, 87, 87, 87, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, + 90, 91, 91, 91, 92, 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 95, + 96, 96, 96, 97, 97, 97, 98, 98, 98, 99, 99, 100, 100, 100, 101, 101, + 102, 102, 102, 103, 103, 104, 104, 104, 105, 105, 106, 106, 107, 107, 107, 108, + 108, 109, 109, 110, 110, 111, 111, 112, 112, 112, 113, 113, 114, 114, 115, 115, + 116, 116, 117, 117, 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 123, 123, + 124, 124, 125, 125, 126, 126, 127, 127, 128, 128, 129, 129, 130, 130, 131, 131, + 132, 132, 133, 133, 134, 135, 135, 136, 136, 137, 137, 138, 138, 139, 139, 140, + 140, 141, 141, 142, 142, 143, 143, 144, 144, 145, 145, 146, 146, 147, 147, 148, +}; + static size_t _zep_hdr_fill_v2_data(socket_zep_t *dev, zep_v2_data_hdr_t *hdr, size_t payload_len) { @@ -581,7 +602,8 @@ static int _read(ieee802154_dev_t *dev, void *buf, size_t max_size, if (info) { info->lqi = zep->lqi_val; - info->rssi = -IEEE802154_RADIO_RSSI_OFFSET; + info->rssi = lqi_to_rssi[zep->lqi_val] + + ((random_uint32() & 0x3) - 2); } memcpy(buf, zep + 1, zep->length - 2);