Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reattempt on parse err flag to AtatCmd #178

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions atat/src/asynch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub trait AtatClient {

match self.send(cmd).await {
Err(Error::Timeout) => {}
Err(Error::Parse) => {
if !Cmd::REATTEMPT_ON_PARSE_ERR {
return Err(Error::Parse);
}
}
r => return r,
}
}
Expand Down
4 changes: 4 additions & 0 deletions atat/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub trait AtatCmd<const LEN: usize> {
/// using `send_retry`.
const ATTEMPTS: u8 = 1;

/// Whether or not to reattempt a command on a parse error
/// using `send_retry`.
const REATTEMPT_ON_PARSE_ERR: bool = true;

/// Force client to look for a response.
/// Empty slice is then passed to parse by client.
/// Implemented to enhance expandability of ATAT
Expand Down
12 changes: 12 additions & 0 deletions atat_derive/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {
resp,
timeout_ms,
attempts,
reattempt_on_parse_err,
abortable,
value_sep,
cmd_prefix,
Expand Down Expand Up @@ -59,6 +60,15 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {
None => quote! {},
};

let reattempt_on_parse_err = match reattempt_on_parse_err {
Some(reattempt_on_parse_err) => {
quote! {
const REATTEMPT_ON_PARSE_ERR: bool = #reattempt_on_parse_err;
}
}
None => quote! {},
};

// let quote_escape_strings = !matches!(quote_escape_strings, Some(false));

let mut cmd_len = cmd_prefix.len() + cmd.len() + termination.len();
Expand Down Expand Up @@ -99,6 +109,8 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {

#attempts

#reattempt_on_parse_err

#[inline]
fn as_bytes(&self) -> atat::heapless::Vec<u8, { #ident_len + #cmd_len }> {
match atat::serde_at::to_vec(self, #cmd, atat::serde_at::SerializeOptions {
Expand Down
16 changes: 16 additions & 0 deletions atat_derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct CmdAttributes {
pub timeout_ms: Option<u32>,
pub attempts: Option<u8>,
pub abortable: Option<bool>,
pub reattempt_on_parse_err: Option<bool>,
pub value_sep: bool,
pub cmd_prefix: String,
pub termination: String,
Expand Down Expand Up @@ -253,6 +254,7 @@ impl Parse for CmdAttributes {
timeout_ms: None,
attempts: None,
abortable: None,
reattempt_on_parse_err: None,
value_sep: true,
cmd_prefix: String::from("AT"),
termination: String::from("\r\n"),
Expand Down Expand Up @@ -289,6 +291,20 @@ impl Parse for CmdAttributes {
))
}
}
} else if optional.path.is_ident("reattempt_on_parse_err") {
match optional.value {
Expr::Lit(ExprLit {
lit: Lit::Bool(v), ..
}) => {
at_cmd.reattempt_on_parse_err = Some(v.value);
}
_ => {
return Err(Error::new(
call_site,
"expected bool value for 'reattempt_on_parse_err'",
))
}
}
} else if optional.path.is_ident("abortable") {
match optional.value {
Expr::Lit(ExprLit {
Expand Down
Loading