/** * @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; }
/** * 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"); }
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)); }
int main(void) { ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); // setup advertising ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_PHONE); ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)NAME, sizeof(NAME) - 1); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); ble.setAdvertisingPayload(); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setActiveScan(false); ble.setAdvertisingInterval(100); ble.addService(uartService); ble.startAdvertising(); while(1) { ble.waitForEvent(); } }
int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); // blink LED every second ble.init(); ble.gap().onDisconnection(disconnectionCallback); /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); /* Setup advertising. */ 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)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ ble.gap().startAdvertising(); // infinite loop while (1) { // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { triggerSensorPolling = false; // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. hrmCounter++; // 100 <= HRM bps <=175 if (hrmCounter == 175) { hrmCounter = 100; } // update bps hrService.updateHeartRate(hrmCounter); } else { ble.waitForEvent(); // low power wait for event } } }
void app_start(int argc, char *argv[]) { ble.init(bleInitComplete); }
void app_start(int, char *[]) { buffer = (uint8_t*)malloc(24); memset(buffer, 0, 24); console.attach(serialHandler); printf("{{end}}\r\n"); // setup buttons // button1.mode(PullUp); // Delay for initial pullup to take effect wait(.01); // button1.fall(button1ISR); // button2.mode(PullUp); // Delay for initial pullup to take effect wait(.01); // button2.fall(button2ISR); /*************************************************************************/ /*************************************************************************/ /* bluetooth le */ ble.init(); // security ble.securityManager().onSecuritySetupInitiated(securityInitiated); ble.securityManager().onSecuritySetupCompleted(securityCompleted); ble.securityManager().onLinkSecured(linkSecured); ble.securityManager().onSecurityContextStored(contextStored); ble.securityManager().onPasskeyDisplay(passkeyDisplay); // connection status handlers ble.gap().onConnection(whenConnected); ble.gap().onDisconnection(whenDisconnected); // set preferred connection parameters to lowest latency Gap::ConnectionParams_t fast; ble.gap().getPreferredConnectionParams(&fast); fast.minConnectionInterval = 16; // 20 ms fast.maxConnectionInterval = 32; // 40 ms fast.slaveLatency = 0; ble.gap().setPreferredConnectionParams(&fast); /* construct advertising beacon */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED|GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME) - 1); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, uuid.getBaseUUID(), uuid.getLen()); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(200); // Apple uses device name instead of beacon name ble.gap().setDeviceName((const uint8_t*) DEVICE_NAME); // ble setup complete - start advertising ble.gap().startAdvertising(); /*************************************************************************/ /*************************************************************************/ bts = new BlockTransferService(); btc = new BlockTransferClient(); watch = new Timer(); bts->init(uuid, SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK); #if 0 writeBlock.push_back(&writeBlockFragment2); writeBlock.push_back(&writeBlockFragment3); writeBlock.push_back(&writeBlockFragment4); #endif // set callback functions bts->setWriteAuthorizationCallback(blockServerWriteHandler, &receiveBlock); bts->setReadAuthorizationCallback(blockServerReadHandler); printf("BlockTransfer: %s %s %d\r\n", __DATE__, __TIME__, MAX_INDEX_SET_SIZE); }