an observer for temperature demo
Dependencies: BLE_API mbed nRF51822 TMP_nrf51
Fork of BLE_Observer by
Revision 8:649bd171929e, committed 2015-07-31
- Comitter:
- sunsmile2015
- Date:
- Fri Jul 31 09:13:50 2015 +0000
- Parent:
- 7:91324daa3bfa
- Commit message:
- add advertiser address information in the output message
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 91324daa3bfa -r 649bd171929e main.cpp --- a/main.cpp Mon Jul 20 09:00:24 2015 +0000 +++ b/main.cpp Fri Jul 31 09:13:50 2015 +0000 @@ -18,21 +18,21 @@ #include "BLE.h" #include "TMP_nrf51/TMP_nrf51.h" -#define COMP_ID_TEST 0xFEFE +#define APP_SPECIFIC_ID_TEST 0xFEFE #pragma pack(1) /* Advertising data */ -typedef struct advertisingData { - uint8_t length; /* doesn't include itself*/ +struct AdvertisingData_t { + 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; +struct ApplicationData_t { + uint16_t applicationSpecificId; /* An ID used to identify temperature value + in the manufacture specific AD data field */ + TMP_nrf51::tmpSensorValue_t tmpSensorValue; /* User defined application data */ +}; #pragma pack() BLE ble; @@ -45,16 +45,17 @@ void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { - advertisingData_t *pAdvData = NULL; + AdvertisingData_t *pAdvData = NULL; uint8_t len = 0; /* Search for the manufacturer data */ while(len < params->advertisingDataLen) { - pAdvData = (advertisingData_t *)¶ms->advertisingData[len]; + 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); + ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data; + if(pAppData->applicationSpecificId == APP_SPECIFIC_ID_TEST) { + printf("From [%02x %02x %02x], ", params->peerAddr[2], params->peerAddr[1], params->peerAddr[0]); + printf("Temp is %f\r\n", (float)pAppData->tmpSensorValue); break; } }