Skip to content

Commit

Permalink
increase buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Oct 29, 2024
1 parent af36723 commit 2b3acff
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 50 deletions.
30 changes: 26 additions & 4 deletions sfy-buoy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sfy-buoy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rtcc = "0.3.0"
anyhow = { version = "1", optional = true }
argh = { version = "*", optional = true }
nb = "1.1.0"
ufmt = { version = "0.2", optional = true }

[dependencies.ahrs-fusion]
git = "https://github.com/gauteh/ahrs-fusion"
Expand All @@ -46,7 +47,7 @@ half = { version = "2.4", features = [ "use-intrinsics", "bytemuck", "serde" ] }
[features]
default = [ "build-bin" ]
continuous = []
continuous-post = [ "continuous" ]
continuous-post = [ "continuous", "dep:ufmt" ]
20Hz = ["fir"]
raw = [ "storage" ]
fir = []
Expand Down
63 changes: 62 additions & 1 deletion sfy-buoy/src/axl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use defmt::{write, Format, Formatter};
use heapless::Vec;
use heapless::{String, Vec};

#[cfg(feature = "raw")]
pub const SAMPLE_NO: usize = 1024;
Expand Down Expand Up @@ -152,6 +152,41 @@ impl AxlPacket {

(meta, b64)
}

#[cfg(feature = "continuous-post")]
pub fn post(&self, device: Option<String<40>>, sn: Option<String<120>>) -> AxlPacketPost {
let (body, payload) = self.split();
let device = device.unwrap_or_else(|| String::from("unknown"));
let sn = sn.unwrap_or_else(|| String::from("unknown"));
let payload = heapless::String::from(core::str::from_utf8(&payload).unwrap());

let mut event: String<100> = String::new();
event.push_str("post-event-");
event.push_str(&device);
ufmt::uwrite!(event, "{}", body.timestamp);

AxlPacketPost {
file: "axl.qo".into(),
received: (body.timestamp / 1000) as u32,
device,
event,
sn,
body,
payload,
}
}
}

#[cfg(feature = "continuous-post")]
#[derive(serde::Serialize, Default)]
pub struct AxlPacketPost {
pub device: String<40>,
pub sn: String<120>,
pub file: String<20>,
pub event: String<100>,
pub received: u32,
pub body: AxlPacketMeta,
pub payload: String<AXL_OUTN>,
}

#[cfg(test)]
Expand Down Expand Up @@ -181,6 +216,32 @@ mod tests {
println!("{}", core::str::from_utf8(&b64).unwrap());
}

#[test]
fn post_package() {
//Some("dev:860264054655056"), sn: Some("WAVEBUG49"), pck: AxlPacket(timestamp: 1730205219000, offset: 0, storage_id: None, position_time: 1730204657, lon: 5.372730468749992, lat: 60.33562750000002, temp: 23.695312, freq: 52.0, accel_range: 16.0, gyro_range: 1000.0, data (length): 3072))
//
let p = AxlPacket {
timestamp: 1730205219000,
position_time: 1730204657,
lon: 5.372730468749992,
lat: 60.33562750000002,
freq: 52.0,
accel_range: 16.,
gyro_range: 1000.,
offset: 0,
storage_id: None,
storage_version: VERSION,
temperature: 23.695312,
data: (0..AXL_SZ)
.map(|v| v as u16)
.collect::<Vec<_, { AXL_SZ }>>(),
};

let post = p.post(Some("dev:860264054655056".into()), Some("WAVEBUG49".into()));
let string = serde_json_core::to_string::<_, { 28_000 }>(&post);
println!("{:?}", string);
}

#[test]
fn postcard_size() {
let p = AxlPacket {
Expand Down
116 changes: 72 additions & 44 deletions sfy-buoy/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ include!(concat!(env!("OUT_DIR"), "/config.rs"));
pub const NOTECARD_STORAGE_INIT_SYNC: u32 = 65;

pub struct Notecarrier<I2C: Read + Write> {
note: Notecard<I2C>,
note: Notecard<I2C, { 28 * 1024 }>,
device: Option<heapless::String<40>>,
sn: Option<heapless::String<120>>,
}

#[derive(serde::Serialize, serde::Deserialize, Default, defmt::Format, PartialEq)]
Expand Down Expand Up @@ -118,7 +120,14 @@ impl<I2C: Read + Write> Notecarrier<I2C> {
let version = note.card().version(delay)?.wait(delay)?;
defmt::info!("Notecard version: {:?}", version);

let mut n = Notecarrier { note };
let dev = note.hub().get(delay)?.wait(delay)?;
defmt::info!("device: {}, sn: {}", dev.device, dev.sn);

let mut n = Notecarrier {
note,
device: dev.device,
sn: dev.sn,
};
n.setup_templates(delay)?;

defmt::info!("initializing initial sync ..");
Expand Down Expand Up @@ -258,53 +267,72 @@ impl<I2C: Read + Write> Notecarrier<I2C> {
pck: &AxlPacket,
delay: &mut impl DelayMs<u16>,
) -> Result<usize, NoteError> {
let (meta, b64) = pck.split();

#[cfg(feature = "continuous-post")]
let r = self
.note
.web()
.post(
delay,
"sfypost",
None,
Some(meta),
None,
// Some(core::str::from_utf8(&b64).unwrap()), // TODO: need to send actual data.
None,
None,
None,
None,
Some(false), // async
)?
.wait(delay)?;
let len = {
defmt::debug!("dev: {:?}, sn: {:?}, pck: {:?}", self.device, self.sn, pck);

let post = pck.post(self.device.clone(), self.sn.clone());
let len = post.payload.len();

let r = self
.note
.web()
.post(
delay,
"sfypost",
None,
Some(post),
None,
None,
None,
None,
None,
Some(false), // async
)?
.wait(delay)?;

defmt::info!(
"Sent data package: {}, bytes: {} (note: {:?})",
pck.storage_id,
len,
r
);

len
};

#[cfg(not(feature = "continuous-post"))]
let r = self
.note
.note()
.add(
delay,
Some("axl.qo"),
None,
Some(meta),
Some(core::str::from_utf8(&b64).unwrap()),
if cfg!(feature = "continuous") {
true
} else {
false
},
)?
.wait(delay)?;
let len = {
let (meta, b64) = pck.split();
let r = self
.note
.note()
.add(
delay,
Some("axl.qo"),
None,
Some(meta),
Some(core::str::from_utf8(&b64).unwrap()),
if cfg!(feature = "continuous") {
true
} else {
false
},
)?
.wait(delay)?;

defmt::info!(
"Sent data package: {}, bytes: {} (note: {:?})",
pck.storage_id,
b64.len(),
r
);
defmt::info!(
"Sent data package: {}, bytes: {} (note: {:?})",
pck.storage_id,
b64.len(),
r
);

Ok(b64.len())
b64.len()
};

Ok(len)
}

#[cfg(feature = "ext-gps")]
Expand Down Expand Up @@ -594,7 +622,7 @@ impl<I2C: Read + Write> Notecarrier<I2C> {
}

impl<I2C: Read + Write> Deref for Notecarrier<I2C> {
type Target = Notecard<I2C>;
type Target = Notecard<I2C, { 28 * 1024 } >;

fn deref(&self) -> &Self::Target {
&self.note
Expand Down

0 comments on commit 2b3acff

Please sign in to comment.