seeed_lora_e5_at_commands/general/
mod.rs

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
60
61
pub mod commands;
pub mod responses;
pub mod types;

#[cfg(feature = "async")]
pub mod asynch {
    use crate::client::asynch::SeeedLoraE5Client;
    use crate::general::commands::{FactoryReset, FirmwareVersion, Reset, VerifyComIsWorking};
    use crate::general::responses::VerResponse;
    use atat::asynch::AtatClient;
    use atat::Error;
    #[cfg(feature = "debug")]
    use defmt::error;
    use embedded_io_async::Write;

    impl<'a, W: Write, const INGRESS_BUF_SIZE: usize> SeeedLoraE5Client<'a, W, INGRESS_BUF_SIZE> {
        pub async fn verify_com_is_working(&mut self) -> Result<bool, Error> {
            let command = VerifyComIsWorking {};
            let response = self.client.send(&command).await?;
            Ok(response.is_ok())
        }

        pub async fn at_echo_on(&mut self) -> Result<bool, Error> {
            // Nop
            Ok(true)
        }

        pub async fn at_echo_set(&mut self, _on: bool) -> Result<bool, Error> {
            // Nop
            Ok(true)
        }

        pub async fn version(&mut self) -> Result<VerResponse, Error> {
            let command = FirmwareVersion {};
            let response = self.client.send(&command).await?;
            Ok(response)
        }

        pub async fn reset(&mut self) -> Result<(), Error> {
            let command = Reset {};
            let resp = self.client.send(&command).await;
            if let Err(e) = resp {
                #[cfg(feature = "debug")]
                error!("Error resetting Seeed LoRa-E5: {:?}", e);
                return Err(e);
            }
            Ok(())
        }

        pub async fn factory_reset(&mut self) -> Result<(), Error> {
            let command = FactoryReset {};
            let resp = self.client.send(&command).await;
            if let Err(e) = resp {
                #[cfg(feature = "debug")]
                error!("Error factory resetting Seeed LoRa-E5: {:?}", e);
                return Err(e);
            }
            Ok(())
        }
    }
}