Skip to content

Commit

Permalink
WiP...
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Mar 25, 2024
1 parent 53d2380 commit 242ceac
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 114 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
path: target/debug/pdtool${{ ((runner.os == 'Windows') && '.exe') || ' ' }}
if-no-files-found: warn
retention-days: 3
overwrite: true
- name: Artifact
run: |
echo 'ID: ${{ steps.upload.outputs.artifact-id }}'
Expand Down
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ workspace = true
default-features = false
features = ["assets-report", "toml"]

[dependencies.tool]
# [dependencies.tool]
# workspace = true
# features = ["clap", "cli"]
[dependencies.device]
workspace = true
features = ["clap", "cli"]
features = ["clap", "async", "tokio-serial", "tokio"]

[dependencies.clap]
workspace = true
Expand Down Expand Up @@ -89,4 +92,4 @@ nix = { version = "0.28", features = ["signal"] }

[features]
default = []
usb = ["tool/usb"]
# usb = ["tool/usb"]
17 changes: 6 additions & 11 deletions support/device/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ default-features = false

[dependencies.tokio]
version = "1.36"
features = ["process"]
features = ["fs", "process", "time", "io-std"]
optional = true

[dependencies.futures-lite]
version = "2.2"
version = "2.3"

[dependencies.futures]
version = "0.3"
optional = true


[dependencies.clap]
features = ["std", "env", "derive", "help"]
features = ["std", "env", "derive", "help", "color"]
workspace = true
optional = true

Expand All @@ -78,11 +78,6 @@ features = [


[features]
default = [
# "async",
"tokio", # TODO: remove this from default
"tokio-serial",
]
# tokio = ["dep:tokio", "tokio-serial"]
async = ["futures"]
tokio-serial = ["dep:tokio-serial", "tokio", "tokio?/io-util"]
default = ["async"]
async = ["futures", "tokio", "tokio-serial"]
tokio-serial = ["dep:tokio-serial", "tokio?/io-util", "tokio?/rt"]
2 changes: 1 addition & 1 deletion support/device/src/device/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum Command {
#[cfg_attr(feature = "clap", command(visible_alias = "btn"))]
Button {
/// Button to press or release.
#[clap(subcommand)]
#[cfg_attr(feature = "clap", clap(subcommand))]
button: Button,
},

Expand Down
2 changes: 2 additions & 0 deletions support/device/src/device/methods.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "tokio")]

use crate::error::Error;
use crate::usb::mode::Mode;

Expand Down
8 changes: 4 additions & 4 deletions support/device/src/usb/discover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::borrow::Cow;

use futures::stream::futures_unordered::IntoIter;
use futures::{FutureExt, Stream, StreamExt};
#[cfg(feature = "futures")]
use futures::{Stream, StreamExt};

use crate::device::query;
use crate::error::Error;
Expand Down Expand Up @@ -61,6 +59,7 @@ pub fn devices_data_with(sn: Option<Sn>) -> Result<impl Iterator<Item = Device>,
}


#[cfg(feature = "futures")]
pub async fn devices_data_for(query: query::DeviceQuery) -> Result<Vec<Device>, Error> {
use query::DeviceQueryValue as Query;
use serial::dev_with_port;
Expand Down Expand Up @@ -123,6 +122,7 @@ pub async fn devices_data_for(query: query::DeviceQuery) -> Result<Vec<Device>,
}


#[cfg(feature = "futures")]
pub async fn for_each_data_interface<F, Fut, T>(query: query::DeviceQuery,
mut f: F)
-> Result<impl Stream<Item = T>, Error>
Expand Down
2 changes: 1 addition & 1 deletion support/device/src/usb/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::Error;
use crate::serial::redirect_interface_to_stdout as redirect_serial_to_stdout;
use crate::usb::mode::DeviceMode;
use crate::usb::mode::Mode;
use crate::usb::{BULK_IN, BULK_OUT};
use crate::usb::BULK_IN;


pub fn read_interface(interface: &Interface,
Expand Down
79 changes: 0 additions & 79 deletions support/device/src/usb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,84 +249,6 @@ impl Interface {
comp.status.map(|_| written)
})
}


// pub fn write_queue(&self, data: &[u8]) -> Result<(), Error> {}


