Skip to content

Commit b119e5e

Browse files
Szynkaarlubos
authored andcommitted
samples: esb: Fix not reading all payloads
Make esb_prx and esb_monitor samples read all received payloads in esb event handler Signed-off-by: Szymon Antkowiak <[email protected]>
1 parent 3145152 commit b119e5e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

samples/esb/esb_monitor/src/main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,20 @@ void event_handler(struct esb_evt const *event)
9191
switch (event->evt_id) {
9292
case ESB_EVENT_RX_RECEIVED:
9393
#if defined(CONFIG_ESB_SNIFFER)
94-
if (esb_read_rx_payload(&packet.payload) == 0) {
94+
struct esb_payload *payload = &packet.payload;
9595
#else
96-
if (esb_read_rx_payload(&rx_payload) == 0) {
96+
struct esb_payload *payload = &rx_payload;
9797
#endif /* !defined(CONFIG_ESB_SNIFFER) */
98+
int err;
99+
100+
while ((err = esb_read_rx_payload(payload)) == 0) {
98101
log_packet();
99102

100103
#if defined(CONFIG_LED_ENABLE) && !defined(CONFIG_ESB_SNIFFER)
101104
leds_update(rx_payload.data[1]);
102105
#endif /* defined(CONFIG_LED_ENABLE) && !defined(CONFIG_ESB_SNIFFER) */
103-
} else {
106+
}
107+
if (err && err != -ENODATA) {
104108
LOG_ERR("Error while reading rx packet");
105109
}
106110
break;

samples/esb/esb_prx/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void event_handler(struct esb_evt const *event)
5454
LOG_DBG("TX FAILED EVENT");
5555
break;
5656
case ESB_EVENT_RX_RECEIVED:
57-
if (esb_read_rx_payload(&rx_payload) == 0) {
57+
int err;
58+
59+
while ((err = esb_read_rx_payload(&rx_payload)) == 0) {
5860
LOG_DBG("Packet received, len %d : "
5961
"0x%02x, 0x%02x, 0x%02x, 0x%02x, "
6062
"0x%02x, 0x%02x, 0x%02x, 0x%02x",
@@ -65,7 +67,8 @@ void event_handler(struct esb_evt const *event)
6567
rx_payload.data[7]);
6668

6769
leds_update(rx_payload.data[1]);
68-
} else {
70+
}
71+
if (err && err != -ENODATA) {
6972
LOG_ERR("Error while reading rx packet");
7073
}
7174
break;

0 commit comments

Comments
 (0)