Skip to main content

Modem

Struct Modem 

Source
pub struct Modem { /* private fields */ }
Expand description

The modem as a state machine: Modem::feed takes what the host wrote and returns what the modem sends back. Plug it into FakeDevice::modem or peer::serve.

Commands match in any case (V.250: at is AT).

The multiplexer keeps the state of each DLC, as 27.010 asks: a channel carries data from its SABM to its DISC, anything else on it is answered with DM. DISC on DLCI 0 and CLD end the multiplexer: what follows is plain AT again.

use serialplugin_testing::Modem;

let mut modem = Modem::new()
    .reply("AT+CPIN?", &["+CPIN: READY"])
    .fails("AT+COPS?", "+CME ERROR: 30");
let log = modem.log();
assert_eq!(modem.feed(b"AT+CPIN?\r"), b"\r\n+CPIN: READY\r\n\r\nOK\r\n");
assert_eq!(modem.feed(b"AT+COPS?\r"), b"\r\n+CME ERROR: 30\r\n");
assert_eq!(log.commands()[1].line, "AT+COPS?");

Implementations§

Source§

impl Modem

Source

pub fn new() -> Self

Answers AT with OK, AT+CSQ with a reading, AT+CMGS=… with the prompt, then +CMGS: 7; anything else with ERROR.

Source

pub fn reply(self, command: &str, lines: &[&str]) -> Self

command answers with lines, then OK.

Source

pub fn fails(self, command: &str, result: &str) -> Self

command answers with the final result result (ERROR, +CME ERROR: 10, …).

Source

pub fn raw(self, command: &str, bytes: &[u8]) -> Self

command answers with exactly bytes.

Source

pub fn silent(self, command: &str) -> Self

command gets no answer.

Source

pub fn echo(self) -> Self

Echo command lines (ATE1).

Source

pub fn numeric(self) -> Self

Numeric result codes (ATV0): 0\r for OK, 4\r for ERROR.

Source

pub fn mux(self, options: MuxOptions) -> Self

AT+CMUX… starts a multiplexer.

Source

pub fn log(&self) -> ModemLog

The log, also after the modem moved into a device.

Source

pub fn feed(&mut self, bytes: &[u8]) -> Vec<u8> ⓘ

What the modem answers to bytes from the host.

Trait Implementations§

Source§

impl Debug for Modem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Modem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for Modem

§

impl Freeze for Modem

§

impl Move for Modem

§

impl RefUnwindSafe for Modem

§

impl Send for Modem

§

impl Sync for Modem

§

impl Unpin for Modem

§

impl UnsafeUnpin for Modem

§

impl UnwindSafe for Modem

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.