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

Add Gaming Audio Profile #606

Merged
merged 3 commits into from
Dec 18, 2024
Merged

Add Gaming Audio Profile #606

merged 3 commits into from
Dec 18, 2024

Conversation

wpiet
Copy link
Contributor

@wpiet wpiet commented Nov 29, 2024

Adds initial support for Gaming Audio Service.

# -----------------------------------------------------------------------------
# Classes
# -----------------------------------------------------------------------------
class GmapRole(OpenIntEnum):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be an enum.IntFlag type, since flags can be combined.
The same applies to UggFeatures, UtgFeatures, BgsFeatures and BgrFeatures below.

)
characteristics.append(self.gmap_role)

if ugg_features:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should check for ugg_features is not None, because you could pass a 0-valued ugg_features parameter, which would evaluate to False in the test, but you still want a characteristic to exist.
The same applies to the other characteristics below.

uuid=GATT_UGG_FEATURES_CHARACTERISTIC,
properties=Characteristic.Properties.READ,
permissions=Characteristic.Permissions.READABLE,
value=struct.pack('<B', ugg_features),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no need for < in the struct pattern, since there's no byte order for just one byte.

Adds initial support for `Gaming Audio Service`.
characteristics.append(self.gmap_role)

if ugg_features is not None:
self.ugg_features = Characteristic(
Copy link
Collaborator

Choose a reason for hiding this comment

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

You still need to set a value when parameters are None, otherwise the attribute will be missing.

Copy link
Contributor Author

@wpiet wpiet Dec 3, 2024

Choose a reason for hiding this comment

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

Even if in given configuration a characteristic should not exist in the service?

As per the GMAP specification, section 4.7 Service characteristics, Table 4.1. GMAS characteristics, depending on the GMAP Role the other 4 characteristics are either mandatory or excluded, thus I added the role check before adding those conditional characteristics.

Copy link
Collaborator

@zxzxwu zxzxwu Dec 4, 2024

Choose a reason for hiding this comment

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

Correct. It's not really related to Bluetooth, but from a readability perspective, you should always set a value for any attribute, especially when you annotate them as Optional, people will expect there is such an attribute even they are None.
Consider if you are using Java, such a pattern will probably be warned that you may access a member without initialization.

Copy link

Choose a reason for hiding this comment

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

Hi @zxzxwu , that would mean that we will have characteristics exposed which are not really needed.

Also from the testing point of view, I see value in having an option to create invalid test device which is missing some characteristics to verify proper error handling on the DUT.

Does it makes sense?

We also had an idea that some of the characteristic could be created as per spec (depends on the role) but in fact as it is now gives good test flexibility.

Other options would be to extend this constructor with a bool's which would tell if given characteristic should be created but this seems to be overkill.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to create a characteristic. What is needed here is

Suggested change
self.ugg_features = Characteristic(
self.ugg_features = Characteristic(
...
else:
self.ugg_features = None

Or set it like

class GamingAudioService(TemplateService):
    UUID = GATT_GAMING_AUDIO_SERVICE

    gmap_role: Characteristic
    ugg_features: Optional[Characteristic] = None
    ugt_features: Optional[Characteristic] = None
    bgs_features: Optional[Characteristic] = None
    bgr_features: Optional[Characteristic] = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, now it is clear. I added the latter suggestion.

wpiet added 2 commits December 4, 2024 12:57
Only adds a characteristic if the corresponding role has been set
Sets default values for characteristics if not specified explicitly
@barbibulle barbibulle merged commit 62e4670 into google:main Dec 18, 2024
56 of 57 checks passed
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