Skip to content

Conversation

nm17
Copy link

@nm17 nm17 commented Aug 31, 2024

Currently a draft, any comments are welcome!

#[repr(u8)]
/// An enum of possible characteristic properties
///
/// Ref: BLUETOOTH CORE SPECIFICATION Version 6.0, Vol 3, Part G, Section 3.3.1.1 Characteristic Properties
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to propose this syntax for referencing Bluetooth core specification. This should help other devs cross reference things.

@nm17
Copy link
Author

nm17 commented Aug 31, 2024

Oh, and I forgot to cargo fmt. I will do it after, I just didn't want to screw something up.

@nm17
Copy link
Author

nm17 commented Aug 31, 2024

Next up I will try to document GattServer and stuff related to it. Then I will:

  • try to split the AttributeData read and write functionality into a separate trait
  • try to make ServiceBuilder::add_characteristic_internal public, but use the trait I added as a dyn type.

@nm17
Copy link
Author

nm17 commented Aug 31, 2024

Also, related issues: #98 #35

nm17 added 4 commits September 1, 2024 14:05
This doesn't give a big improvement in terms of LOC, but IMHO makes the code a lot more readable. I added docstrings where I could, but I might have missed some.

Also, the AttributeTable now uses heapless::Vec instead of what was before. Should have no impact on the performance, since the previous implementation was basically the same. This also means that we have an actual iterator, so we can use for loops instead of while-next loops.
@nm17
Copy link
Author

nm17 commented Sep 1, 2024

I have no idea how the error[E0597]: bat_level does not live long enough error came to be in example/apps/ble_bas_peripheral.rs. I would like some help with this. I don't think that I've yet changed anything in how the AttributeData works...

@HaoboGu
Copy link
Collaborator

HaoboGu commented Sep 2, 2024

I have no idea how the error[E0597]: bat_level does not live long enough error came to be in example/apps/ble_bas_peripheral.rs. I would like some help with this. I don't think that I've yet changed anything in how the AttributeData works...

I encountered similar error before, see #95 . But I'm not sure whether this is your case. There're some complex lifetime calculations.

Copy link
Member

@lulf lulf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've had a first look through it, but the general set of changes look good.

As for the lifetime issues, I think this is why I didn't use Vec originally, as it's lifetime would be shorter than the data that gets pushed to it which the compiler wouldn't accept. (Might be a way around it, maybe using some MaybeUninit trickery..)

#[repr(u8)]
/// An enum of possible characteristic properties
///
/// Ref: BLUETOOTH CORE SPECIFICATION Version 6.0, Vol 3, Part G, Section 3.3.1.1 Characteristic Properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to refer to the speak, please use something like this, which makes it a lot easier to lookup and check:

https://github.com/embassy-rs/bt-hci/blob/main/src/event/le.rs#L182

pub struct Attribute<'d> {
/// Attribute type UUID
///
/// Do not mistake it with Characteristic UUID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is entirely correct, every characteristic has a UUID, but there are different types, like the characteristic declaration or the characteristic value. This UUID can be either.

},
/// Last handle value in the group
///
/// When a [`ServiceBuilder`] finishes building, it returns the handle for the service, but also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentence ends prematurely.


#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep the uuid not Copy if possible, as it can easily explode memory usage if copied uncritically throughout the usage.

@lulf
Copy link
Member

lulf commented Apr 9, 2025

The attribute modules have changed a lot since this initial PR, and I think some of the original feature requests around making the attribute server optional (supported) as well as more control over how to handle/reject requests in attribute server is resolved. Is there a reason to keep this open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants