From 1fbe885cf84f8be38b8aa1fefd539a077cdafe0f Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Tue, 26 Mar 2024 00:29:39 +0400 Subject: [PATCH] WiP... --- .github/workflows/dev-build.yml | 1 + Cargo.lock | 3 +- cargo/Cargo.toml | 9 ++-- support/device/Cargo.toml | 17 +++--- support/device/src/device/command.rs | 2 +- support/device/src/device/methods.rs | 2 + support/device/src/usb/discover.rs | 8 +-- support/device/src/usb/io.rs | 2 +- support/device/src/usb/mod.rs | 79 ---------------------------- support/tool2/Cargo.toml | 6 +-- support/tool2/src/main.rs | 13 ++--- support/tool2/src/report.rs | 3 +- 12 files changed, 31 insertions(+), 114 deletions(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index ceae9009..d4b6c865 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -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 }}' diff --git a/Cargo.lock b/Cargo.lock index 62fc6d36..1c149670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,7 +444,7 @@ dependencies = [ "nix 0.28.0", "once_cell", "playdate-build", - "playdate-tool", + "playdate-device", "rand", "regex", "semver", @@ -3353,7 +3353,6 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tokio-serial", ] [[package]] diff --git a/cargo/Cargo.toml b/cargo/Cargo.toml index 0495df81..bc93bda8 100644 --- a/cargo/Cargo.toml +++ b/cargo/Cargo.toml @@ -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 @@ -89,4 +92,4 @@ nix = { version = "0.28", features = ["signal"] } [features] default = [] -usb = ["tool/usb"] +# usb = ["tool/usb"] diff --git a/support/device/Cargo.toml b/support/device/Cargo.toml index 23bf5da8..8a986a10 100644 --- a/support/device/Cargo.toml +++ b/support/device/Cargo.toml @@ -39,11 +39,11 @@ 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" @@ -51,7 +51,7 @@ optional = true [dependencies.clap] -features = ["std", "env", "derive", "help"] +features = ["std", "env", "derive", "help", "color"] workspace = true optional = true @@ -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"] diff --git a/support/device/src/device/command.rs b/support/device/src/device/command.rs index 5ef9bcad..4e189f99 100644 --- a/support/device/src/device/command.rs +++ b/support/device/src/device/command.rs @@ -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, }, diff --git a/support/device/src/device/methods.rs b/support/device/src/device/methods.rs index c7cde5d1..228ece09 100644 --- a/support/device/src/device/methods.rs +++ b/support/device/src/device/methods.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "tokio")] + use crate::error::Error; use crate::usb::mode::Mode; diff --git a/support/device/src/usb/discover.rs b/support/device/src/usb/discover.rs index dd0e1c90..790b43d6 100644 --- a/support/device/src/usb/discover.rs +++ b/support/device/src/usb/discover.rs @@ -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; @@ -61,6 +59,7 @@ pub fn devices_data_with(sn: Option) -> Result, } +#[cfg(feature = "futures")] pub async fn devices_data_for(query: query::DeviceQuery) -> Result, Error> { use query::DeviceQueryValue as Query; use serial::dev_with_port; @@ -123,6 +122,7 @@ pub async fn devices_data_for(query: query::DeviceQuery) -> Result, } +#[cfg(feature = "futures")] pub async fn for_each_data_interface(query: query::DeviceQuery, mut f: F) -> Result, Error> diff --git a/support/device/src/usb/io.rs b/support/device/src/usb/io.rs index ae532eae..66626ba0 100644 --- a/support/device/src/usb/io.rs +++ b/support/device/src/usb/io.rs @@ -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, diff --git a/support/device/src/usb/mod.rs b/support/device/src/usb/mod.rs index 749e09d5..e0086ad2 100644 --- a/support/device/src/usb/mod.rs +++ b/support/device/src/usb/mod.rs @@ -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 { - 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> = 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> { - 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) - } } @@ -338,7 +260,6 @@ pub struct PoolStream<'pool> { } impl<'pool> futures::Stream for PoolStream<'pool> { - // type Item = Result>, TransferError>; type Item = Result>, TransferError>; fn poll_next(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll> { diff --git a/support/tool2/Cargo.toml b/support/tool2/Cargo.toml index d5e74eb7..35bf2452 100644 --- a/support/tool2/Cargo.toml +++ b/support/tool2/Cargo.toml @@ -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"] } @@ -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"] diff --git a/support/tool2/src/main.rs b/support/tool2/src/main.rs index 331fff58..d4a62fc9 100644 --- a/support/tool2/src/main.rs +++ b/support/tool2/src/main.rs @@ -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; @@ -98,7 +95,7 @@ async fn run_on_device(query: DeviceQuery, async fn run_with_sim(pdx: PathBuf, sdk: Option, _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")) } diff --git a/support/tool2/src/report.rs b/support/tool2/src/report.rs index bf511b49..5ac3783b 100644 --- a/support/tool2/src/report.rs +++ b/support/tool2/src/report.rs @@ -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<'_>; } @@ -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); @@ -120,7 +122,6 @@ impl<'dev> DevState<'dev> { buf.push(' '); buf.push_str(interface); } - // } }