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


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

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


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

示例1: 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

示例2: 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

示例3: onDataWritten


//.........这里部分代码省略.........
                        for(int i = 0; i < 8; i++) {
                            sprintf(&answer[strlen(answer)],"%02x",tag.uid[i]);
                        }
                        sprintf(&answer[strlen(answer)],"!");
                    } else {
                        DEBUG("BM019 NOT answered inventory\n");
                        sprintf(answer,"-t!");
                    }
                    handled = true;
                }
                break;

                case 'd':
                case 'D': {
                    DEBUG("handle d\n");
                    if(i + 5 <= bytesRead) {
                        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("read from %#04x\n",adr);
                        i+=5;
                        uint8_t rb[256];
                        int l = readBM019(adr,rb,256);
                        if(l>0) {
                            DEBUG("BM019 answered read\n");
                            sprintf(answer,"+d:");
                            for(int i = 0; i < l; i++) {
                                sprintf(&answer[strlen(answer)],"%02x",rb[i]);
                            }
                            sprintf(&answer[strlen(answer)],"!");
                        } else {
                            DEBUG("BM019 NOT answered read\n");
                            sprintf(answer,"-d!");
                        }
                    } else {
                        DEBUG("BM019 NOT answered read, no adr given\n");
                        sprintf(answer,"-d!");
                    }
                    handled = true;
                }
                break;

                case 'm':
                case 'M': {
                    DEBUG("handle multi d\n");
                    if(i + 10 <= bytesRead) {
                        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);

                        int count = 0;
                        b[0] = params->data[i+9];
                        b[1] = params->data[i+10];
                        b[2] = 0;
                        sscanf(b,"%x",&count);
                        DEBUG("read from %#04x for %d\n",adr,count);
                        i+=10;
                        uint8_t rb[256];
                        int l = readMultiBM019(adr,count,rb,256);
                        if(l>0) {
                            DEBUG("BM019 answered multi\n");
                            sprintf(answer,"+m:");
                            for(int i = 0; i < l; i++) {
                                sprintf(&answer[strlen(answer)],"%02x",rb[i]);
                            }
                            sprintf(&answer[strlen(answer)],"!");
                        } else {
                            DEBUG("BM019 NOT answered multi\n");
                            sprintf(answer,"-m!");
                        }
                    } else {
                        DEBUG("BM019 NOT answered read, no adr&count given\n");
                        sprintf(answer,"-m!");
                    }
                    handled = true;
                }
                break;
            }
        }

        if(handled) {
            DEBUG("writing \"%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;
            }

        } else {
            DEBUG("received %u bytes.. nothing handled.. echo\n", bytesRead);
            ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
        }
    }
开发者ID:SandraK82,项目名称:bm019-library,代码行数:101,代码来源:main.cpp

示例4: echo

void echo() {
  ble.updateCharacteristicValue(
      uartServicePtr->getRXCharacteristicHandle(),
      data, len);
}
开发者ID:sander,项目名称:mbed-code,代码行数:5,代码来源:main.cpp

示例5: 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


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