Skip to content

Commit

Permalink
Merge pull request #13 from lulf/add-raw-param
Browse files Browse the repository at this point in the history
Add support for adding an unformatted raw parameter
  • Loading branch information
diondokter authored Sep 26, 2024
2 parents a2a5df8 + 953406c commit b5d1b82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ impl<'a> CommandBuilder<'a, Set> {
self.try_append_data(b",");
self
}

/// Add an unformatted parameter
pub fn with_raw_parameter<T: AsRef<[u8]>>(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> {
Expand Down Expand Up @@ -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");
}
}

0 comments on commit b5d1b82

Please sign in to comment.