Skip to content

Commit d2db542

Browse files
committed
ntn: add ntn.reset and ntn.status
1 parent c932aa8 commit d2db542

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod dfu;
2020
pub mod hub;
2121
pub mod note;
2222
pub mod web;
23+
pub mod ntn;
2324

2425
/// Delay between polling for new response.
2526
const RESPONSE_DELAY: u16 = 25;
@@ -560,6 +561,11 @@ impl<IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BUF_SIZE: usize>
560561
pub fn dfu(&mut self) -> dfu::DFU<IOM, BUF_SIZE> {
561562
dfu::DFU::from(self)
562563
}
564+
565+
/// [NtN Requests](https://dev.blues.io/reference/notecard-api/ntn-requests/)
566+
pub fn ntn(&mut self) -> ntn::NTN<IOM, BUF_SIZE> {
567+
ntn::NTN::from(self)
568+
}
563569
}
564570

565571
/// A future response.

src/ntn.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)