Skip to content

Response with \r\r\n confuses URC Parser #191

Description

@patsoffice

Hello,

I am attempting to make use of atat for an application to make and answer voice calls as well as sending and interpreting DTMF tones. The modem I'm using emits the following when a voice call comes in:

\r\r\nRING\r\r\n

I was able to return a single Urc on a ring with the following (note the urc_helper in impl Parser for Urc has a trailing '\r':

#[derive(Clone, Debug)]
pub enum Urc {
    // #[at_urc(b"RING")]
    Ring,
    // #[at_urc(b"RDY")]
    Ready,
    // #[at_urc(b"MISSED_CALL")]
    MissedCall,
    // #[at_urc(b"+RXDTMF")]
    Dtmf,
}

impl AtatUrc for Urc {
    type Response = Urc;
    #[inline]
    fn parse(resp: &[u8]) -> Option<Self::Response> {
        let index = resp.iter().position(|&x| x == b':').unwrap_or(resp.len());
        Some(match &resp[..index] {
            b"MISSED_CALL" => Urc::MissedCall,
            b"RING" => Urc::Ring,
            b"RDY" => Urc::Ready,
            b"+RXDTMF" => Urc::Dtmf,
            _ => return None,
        })
    }
}

impl Parser for Urc {
    fn parse<'a>(buf: &'a [u8]) -> Result<(&'a [u8], usize), ParseError> {
        let (_, r) = alt((
            urc_helper(&b"MISSED_CALL"[..]),
            urc_helper(&b"RING\r"[..]),
            urc_helper(&b"RDY"[..]),
            urc_helper(&b"+RXDTMF"[..]),
        ))(buf)?;
        Ok(r)
    }
}

However, if there is a subsequent \r\r\nRING\r\r\n I seem to stop getting any more data from the Digester (calls to try_next_message_pure() on the Urc subscription channel return None).

I'm not sure where exactly to begin to debug this further as I am quite the Rust n00b.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions