|
| 1 | +//! https://dev.blues.io/api-reference/notecard-api/ntn-requests/ |
| 2 | +
|
| 3 | +#[allow(unused_imports)] |
| 4 | +use defmt::{debug, error, info, trace, warn}; |
| 5 | +use embedded_hal::blocking::delay::DelayMs; |
| 6 | +use embedded_hal::blocking::i2c::{Read, SevenBitAddress, Write}; |
| 7 | +use serde::{Deserialize, Serialize}; |
| 8 | + |
| 9 | +use super::{FutureResponse, NoteError, Notecard}; |
| 10 | + |
| 11 | +pub struct NTN<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS: usize> { |
| 12 | + note: &'a mut Notecard<IOM, BS>, |
| 13 | +} |
| 14 | + |
| 15 | +impl<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS: usize> NTN<'a, IOM, BS> { |
| 16 | + pub fn from(note: &mut Notecard<IOM, BS>) -> NTN<'_, IOM, BS> { |
| 17 | + NTN { note } |
| 18 | + } |
| 19 | + |
| 20 | + /// Once a Notecard is connected to a Starnote device, the presence of a physical Starnote is stored in a permanent configuration that is not affected by a card.restore request. This request clears this configuration and allows you to return to testing NTN mode over cellular or Wi-Fi. |
| 21 | + pub fn reset<const PS: usize>( |
| 22 | + self, |
| 23 | + delay: &mut impl DelayMs<u16>, |
| 24 | + ) -> Result<FutureResponse<'a, res::Empty, IOM, BS>, NoteError> { |
| 25 | + self.note |
| 26 | + .request_raw(delay, b"{\"req\":\"ntn.reset\"}\n")?; |
| 27 | + Ok(FutureResponse::from(self.note)) |
| 28 | + } |
| 29 | + |
| 30 | + /// Gets and sets the background download status of MCU host or Notecard |
| 31 | + /// firmware updates. |
| 32 | + pub fn status( |
| 33 | + self, |
| 34 | + delay: &mut impl DelayMs<u16>, |
| 35 | + ) -> Result<FutureResponse<'a, res::Status, IOM, BS>, NoteError> { |
| 36 | + self.note |
| 37 | + .request_raw(delay, b"{\"req\":\"ntn.status\"}\n")?; |
| 38 | + |
| 39 | + Ok(FutureResponse::from(self.note)) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +pub mod req { |
| 44 | + use super::*; |
| 45 | +} |
| 46 | + |
| 47 | +pub mod res { |
| 48 | + use super::*; |
| 49 | + |
| 50 | + #[derive(Deserialize, defmt::Format)] |
| 51 | + pub struct Empty {} |
| 52 | + |
| 53 | + #[derive(Deserialize, defmt::Format)] |
| 54 | + pub struct Status { |
| 55 | + pub err: Option<heapless::String<120>>, |
| 56 | + pub status: Option<heapless::String<120>>, |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +#[cfg(test)] |
| 61 | +mod tests { |
| 62 | + use super::*; |
| 63 | +} |
| 64 | + |
0 commit comments