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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::at_command::{AtRequest, BufferType};
use crate::{AtError, BUFFER_SIZE};
use defmt::Format;
use embedded_io::Write;

const CSTT_SIZE_MAX: usize = 32; // AT Datasheet page 172

#[derive(Format)]
/// Enter PIN.
pub struct GetAPNUserPassword {}

impl AtRequest for GetAPNUserPassword {
    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("+CSTT")
            .finish()
    }
}

#[derive(Format)]
/// Enter PIN.
pub struct SetAPNUserPassword {
    pub(crate) apn: Option<[u8; CSTT_SIZE_MAX]>,
    pub(crate) user: Option<[u8; CSTT_SIZE_MAX]>,
    pub(crate) password: Option<[u8; CSTT_SIZE_MAX]>,
}

impl SetAPNUserPassword {
    pub fn new() -> Self {
        Self {
            apn: None,
            user: None,
            password: None,
        }
    }
    pub fn with_apn(mut self, apn: &str) -> Self {
        let mut apn_b = [b'\0'; CSTT_SIZE_MAX];
        for (i, b) in apn.as_bytes().iter().enumerate() {
            apn_b[i] = *b;
        }
        self.apn = Some(apn_b);
        self
    }
}

impl AtRequest for SetAPNUserPassword {
    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("CSTT")
            .with_optional_string_parameter(self.apn)
            .with_optional_string_parameter(self.user)
            .with_optional_string_parameter(self.password)
            .finish()
    }
}