pub fn read_queue(&self,
buffer_size: usize,
buffers_num: usize)
-> Result<impl futures_lite::stream::Stream, Error> {
let mut inp = self.inner.bulk_in_queue(BULK_IN);

// preallocate buffers
let new_buf = || {
trace!("buffer allocated");
Vec::with_capacity(buffer_size)
};
let pool: Pool<Vec<u8>> = Pool::new(buffers_num, new_buf);
while inp.pending() < buffers_num {
// inp.submit(RequestBuffer::new(buffer_size));
let (pool, buf) = pool.pull(new_buf).detach();
inp.submit(RequestBuffer::reuse(buf, buffer_size));
}

// let stream = futures_lite::stream::poll_fn(move |ctx| inp.poll_next(ctx).map(Some)).map(move |out| {
// match out.status {
// Ok(_) => {
// println!("pool: len: {}, empty: {}", pool.len(), pool.is_empty());

// // make received data reusable
// // let data = Reusable::new(&pool, out.data);

// // prepare next request
// // let (_, buf) = pool.pull(new_buf).detach();
// // inp.submit(RequestBuffer::reuse(buf, buffer_size));

// // trace!("cancel all IN queue");
// // inp.cancel_all();
// // Some(Ok(data))
// Some(Ok(out.data))
// // Some(Ok(Reusable::new(&pool, out.data)))
// // Some(Ok(Reusable::new(&pool, out.data)))
// },
// Err(err) => {
// // inp.cancel_all();
// Some(Err(err))
// },
// }
// });

let stream = futures_lite::stream::poll_fn(move |ctx| {
inp.poll_next(ctx).map(|out| -> Option<Result<_, TransferError>> {
match out.status {
Ok(_) => {
println!("pool: len: {}, empty: {}", pool.len(), pool.is_empty());

// make received data reusable
// let data = Reusable::new(&pool, out.data);

// prepare next request
// let (_, buf) = pool.pull(new_buf).detach();
// inp.submit(RequestBuffer::reuse(buf, buffer_size));

// trace!("cancel all IN queue");
// inp.cancel_all();
// Some(Ok(data))
Some(Ok(out.data))
// Some(Ok(Reusable::new(&pool, out.data)))
},
Err(err) => {
inp.cancel_all();
Some(Err(err))
},
}
})
});

Ok(stream)
}
}


Expand All @@ -338,7 +260,6 @@ pub struct PoolStream<'pool> {
}

impl<'pool> futures::Stream for PoolStream<'pool> {
// type Item = Result<impl Deref<Vec<u8>>, TransferError>;
type Item = Result<Reusable<'pool, Vec<u8>>, TransferError>;

fn poll_next(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
6 changes: 2 additions & 4 deletions support/tool2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ name = "pdtool"


[dependencies]
# TEMP:
tokio-serial = "5.4"
# RT, async:
tokio = { version = "1.36", features = ["full"] }
futures-lite = { version = "2.2" }
futures-lite = { version = "2.3" }
futures = { version = "0.3" }

serde = { workspace = true, features = ["derive"] }
Expand All @@ -32,7 +30,7 @@ serde_json.workspace = true
log.workspace = true
env_logger.workspace = true
thiserror = "1.0"
miette = { version = "7.1", features = ["fancy"] }
miette = { version = "7.2", features = ["fancy"] }

[dependencies.clap]
features = ["std", "env", "derive", "help", "usage", "color"]
Expand Down
13 changes: 5 additions & 8 deletions support/tool2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
extern crate log;
extern crate device as pddev;

use std::borrow::Cow;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use futures::stream::FuturesUnordered;
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
use futures::{FutureExt, StreamExt, TryFutureExt};
use pddev::device::query::DeviceQueryValue;
use pddev::device::serial::SerialNumber;
use pddev::error::Error;
use pddev::mount::{MountedDevice, UnmountAsync};
use pddev::{device::query::DeviceQuery, usb::mode::DeviceMode};
use pddev::device::query::DeviceQuery;
use pddev::*;


use miette::{Context, IntoDiagnostic};
use miette::IntoDiagnostic;
use report::AsReport;


Expand Down Expand Up @@ -98,7 +95,7 @@ async fn run_on_device(query: DeviceQuery,

async fn run_with_sim(pdx: PathBuf, sdk: Option<PathBuf>, _format: cli::Format) -> Result<(), error::Error> {
run::run_with_sim(pdx, sdk).await
.inspect(|_| debug!("run with sim done"))
.inspect(|_| trace!("sim execution is done"))
}


Expand Down
3 changes: 2 additions & 1 deletion support/tool2/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pddev::usb::mode::DeviceMode;


pub trait AsReport {
#[allow(unused)]
fn as_report(&self) -> DevInfo<'_>;
fn as_report_short(&self) -> DevInfoShort<'_>;
}
Expand Down Expand Up @@ -103,6 +104,7 @@ impl<'dev> DevState<'dev> {
interface }
}

#[allow(unused)]
pub fn to_printable_line(&self) -> impl std::fmt::Display {
let mut s = String::new();
self.to_printable_line_to(&mut s);
Expand All @@ -120,7 +122,6 @@ impl<'dev> DevState<'dev> {
buf.push(' ');
buf.push_str(interface);
}
//
}
}

Expand Down

0 comments on commit 242ceac

Please sign in to comment.