From dd3823351bf353f6d7582c29ef2d56214de233b6 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 26 Sep 2024 15:16:03 +0200 Subject: [PATCH 1/2] Add support for adding an unformatted raw parameter This allows passing i.e. configuration data directly from network or flash without needing to parse or transform it, such as a pin number which is more a 'series of digits' than an integer. --- src/builder.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index acd1e79..500aaa2 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -204,6 +204,13 @@ impl<'a> CommandBuilder<'a, Set> { self.try_append_data(b","); self } + + /// Add an unformatted parameter + pub fn with_raw_parameter>(mut self, value: T) -> Self { + self.try_append_data(value.as_ref()); + self.try_append_data(b","); + self + } } impl<'a, F: Finishable> CommandBuilder<'a, F> { @@ -454,4 +461,16 @@ mod tests { "AT+HTTPCLIENT=2,1,\"http://localpc/ip\",,,1\r\n" ); } + + #[test] + fn test_raw_parameter() { + let mut buffer = [0; 128]; + let value = CommandBuilder::create_set(&mut buffer, true) + .named("+CPIN") + .with_raw_parameter(b"1234") + .with_optional_int_parameter(Some(9)) + .finish_with(b"\r") + .unwrap(); + assert_eq!(core::str::from_utf8(value).unwrap(), "AT+CPIN=1234,9\r"); + } } From 953406cc3c5457e8348670ab7a2f5c304bc555b3 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 26 Sep 2024 15:24:18 +0200 Subject: [PATCH 2/2] Add missing changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67a88e5..97ca91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Add raw parameter to command builder. + ## [0.5.4] - 2023-09-18 - Added optional parser parameters: [diondokter/at-commands#9](https://github.com/diondokter/at-commands/pull/9) - Changed &str to AsRef<[u8]> in CommandBuilder methods: [diondokter/at-commands#10](https://github.com/diondokter/at-commands/pull/10)