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 optional response_code for at_cmd macro #220

Merged
merged 3 commits into from
Mar 3, 2025
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
12 changes: 12 additions & 0 deletions atat_derive/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {
attempts,
reattempt_on_parse_err,
abortable,
response_code,
value_sep,
cmd_prefix,
termination,
Expand Down Expand Up @@ -61,6 +62,15 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {
None => quote! {},
};

let response = match response_code {
Some(is_resp) => {
quote! {
const EXPECTS_RESPONSE_CODE: bool = #is_resp;
}
}
None => quote! {},
};

let reattempt_on_parse_err = match reattempt_on_parse_err {
Some(reattempt_on_parse_err) => {
quote! {
Expand Down Expand Up @@ -136,6 +146,8 @@ pub fn atat_cmd(input: TokenStream) -> TokenStream {

#attempts

#response

#reattempt_on_parse_err

#[inline]
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 @@ -24,6 +24,7 @@ pub struct CmdAttributes {
pub attempts: Option<u8>,
pub abortable: Option<bool>,
pub reattempt_on_parse_err: Option<bool>,
pub response_code: Option<bool>,
pub value_sep: bool,
pub cmd_prefix: String,
pub termination: String,
Expand Down Expand Up @@ -270,6 +271,7 @@ impl Parse for CmdAttributes {
attempts: None,
abortable: None,
reattempt_on_parse_err: None,
response_code: None,
value_sep: true,
cmd_prefix: String::from("AT"),
termination: String::from("\r\n"),
Expand Down Expand Up @@ -402,6 +404,20 @@ impl Parse for CmdAttributes {
))
}
}
} else if optional.path.is_ident("response_code") {
match optional.value {
Expr::Lit(ExprLit {
lit: Lit::Bool(v), ..
}) => {
at_cmd.response_code = Some(v.value);
}
_ => {
return Err(Error::new(
Span::call_site(),
"expected bool value for 'response_code'",
))
}
}
}
}

Expand Down
Loading