Skip to content

Commit 1c6b361

Browse files
ivmarkovCopilot
andcommitted
Apply code review feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c452d1a commit 1c6b361

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

openthread/src/esp.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ impl<'a> EspRadio<'a> {
6363
pan_id: config.pan_id,
6464
short_addr: config.short_addr,
6565
ext_addr: config.ext_addr,
66+
// The default of 10 is too small for OpenThread,
67+
// which can have bursts of incoming frames, so we increase it to 50.
68+
// TODO: See if we can get by with a smaller number to save memory.
6669
rx_queue_size: 50,
6770
..Default::default()
6871
};
@@ -138,12 +141,17 @@ impl Radio for EspRadio<'_> {
138141
ack_frame.channel
139142
);
140143

141-
let rssi = ack_frame.data[1..][ack_psdu_len] as i8;
144+
// Only read RSSI if there is at least one byte after the PSDU.
145+
let rssi = if ack_frame.data.len() > 1 + ack_psdu_len {
146+
Some(ack_frame.data[1 + ack_psdu_len] as i8)
147+
} else {
148+
None
149+
};
142150

143151
return Ok(Some(PsduMeta {
144152
len: ack_psdu_len,
145153
channel: ack_frame.channel,
146-
rssi: Some(rssi),
154+
rssi,
147155
}));
148156
}
149157
}
@@ -152,7 +160,7 @@ impl Radio for EspRadio<'_> {
152160
} else {
153161
trace!("ESP Radio, transmission failed");
154162

155-
// Report as NoAck error so OpenThread SubMac retries
163+
// Report as a failure so OpenThread SubMac retries
156164
Err(RadioErrorKind::TxFailed)
157165
}
158166
}

openthread/src/radio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,13 @@ impl Config {
168168
pub const fn new() -> Self {
169169
Self {
170170
channel: 11,
171+
// Run with max power by default
172+
// TODO: Figure out how to have this specified by the user
171173
power: 20,
172174
cca: Cca::Carrier,
173175
sfd: 0,
174176
promiscuous: false,
177+
// OpenThread can have bursts of incoming frames, so we need to receive during idle state to not miss them.
175178
rx_when_idle: true,
176179
pan_id: None,
177180
short_addr: None,

0 commit comments

Comments
 (0)