Skip to content

Commit

Permalink
little cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Funnyklown committed Jan 17, 2025
1 parent d6a9e1c commit 0e80d5d
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/ota/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// TODO
use core::mem::size_of;

use embedded_svc::http::Headers;
use http::header::ACCEPT;
use http::Uri;
use embedded_svc::http::client::Client;
use embedded_svc::http::{Headers, Method};
use embedded_svc::ota::FirmwareInfo;
use embedded_svc::http::{client::Client, Method};
use esp_idf_svc::http::client::{Configuration, EspHttpConnection};
use esp_idf_svc::ota::EspOta;
use esp_idf_svc::sys::{EspError, ESP_ERR_IMAGE_INVALID, ESP_ERR_INVALID_RESPONSE};
use http::header::ACCEPT;
use http::Uri;

/// Macro to quickly create EspError from an ESP_ERR_ constant.
#[macro_export]
Expand All @@ -19,18 +19,17 @@ macro_rules! esp_err {
}

// Config to use once https is enabled
//
//use esp_idf_svc::sys::esp_crt_bundle_attach;
//
// use esp_idf_svc::sys::esp_crt_bundle_attach;
//
//...
//Configuration {
// buffer_size: Some(1024 * 4),
// use_global_ca_store: true,
// crt_bundle_attach: Some(esp_crt_bundle_attach),
// ..Default::default()
// Configuration {
// buffer_size: Some(1024 * 4),
// use_global_ca_store: true,
// crt_bundle_attach: Some(esp_crt_bundle_attach),
// ..Default::default()
//}


const FIRMWARE_DOWNLOAD_CHUNK_SIZE: usize = 1024 * 20;
// Not expect firmware bigger than 2MB
const FIRMWARE_MAX_SIZE: usize = 1024 * 1024 * 2;
Expand All @@ -43,19 +42,15 @@ pub fn download_and_update_firmware(url: Uri) -> Result<(), EspError> {
})?);
let headers = [(ACCEPT.as_str(), mime::APPLICATION_OCTET_STREAM.as_ref())];
let surl = url.to_string();
let request = client
.request(Method::Get, &surl, &headers)
.map_err(|e| e.0)?;
let request = client.request(Method::Get, &surl, &headers).map_err(|e| e.0)?;
let mut response = request.submit().map_err(|e| e.0)?;
if response.status() != 200 {
log::info!("Bad HTTP response: {}", response.status());
return Err(esp_err!(ESP_ERR_INVALID_RESPONSE));
}
let file_size = response.content_len().unwrap_or(0) as usize;
if file_size <= FIRMWARE_MIN_SIZE {
log::info!(
"File size is {file_size}, too small to be a firmware! No need to proceed further."
);
log::info!("File size is {file_size}, too small to be a firmware! No need to proceed further.");
return Err(esp_err!(ESP_ERR_IMAGE_INVALID));
}
if file_size > FIRMWARE_MAX_SIZE {
Expand Down Expand Up @@ -94,12 +89,14 @@ pub fn download_and_update_firmware(url: Uri) -> Result<(), EspError> {
return work.abort();
}
if total_read_len < file_size {
log::error!("Supposed to download {file_size} bytes, but we could only get {total_read_len}. May be network error?");
log::error!(
"Supposed to download {file_size} bytes, but we could only get {total_read_len}. May be network error?"
);
return work.abort();
}
work.complete()
}

fn get_firmware_info(buff: &[u8]) -> Result<(), EspError>{
fn get_firmware_info(buff: &[u8]) -> Result<(), EspError> {
todo!()
}
}

0 comments on commit 0e80d5d

Please sign in to comment.