Skip to content

Commit 34aa554

Browse files
authored
Merge pull request #72 from Jim-Hodapp-Coaching/more_robust_wait_response_cmd
More robust handling of responses from NINA-FW
2 parents 529e4f8 + fa7cab9 commit 34aa554

File tree

8 files changed

+407
-162
lines changed

8 files changed

+407
-162
lines changed

cross/send_data_tcp/src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ fn main() -> ! {
171171
mode,
172172
&mut delay,
173173
&mut |tcp_client| {
174-
defmt::info!(
175-
"TCP connection to {:?}:{:?} successful",
176-
hostname,
177-
port
178-
);
174+
defmt::info!("TCP connection to {:?}:{:?} successful", hostname, port);
179175
defmt::info!("Hostname: {:?}", tcp_client.server_hostname());
180176
defmt::info!("Sending HTTP Document: {:?}", http_document.as_str());
181177
match tcp_client.send_data(&http_document) {

esp32-wroom-rp/src/gpio.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
//! };
3131
//! ```
3232
33+
use core::hint;
34+
3335
use embedded_hal::blocking::delay::DelayMs;
3436
use embedded_hal::digital::v2::{InputPin, OutputPin};
3537

@@ -131,13 +133,13 @@ where
131133

132134
fn wait_for_esp_ready(&self) {
133135
while !self.get_esp_ready() {
134-
//cortex_m::asm::nop(); // Make sure rustc doesn't optimize this loop out
136+
hint::spin_loop(); // Make sure rustc doesn't optimize this loop out
135137
}
136138
}
137139

138140
fn wait_for_esp_ack(&self) {
139141
while !self.get_esp_ack() {
140-
//cortex_m::asm::nop(); // Make sure rustc doesn't optimize this loop out
142+
hint::spin_loop(); // Make sure rustc doesn't optimize this loop out
141143
}
142144
}
143145

esp32-wroom-rp/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ use network::NetworkError;
163163

164164
use protocol::ProtocolError;
165165

166-
const ARRAY_LENGTH_PLACEHOLDER: usize = 8;
167-
168166
/// Highest level error types for this crate.
169167
#[derive(Debug, Eq, PartialEq)]
170168
pub enum Error {
@@ -212,17 +210,15 @@ pub struct FirmwareVersion {
212210
}
213211

214212
impl FirmwareVersion {
215-
fn new(version: [u8; ARRAY_LENGTH_PLACEHOLDER]) -> FirmwareVersion {
213+
fn new(version: &[u8]) -> FirmwareVersion {
216214
Self::parse(version)
217215
}
218216

219217
// Takes in 8 bytes (e.g. 1.7.4) and returns a FirmwareVersion instance
220-
fn parse(version: [u8; ARRAY_LENGTH_PLACEHOLDER]) -> FirmwareVersion {
221-
let major_version: u8;
222-
let minor_version: u8;
223-
let patch_version: u8;
224-
225-
[major_version, _, minor_version, _, patch_version, _, _, _] = version;
218+
fn parse(version: &[u8]) -> FirmwareVersion {
219+
let major_version: u8 = version[0];
220+
let minor_version: u8 = version[2];
221+
let patch_version: u8 = version[4];
226222

227223
FirmwareVersion {
228224
major: major_version,
@@ -248,8 +244,7 @@ mod tests {
248244

249245
#[test]
250246
fn firmware_new_returns_a_populated_firmware_struct() {
251-
let firmware_version: FirmwareVersion =
252-
FirmwareVersion::new([0x1, 0x2e, 0x7, 0x2e, 0x4, 0x0, 0x0, 0x0]);
247+
let firmware_version: FirmwareVersion = FirmwareVersion::new(&[0x1, 0x2e, 0x7, 0x2e, 0x4]);
253248

254249
assert_eq!(
255250
firmware_version,

0 commit comments

Comments
 (0)