Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement creation of ble payload in userland
- adapt run parameters for tockloader
- Loading branch information
1 parent
812297d
commit 090398c
Showing
10 changed files
with
163 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use alloc::*; | ||
|
||
pub mod gap_types { | ||
pub static COMPLETE_LOCAL_NAME: u8 = 0x09; | ||
pub static SERVICE_DATA: u8 = 0x16; | ||
pub static UUID: u8 = 0x02; | ||
pub static FLAGS: u8 = 0x01; | ||
} | ||
|
||
pub mod flags { | ||
pub static LE_GENERAL_DISCOVERABLE: u8 = 0x01; | ||
} | ||
|
||
pub struct BlePayload { | ||
pub bytes: Vec<u8>, | ||
} | ||
|
||
impl BlePayload { | ||
pub fn add(&mut self, kind: u8, content: &[u8]) { | ||
self.bytes.push((content.len() + 1) as u8); | ||
self.bytes.push(kind); | ||
for e in content { | ||
self.bytes.push(*e); | ||
} | ||
} | ||
|
||
pub fn add_flag(&mut self, flag: u8) { | ||
self.bytes.push(2); | ||
self.bytes.push(gap_types::FLAGS); | ||
self.bytes.push(flag); | ||
} | ||
|
||
pub fn new() -> Self { | ||
BlePayload { bytes: Vec::new() } | ||
} | ||
|
||
pub fn add_service_payload(&mut self, uuid: [u8; 2], content: &[u8]) { | ||
self.bytes.push((content.len() + 3) as u8); | ||
self.bytes.push(gap_types::SERVICE_DATA); | ||
self.bytes.push(uuid[0]); | ||
self.bytes.push(uuid[1]); | ||
for e in content { | ||
self.bytes.push(*e); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use ble_composer::*; | ||
#[test] | ||
pub fn test_add() { | ||
let mut pld = BlePayload::new(); | ||
pld.add(1, &[2]); | ||
assert_eq!(pld.bytes, vec![2, 1, 2]) | ||
} | ||
|
||
#[test] | ||
pub fn test_add_service_payload() { | ||
let mut pld = BlePayload::new(); | ||
pld.add_service_payload([1, 2], &[2]); | ||
assert_eq!(pld.bytes, &[4, 0x16, 1, 2, 2]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.