Add a route to upload update to the platform
This commit is contained in:
@ -1 +1,2 @@
|
||||
pub mod ota_manager;
|
||||
pub mod ota_update;
|
||||
|
24
central_backend/src/ota/ota_manager.rs
Normal file
24
central_backend/src/ota/ota_manager.rs
Normal 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(())
|
||||
}
|
@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user