Skip to content

Commit

Permalink
socket_zep: simulate RSSI
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Aug 8, 2023
1 parent 2b4db0f commit 78857f1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cpu/native/socket_zep/socket_zep.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "net/ieee802154/radio.h"
#include "socket_zep.h"
#include "random.h"

#define ENABLE_DEBUG 0
#include "debug.h"
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 78857f1

Please sign in to comment.