virtual LGATTServiceInfo * onLoadService( int32_t index ) = 0;
virtual LGATTServiceInfo * onLoadService( int32_t index ) = 0;
You need to override this method in order to define a Bluetooth GATT service. This function is called immediately upon calling LGATTServer.begin(), and it must return an array of LGATTServiceInfo beginning with the type TYPE_SERVICE, followed by elements of TYPE_CHARACTERISTIC or TYPE_DESCRIPTOR. Also, it must be terminated with an element of TYPE_END.
|
Parameters |
Description |
|
int32_t index |
The index of this object in LGATTServer.begin(). For example, LGATTServer.begin(2, &serviceA, &serviceB) the loadService() of serviceA will receive 0 as index, while serviceB receives 1 as index. |
Pointer pointing to the beginning of an array of LGATTServiceInfo. This array must be valid until LGATTServerClass.end() is called.
Returning NULL will fail LGATTServer.begin().
static LGATTServiceInfo g_my_gatt_service[] = { {TYPE_SERVICE, "6e400001-b5a3-f393-e0a9-e50e24dcca9e", TRUE, 0, 0, 0}, {TYPE_CHARACTERISTIC, "6e400002-b5a3-f393-e0a9-e50e24dcca9e", FALSE, VM_GATT_CHAR_PROP_WRITE, VM_GATT_PERM_WRITE, 0}, {TYPE_CHARACTERISTIC, "6e400003-b5a3-f393-e0a9-e50e24dcca9e", FALSE, VM_GATT_CHAR_PROP_NOTIFY | VM_GATT_CHAR_PROP_INDICATE, VM_GATT_PERM_READ, 0}, {TYPE_DESCRIPTOR, "00002902-0000-1000-8000-00805f9b34fb", FALSE, VM_GATT_CHAR_PROP_NOTIFY, VM_GATT_PERM_READ | VM_GATT_PERM_WRITE, 0}, {TYPE_END, 0, 0, 0, 0, 0} }; LGATTServiceInfo *LGATTUT::loadService(int32_t index) { return g_my_gatt_service; }
This defines a service of UUID 6e400001-b5a3-f393-e0a9-e50e24dcca9e with two characteristics and one descriptor.
This array must be valid until LGATTServerClass.end() is called, therefore you should avoid getting a return of an array declared in the local scope.
It is recommended to return a globally, statically defined array like the example above.
LGATTServer.h