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


C++ BLEDevice类代码示例

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


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

示例1: ble

/**
 * 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: BLEAttribute

BLECharacteristicImp::BLECharacteristicImp(const bt_uuid_t* uuid, 
                                           unsigned char properties,
                                           uint16_t handle,
                                           const BLEDevice& bledevice):
    BLEAttribute(uuid, BLETypeCharacteristic),
    _value_length(0),
    _value_buffer(NULL),
    _value_updated(false),
    _value_handle(handle),
    _cccd_handle(0),
    _attr_chrc_value(NULL),
    _attr_cccd(NULL),
    _subscribed(false),
    _reading(false),
    _ble_device()
{
    _value_size = BLE_MAX_ATTR_DATA_LEN;// Set as MAX value. TODO: long read/write need to twist
    _value = (unsigned char*)malloc(_value_size);

    // TODO: Enable when max value is not set.
    //    if (_value_size > BLE_MAX_ATTR_DATA_LEN)
    //    {
    //        _value_buffer = (unsigned char*)malloc(_value_size);
    //    }

    if (_value)
    {
      memset(_value, 0, _value_size);
    }
    else
    {
        errno = ENOMEM;
    }
    
    memset(&_ccc_cfg, 0, sizeof(_ccc_cfg));
    memset(&_ccc_value, 0, sizeof(_ccc_value));
    memset(&_gatt_chrc, 0, sizeof(_gatt_chrc));
    memset(&_sub_params, 0, sizeof(_sub_params));
    memset(&_discover_params, 0, sizeof(_discover_params));
    
    _ccc_value.cfg = &_ccc_cfg;
    _ccc_value.cfg_len = 1;
    if (BLERead & properties)
    {
        _gatt_chrc.properties |= BT_GATT_CHRC_READ;
    }
    if (BLEWrite & properties)
    {
        _gatt_chrc.properties |= BT_GATT_CHRC_WRITE;
    }
    if (BLEWriteWithoutResponse & properties)
    {
        _gatt_chrc.properties |= BT_GATT_CHRC_WRITE_WITHOUT_RESP;
    }
    if (BLENotify & properties)
    {
        _gatt_chrc.properties |= BT_GATT_CHRC_NOTIFY;
        _sub_params.value |= BT_GATT_CCC_NOTIFY;
    }
    if (BLEIndicate & properties)
    {
        _gatt_chrc.properties |= BT_GATT_CHRC_INDICATE;
        _sub_params.value |= BT_GATT_CCC_INDICATE;
    }
    _gatt_chrc.uuid = (bt_uuid_t*)this->bt_uuid();//&_characteristic_uuid;//this->uuid();
    memset(_event_handlers, 0, sizeof(_event_handlers));
    memset(_oldevent_handlers, 0, sizeof(_oldevent_handlers));
    
    _sub_params.notify = profile_notify_process;
        
    // Update BLE device object
    _ble_device.setAddress(*bledevice.bt_le_address());
    
    memset(&_descriptors_header, 0, sizeof(_descriptors_header));
}
开发者ID:calvinatintel,项目名称:corelibs-arduino101,代码行数:75,代码来源:BLECharacteristicImp.cpp

示例3: connected

bool BLEPeripheral::connected(void)
{
    BLEDevice centralBle = BLE.central();
    return centralBle.connected();
}
开发者ID:01org,项目名称:corelibs-arduino101,代码行数:5,代码来源:BLEPeripheral.cpp

示例4: main

int main() {

    ble.init();
    ble.onDisconnection(disconnectionCallback);
    ble.onDataWritten(onDataWritten);

    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName));
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */

    ble.startAdvertising();

    GattCharacteristic toggleCharacteristic(0x2222,
                                            &relayState,
                                            sizeof(relayState),
                                            sizeof(relayState),
                                            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);

    GattCharacteristic *charTable[] = {&toggleCharacteristic};
    GattService toggleService(0x2220, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
    ble.addService(toggleService);

    while (true) {
        if (rxPayloadUpdated)
        {
            relayPIN = rxPayload[0];
            rxPayloadUpdated = false;
        }
            
        ble.waitForEvent();
    }
}
开发者ID:3PG-h4ck3rs,项目名称:smartlet-firmware,代码行数:33,代码来源:main.cpp

