Skip to content

Commit f647645

Browse files
committed
feat:io rework
Signed-off-by: addrian-77 <lunguadrian30@gmail.com>
1 parent dfd0f39 commit f647645

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

tockloader-lib/src/command_impl/probers/io.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ impl IOCommands for ProbeRSConnection {
4545
if !self.is_open() {
4646
return Err(InternalError::ConnectionNotOpen.into());
4747
}
48+
<<<<<<< HEAD
4849
let start_address = self.get_settings().start_address;
4950
let session = self.session.as_mut().expect("Board must be open");
5051
let mut core = session.core(self.target_info.core)?;
5152

5253
AppAttributes::read_apps_data_probe(&mut core, start_address)
54+
=======
55+
let settings = self.get_settings();
56+
let session = self.session.as_mut().expect("Board must be open");
57+
let mut core = session.core(self.target_info.core)?;
58+
59+
AppAttributes::read_apps_data_probe(&mut core, settings.start_address)
60+
>>>>>>> 6df3b8d (feat:io rework)
5361
}
5462

5563
async fn read_system_attributes(&mut self) -> Result<SystemAttributes, TockloaderError> {

tockloader-lib/src/command_impl/serial/io.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ use crate::{
1212
impl IO for SerialConnection {
1313
async fn read(&mut self, address: u64, size: usize) -> Result<Vec<u8>, TockloaderError> {
1414
let mut pkt = (address as u32).to_le_bytes().to_vec();
15+
<<<<<<< HEAD
1516
pkt.append(&mut (size as u16).to_le_bytes().to_vec());
17+
=======
18+
let length = (size as u16).to_le_bytes().to_vec();
19+
for i in length {
20+
pkt.push(i);
21+
}
22+
>>>>>>> 6df3b8d (feat:io rework)
1623
let stream = self.stream.as_mut().expect("Board must be open");
1724

1825
let (_, appdata) = issue_command(
@@ -34,6 +41,7 @@ impl IO for SerialConnection {
3441
}
3542

3643
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError> {
44+
<<<<<<< HEAD
3745
let page_size = self.get_settings().page_size as usize;
3846
let stream = self.stream.as_mut().expect("Board must be open");
3947
let mut binary = pkt.to_vec();
@@ -48,6 +56,28 @@ impl IO for SerialConnection {
4856
.to_vec();
4957
pkt.append(
5058
&mut binary[(page_number * page_size)..((page_number + 1) * page_size)].to_vec(),
59+
=======
60+
let settings = self.get_settings();
61+
let stream = self.stream.as_mut().expect("Board must be open");
62+
let mut binary = pkt.to_vec();
63+
64+
if !binary.len().is_multiple_of(settings.page_size as usize) {
65+
binary.extend(vec![
66+
0u8;
67+
settings.page_size as usize
68+
- (binary.len() % settings.page_size as usize)
69+
]);
70+
}
71+
72+
for page_number in 0..(binary.len() / settings.page_size as usize) {
73+
let mut pkt = (address as u32 + page_number as u32 * settings.page_size as u32)
74+
.to_le_bytes()
75+
.to_vec();
76+
pkt.append(
77+
&mut binary[(page_number * settings.page_size as usize)
78+
..((page_number + 1) * settings.page_size as usize)]
79+
.to_vec(),
80+
>>>>>>> 6df3b8d (feat:io rework)
5181
);
5282
let _ = issue_command(stream, Command::WritePage, pkt, true, 0, Response::OK).await?;
5383
}
@@ -67,12 +97,20 @@ impl IOCommands for SerialConnection {
6797
if !self.is_open() {
6898
return Err(InternalError::ConnectionNotOpen.into());
6999
}
100+
<<<<<<< HEAD
70101
let start_address = self.get_settings().start_address;
102+
=======
103+
let settings = self.get_settings();
104+
>>>>>>> 6df3b8d (feat:io rework)
71105
let stream = self.stream.as_mut().expect("Board must be open");
72106

73107
ping_bootloader_and_wait_for_response(stream).await?;
74108

109+
<<<<<<< HEAD
75110
AppAttributes::read_apps_data_serial(stream, start_address).await
111+
=======
112+
AppAttributes::read_apps_data_serial(stream, settings.start_address).await
113+
>>>>>>> 6df3b8d (feat:io rework)
76114
}
77115

78116
async fn read_system_attributes(&mut self) -> Result<SystemAttributes, TockloaderError> {

tockloader-lib/src/connection.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ pub trait Connection {
5252
/// `open` or any other method is undefined behavior.
5353
async fn close(&mut self) -> Result<(), TockloaderError>;
5454
fn is_open(&self) -> bool;
55+
<<<<<<< HEAD
5556
fn get_settings(&self) -> &BoardSettings;
57+
=======
58+
fn get_settings(&self) -> BoardSettings;
59+
>>>>>>> 6df3b8d (feat:io rework)
5660
}
5761

5862
pub struct ProbeRSConnection {
@@ -62,7 +66,11 @@ pub struct ProbeRSConnection {
6266
pub(crate) target_info: ProbeTargetInfo,
6367
/// Only used for opening a new connection
6468
debug_probe: DebugProbeInfo,
69+
<<<<<<< HEAD
6570
settings: BoardSettings,
71+
=======
72+
pub settings: BoardSettings,
73+
>>>>>>> 6df3b8d (feat:io rework)
6674
}
6775

6876
impl ProbeRSConnection {
@@ -102,8 +110,13 @@ impl Connection for ProbeRSConnection {
102110
self.session.is_some()
103111
}
104112

113+
<<<<<<< HEAD
105114
fn get_settings(&self) -> &BoardSettings {
106115
&self.settings
116+
=======
117+
fn get_settings(&self) -> BoardSettings {
118+
self.settings.clone()
119+
>>>>>>> 6df3b8d (feat:io rework)
107120
}
108121
}
109122

@@ -114,7 +127,11 @@ pub struct SerialConnection {
114127
pub(crate) target_info: SerialTargetInfo,
115128
/// Path to the serial port. This is only used for opening a new connection.
116129
port: String,
130+
<<<<<<< HEAD
117131
settings: BoardSettings,
132+
=======
133+
pub settings: BoardSettings,
134+
>>>>>>> 6df3b8d (feat:io rework)
118135
}
119136

120137
impl SerialConnection {
@@ -165,8 +182,13 @@ impl Connection for SerialConnection {
165182
self.stream.is_some()
166183
}
167184

185+
<<<<<<< HEAD
168186
fn get_settings(&self) -> &BoardSettings {
169187
&self.settings
188+
=======
189+
fn get_settings(&self) -> BoardSettings {
190+
self.settings.clone()
191+
>>>>>>> 6df3b8d (feat:io rework)
170192
}
171193
}
172194

@@ -213,7 +235,11 @@ impl Connection for TockloaderConnection {
213235
}
214236
}
215237

238+
<<<<<<< HEAD
216239
fn get_settings(&self) -> &BoardSettings {
240+
=======
241+
fn get_settings(&self) -> BoardSettings {
242+
>>>>>>> 6df3b8d (feat:io rework)
217243
match self {
218244
TockloaderConnection::ProbeRS(conn) => conn.get_settings(),
219245
TockloaderConnection::Serial(conn) => conn.get_settings(),

0 commit comments

Comments
 (0)