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: mbed BLE_API Adafruit_GFX nRF51822
main.cpp
- Committer:
- mamont090671
- Date:
- 2019-12-13
- Revision:
- 10:b7d532c63124
- Parent:
- 9:56bb343c76ae
- Child:
- 11:f6274e2a0b07
File content as of revision 10:b7d532c63124:
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "BLE.h"
//#include "TMP_nrf51/TMP_nrf51.h"
#define APP_SPECIFIC_ID_TEST 0x0059 //0xFEFE
#pragma pack(1)
/* Advertising data */
struct AdvertisingData_t {
uint8_t length; /* doesn't include itself */
GapAdvertisingData::DataType dataType;
uint8_t data[1];
};
struct ApplicationData_t {
uint16_t applicationSpecificId; /* An ID used to identify temperature value
in the manufacture specific AD data field */
uint8_t tmpSensorValue; /* User defined application data */
uint8_t btnA_Value;
uint8_t btnB_Value;
};
#pragma pack()
BLE ble;
DigitalOut led1(LED1);
Serial pc(USBTX, USBRX);
void periodicCallback(void)
{
led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
}
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
{
AdvertisingData_t *pAdvData = NULL;
uint8_t len = 0;
/* Search for the manufacturer data */
while(len < params->advertisingDataLen) {
pAdvData = (AdvertisingData_t *)¶ms->advertisingData[len];
if(pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data;
if(pAppData->applicationSpecificId == APP_SPECIFIC_ID_TEST) {
pc.printf("From [%02x %02x %02x %02x %02x %02x], ", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0]);
pc.printf("Temp is %.02f", (float)pAppData->tmpSensorValue);
pc.printf(" ButtonAB is %02x", pAppData->btnA_Value);
pc.printf("%02x\r", pAppData->btnB_Value);
break;
}
}
len += (pAdvData->length + 1);
}
}
int main(void)
{
led1 = 1;
Ticker ticker;
ticker.attach(periodicCallback, 1);
ble.init();
ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
ble.gap().startScan(advertisementCallback);
pc.baud(9600);
pc.printf("Observer Init \r\n");
while (true) {
ble.waitForEvent();
}
}