示例5: disconnectionCallback

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    isConnected = 0;
    (*led1) = 0;

    ticker->detach();
    ticker->attach(periodicCallback, 0.4f); // blink LED every second

    ble.startAdvertising();
}
开发者ID:jxustlq,项目名称:bleController,代码行数:10,代码来源:main.cpp

示例6: disconnectionCallback

void disconnectionCallback(Gap::Handle_t handle,
                     Gap::DisconnectionReason_t disconnectReason)
{
  pc.printf(">>Disconnected\n");
  /*led1.write(0);
  led2.write(0);
  led3.write(0);
  led4.write(0);
  */

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

示例7: timerCallback

void timerCallback(void)
{
    DEBUG("start timer callback");
    sprintf(answer,"+.!");
    DEBUG("writing beatpulse \"%s\" with len %d to ble\n",answer,strlen(answer));
    int l = strlen(answer);
    for(int i = 0; i*20 < strlen(answer); i++) {
        int len = 20 < l ? 20 : l;
        ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t *)&answer[i*20], len);
        l -= 20;
    }
    ticker.detach();
}
开发者ID:SandraK82,项目名称:bm019-library,代码行数:13,代码来源:main.cpp

示例8: writeCharCallback

/**
 * Write callback
 * Called when a Gatt characteristic is written to by a central device
 */
void writeCharCallback(const GattWriteCallbackParams *params)
{
    /* Prepare to add header to transmit message to the MicroView */
    char *total;
    total = (char*)malloc(sizeof(char)*(params->len+1));
    strcat(total+1, (char*)params->data);
    total[params->len+1]= '\0';
    
    // Check to see what characteristic was written, by handle    
    /* If it's a standard message (comming from a notification) */
    if(params->handle == writeChar.getValueHandle()) {
        /* If only one byte is sent, we change the LED's state with its value*/
        if(params->len == 1)
            led1 = params->data[0];
        else {
            //pc.printf("\n\r Data received: length = %d, data = 0x",params->len);
            /* If the data received is equal to "ON" or "OFF", we modify the LED's state accordingly */
            if(strncmp((char*)params->data, "ON",2) == 0) {
                //pc.printf("LED ON");
                led1=1;
            } else if(strncmp((char*)params->data, "OFF",3) == 0) {
                //pc.printf("LED OFF");
                led1=0;
            }
            else {
                /* For each message, we toggle the LED's state */
                led1=!led1;
            }
        }
                
         /* Add the header specific to standard messages (not time sync) */
        total[0] = headerSms;
        /* Update the readChar characteristic with the value of writeChar */
        //ble.updateCharacteristicValue(readChar.getValueHandle(), params->data, params->len);
        ble.updateCharacteristicValue(readChar.getValueHandle(), (const uint8_t *)total, strlen(total)+1);
        /* Send the whole string, including the header, to the Microview */
        i2c_port.write(addr, total, strlen(total)+1);
    }
    /* If the message has been sent to the timeSync Gatt characteristic */
    else if(params->handle == timeSyncChar.getValueHandle()) {
        /* Set the corresponding header byte */
        total[0] = headerTime;
        /* Send the whole string, including the header, to the MicroView */
        i2c_port.write(addr, total, strlen(total)+1);
        led1 = !led1;
    }
    free(total);
}
开发者ID:nono313,项目名称:Smartwatch-on-blenano-and-microview,代码行数:52,代码来源:main.cpp

示例9: main

int main() {
  ble.init();
  ble.onConnection(onConnection);
  ble.onDisconnection(onDisconnection);
  ble.onDataWritten(onDataWritten);
 
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::BREDR_NOT_SUPPORTED);
  ble.setAdvertisingType(
      GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::SHORTENED_LOCAL_NAME,
      (const uint8_t *)NAME,
      sizeof(NAME) - 1);
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
      (const uint8_t *)UARTServiceUUID_reversed,
      sizeof(UARTServiceUUID_reversed));
  ble.accumulateScanResponse(
      GapAdvertisingData::SHORTENED_LOCAL_NAME,
      (const uint8_t *)NAME,
      sizeof(NAME) - 1);
  ble.accumulateScanResponse(
      GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
      (const uint8_t *)UARTServiceUUID_reversed,
      sizeof(UARTServiceUUID_reversed));

  ble.setDeviceName((const uint8_t *)NAME);
 
  ble.setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000));
  ble.startAdvertising();
 
  UARTService uartService(ble);
  uartServicePtr = &uartService;

  while (true) {
    ble.waitForEvent();
  }
}
开发者ID:sander,项目名称:mbed-code,代码行数:39,代码来源:main.cpp

示例10: main

int main(void)
{
    int ret = 0;
    uint8_t *pTemp;
    int len;
    int ch;

//    led1 = new DigitalOut(P0_4);
    led1 = new DigitalOut(LED2);
     ticker = new Ticker();
    ticker->attach(periodicCallback, 0.4f); // blink LED
    serialPort = new Serial(USBTX, USBRX);
//    serialPort = new Serial(P0_0, P0_1);
    (*led1) = 1;
    serialPort->baud(115200);
    serialPort->attach(&rxInterrupt,SerialBase::RxIrq);

//    serialPort->printf("Yeth sport\r\n");
    wait_ms(100);
    ret = bicProcessInit();
    if (ret)
    {
        serialPort->printf("bic process init failed:%d\r\n", ret);
        while(1);
    }
//    serialPort->printf("%s\r\n", __TIME__);
    ble.init();
    ble.onDisconnection(disconnectionCallback);
    ble.onConnection(connectionEventCallback);

    uart = new UARTService(ble);

    recordInit();

    /* setup advertising */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                     (const uint8_t *)"ysport", sizeof("ysport") - 1);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));

    ble.setAdvertisingInterval(50); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();

    while (true) {
        ble.waitForEvent();
        ch = EOF;
        if (ledToggle) {
            (*led1) = !(*led1);
            ledToggle = 0;
        }
        while(1)
        {
            ch = uart->_getc();
            if (ch == EOF)
                break;
            serialPort->putc(ch);
            bicReceiveChar((uint8_t)ch);
        }

        while(0 == bicProcessDispatchEvents()){
            wait_ms(20);
        }
    }
}
开发者ID:jxustlq,项目名称:bleController,代码行数:66,代码来源:main.cpp

示例11: onDataWritten

