当前位置: 首页>>代码示例>>C++>>正文


C++ BLEDevice::gattServer方法代码示例

本文整理汇总了C++中BLEDevice::gattServer方法的典型用法代码示例。如果您正苦于以下问题:C++ BLEDevice::gattServer方法的具体用法?C++ BLEDevice::gattServer怎么用?C++ BLEDevice::gattServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BLEDevice的用法示例。


在下文中一共展示了BLEDevice::gattServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rxCharacteristic

/**
 * Constructor for the UARTService.
 * @param _ble an instance of BLEDevice
 * @param rxBufferSize the size of the rxBuffer
 * @param txBufferSize the size of the txBuffer
 *
 * @note defaults to 20
 */
MicroBitUARTService::MicroBitUARTService(BLEDevice &_ble, uint8_t rxBufferSize, uint8_t txBufferSize) : ble(_ble)
{
    rxBufferSize += 1;
    txBufferSize += 1;

    txBuffer = (uint8_t *)malloc(txBufferSize);
    rxBuffer = (uint8_t *)malloc(rxBufferSize);

    rxBufferHead = 0;
    rxBufferTail = 0;
    this->rxBufferSize = rxBufferSize;

    txBufferHead = 0;
    txBufferTail = 0;
    this->txBufferSize = txBufferSize;

    GattCharacteristic rxCharacteristic(UARTServiceRXCharacteristicUUID, rxBuffer, 1, rxBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);

    txCharacteristic = new GattCharacteristic(UARTServiceTXCharacteristicUUID, txBuffer, 1, txBufferSize, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE);

    GattCharacteristic *charTable[] = {txCharacteristic, &rxCharacteristic};

    GattService uartService(UARTServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));

    _ble.addService(uartService);

    this->rxCharacteristicHandle = rxCharacteristic.getValueAttribute().getHandle();

    _ble.gattServer().onDataWritten(this, &MicroBitUARTService::onDataWritten);
    _ble.gattServer().onConfirmationReceived(on_confirmation);
}
开发者ID:CareyJWilliams,项目名称:microbit-dal,代码行数:39,代码来源:MicroBitUARTService.cpp

示例2: main

int main(){
    //pc.wait(1);
    gatt_characteristics[CHARACTERISTIC_LED] =
        new GattCharacteristic(
            nRF51_GATT_CHAR_LED,
            &gatt_char_value[CHARACTERISTIC_LED], 1, 1,
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE |
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);

    gatt_service = new GattService(nRF51_GATT_SERVICE, gatt_characteristics, CHARACTERISTIC_COUNT);
    //Initialize BLE Device
    ble.init();

    ble.setDeviceName((uint8_t *)DEVICE_NAME);

    // configure our advertising type, payload and interval00
    ble.accumulateAdvertisingPayload(
          GapAdvertisingData::BREDR_NOT_SUPPORTED |
          GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(
          GapAdvertisingData::COMPLETE_LOCAL_NAME,
          (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));

    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(160); // 100ms

    /*
    led1.write(1);
    led3.write(1);
    led2.write(1);
    led4.write(1);
    */
    for(int i=0; i<10; i++)
        pc.printf("Hello World\n");
    ble.onConnection((Gap::ConnectionEventCallback_t)connectionCallback);
    ble.onDisconnection(disconnectionCallback);
    ble.gattServer().onDataWritten(onDataWritten);

    ble.addService(*gatt_service);

    ble.startAdvertising();

    /* Adding below for scanning */
        ble.setScanParams(500 /* scan interval */, 200 /* scan window */);
        ble.startScan(advertisementCallback);
    /**END OF PART FOR SCANNING**/

    for (;;)
    {
      ble.waitForEvent();
    }
}
开发者ID:VanshKhanna,项目名称:android-nrf-mbed,代码行数:53,代码来源:main.cpp


注:本文中的BLEDevice::gattServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。