From 829d4e28b4e208e852102c6d16c28af30ae30b2d Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Mon, 11 Dec 2023 11:28:27 +0100 Subject: [PATCH] Remove Buffers type --- atat/src/buffers.rs | 78 ----------------------------------- atat/src/lib.rs | 2 - examples/src/bin/embassy.rs | 17 ++++---- examples/src/bin/std-tokio.rs | 18 ++++---- 4 files changed, 21 insertions(+), 94 deletions(-) delete mode 100644 atat/src/buffers.rs diff --git a/atat/src/buffers.rs b/atat/src/buffers.rs deleted file mode 100644 index 4e19ef56..00000000 --- a/atat/src/buffers.rs +++ /dev/null @@ -1,78 +0,0 @@ -use embedded_io::Write; - -use crate::{ - response_channel::ResponseChannel, urc_channel::UrcChannel, AtatUrc, Config, Digester, Ingress, -}; - -pub struct Buffers< - Urc: AtatUrc, - const INGRESS_BUF_SIZE: usize, - const URC_CAPACITY: usize, - const URC_SUBSCRIBERS: usize, -> { - res_channel: ResponseChannel, - /// The URC pub/sub channel - pub urc_channel: UrcChannel, -} - -impl< - Urc: AtatUrc, - const INGRESS_BUF_SIZE: usize, - const URC_CAPACITY: usize, - const URC_SUBSCRIBERS: usize, - > Buffers -{ - pub const fn new() -> Self { - Self { - res_channel: ResponseChannel::new(), - urc_channel: UrcChannel::new(), - } - } -} - -impl< - Urc: AtatUrc, - const INGRESS_BUF_SIZE: usize, - const URC_CAPACITY: usize, - const URC_SUBSCRIBERS: usize, - > Buffers -{ - #[cfg(feature = "async")] - pub fn split( - &self, - writer: W, - digester: D, - config: Config, - ) -> ( - Ingress, - crate::asynch::Client, - ) { - ( - Ingress::new( - digester, - self.res_channel.publisher().unwrap(), - self.urc_channel.publisher(), - ), - crate::asynch::Client::new(writer, &self.res_channel, config), - ) - } - - pub fn split_blocking( - &self, - writer: W, - digester: D, - config: Config, - ) -> ( - Ingress, - crate::blocking::Client, - ) { - ( - Ingress::new( - digester, - self.res_channel.publisher().unwrap(), - self.urc_channel.publisher(), - ), - crate::blocking::Client::new(writer, &self.res_channel, config), - ) - } -} diff --git a/atat/src/lib.rs b/atat/src/lib.rs index caec3ef7..09a7df3f 100644 --- a/atat/src/lib.rs +++ b/atat/src/lib.rs @@ -222,7 +222,6 @@ // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; -mod buffers; mod config; pub mod digest; mod error; @@ -261,7 +260,6 @@ pub use serde_at; #[cfg(feature = "derive")] pub use heapless; -pub use buffers::Buffers; pub use config::Config; pub use digest::{AtDigester, AtDigester as DefaultDigester, DigestResult, Digester, Parser}; pub use error::{CmeError, CmsError, ConnectionError, Error, InternalError}; diff --git a/examples/src/bin/embassy.rs b/examples/src/bin/embassy.rs index 668154a3..3f19117d 100644 --- a/examples/src/bin/embassy.rs +++ b/examples/src/bin/embassy.rs @@ -3,7 +3,10 @@ #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] -use atat::{asynch::AtatClient, AtatIngress, Buffers, DefaultDigester, Ingress}; +use atat::{ + asynch::{AtatClient, Client}, + AtatIngress, DefaultDigester, Ingress, ResponseChannel, UrcChannel, +}; use atat_examples::common; use embassy_executor::Spawner; use embassy_executor::_export::StaticCell; @@ -47,14 +50,14 @@ async fn main(spawner: Spawner) { ); let (reader, writer) = uart.split(); - static BUFFERS: Buffers = - Buffers::::new(); - - let (ingress, mut client) = BUFFERS.split( - writer, + static RES_CHANNEL: ResponseChannel = ResponseChannel::new(); + static URC_CHANNEL: UrcChannel = UrcChannel::new(); + let ingress = Ingress::new( DefaultDigester::::default(), - atat::Config::default(), + RES_CHANNEL.publisher(), + URC_CHANNEL.publisher(), ); + let mut client = Client::new(writer, RES_CHANNEL.subscriber(), atat::Config::default()); spawner.spawn(ingress_task(ingress, reader)).unwrap(); diff --git a/examples/src/bin/std-tokio.rs b/examples/src/bin/std-tokio.rs index c7187be2..438cb885 100644 --- a/examples/src/bin/std-tokio.rs +++ b/examples/src/bin/std-tokio.rs @@ -4,7 +4,7 @@ use atat_examples::common; use std::process::exit; -use atat::{asynch::AtatClient, AtatIngress, Buffers, Config, DefaultDigester, Ingress}; +use atat::{asynch::AtatClient, AtatIngress, Config, DefaultDigester, Ingress}; use embedded_io_adapters::tokio_1::FromTokio; use tokio_serial::SerialStream; @@ -16,15 +16,19 @@ const URC_SUBSCRIBERS: usize = 3; async fn main() -> ! { env_logger::init(); - static BUFFERS: Buffers = - Buffers::::new(); - let (reader, writer) = SerialStream::pair().expect("Failed to create serial pair"); - let (ingress, mut client) = BUFFERS.split( - FromTokio::new(writer), + static RES_CHANNEL: ResponseChannel = ResponseChannel::new(); + static URC_CHANNEL: UrcChannel = UrcChannel::new(); + let ingress = Ingress::new( DefaultDigester::::default(), - Config::default(), + RES_CHANNEL.publisher(), + URC_CHANNEL.publisher(), + ); + let mut client = Client::new( + FromTokio::new(writer), + RES_CHANNEL.subscriber(), + atat::Config::default(), ); tokio::spawn(ingress_task(ingress, FromTokio::new(reader)));