Skip to content

Add example exercising the GattClient API. #111

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

Merged
merged 9 commits into from
Jul 18, 2018

Conversation

pan-
Copy link
Member

@pan- pan- commented Oct 31, 2017

The example demonstrate uses of:

  • Service and characteristics discovery.
  • Descriptor discovery
  • Attribute read
  • Attribute write
  • CCCD subscription
  • Handling of server initiated event

TODO

Improve the documentation

@pan-
Copy link
Member Author

pan- commented Oct 31, 2017

@apalmieriGH @marcbonnici Could you review the code of this example.

It doesn't work on NRF based targets due to a timing issue and it works on Nucleo targets with the help of this patch: ARMmbed/ble-x-nucleo-idb0xa1#33

Copy link
Contributor

@marcbonnici marcbonnici left a comment

Choose a reason for hiding this comment

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

The code itself looks fine to me.

@@ -0,0 +1,32 @@
# BLE Gatt Client example

This application demonstrate detailed uses of the GattClient APIs.
Copy link
Contributor

Choose a reason for hiding this comment

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

"demonstrate" -> "demonstrates"


This application demonstrate detailed uses of the GattClient APIs.

When the application is started it advertise itself to its environment with the
Copy link
Contributor

Choose a reason for hiding this comment

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

"advertise" -> "advertises"

This application demonstrate detailed uses of the GattClient APIs.

When the application is started it advertise itself to its environment with the
device name `GattClient`. Once you connected the device with your mobile phone,
Copy link
Contributor

Choose a reason for hiding this comment

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

"you connected the" -> "you have connected to the" or "you connect to the" ?

discovered and subscribes to the characteristics emitting notifications or
indications.

The device print the value of any indication or notification received from the
Copy link
Contributor

Choose a reason for hiding this comment

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

"print" -> "prints"


## Requirements

You may us a generic BLE scanners:
Copy link
Contributor

Choose a reason for hiding this comment

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

"us" -> "use"
"scanners" -> "scanner"

*/
void when_service_discovered(const DiscoveredService *discovered_service)
{
// print informations of the service discovered
Copy link
Contributor

Choose a reason for hiding this comment

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

"informations" -> "information"

/**
* Handle characteristics discovered.
*
* The GattClient invoke this function when a characteristic has been
Copy link
Contributor

Choose a reason for hiding this comment

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

"invoke" -> "invokes"

/**
* Handle termination of the service and characteristic discovery process.
*
* The GattClient invoke this function when a the service and characteristic
Copy link
Contributor

Choose a reason for hiding this comment

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

"invoke" -> "invokes"
Remove "a" from "a the service"

};

/**
* Handle initialization adn shutdown of the BLE Instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

"adn" -> "and"

}

/**
* Stop the gatt client process when a the device is disconnected then
Copy link
Contributor

Choose a reason for hiding this comment

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

"when a the device disconnected" -> "when a device disconnects"

@pan-
Copy link
Member Author

pan- commented Nov 1, 2017

@marcbonnici Thanks for the review; I have addressed your comments.

@apalmieriGH
Copy link
Collaborator

@pan- very useful example, it is good for me.

@pan-
Copy link
Member Author

pan- commented Nov 6, 2017

@nvlsianpu There is some faillure on NRF targets with that example; the issue seems located in the client class. Could you look after those ?

@pan-
Copy link
Member Author

pan- commented Nov 23, 2017

@paul-szczepanek-arm Could you review this example ?

*/
void process_next_characteristic(void)
{
if (_it == 0) {
Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm Nov 23, 2017

Choose a reason for hiding this comment

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

if (_it == NULL) {
alternatively reverse order of the if else to avoid comparing to NULL, I'm just complaining about using 0 for pointer comparison

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree we have to be consistent; even if the meaning is exactly the same in C++ (NULL is an integer that evaluate to 0).

However we do not use the yoda notation in our code.

Choose a reason for hiding this comment

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

I didn't mean reverse the order of the variables in the if I meant reverse the if statements:
if (_it) {
_it = _it->next;
} else {
_it = _characteristics;
}
Yoda either I do not like.


events::EventQueue &_event_queue;
BLE &_ble_interface;
GattClientProcess gatt_client_process;

Choose a reason for hiding this comment

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

missing _ prefix from private var

return;
}

gap.setAdvertisingParams(make_advertising_params());

Choose a reason for hiding this comment

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

I'm getting mixed messages here, the API doc says: "It would be uncommon for this API to be used directly; there are other APIs to tweak advertisement parameters individually" yet we use it in examples?

Copy link
Member Author

Choose a reason for hiding this comment

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

That comment has been removed from the Gap class; unfortunatelly it is still present in the BLE class but the member function is deprecated.

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm left a comment

Choose a reason for hiding this comment

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

review concluded offline with agreement to separate/hide the gap part

@pan-
Copy link
Member Author

pan- commented Nov 28, 2017

@nvlsianpu Any update ?

@pan-
Copy link
Member Author

pan- commented Dec 4, 2017

@paul-szczepanek-arm I've updated the PR accordingly to your comments; Could you review the changes ?

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm left a comment

Choose a reason for hiding this comment

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

you appear to have reverted a few minor fixes in the last commit (diff with last)

}

/**
* Stop the gatt client process when a the device is disconnected then
Copy link
Member

Choose a reason for hiding this comment

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

"a the" -> "the"

@pan-
Copy link
Member Author

pan- commented Jun 25, 2018

I think this is good to go; @paul-szczepanek-arm @donatieng What do you think ?

@paul-szczepanek-arm
Copy link
Member

merge

@donatieng donatieng merged commit 94ec493 into ARMmbed:master Jul 18, 2018
pan- pushed a commit to pan-/mbed-os-example-ble that referenced this pull request Sep 4, 2018
Add example exercising the GattClient API.
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.

5 participants