本文整理汇总了C++中BLE类的典型用法代码示例。如果您正苦于以下问题:C++ BLE类的具体用法?C++ BLE怎么用?C++ BLE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BLE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bleInitComplete
/**
* Callback triggered when the ble initialization process has finished
*/
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
BLE& ble = params->ble;
ble_error_t error = params->error;
if (error != BLE_ERROR_NONE) {
// in case of error, forward the error handling to onBleInitError
onBleInitError(ble, error);
return;
}
// ensure that it is the default instance of BLE
if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
return;
}
/**
* The Beacon payload has the following composition:
* 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
* Major/Minor = 0x1122 / 0x3344
* Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
*
* Note: please remember to calibrate your beacons TX Power for more accurate results.
*/
const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61};
uint16_t majorNumber = 1122;
uint16_t minorNumber = 3344;
uint16_t txPower = 0xC8;
iBeacon ibeacon(ble, uuid, majorNumber, minorNumber, txPower);
ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
ble.gap().startAdvertising();
}
示例2: initializeSecurity
void initializeSecurity(BLE &ble)
{
bool enableBonding = true;
bool requireMITM = HID_SECURITY_REQUIRE_MITM;
ble.securityManager().onSecuritySetupInitiated(securitySetupInitiatedCallback);
ble.securityManager().onPasskeyDisplay(passkeyDisplayCallback);
ble.securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
ble.securityManager().init(enableBonding, requireMITM, HID_SECURITY_IOCAPS);
}
示例3: whenDisconnected
/*
Function called when BLE device has been disconnected.
*/
void whenDisconnected(Gap::Handle_t, Gap::DisconnectionReason_t)
{
printf("main: Disconnected!\r\n");
printf("main: Restarting the advertising process\r\n");
watch->stop();
watch->reset();
ble.gap().startAdvertising();
}
示例4: initializeHOGP
void initializeHOGP(BLE &ble)
{
static const uint16_t uuid16_list[] = {GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE,
GattService::UUID_DEVICE_INFORMATION_SERVICE,
GattService::UUID_BATTERY_SERVICE};
DeviceInformationService deviceInfo(ble, "ARM", "m1", "abc", "def", "ghi", "jkl");
BatteryService batteryInfo(ble, 80);
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED |
GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
(uint8_t *)uuid16_list, sizeof(uuid16_list));
// see 5.1.2: HID over GATT Specification (pg. 25)
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
// 30ms to 50ms is recommended (5.1.2)
ble.gap().setAdvertisingInterval(50);
}
示例5: changePayloadTest
/**
* Test to change advertisement payload
*/
void changePayloadTest(void)
{
ble.gap().clearAdvertisingPayload();
ble.gap().setAdvertisingTimeout(0);
ASSERT_NO_FAILURE(ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::LE_GENERAL_DISCOVERABLE | GapAdvertisingData::BREDR_NOT_SUPPORTED));
ASSERT_NO_FAILURE(ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::OUTDOOR_GENERIC));
ASSERT_NO_FAILURE(ble.gap().accumulateAdvertisingPayloadTxPower(10)); /* in dbm. */
const static uint8_t trivialAdvPayload[] = {123, 123, 123, 123, 123};
ASSERT_NO_FAILURE(ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, trivialAdvPayload, sizeof(trivialAdvPayload)));
ble.gap().setAdvertisingInterval(500); /* in milliseconds. */
ASSERT_NO_FAILURE(ble.gap().startAdvertising());
printf("ASSERTIONS DONE\r\n");
}
示例6: responseTest
/**
* Test to change add a scan response
*/
void responseTest(void)
{
ble.gap().clearAdvertisingPayload();
ble.gap().clearScanResponse();
ble.gap().setAdvertisingTimeout(0);
ble.setAdvertisingType(GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED);
const static uint8_t trivialAdvPayload[] = {50, 50, 50, 50, 50};
ASSERT_NO_FAILURE(ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, trivialAdvPayload, sizeof(trivialAdvPayload)));
const static uint8_t trivialScanResponse[] = {50, 50, 50, 50, 50};
ASSERT_NO_FAILURE(ble.gap().accumulateScanResponse(GapAdvertisingData::SERVICE_DATA, trivialScanResponse, sizeof(trivialScanResponse)));
ble.gap().setAdvertisingInterval(500); /* in units of milliseconds. */
ASSERT_NO_FAILURE(ble.gap().startAdvertising());
printf("ASSERTIONS DONE\r\n");
}
示例7: main
int main(void)
{
app_start(0, NULL);
for(;;)
{
// send notification outside of interrupt context
if (sendHello)
{
ble_error_t result = bts->updateCharacteristicValue((const uint8_t*)"hello", 5);
if (result == BLE_ERROR_NONE)
{
sendHello = false;
}
}
ble.waitForEvent();
}
}
示例8: changeIntervalTest
/**
* Test to change advertisement interval
*/
void changeIntervalTest(void)
{
ble.gap().setAdvertisingTimeout(0);
ble.gap().setAdvertisingInterval(500); /* in milliseconds. */
ASSERT_NO_FAILURE(ble.gap().startAdvertising());
printf("ASSERTIONS DONE\r\n");
}
示例9: shutdownTest
/**
* Test of the ble shutdown function. Reinitializes and makes sure it
*/
void shutdownTest(void)
{
ASSERT_NO_FAILURE(ble.shutdown());
ASSERT_NO_FAILURE(ble.init());
ASSERT_NO_FAILURE(ble.gap().startAdvertising());
printf("ASSERTIONS DONE\r\n");
}
示例10: verifyBasicAssumptions
/**
* @return 0 if basic assumptions are validated. Non-zero returns are used to
* terminate the second-level python script early.
*/
unsigned verifyBasicAssumptions()
{
if (ble.init()) {
return 1;
}
/* Read in the MAC address of this peripheral. The corresponding central will be
* commanded to co-ordinate with this address. */
Gap::AddressType_t addressType;
Gap::Address_t address;
if (ble.gap().getAddress(&addressType, address)) {
return 1;
} /* TODO: if this fails, then bail out with a useful report. */
/* Check that the state is one of the valid values. */
Gap::GapState_t state = ble.gap().getState();
if ((state.connected == 1) || (state.advertising == 1)) {
printf("{{failure}} ble.gap().getState() at line %u\r\n", __LINE__); /* writing out {{failure}} will halt the host test runner. */
return 1;
}
const char *version = ble.getVersion();
printf("%s\r\n", version);
printf("{{success}}\r\n");
return 0;
}
示例11: app_start
void app_start(int, char *[])
{
ble.init();
ble.onDisconnection(disconnectionCallback);
/*
* Load parameters from (platform specific) persistent storage. Parameters
* can be set to non-default values while the URIBeacon is in configuration
* mode (within the first 60 seconds of power-up). Thereafter, parameters
* get copied out to persistent storage before switching to normal URIBeacon
* operation.
*/
bool fetchedFromPersistentStorage = loadURIBeaconConfigParams(¶ms);
/* Initialize a URIBeaconConfig service providing config params, default URI, and power levels. */
static URIBeaconConfigService::PowerLevels_t defaultAdvPowerLevels = {-20, -4, 0, 10}; // Values for ADV packets related to firmware levels
uriBeaconConfig = new URIBeaconConfigService(ble, params, !fetchedFromPersistentStorage, "http://uribeacon.org", defaultAdvPowerLevels);
if (!uriBeaconConfig->configuredSuccessfully()) {
error("failed to accommodate URI");
}
// Setup auxiliary services to allow over-the-air firmware updates, etc
DFUService *dfu = new DFUService(ble);
DeviceInformationService *deviceInfo = new DeviceInformationService(ble, "ARM", "UriBeacon", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
ble.startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the URIBeaconConfig
* service. This can then be switched to the normal URIBeacon functionality after a timeout. */
/* Post a timeout callback to be invoked in ADVERTISEMENT_TIMEOUT_SECONDS to affect the switch to beacon mode. */
minar::Scheduler::postCallback(timeout).delay(minar::milliseconds(CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS * 1000));
}
示例12: setTimeoutTest
/**
* Test to change advertisement timeout.
*/
void setTimeoutTest(void)
{
ble.gap().clearAdvertisingPayload();
ble.gap().clearScanResponse();
ble.gap().setAdvertisingTimeout(5); /* 5 seconds */
ASSERT_NO_FAILURE(ble.gap().startAdvertising());
printf("ASSERTIONS DONE\r\n");
}
示例13: timeout
/**
* Stop advertising the UriBeaconConfig Service after a delay; and switch to normal URIBeacon.
*/
void timeout(void)
{
Gap::GapState_t state;
state = ble.getGapState();
if (!state.connected) { /* don't switch if we're in a connected state. */
uriBeaconConfig->setupURIBeaconAdvertisements();
ble.startAdvertising();
} else {
minar::Scheduler::postCallback(timeout).delay(minar::milliseconds(CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS * 1000));
}
}
示例14: button1ISR
/*
Start or stop scanning. Device becomes central.
*/
void button1ISR()
{
if (!scanning)
{
scanning = true;
printf("start scan\r\n");
ble.gap().setScanParams(1000, 1000);
ble.gap().startScan(advertisementCallback);
}
else
{
scanning = false;
printf("stop scan\r\n");
ble.gap().stopScan();
}
}
示例15: setAddrTest
/**
* Test for setting and getting MAC address
*/
void setAddrTest(void)
{
Gap::AddressType_t addressType;
Gap::Address_t origAddress;
ble.gap().getAddress(&addressType, origAddress);
const static Gap::Address_t newAddress = {110, 100, 100, 100, 100, 100}; /* A randomly chosen address for assigning to the peripheral. */
ASSERT_NO_FAILURE(ble.gap().setAddress(Gap::ADDR_TYPE_PUBLIC, newAddress));
Gap::Address_t fetchedAddress;
ASSERT_NO_FAILURE(ble.gap().getAddress(&addressType, fetchedAddress));
printf("ASSERTIONS DONE\r\n");
printf("%d:%d:%d:%d:%d:%d\n", newAddress[0], newAddress[1], newAddress[2], newAddress[3], newAddress[4], newAddress[5]);
printf("%d:%d:%d:%d:%d:%d\n", fetchedAddress[0], fetchedAddress[1], fetchedAddress[2], fetchedAddress[3], fetchedAddress[4], fetchedAddress[5]);
ble.gap().setAddress(Gap::ADDR_TYPE_PUBLIC, origAddress);
}