[][src]Trait atat::UrcMatcher

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

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<BufLen: ArrayLength<u8>> UrcMatcher<BufLen> for FooUrcMatcher {
    fn process(&mut self, buf: &mut Vec<u8, BufLen>) -> UrcMatcherResult<BufLen> {
        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

pub fn process(&mut self, buf: &mut Vec<u8, BufLen>) -> UrcMatcherResult<BufLen>[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<BufLen: ArrayLength<u8>> UrcMatcher<BufLen> for NoopUrcMatcher[src]

Loading content...