Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822 TMP_nrf51
Fork of BLE_Observer by
Revision 7:91324daa3bfa, committed 2015-07-20
- Comitter:
- sunsmile2015
- Date:
- Mon Jul 20 09:00:24 2015 +0000
- Parent:
- 6:850f44146c9f
- Child:
- 8:649bd171929e
- Commit message:
- 1. change the coding style; 2. add struct for adv data and manufacturer data
Changed in this revision
| TMP_nrf51.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TMP_nrf51.lib Mon Jul 20 09:00:24 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/sunsmile2015/code/TMP_nrf51/#189632d43a8f
--- a/main.cpp Wed Jul 15 02:53:12 2015 +0000
+++ b/main.cpp Mon Jul 20 09:00:24 2015 +0000
@@ -16,6 +16,24 @@
#include "mbed.h"
#include "BLE.h"
+#include "TMP_nrf51/TMP_nrf51.h"
+
+#define COMP_ID_TEST 0xFEFE
+
+#pragma pack(1)
+/* Advertising data */
+typedef struct advertisingData {
+ uint8_t length; /* doesn't include itself*/
+ GapAdvertisingData::DataType dataType;
+ uint8_t data[1];
+} advertisingData_t;
+
+typedef struct manufacturerData {
+ uint16_t companyId;
+ /* User defined manufacture data */
+ TMP_nrf51::tmpSensorValue_t tmpSensorValue;
+} manufacturerData_t;
+#pragma pack()
BLE ble;
DigitalOut led1(LED1);
@@ -27,19 +45,20 @@
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
{
- if((params->advertisingData[9] == 0xFE) && (params->advertisingData[10] == 0xFE)) {
- float tempVal = 0;
- printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
- params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
- params->rssi, params->isScanResponse, params->type);
+ advertisingData_t *pAdvData = NULL;
+ uint8_t len = 0;
- for (unsigned index = 0; index < params->advertisingDataLen; index++) {
- printf("%02x ", params->advertisingData[index]);
+ /* Search for the manufacturer data */
+ while(len < params->advertisingDataLen) {
+ pAdvData = (advertisingData_t *)¶ms->advertisingData[len];
+ if(pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
+ manufacturerData_t *pManuData = (manufacturerData_t *)pAdvData->data;
+ if(pManuData->companyId == COMP_ID_TEST) {
+ printf("Recv temp is %f\r\n", (float)pManuData->tmpSensorValue);
+ break;
+ }
}
-
- memcpy(&tempVal, ¶ms->advertisingData[11], 4); /* temperature value */
- printf("temp is %f\r\n", tempVal);
-
+ len += (pAdvData->length + 1);
}
}
@@ -50,7 +69,6 @@
ticker.attach(periodicCallback, 1);
ble.init();
-
ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
ble.gap().startScan(advertisementCallback);
