init
Dependencies: BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 1:4bdebb81dcd5
- Parent:
- 0:84779d0d1ff5
- Child:
- 2:95c770f35636
--- a/main.cpp Tue Jul 21 08:39:03 2015 +0000 +++ b/main.cpp Mon Jul 27 07:30:47 2015 +0000 @@ -31,7 +31,8 @@ const static char DEVICE_NAME[] = "HRMTEST"; static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, - GattService::UUID_DEVICE_INFORMATION_SERVICE}; + GattService::UUID_DEVICE_INFORMATION_SERVICE, + LEDService::LED_SERVICE_UUID}; static volatile bool triggerSensorPolling = false; void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) @@ -45,15 +46,6 @@ /* Note that the periodicCallback() executes in interrupt context, so it is safer to do * heavy-weight sensor polling from the main thread. */ - if (ble.getGapState().connected){ - hrmCounter++; - // 100 <= HRM bps <=175 - if (hrmCounter == 175) { - hrmCounter = 100; - } - // update bps - hrService.updateHeartRate(hrmCounter); - } } void connectionCallback(const Gap::ConnectionCallbackParams_t *params){ @@ -66,11 +58,17 @@ } void testDeviceName(){ + if (ble.gap().getState().connected){ + printf("Device must be disconnected\n"); + return; + } uint8_t deviceName[10]; uint8_t deviceNameIn[] = {0x4A, 0x4F, 0x53, 0x48, 0x54, 0x45, 0x53, 0x54, 0x00}; unsigned length = 10; BLE_CHECK(ble.gap().setDeviceName(deviceNameIn)); + wait(0.5); BLE_CHECK(ble.gap().getDeviceName(deviceName, &length)); + wait(0.5); for (int i = 0; i < length; i++){ printf("%02x ", deviceName[i]); } @@ -82,13 +80,23 @@ } void testAppearance(){ + if ((ble.gap().getState().connected)){ + printf("Device must be disconnected\n"); + return; + } GapAdvertisingData::Appearance appearance; BLE_CHECK(ble.gap().setAppearance(GapAdvertisingData::GENERIC_PHONE)); + wait(0.5); BLE_CHECK(ble.gap().getAppearance(&appearance)); + wait(0.5); printf("%d\r\n",appearance); } void connParams(){ + if ((ble.gap().getState().connected)){ + printf("Device must be disconnected\n"); + return; + } Gap::ConnectionParams_t params; Gap::ConnectionParams_t paramsOut = {50,500,0,500}; Gap::ConnectionParams_t temp; @@ -103,31 +111,13 @@ } -void testcentre(void){ - - scanf("%d", &x); - testDeviceName(); - scanf("%d", &x); - testAppearance(); - scanf("%d", &x); - connParams(); - int x; +void commandInterpreter(void){ + char command[50]; while(1){ - scanf("%d", &x); - switch(x){ - case 0: - testDeviceName(); - break; - case 1: - testAppearance(); - break; - case 2: - connParams(); - break; - case 3: - - break; - } + scanf("%s", command); + if (!strcmp(command, "setDeviceName")) testDeviceName(); + else if (!strcmp(command, "setAppearance")) testAppearance(); + else if (!strcmp(command, "testConnectionParams")) connParams(); } } @@ -143,6 +133,9 @@ /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + + bool initialValueForLEDCharacteristic = false; + LEDService ledService(ble, initialValueForLEDCharacteristic); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); @@ -161,7 +154,8 @@ int x; scanf("%d" , &x); printf("%d:%d:%d:%d:%d:%d\n", address[0], address[1], address[2], address[3], address[4], address[5]); - testCentre(); + commandInterpreter(); +/* scanf("%d", &x); testDeviceName(); //printf("%d\n",ble.gattServer().onDataRead(dataReadCallback)); @@ -188,4 +182,5 @@ ble.waitForEvent(); // low power wait for event } } +*/ }