Trait atat::UrcMatcher[][src]

pub trait UrcMatcher {
    fn process<L: ArrayLength<u8>>(
        &mut self,
        buf: &mut Vec<u8, L>
    ) -> UrcMatcherResult<L>; }

A user-defined URC matcher

This is used to detect and consume URCs that are not terminated with standard response codes like "OK". An example could be an URC that returns length-value (LV) encoded data without a terminator.

Note that you should only detect and consume but not process URCs. Processing should be done by an AtatUrc implementation.

A very simplistic example that can only handle the URC +FOO,xx (with xx being two arbitrary characters) followed by CRLF:

use atat::{UrcMatcher, UrcMatcherResult};
use heapless::{consts, ArrayLength, Vec};

struct FooUrcMatcher {}

impl UrcMatcher for FooUrcMatcher {
    fn process<L: ArrayLength<u8>>(&mut self, buf: &mut Vec<u8, L>) -> UrcMatcherResult<L> {
        if buf.starts_with(b"+FOO,") {
            if buf.len() >= 9 {
                if &buf[7..9] == b"\r\n" {
                    // URC is complete
                    let data = Vec::from_slice(&buf[..9]).unwrap();
                    *buf = Vec::from_slice(&buf[9..]).unwrap();
                    UrcMatcherResult::Complete(data)
                } else {
                    // Invalid, reject
                    UrcMatcherResult::NotHandled
                }
            } else {
                // Insufficient data
                UrcMatcherResult::Incomplete
            }
        } else {
            UrcMatcherResult::NotHandled
        }
    }
}

Required methods

fn process<L: ArrayLength<u8>>(
    &mut self,
    buf: &mut Vec<u8, L>
) -> UrcMatcherResult<L>
[src]

Take a look at buf. Then:

  • If the buffer contains a full URC, remove these bytes from the buffer and return Complete with the matched data.
  • If it contains an incomplete URC, return Incomplete.
  • Otherwise, return NotHandled.
Loading content...

Implementors

impl UrcMatcher for DefaultUrcMatcher[src]

Loading content...