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
impl Modem
Sourcepub fn new() -> Self
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.
Sourcepub fn fails(self, command: &str, result: &str) -> Self
pub fn fails(self, command: &str, result: &str) -> Self
command answers with the final result result (ERROR, +CME ERROR: 10, …).
Sourcepub fn mux(self, options: MuxOptions) -> Self
pub fn mux(self, options: MuxOptions) -> Self
AT+CMUX… starts a multiplexer.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more