1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::at_command::{AtRequest, BufferType};
use crate::AtError;
use defmt::Format;
use embedded_io::Write;

#[derive(Format)]
/// Test if a pin is required.
pub struct PINRequired;

impl AtRequest for PINRequired {
    type Response = Result<(), AtError>;

    fn get_command<'a>(&'a self, buffer: &'a mut BufferType) -> Result<&'a [u8], usize> {
        at_commands::builder::CommandBuilder::create_test(buffer, true)
            .named("+CPIN")
            .finish()
    }
}

#[derive(Format)]
/// Enter PIN.
pub struct EnterPIN {
    pin: u16,
}

impl AtRequest for EnterPIN {
    type Response = Result<(), AtError>;

    fn get_command<'a>(&'a self, buffer: &'a mut BufferType) -> Result<&'a [u8], usize> {
        at_commands::builder::CommandBuilder::create_set(buffer, true)
            .named("+CPIN")
            .with_int_parameter(self.pin)
            .finish()
    }
}