Comments (8)
Yeah I guess a builder isn't justified. Especially if we don't use builders elsewhere (like for config). We have to be consistent.
I think this library is low level enough to use struct/enum directly.
I will use nordic SDK as starting point and use a rubble like implementation.
from nrf-softdevice.
I started working on it, and I came up with that:
pub enum DeviceName<'a> {
Short(&'a str),
Long(&'a str),
}
// maybe implement something like rubble name()
pub struct CompanyId(u16);
pub struct ManufacturerData<'a> {
company_identifier: CompanyId,
data: &'a [u8],
}
pub struct RawData<'a> (u8, &'a [u8]);
pub struct ServiceData<'a> (u16, &'a [u8]);
pub struct Flags(u8);
pub enum Uuid {
U16(u16),
U32(u32),
U128([u8;4]),
}
pub struct AdvertData<'a> {
flags: Flags,
name: Option<&'a DeviceName<'a>>,
service: Option<&'a [ServiceData<'a>]>,
manufacturer: Option<&'a ManufacturerData<'a>>,
uuids_more_available: Option<&'a [Uuid]>,
uuids_complete: Option<&'a [Uuid]>,
uuids_solicited: Option<&'a [Uuid]>,
raw: Option<&'a [RawData<'a>]>
}
pub struct ScanData<'a> {
name: Option<&'a DeviceName<'a>>,
service: Option<&'a [ServiceData<'a>]>,
manufacturer: Option<&'a ManufacturerData<'a>>,
uuids_more_available: Option<&'a [Uuid]>,
uuids_complete: Option<&'a [Uuid]>,
uuids_solicited: Option<&'a [Uuid]>,
raw: Option<&'a [RawData<'a>]>
}
Rubble uses a list of enums, but the problem with the list of enum is that we can specify the same thing multiple times, so the API is not fully safe. Also, scan response data cannot include flags, that's why I duplicated the structure. But we could also imagine passing a is_scan_data
bool on the to_bytes
method and specify that to get either advert or scan data from the struct.
I am also wondering if we should include something like rubble bitflags for flags.
The above structure is the closest I could come to represent the underlying data the best, they are a bit verbose, but with Default
it should be ok. They are also unfinished, I need to include appearance and a few other things.
Also, rubble has a list of appearances in the gatt, which can be included in the advert data, do you think we should include a list like that?
Finally, in the nordic SDK, to include appearance (or name), you only pass a bool and the SDK gets the appearance (or name) from gap data, but I think it's better to have a complete data struct and not rely on existing gap data.
from nrf-softdevice.
Doing it at runtime is probably fine, that's what the C nrf5-sdk does. Also it makes it possible to make stuff like device names dynamic which is nice.
Getting it to work wth today's const fn
limitations will be quite hard though, I'd just focus on runtime building.
It can be "translate to/from struct" like the one above, or a "builder" where you add data and it writes it to a buffer as you go. I have the suspicion the second will be better for code size.
from nrf-softdevice.
I'm trying to gather as much reference as possible:
- List of AD types (first byte after length) https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/
- List of GATT services, which are two bytes (little endian, so reversed) used with type
0x03
https://www.bluetooth.com/specifications/gatt/services/
from nrf-softdevice.
I'd like to tackle this issue, but I need to know a few things:
- Is a builder pattern OK, or do you prefer a plain rust struct that will be transformed into data?
- what AD types and GATT services should we support with the "simple API"
- GATT services are also used when creating gatt server, so I guess it would be better to have their definition at only one place
from nrf-softdevice.
A good starting point would be what the Nordic SDK supports:
https://github.com/akiles/nrf5_sdk/blob/master/components/ble/common/ble_advdata.h#L146
https://github.com/akiles/nrf5_sdk/blob/master/components/ble/common/ble_advdata.c#L509
Also, Rubble already has support for this in Rust
https://jonas-schievink.github.io/rubble/rubble/link/ad_structure/enum.AdStructure.html
For builder pattern vs struct: I'd prefer a plain struct that you then encode to bytes (like rubble and the Nordic sdk). There are not that many fields to justify a builder IMO. Also using a builder opens interesting questions, for example: what if you set the UUID list 2 times? Does it use the last one? Do they get concatenated? If it's a regular Rust struct you don't have these issues.
About GATT services: they're a separate concern from advertising data. In advertising data you supply a list of UUIDs that may or may not match the list of GATT services you support after the connection is established.
from nrf-softdevice.
I'd like to tackle this issue, @Dirbaio what do you think?
from nrf-softdevice.
@Dirbaio what are you thoughts on overhead of helpers to construct packets? I'm not sure that they would end up as zero-cost abstractions. If not, they could be compile-time macros. Or when you're able to create &'static [u8]
in const fns that would be the best solution.
from nrf-softdevice.
Related Issues (20)
- Including in a separate Cargo project HOT 4
- Dependency cortex-m-rt requires update due to miscompilation advisory HOT 1
- Panic when a connection is initiated HOT 2
- nRF51 SoftDevice support
- Async callback to gatt_server::run HOT 5
- Unable to connect to examples from iPad (NRFConnect/LightBlue) HOT 3
- What is the difference between nordic crate HOT 1
- Pairing Initiated from Central Device HOT 1
- ERROR panicked at 'sd_softdevice_enable err SdmIncorrectInterruptConfiguration' HOT 8
- `FixedGattValue` improperly implemented for primitives that are not u8/i8 HOT 3
- `FixedGattValue` (and other ble traits) should be provided by a separate library
- Recommendation to enable squash merges?
- Use PHY Coded as Primary PHY for advertisement HOT 1
- Connecting to an incorrect Mac address causes a "hang" due to underlying NRF_ERROR_NOT_FOUND HOT 1
- Connecting with 2M PHY HOT 4
- L2CAP Channel API Design Flaws HOT 1
- Switch examples to use default `gatts_attr_tab_size` ? HOT 1
- Add descriptor to a characteristic HOT 2
- NRF52832/S132 Freezes Upon Connection HOT 3
- There is currently no way to disable the SoftDevice HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nrf-softdevice.