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

AtDigester consumes first line of responses as echos #13

Closed
nbarrios opened this issue Jan 4, 2023 · 3 comments
Closed

AtDigester consumes first line of responses as echos #13

nbarrios opened this issue Jan 4, 2023 · 3 comments
Labels
bug Something isn't working enhancement New feature or request question Further information is requested

Comments

@nbarrios
Copy link

nbarrios commented Jan 4, 2023

I started working on adding UART config commands (get/set AT+UART_CUR and AT+UART_DEF), but the responses always failed to parse.

example response (with echo): AT+UART_CUR?\r\n+UART_CUR:115201,8,1,0,1\r\n

I think I tracked it down to:

impl<P: Parser> Digester for AtDigester<P> {
    fn digest<'a>(&mut self, input: &'a [u8]) -> (DigestResult<'a>, usize) {
        // 1. Optionally discard echo
        let (buf, echo_bytes) = match nom::combinator::opt(parser::echo)(input) {
            Ok((buf, echo)) => (buf, echo.unwrap_or_default().len()),
            Err(nom::Err::Incomplete(_)) => return (DigestResult::None, 0),
            Err(_) => panic!("NOM ERROR - opt(echo)"),
        };

        // 2. Match for URC's
        if let Ok((urc, len)) = P::parse(input) {
            return (DigestResult::Urc(urc), len);
        }

        // 3. Parse for success responses
        // Custom successful replies first, if any
        if let Ok((response, len)) = (self.custom_success)(buf) {
            return (DigestResult::Response(Ok(response)), len + echo_bytes);
        }
...

That first step always seems to discard the first line as an echo, but then the original input is used to match for URCs. URCDigester then matches the echo as a valid URC and returns. On the next digest, the first step discards the entire first line of any response (the entire response in the case of AT+UART_CUR?).

Preventing URCDigester from matching echos allows the responses to parse correctly. The AtDigester docs suggest that it should work with echo disabled, but it always seems to discard the first line as echo unless I'm misunderstanding something. Another solution is to change AtDigester to hand P::parse() the buf after discarding the echo instead of input like it does now.

The same issue happens with get_address(). The first response disappears (the ipv4 address for me).

I'm new to rust and embedded rust so I appreciate any help.

@marius-meissner marius-meissner added enhancement New feature or request question Further information is requested bug Something isn't working labels Apr 5, 2023
@marius-meissner
Copy link
Member

marius-meissner commented Apr 5, 2023

First of all, sorry for the late response and thanks a lot for bringing this up!

I can confirm the issue, and seems like matching echos in URC is a bad idea.
I just removed it and everything seems to work, except parsing of get_address(). As far as I can remember, echo matching was a workaround for multiline responses.

@nbarrios Did you by chance manage to disable echo matching and that get_address() still worked?

@MathiasKoch Sorry for stealing your time. Could you maybe give us a hint, what's the right approach for parsing responses like that?

AT+CIFSR
+CIFSR:STAIP,"10.0.0.160"
+CIFSR:STAMAC,"c8:c9:a3:8b:d8:24"

@MathiasKoch
Copy link

Hmm, not really sure how to do that, but it will most likely require a custom implementation instead of the derived AtatCmd

@marius-meissner
Copy link
Member

From my point of view #14 fixed the issue. If anyone encounters further errors, please create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants