Add a route to upload update to the platform

This commit is contained in:
2024-10-05 15:50:46 +02:00
parent e1a94acdcb
commit 2f971c0055
10 changed files with 211 additions and 5 deletions

View File

@ -1 +1,2 @@
pub mod ota_manager;
pub mod ota_update;

View File

@ -0,0 +1,24 @@
use crate::app_config::AppConfig;
use crate::ota::ota_update::OTAPlatform;
use crate::utils::files_utils;
/// Check out whether a given update exists or not
pub fn update_exists(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<bool> {
Ok(AppConfig::get()
.path_ota_update(platform, version)
.is_file())
}
/// Save a new firmware update
pub fn save_update(
platform: OTAPlatform,
version: &semver::Version,
update: &[u8],
) -> anyhow::Result<()> {
let path = AppConfig::get().path_ota_update(platform, version);
files_utils::create_directory_if_missing(path.parent().unwrap())?;
std::fs::write(path, update)?;
Ok(())
}

View File

@ -1,5 +1,22 @@
use std::fmt::{Display, Formatter};
#[derive(serde::Serialize, serde::Deserialize, Debug, Copy, Clone, Eq, PartialEq)]
pub enum OTAPlatform {
#[serde(rename = "Wt32-Eth01")]
Wt32Eth01,
}
impl Display for OTAPlatform {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = serde_json::to_string(&self).unwrap().replace('"', "");
write!(f, "{s}")
}
}
/// Single OTA update information
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct OTAUpdate {
platform: OTAPlatform,
version: semver::Version,
file_size: usize,
}