void onDataWritten(const GattWriteCallbackParams *params)
{
    if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) {
        uint16_t bytesRead = params->len;
        bool handled = false;


        for(int i = 0; !handled && i < bytesRead; i++) {
            switch(params->data[i]) {
                case '?': {
                    DEBUG("Handle ?\n");
                    switch(getStateBM019()) {
                        case BM019_STATE_UNKNOWN:
                            DEBUG("BM019 Status: unknown\n");
                            sprintf(answer,"+?:0!");
                            break;
                        case BM019_STATE_ANSWERING:
                            DEBUG("BM019 Status: answering\n");
                            sprintf(answer,"+?:1!");
                            break;
                        case BM019_STATE_PROTOCOL:
                            DEBUG("BM019 Status: protocol set\n");
                            sprintf(answer,"+?:2!");
                            break;
                        default:
                            sprintf(answer,"-?%d!",getStateBM019());
                            DEBUG("BM019 Status: forgotten state\n");
                    }
                    handled = true;
                }
                break;

                case 'b':
                case 'B':
                    DEBUG("Handling b\n");
                    if(i + 5 <= bytesRead) {
                        sprintf(answer,"+b!");
                        int adr = 0;
                        char b[3];
                        b[0] = params->data[i+4];
                        b[1] = params->data[i+5];
                        b[2] = 0;
                        sscanf(b,"%x",&adr);
                        DEBUG("beat in %d sec\n",adr);
                        ticker.attach(timerCallback, adr);
                        i+=5;
                        handled=true;
                    } else {
                        sprintf(answer,"-b!");
                        handled=true;
                    }

                    break;
                case 'h':
                case 'H': {
                    DEBUG("Handling h\n");
                    if(hybernateBM019()) {
                        sprintf(answer,"+h!");
                    } else {
                        DEBUG("BM019 did hybernate wake\n")
                        sprintf(answer,"-h!");
                    }
                    handled=true;

                }
                break;

                case 'w':
                case 'W': {
                    DEBUG("handle w\n")

                    if(wakeBM019(100)) {
                        DEBUG("BM019 did wake\n")
                        sprintf(answer,"+w!");
                    } else {
                        DEBUG("BM019 did NOT wake\n")
                        sprintf(answer,"-w!");
                    }
                    handled = true;
                }
                break;

                case 'i':
                case 'I': {
                    DEBUG("handle i\n");
                    BM019_IDN idn;
                    if(idnBM019(&idn)) {
                        sprintf(answer,"+i:");
                        int i;
                        for(i = 0; i < 13; i++) {
                            sprintf(&answer[strlen(answer)],"%x",idn.deviceID[i]);
                        }
                        sprintf(&answer[strlen(answer)],":");
                        sprintf(&answer[strlen(answer)],"%x%x!",idn.romCRC[0],idn.romCRC[1]);
                        DEBUG("answered: %s",answer);
                    } else {
                        DEBUG("BM019 failed idn\n")
                        sprintf(answer,"-i!");
                    }

//.........这里部分代码省略.........
开发者ID:SandraK82,项目名称:bm019-library,代码行数:101,代码来源:main.cpp

示例12: disconnectionCallback

void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
    DEBUG("Disconnected!\n\r");
    DEBUG("Restarting the advertising process\n\r");
    ble.startAdvertising();
}
开发者ID:SandraK82,项目名称:bm019-library,代码行数:6,代码来源:main.cpp

示例13: tick

void tick(void)
{
    bool send_threshold = threshold_update;
    int last_compare = current_compare;
    current_input = sensor.read();

    if (threshold_update) {
        threshold_update = 0;

        input_threshold = (single_click_input + double_click_input) / 2.0;
        invert_output = (double_click_input < single_click_input);

        force_update = true;

        DEBUG("threshold: %f\n\r", input_threshold);
    }


    if (0 == current_compare && current_input > input_threshold) {
        float extra_input = sensor.read();
        if (extra_input > input_threshold) {
            current_compare = 1;
        }
    } else if (1 == current_compare && current_input < input_threshold) {
        float extra_input = sensor.read();
        if (extra_input < input_threshold) {
            current_compare = 0;
        }
    }

    current_output = current_compare;
    if ((last_compare != current_compare) || force_update) {
        if (invert_output) {
            current_output = 1 - current_compare;
        }

        actuator = current_output;
    }

    DEBUG("in: %f, out: %d, invert: %d\n\r", current_input, current_output, invert_output);

    int txPayloadLength;
    if (send_threshold) {
        txPayloadLength = snprintf((char*)txPayload, 20, "%c %d", invert_output ? '<' : '>', (int)(input_threshold * 10000));
    } else {
        txPayloadLength = snprintf((char*)txPayload, 20, "* %d %d", (int)(current_input * 10000), current_output);

    }

    ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), txPayload, txPayloadLength);

    if (blue_led_time_to_off) {
        blue_led_time_to_off--;
        if (blue_led_blink) {
            blue = (blue_led_time_to_off & 1) ? LED_ON : LED_OFF;
        }

        if (0 == blue_led_time_to_off) {
            blue_led_blink = false;
            blue = LED_OFF;
        }
    }

    if (green_led_time_to_off) {
        green_led_time_to_off--;
        if (green_led_blink) {
            green = (green_led_time_to_off & 1) ? LED_ON : LED_OFF;
        }

        if (0 == green_led_time_to_off) {
            green_led_blink = false;
            green = LED_OFF;
        }
    }
}
开发者ID:2thetop,项目名称:mbed_ble,代码行数:75,代码来源:main.cpp

示例14: disconnectionCallback

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    ble.startAdvertising();
}
开发者ID:3PG-h4ck3rs,项目名称:smartlet-firmware,代码行数:4,代码来源:main.cpp

示例15: onDisconnection

void onDisconnection(const Gap::DisconnectionCallbackParams_t *params) {
  echoer.detach();
  ble.startAdvertising();
}
开发者ID:sander,项目名称:mbed-code,代码行数:4,代码来源:main.cpp


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