1

我正在设计一款充当 GATT 服务器的设备,以大约 33Bps 的速度传输五个特征。我已经建立了 GATT 服务并设置了我的特性,虽然可以读取它们,但通知不会发送到连接的客户端。

我为我的服务创建了一个自定义类 - 定义摘要如下。

public:
    GattService() : 
        _raw_char(
            "236fd558-ed37-4d21-a791-2119aede27bb",0,
            sizeof(Payload),
            sizeof(Payload),
            (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) ,
            NULL,
            0,
            false),
        _server(NULL),
        _ble(NULL),
        _event_queue(NULL),
        _gatt_service(
            "4f815c30-e3ff-4c1a-a81d-339698ced987",
             _raw_characteristic,
            1
         )

    void start(BLE &ble_interface, events::EventQueue &event_queue)
    {

        _ble = &ble_interface;
        _server = &ble_interface.gattServer();
        _event_queue = &event_queue;

        _server->addService(_gatt_service);

        _server->onDataSent(as_cb(&Self::when_data_sent));
        _server->onDataRead(as_cb(&Self::when_data_read));

        _server->onUpdatesEnabled(as_cb(&Self::when_update_enabled));
        _server->onUpdatesDisabled(as_cb(&Self::when_update_disabled));
        _server->onConfirmationReceived(as_cb(&Self::when_confirmation_received));

    }

     void setValue(Payload payload){

        bool enabled = false;
        _server->areUpdatesEnabled(_raw_char, &enabled);
        if(enabled){
            _server->write(_raw_char.getValueHandle(), (uint8_t*)&payload, sizeof(payload), false);
        }
    }

private:
     GattCharacteristic _raw_char;
     GattService _gatt_service;
     GattServer* _server;
     BLE* _ble;
     events::EventQueue *_event_queue;

通过调试,我知道 AttsHandleValueNtf() 正在按预期调用,但是根本没有发送通知,客户端也没有收到更新的值。

4

0 回答 0