Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust handling of responses from NINA-FW #72

Merged
merged 12 commits into from
Feb 17, 2023
6 changes: 1 addition & 5 deletions cross/send_data_tcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ fn main() -> ! {
mode,
&mut delay,
&mut |tcp_client| {
defmt::info!(
"TCP connection to {:?}:{:?} successful",
hostname,
port
);
defmt::info!("TCP connection to {:?}:{:?} successful", hostname, port);
defmt::info!("Hostname: {:?}", tcp_client.server_hostname());
defmt::info!("Sending HTTP Document: {:?}", http_document.as_str());
match tcp_client.send_data(&http_document) {
Expand Down
6 changes: 4 additions & 2 deletions esp32-wroom-rp/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
//! };
//! ```

use core::hint;

use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::digital::v2::{InputPin, OutputPin};

Expand Down Expand Up @@ -131,13 +133,13 @@ where

fn wait_for_esp_ready(&self) {
while !self.get_esp_ready() {
//cortex_m::asm::nop(); // Make sure rustc doesn't optimize this loop out
hint::spin_loop(); // Make sure rustc doesn't optimize this loop out
calebbourg marked this conversation as resolved.
Show resolved Hide resolved
}
}

fn wait_for_esp_ack(&self) {
while !self.get_esp_ack() {
//cortex_m::asm::nop(); // Make sure rustc doesn't optimize this loop out
hint::spin_loop(); // Make sure rustc doesn't optimize this loop out
}
}

Expand Down
17 changes: 6 additions & 11 deletions esp32-wroom-rp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ use network::NetworkError;

use protocol::ProtocolError;

const ARRAY_LENGTH_PLACEHOLDER: usize = 8;

/// Highest level error types for this crate.
#[derive(Debug, Eq, PartialEq)]
pub enum Error {
Expand Down Expand Up @@ -212,17 +210,15 @@ pub struct FirmwareVersion {
}

impl FirmwareVersion {
fn new(version: [u8; ARRAY_LENGTH_PLACEHOLDER]) -> FirmwareVersion {
fn new(version: &[u8]) -> FirmwareVersion {
Self::parse(version)
}

// Takes in 8 bytes (e.g. 1.7.4) and returns a FirmwareVersion instance
fn parse(version: [u8; ARRAY_LENGTH_PLACEHOLDER]) -> FirmwareVersion {
let major_version: u8;
let minor_version: u8;
let patch_version: u8;

[major_version, _, minor_version, _, patch_version, _, _, _] = version;
fn parse(version: &[u8]) -> FirmwareVersion {
let major_version: u8 = version[0];
let minor_version: u8 = version[2];
let patch_version: u8 = version[4];

FirmwareVersion {
major: major_version,
Expand All @@ -248,8 +244,7 @@ mod tests {

#[test]
fn firmware_new_returns_a_populated_firmware_struct() {
let firmware_version: FirmwareVersion =
FirmwareVersion::new([0x1, 0x2e, 0x7, 0x2e, 0x4, 0x0, 0x0, 0x0]);
let firmware_version: FirmwareVersion = FirmwareVersion::new(&[0x1, 0x2e, 0x7, 0x2e, 0x4]);

assert_eq!(
firmware_version,
Expand Down
Loading