Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on the Attribute module #99

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nm17
Copy link

@nm17 nm17 commented Aug 31, 2024

Currently a draft, any comments are welcome!

@@ -24,45 +24,85 @@ pub const GENERIC_ATTRIBUTE_UUID16: Uuid = Uuid::Uuid16(0x1801u16.to_le_bytes())

#[derive(Debug, Clone, Copy)]
#[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

host/src/attribute.rs Outdated Show resolved Hide resolved
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

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..)

.gitignore Show resolved Hide resolved
#[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.

host/src/attribute/mod.rs Show resolved Hide resolved
},
/// 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.

@@ -1,7 +1,7 @@
use crate::codec::{Decode, Encode, Error, Type};

#[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.

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