sim7020/at_command/
model_identification.rs1use crate::at_command::{AtRequest, AtResponse, BufferType};
2use crate::AtError;
3#[cfg(feature = "defmt")]
4use defmt::error;
5
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7pub struct ModelIdentification {}
8
9impl AtRequest for ModelIdentification {
10    type Response = Result<AtResponse, AtError>;
11
12    fn get_command<'a>(&'a self, buffer: &'a mut BufferType) -> Result<&'a [u8], usize> {
13        at_commands::builder::CommandBuilder::create_execute(buffer, true)
14            .named("+CGMM")
15            .finish()
16    }
17
18    fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
19        let (parsed,) = at_commands::parser::CommandParser::parse(data)
20            .expect_identifier(b"\r\n")
21            .expect_raw_string()
22            .expect_identifier(b"\r\n\r\nOK")
23            .finish()
24            .inspect(|_e| {
25                #[cfg(feature = "defmt")]
26                error!("Failed to parse response: {=[u8]:a}", data);
27            })?;
28
29        let mut id: [u8; 8] = [0; 8];
30        for (i, b) in parsed.as_bytes().iter().enumerate() {
31            id[i] = *b;
32        }
33        Ok(AtResponse::ModelIdentifier(id))
34    }
35}