Skip to content

Commit

Permalink
Add the common package
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Nov 17, 2024
1 parent 69315ac commit bb01c27
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
5 changes: 5 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[workspace]
members = [
"common",
"nrf52840",
"python",
]
default-members = ["python"]
default-members = ["common", "python"]
resolver = "2"

[workspace.dependencies]
Expand Down
6 changes: 6 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "common"
version = "0.1.0"
edition = "2021"

[dependencies]
29 changes: 29 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![no_std]
use core::option::{Option, Option::None, Option::Some};

pub fn split_at_response(line: &str) -> Option<(&str, &str)> {
if line.starts_with('+') {
if let Some(prefix_len) = line.find(": ") {
let prefix = &line[1..prefix_len];
let rest = &line[prefix_len + 2..];
return Some((prefix, rest));
}
}
None
}

#[cfg(test)]
mod test_at_utils {
use super::*;

#[test]
fn test_split_at_response() {
let res = "+QMTSTAT: 0,2";
assert_eq!(split_at_response(res), Some(("QMTSTAT", "0,2")));

let res = "QMTSTAT: 0,2";
assert_eq!(split_at_response(res), None);
let res = "+QMTSTAT 0,2";
assert_eq!(split_at_response(res), None);
}
}
5 changes: 2 additions & 3 deletions nrf52840/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ resolver = "2"
rust-version = "1.81"

[dependencies]
common = { path = "../common" }

defmt = "0.3"
defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }
Expand All @@ -27,6 +29,3 @@ heapless = { git = "https://github.com/rust-embedded/heapless.git", rev = "0ebc
thiserror = { version = "2.0.0", default-features = false }
embassy-sync = "0.6.0"
chrono = { workspace = true }

[profile.release]
debug = 2
26 changes: 1 addition & 25 deletions nrf52840/src/at_utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common::split_at_response;
use core::str::{from_utf8, FromStr};
use defmt::*;
use embassy_executor::Spawner;
Expand All @@ -10,17 +11,6 @@ use heapless::{format, String, Vec};

use crate::error::Error;

pub fn split_at_response(line: &str) -> Option<(&str, &str)> {
if line.starts_with('+') {
if let Some(prefix_len) = line.find(": ") {
let prefix = &line[1..prefix_len];
let rest = &line[prefix_len + 2..];
return Some((prefix, rest));
}
}
None
}

#[derive(Clone)]
pub enum FromModem {
Line(String<AT_COMMAND_SIZE>),
Expand Down Expand Up @@ -367,17 +357,3 @@ impl AtUart {
Ok(response)
}
}

//#[cfg(test)]
//mod test_at_utils {
// #[test]
// fn test_split_at_response() {
// let res = "+QMTSTAT: 0,2";
// assert_eq!(split_at_response(res), Some(("QMTSTAT", "0,2")));
//
// let res = "QMTSTAT: 0,2";
// assert_eq!(split_at_response(res), None);
// let res = "+QMTSTAT 0,2";
// assert_eq!(split_at_response(res), None);
// }
//}
3 changes: 2 additions & 1 deletion nrf52840/src/bg77.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
at_utils::{split_at_response, AtUart, URC_CHANNEL},
at_utils::{AtUart, URC_CHANNEL},
error::Error,
};
use chrono::{NaiveDateTime, TimeDelta};
use common::split_at_response;
use defmt::{error, info, unwrap};
use embassy_executor::Spawner;
use embassy_nrf::{
Expand Down

0 comments on commit bb01c27

Please sign in to comment.