Skip to content

Commit 5f4c2b2

Browse files
committed
ntn: add ntn.gps
1 parent d9bc7ab commit 5f4c2b2

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

src/ntn.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ pub struct NTN<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS
1212
note: &'a mut Notecard<IOM, BS>,
1313
}
1414

15+
#[derive(Clone, Copy, defmt::Format)]
16+
pub enum NtnSetGps {
17+
/// Use notecard gps on starnote as well
18+
Notecard,
19+
20+
/// Use starnotes own gps (default).
21+
Starnote,
22+
}
23+
1524
impl<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS: usize> NTN<'a, IOM, BS> {
1625
pub fn from(note: &mut Notecard<IOM, BS>) -> NTN<'_, IOM, BS> {
1726
NTN { note }
@@ -22,8 +31,7 @@ impl<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS: usize> N
2231
self,
2332
delay: &mut impl DelayMs<u16>,
2433
) -> Result<FutureResponse<'a, res::Empty, IOM, BS>, NoteError> {
25-
self.note
26-
.request_raw(delay, b"{\"req\":\"ntn.reset\"}\n")?;
34+
self.note.request_raw(delay, b"{\"req\":\"ntn.reset\"}\n")?;
2735
Ok(FutureResponse::from(self.note))
2836
}
2937

@@ -38,10 +46,38 @@ impl<'a, IOM: Write<SevenBitAddress> + Read<SevenBitAddress>, const BS: usize> N
3846

3947
Ok(FutureResponse::from(self.note))
4048
}
49+
50+
/// Determines whether a Notecard should override a paired Starnote's GPS/GNSS location with its own GPS/GNSS location. The paired Starnote uses its own GPS/GNSS location by default.
51+
pub fn gps(
52+
self,
53+
delay: &mut impl DelayMs<u16>,
54+
gps: Option<NtnSetGps>,
55+
) -> Result<FutureResponse<'a, res::Gps, IOM, BS>, NoteError> {
56+
self.note.request(
57+
delay,
58+
req::Gps {
59+
req: "ntn.gps",
60+
on: gps.map(|g| matches!(g, NtnSetGps::Notecard)),
61+
off: gps.map(|g| matches!(g, NtnSetGps::Starnote)),
62+
},
63+
)?;
64+
Ok(FutureResponse::from(self.note))
65+
}
4166
}
4267

4368
pub mod req {
4469
use super::*;
70+
71+
#[derive(Deserialize, Serialize, defmt::Format, Default)]
72+
pub struct Gps {
73+
pub req: &'static str,
74+
75+
#[serde(skip_serializing_if = "Option::is_none")]
76+
pub on: Option<bool>,
77+
78+
#[serde(skip_serializing_if = "Option::is_none")]
79+
pub off: Option<bool>,
80+
}
4581
}
4682

4783
pub mod res {
@@ -50,15 +86,23 @@ pub mod res {
5086
#[derive(Deserialize, defmt::Format)]
5187
pub struct Empty {}
5288

89+
#[derive(Deserialize, Serialize, defmt::Format, Default)]
90+
pub struct Gps {
91+
#[serde(skip_serializing_if = "Option::is_none")]
92+
pub on: Option<bool>,
93+
94+
#[serde(skip_serializing_if = "Option::is_none")]
95+
pub off: Option<bool>,
96+
}
97+
5398
#[derive(Deserialize, defmt::Format)]
5499
pub struct Status {
55100
pub err: Option<heapless::String<120>>,
56101
pub status: Option<heapless::String<120>>,
57102
}
58103
}
59104

60-
#[cfg(test)]
61-
mod tests {
62-
use super::*;
63-
}
64-
105+
// #[cfg(test)]
106+
// mod tests {
107+
// use super::*;
108+
// }

0 commit comments

Comments
 (0)