-
Notifications
You must be signed in to change notification settings - Fork 23
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
Automatically calculate attribute table size #176
Open
petekubiak
wants to merge
9
commits into
embassy-rs:main
Choose a base branch
from
dysonltd:automatically-calculate-attribute-table-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Automatically calculate attribute table size #176
petekubiak
wants to merge
9
commits into
embassy-rs:main
from
dysonltd:automatically-calculate-attribute-table-size
Conversation
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
/test |
jamessizeland
approved these changes
Nov 22, 2024
host-macros/src/server.rs
Outdated
let buffer = meta.value().map_err(|_| Error::custom("attribute_data_size msut be followed by `= [size]`. e.g. attribute_data_size = 32".to_string()))?; | ||
self.attribute_data_size = Some(buffer.parse()?); | ||
"attribute_table_size" => { | ||
let buffer = meta.value().map_err(|_| Error::custom("attribute_table_size msut be followed by `= [size]`. e.g. attribute_table_size = 32".to_string()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo there from older code "msut"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye
Beautiful, and very nice code comments. |
/test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #173.
This PR implements automatic sizing of the attribute table when using the
gatt_server
macro.The number of attributes for each service is calculated in the
gatt_service
macro, and this is then summed up by thegatt_server
macro to determine the size of the table.The option to override this and manually set the attribute table size still exists.
I have also renamed the attribute macro argument to
attribute_table_size
as this more accurately reflects the value being set.Topic for discussion
I have implemented a static assertion to throw a compile-time error if the table size is overridden with a value too small to hold the calculated number of attributes. The advantage of this is of course that the user will be notified before flashing their device, meaning that they do not need to be monitoring the device's trace to see the issue.
However, I cannot use formatted strings in a "constant assertion", so the compile-time error looks like this:
The alternative would be to use a normal
assert!
which would be evaluated at run-time. This would allow a formatted message of something like:but of course this would only be visible in the device's trace.
I personally lean toward the static assertion, but I'd be keen to hear other opinions on this!