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
Bluetooth: audio: has: Add non-volatile settings #64164
Bluetooth: audio: has: Add non-volatile settings #64164
Conversation
ace3e84
to
f7ed5b5
Compare
Open questions:
Those questions relate to this PR, because if the answer is "Yes" to any of those questions then more information will be needed to be stored in NVM. |
I guess that depends on the semantic meaning of what "value has changed" is. I'm mostly in favor of saying yes it has changed, and no we should not store last value.
Same answer
Isn't this breaking spec compliancy? If a client subscribes to notifications, don't we have to send them regardless of whether they read the previous value? |
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.
Overall what this PR suggests, is that the services themselves will be responsible for storing and retrieving data from flash (similar to how GAP and GATT does). I don't think that is a bad idea, compared to providing the application the tools to do the same.
One thing we need to consider is that the structure of these settings may be fairly complex for some of the larger services, and they can easily be error prone, so we need to find a way to catch any errors that may be introduced with new updates, i.e. we need to be able to test these in CI
if (IS_ENABLED(CONFIG_BT_SETTINGS)) { | ||
bt_settings_delete("has", 0, addr); | ||
} |
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.
We don't really have documentation for the internal bt_settings
APIs; when setting id=0
does that mean delete for any IDs, or specifically for BT_ID_DEFAULT
(0)?
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.
I believe it deletes the one with the ID that was provided when the entry was added (0 in this case).
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.
Looks like id == 0
is a special case:
int bt_settings_delete(const char *key, uint8_t id, const bt_addr_le_t *addr)
{
int err;
char id_str[4];
char key_str[BT_SETTINGS_KEY_MAX];
if (addr) {
if (id) {
u8_to_dec(id_str, sizeof(id_str), id);
}
bt_settings_encode_key(key_str, sizeof(key_str), key, addr, (id ? id_str : NULL));
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.
Not necessarily something that needs to be fixed in this PR, but I think we should figure out and understand how the 0
ID value here is used in the bt_settings
, and preferably also replace all the literal constant values used by the stack with a #define
if it has special meaning.
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.
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.
@jhedberg Do you know the intention of the id
parameter in bt_settings
?
As I mentioned on host-meeting, as I see this, for all mentioned cases in worst case scenarios we will always have to send all notifications anyway. This means that we actually can't save memory, but instead just add usage in NVM. I would have to say that I'm tilting towards saying no, we don't want these optimizations. |
I think it is preferable to send the notification, which gives simpler code.
Same as for 1.
IMO the client subscribed to notifications, so we need to send the notification. |
f7ed5b5
to
bf22800
Compare
This adds non-volatile settings for the HAS Server. Those are needed to restore the client awareness of preset list entries exposed by the server. Based on the settings, the implementation determines how to notify the client about the HAS related characteristic value changes. Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
bf22800
to
996c749
Compare
|
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.
PR LGTM but I'd like to get a resolution of the ID for bt_settings
.
The literal value 0
should IMO not be used.
If it refers to the default ID, BT_ID_DEFAULT
should be used.
If it refers to some magical number in BT_SETTINGS
then we need to expose that as a value and use that.
This adds non-volatile settings for the HAS Server. Those are needed to
restore the client awareness of preset list entries exposed by the
server. Based on the settings, the implementation determines how to
notify the client about the HAS related characteristic value changes.
Depends on: #61980