Skip to content

Commit 37fde6f

Browse files
author
George Cosma
committed
wip: refactor info command
Signed-off-by: George Cosma <george.cosma@wyliodrin.com>
1 parent 7df2a24 commit 37fde6f

3 files changed

Lines changed: 65 additions & 34 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::attributes::app_attributes::AppAttributes;
2+
use crate::attributes::general_attributes::GeneralAttributes;
3+
use crate::attributes::system_attributes::SystemAttributes;
4+
use crate::board_settings::BoardSettings;
5+
use crate::connection::{Connection, ProbeRSConnection};
6+
use crate::errors::TockloaderError;
7+
use crate::CommandInfo;
8+
9+
impl CommandInfo for ProbeRSConnection {
10+
async fn info(
11+
&mut self,
12+
settings: &BoardSettings,
13+
) -> Result<GeneralAttributes, TockloaderError> {
14+
if !self.is_open() {
15+
todo!("Error here");
16+
}
17+
let session = self.session.as_mut().expect("Board must be open");
18+
19+
let mut core = session
20+
.core(self.target_info.core)
21+
.map_err(|e| TockloaderError::CoreAccessError(self.target_info.core, e))?;
22+
23+
// TODO(george-cosma): extract these informations without bootloader
24+
let system_attributes = SystemAttributes::read_system_attributes_probe(&mut core)?;
25+
let app_attributes =
26+
AppAttributes::read_apps_data_probe(&mut core, settings.start_address)?;
27+
28+
Ok(GeneralAttributes::new(system_attributes, app_attributes))
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::time::Duration;
2+
3+
use crate::attributes::app_attributes::AppAttributes;
4+
use crate::attributes::general_attributes::GeneralAttributes;
5+
use crate::attributes::system_attributes::SystemAttributes;
6+
use crate::board_settings::BoardSettings;
7+
use crate::bootloader_serial::{ping_bootloader_and_wait_for_response, Response};
8+
use crate::connection::{Connection, SerialConnection};
9+
use crate::errors::TockloaderError;
10+
use crate::CommandInfo;
11+
12+
impl CommandInfo for SerialConnection {
13+
async fn info(
14+
&mut self,
15+
settings: &BoardSettings,
16+
) -> Result<GeneralAttributes, TockloaderError> {
17+
if !self.is_open() {
18+
todo!("Error here");
19+
}
20+
let stream = self.stream.as_mut().expect("Board must be open");
21+
22+
let response = ping_bootloader_and_wait_for_response(stream).await?;
23+
24+
if response as u8 != Response::Pong as u8 {
25+
tokio::time::sleep(Duration::from_millis(100)).await;
26+
let _ = ping_bootloader_and_wait_for_response(stream).await?;
27+
}
28+
29+
let system_attributes = SystemAttributes::read_system_attributes_serial(stream).await?;
30+
let app_attributes =
31+
AppAttributes::read_apps_data_serial(stream, settings.start_address).await?;
32+
33+
Ok(GeneralAttributes::new(system_attributes, app_attributes))
34+
}
35+
}

tockloader-lib/src/lib.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,6 @@ pub trait CommandInstall {
7171
) -> Result<(), TockloaderError>;
7272
}
7373

74-
pub async fn info(
75-
connection: &mut Connection,
76-
settings: &BoardSettings,
77-
) -> Result<GeneralAttributes, TockloaderError> {
78-
match connection {
79-
Connection::ProbeRS { session, info } => {
80-
let mut core = session
81-
.core(info.core)
82-
.map_err(|e| TockloaderError::CoreAccessError(info.core, e))?;
83-
84-
// TODO: extract these informations without bootloader
85-
let system_attributes = SystemAttributes::read_system_attributes_probe(&mut core)?;
86-
let app_attributes =
87-
AppAttributes::read_apps_data_probe(&mut core, settings.start_address)?;
88-
89-
Ok(GeneralAttributes::new(system_attributes, app_attributes))
90-
}
91-
Connection::Serial { stream, info: _ } => {
92-
let response = ping_bootloader_and_wait_for_response(stream).await?;
93-
94-
if response as u8 != Response::Pong as u8 {
95-
tokio::time::sleep(Duration::from_millis(100)).await;
96-
let _ = ping_bootloader_and_wait_for_response(stream).await?;
97-
}
98-
99-
let system_attributes = SystemAttributes::read_system_attributes_serial(stream).await?;
100-
let app_attributes =
101-
AppAttributes::read_apps_data_serial(stream, settings.start_address).await?;
102-
103-
Ok(GeneralAttributes::new(system_attributes, app_attributes))
104-
}
105-
}
106-
}
107-
10874
pub async fn install_app(
10975
connection: &mut Connection,
11076
settings: &BoardSettings,

0 commit comments

Comments
 (0)