2015-10-25 3 views
0

J'essaie d'ajouter des descriptions d'utilisateur caractéristiques à mon service BLE GATT personnalisé, en utilisant le mbed API. Mon travail a jusqu'à présent été basé sur la structure du code this. Cependant, j'aimerais ajouter des noms à ces caractéristiques. Il n'y a pas beaucoup d'informations que je pourrais trouver sur la façon de le faire. Cependant, ci-dessous est un commentaire d'un forum, indiquant comment le faire.Ajout de la description d'utilisateur caractéristique au service GATT C++ BLE GATT

The constructor for GattCharacteristic() takes an array of GattAttribtues as an optional argument. You can populate your User-Description into a GattAttribute and pass it along to the Characteristic. 

Jusqu'ici, j'ai cette structure qui configure mes caractéristiques.

uint16_t newServiceUUID   = 0xA000; 
uint16_t PercentageUUID   = 0xA001; 
uint16_t TimeUUID    = 0xA002; 
uint16_t UseProfileUUID   = 0xA003; 

const static char  DEVICE_NAME[]  = "Device"; // Device name 
static const uint16_t uuid16_list[]  = {0xFFF};  

static uint8_t percentageValue[10] = {0}; 
WriteOnlyArrayGattCharacteristic<uint8_t, 
     sizeof(percentageValue)> percentageChar(PercentageUUID, percentageValue); 

static uint8_t timeValue[10] = {0}; 
ReadWriteArrayGattCharacteristic<uint8_t, 
     sizeof(timeValue)> timeChar(TimeUUID, timeValue); 

static uint8_t UseProfileValue[10] = {0}; 
WriteOnlyArrayGattCharacteristic<uint8_t, 
     sizeof(UseProfileValue)> UseProfileChar(UseProfileUUID, UseProfileValue); 

// Set up custom service 

GattCharacteristic *characteristics[] = {&percentageChar, &timeChar, &UseProfileChar}; 
GattService  newService(newServiceUUID, characteristics, sizeof(characteristics)/sizeof(GattCharacteristic *)); 

Comment ajouter les descriptions à ces 3 caractéristiques?

EDIT

J'ai maintenant:

static uint8_t percentageValue[10] = {0}; 
GattAttribute descr(BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)"Percentage", strlen("Percentage")); 
WriteOnlyArrayGattCharacteristic<uint8_t, 
     sizeof(percentageValue)> percentageChar(PercentageUUID, 
               percentageValue, 
               GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES, 
               &descr, 
               1); 

Il jette un Error: No instance of constructor "WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>::WriteOnlyArrayGattCharacteristic [with T=std::uint8_t, NUM_ELEMENTS=10U]" matches the argument list in "main.cpp" sur la ligne "de taille".

Répondre

1

Consultez l'API de classe Characteristic: https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/file/d494ad3e87bd/ble/GattCharacteristic.h:

template <typename T> 
class WriteOnlyGattCharacteristic : public GattCharacteristic { 
public: 
    WriteOnlyGattCharacteristic<T>(const UUID  &uuid, 
            T    *valuePtr, 
            uint8_t  additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, 
            GattAttribute *descriptors[]  = NULL, 
            unsigned  numDescriptors  = 0) : 
     GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T), 
          BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) { 
     /* empty */ 
    } 
}; 

Descripteurs attachés à une caractéristique ont à être passé comme quatrième paramètre (GattAttribute *descriptors[], par défaut, il est NULL, ce qui signifie la caractéristique n'a pas descripteur) du *ArrayGattCharacteristic objets que vous créez. Ils sont GattAttribute, à créer avant vos caractéristiques et transmis à la création.

Peut-être que cela pourrait fonctionner pour ajouter un descripteur (non testé ), les tableaux doivent être utilisés pour ajouter plus (comme vous l'avez fait pour les caractéristiques):

static uint8_t percentageValue[10] = {0}; 
GattAttribute nameDescr(BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)"Percentage", strlen("Percentage")); 
GattAttribute *descriptors[] = {&nameDescr}; 
WriteOnlyArrayGattCharacteristic<uint8_t,sizeof(percentageValue)> 
     percentageChar(PercentageUUID, 
         percentageValue, 
         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES, 
         descriptors, 
         sizeof(descriptors)/sizeof(GattAttribute*)); 

Hope this helps (encore une fois ;-))

+0

Merci, la première ligne renvoie cette erreur: Erreur: 'Aucune instance de constructeur" WriteOnlyArrayGattCharacteristic :: WriteOnlyArrayGattCharacteristic [avec T = std :: uint8_t, NUM_ELEMENTS = 10U] "correspond à la liste des arguments dans" main .cpp "' –

+0

Essayez '&& descr' car cela nécessite un pointeur vers le tableau. Il serait plus sûr/plus agréable de déclarer un tableau réel de 'GattAttribute', comme vous l'avez fait pour les caractéristiques. – jpo38

+0

qui déclenche l'erreur du compilateur: 230 - Erreur (s) de syntaxe dans Assembly. –