Skip to content

Commit 99daf7a

Browse files
committed
Implement sending file chunk
1 parent bf57c18 commit 99daf7a

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Cargo.lock

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ futures = "0.3.31"
3232
serde = { version = "1.0.217", features = ["derive"] }
3333
serde_json = "1.0.134"
3434
time = { version = "0.3.37", features = ["std", "serde-human-readable"] }
35+
rmp-serde = "1.3.0"
3536

3637
[[package.metadata.esp-idf-sys.extra_components]]
3738
remote_component = { name = "espressif/esp_tinyusb", version = "96cbb5b308f92d2493a0c714f097dcfc51add807", git = "https://github.com/LaunchPlatform/esp-usb.git", path = "device/esp_tinyusb" }

src/api/processor.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ impl Processor {
9595

9696
fn list_files(&self, path: &str) -> anyhow::Result<Response> {
9797
let dir_path = Path::new(&self.root_dir).join(path);
98-
log::info!("Listing files at {}", dir_path.to_str().unwrap_or("<Unknown>"));
98+
log::info!(
99+
"Listing files at {}",
100+
dir_path.to_str().unwrap_or("<Unknown>")
101+
);
99102
// Ideally we should find a way to learn the size of all files, but we need to
100103
// iterate over all files anyway... so.. maybe not? :/
101104
let mut files: Vec<File> = vec![];
@@ -143,7 +146,8 @@ impl Processor {
143146
let mut buf = vec![0; chunk_size as usize];
144147
for offset in (0..file_size).step_by(chunk_size as usize) {
145148
file.read(&mut buf)?;
146-
assert_eq!(file.stream_position().unwrap(), offset);
149+
// TODO: somehow stream_position doesn't work correctly?
150+
// assert_eq!(file.stream_position().unwrap(), offset);
147151
send(CommandResponse {
148152
id: req_id.to_string(),
149153
response: FetchFileChunk {
@@ -216,9 +220,12 @@ pub async fn process_events(
216220
Ok(request) => processor.as_mut().unwrap().process(
217221
&request,
218222
|response: CommandResponse| match response.response {
219-
FetchFileChunk { .. } => {
220-
// TODO:
221-
}
223+
FetchFileChunk { .. } => client
224+
.send(
225+
FrameType::Binary(false),
226+
&rmp_serde::to_vec(&response).unwrap(),
227+
)
228+
.unwrap(),
222229
_ => client
223230
.send(
224231
FrameType::Text(false),

0 commit comments

Comments
 (0)