Hello,
Totally as per requirement, there should be 5 gatt services added to Kw36 gatt db out of which 4 gatt services i need to add statically to gatt database and one service i need to add dynamically to gatt database, can i do like this in kw36, if possible, please explain the procedure.
I request to answer my query asap as i am struck with my implementation.
Please get back if you didnt understand my query. Thanks.
Regards,
Sai Kalyana Raman
Sorry I don't understand your question. What do you mean by "static" and "dynamic"?
I thought all attributes (i.e. service, characteristic etc.) should be pre-defined in a header file.
Hi xiangli,
As you mentioned, we can add attributes in a predefined header file in gatt_db.h file using the macros PRIMARY_SERVICE,etc, this i mean/refer as static method and what i mean by dynamic method is to add attribute using "GattDbDynamic_AddPrimaryServiceDeclaration, GattDbDynamic_AddSecondaryServiceDeclaration, etc" API's.
My requirement is like some of the attributes i want to predefine in gatt_db.h and some of the attributes i want to add using GattDbDynamic_AddPrimaryServiceDeclaration,GattDbDynamic_AddCharacteristicDeclarationAndValue,etc.
Please get back if you didnt get me. I have attached the application developer guide which i have referred(please refer section 7)
Many thanks in advance.
Regards,
Sai Kalyana Raman
Thanks Sai Kalyana Raman, now I understand your question.
I did a quick look. As in the doc you pointed out, Section 7.2, the 1st sentence:
"To define a GATT Database at run-time, the gGattDbDynamic_d macro must be defined in app_preinclude.h with the value equal to 1."
And if we search the macro gGattDbDynamic_d in file gatt_database.c, the codes look like:
#if !gGattDbDynamic_d ... ... /*! Declare the Attribute database */ gattDbAttribute_t static_gattDatabase[] = { #include "gatt_decl_x.h" }; gattDbAttribute_t* gattDatabase = static_gattDatabase; ... ... #else gattDbAttribute_t* gattDatabase; uint16_t gGattDbAttributeCount_c; #endif
So this looks clear to me the Static and Dynamic should be mutual exclusive. At least the code is designed in such way.
If the macro is defined as "1" dynamic, the application needs to allocate an array and assign the pointer to gattDatabase, and count value to gGattDbAttributeCount_c
If the macro is defined as "0" static, the BLE static will allocate a static_gattDatabase[] for you.
I hope this answered your question.
If there is a use case where a dynamic GATT database must be used, why not try to config all your 5x services in the dynamic way?
What I would do is:
(1) Create dynamic GATT database with X services.
(2) Make BLE connection, and do a service discovery
(3) Do the BLE thing as needed.
(4) If we want to update the GATT database structure, I'd disconnect first.
(5) Update dynamically (i.e. in run-time) GATT database with Y services.
(6) Reconnect, and make another service discovery, this is needed so the GATT client knows your database has been changed.
(7) Continue with updated GATT database.
Kind regards,
Xiang