UpdatedDecryp
Dependencies: BahlDecrypModified CyaSSL mbed nRF51822
Fork of Decryptulator by
main.cpp@9:69a2ad0bcdb7, 2015-08-26 (annotated)
- Committer:
- rgrover1
- Date:
- Wed Aug 26 12:58:23 2015 +0000
- Revision:
- 9:69a2ad0bcdb7
- Parent:
- 8:649bd171929e
- Child:
- 11:16f67d5752e1
An import from Xiao Sun's demo for Temperature Observer.; Has minor cleanup.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:332983584a9c | 1 | /* mbed Microcontroller Library |
rgrover1 | 0:332983584a9c | 2 | * Copyright (c) 2006-2015 ARM Limited |
rgrover1 | 0:332983584a9c | 3 | * |
rgrover1 | 0:332983584a9c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 0:332983584a9c | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 0:332983584a9c | 6 | * You may obtain a copy of the License at |
rgrover1 | 0:332983584a9c | 7 | * |
rgrover1 | 0:332983584a9c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 0:332983584a9c | 9 | * |
rgrover1 | 0:332983584a9c | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 0:332983584a9c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 0:332983584a9c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 0:332983584a9c | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 0:332983584a9c | 14 | * limitations under the License. |
rgrover1 | 0:332983584a9c | 15 | */ |
rgrover1 | 0:332983584a9c | 16 | |
rgrover1 | 0:332983584a9c | 17 | #include "mbed.h" |
rgrover1 | 9:69a2ad0bcdb7 | 18 | #include "toolchain.h" |
rgrover1 | 9:69a2ad0bcdb7 | 19 | #include "ble/BLE.h" |
sunsmile2015 | 7:91324daa3bfa | 20 | #include "TMP_nrf51/TMP_nrf51.h" |
sunsmile2015 | 7:91324daa3bfa | 21 | |
rgrover1 | 5:103717ce54e5 | 22 | BLE ble; |
rgrover1 | 9:69a2ad0bcdb7 | 23 | DigitalOut alivenessLED(LED1, 1); |
rgrover1 | 0:332983584a9c | 24 | |
rgrover1 | 0:332983584a9c | 25 | void periodicCallback(void) |
rgrover1 | 0:332983584a9c | 26 | { |
rgrover1 | 9:69a2ad0bcdb7 | 27 | alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events. This is optional. */ |
rgrover1 | 0:332983584a9c | 28 | } |
rgrover1 | 0:332983584a9c | 29 | |
rgrover1 | 9:69a2ad0bcdb7 | 30 | /* |
rgrover1 | 9:69a2ad0bcdb7 | 31 | * This function is called every time we scan an advertisement. |
rgrover1 | 9:69a2ad0bcdb7 | 32 | */ |
sunsmile2015 | 6:850f44146c9f | 33 | void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) |
sunsmile2015 | 6:850f44146c9f | 34 | { |
rgrover1 | 9:69a2ad0bcdb7 | 35 | struct AdvertisingData_t { |
rgrover1 | 9:69a2ad0bcdb7 | 36 | uint8_t length; /* doesn't include itself */ |
rgrover1 | 9:69a2ad0bcdb7 | 37 | GapAdvertisingData::DataType_t dataType; |
rgrover1 | 9:69a2ad0bcdb7 | 38 | uint8_t data[0]; |
rgrover1 | 9:69a2ad0bcdb7 | 39 | } PACKED; |
rgrover1 | 9:69a2ad0bcdb7 | 40 | |
rgrover1 | 9:69a2ad0bcdb7 | 41 | struct ApplicationData_t { |
rgrover1 | 9:69a2ad0bcdb7 | 42 | uint16_t applicationSpecificId; /* An ID used to identify temperature value |
rgrover1 | 9:69a2ad0bcdb7 | 43 | in the manufacture specific AD data field */ |
rgrover1 | 9:69a2ad0bcdb7 | 44 | TMP_nrf51::TempSensorValue_t tmpSensorValue; /* User defined application data */ |
rgrover1 | 9:69a2ad0bcdb7 | 45 | } PACKED; |
rgrover1 | 9:69a2ad0bcdb7 | 46 | |
rgrover1 | 9:69a2ad0bcdb7 | 47 | static const uint16_t APP_SPECIFIC_ID_TEST = 0xFEFE; |
rgrover1 | 9:69a2ad0bcdb7 | 48 | |
rgrover1 | 9:69a2ad0bcdb7 | 49 | /* Search for the manufacturer specific data with matching application-ID */ |
rgrover1 | 9:69a2ad0bcdb7 | 50 | AdvertisingData_t *pAdvData; |
rgrover1 | 9:69a2ad0bcdb7 | 51 | size_t index = 0; |
rgrover1 | 9:69a2ad0bcdb7 | 52 | while (index < params->advertisingDataLen) { |
rgrover1 | 9:69a2ad0bcdb7 | 53 | pAdvData = (AdvertisingData_t *)¶ms->advertisingData[index]; |
rgrover1 | 9:69a2ad0bcdb7 | 54 | if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) { |
sunsmile2015 | 8:649bd171929e | 55 | ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data; |
rgrover1 | 9:69a2ad0bcdb7 | 56 | if (pAppData->applicationSpecificId == APP_SPECIFIC_ID_TEST) { |
rgrover1 | 9:69a2ad0bcdb7 | 57 | /* dump information on the console. */ |
sunsmile2015 | 8:649bd171929e | 58 | printf("From [%02x %02x %02x], ", params->peerAddr[2], params->peerAddr[1], params->peerAddr[0]); |
rgrover1 | 9:69a2ad0bcdb7 | 59 | printf("Temp is %f\r\n", (TMP_nrf51::TempSensorValue_t)pAppData->tmpSensorValue); |
sunsmile2015 | 7:91324daa3bfa | 60 | break; |
sunsmile2015 | 7:91324daa3bfa | 61 | } |
sunsmile2015 | 6:850f44146c9f | 62 | } |
rgrover1 | 9:69a2ad0bcdb7 | 63 | index += (pAdvData->length + 1); |
rgrover1 | 0:332983584a9c | 64 | } |
rgrover1 | 0:332983584a9c | 65 | } |
rgrover1 | 0:332983584a9c | 66 | |
rgrover1 | 0:332983584a9c | 67 | int main(void) |
rgrover1 | 0:332983584a9c | 68 | { |
rgrover1 | 0:332983584a9c | 69 | Ticker ticker; |
rgrover1 | 0:332983584a9c | 70 | ticker.attach(periodicCallback, 1); |
rgrover1 | 0:332983584a9c | 71 | |
rgrover1 | 0:332983584a9c | 72 | ble.init(); |
sunsmile2015 | 6:850f44146c9f | 73 | ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */); |
rgrover1 | 5:103717ce54e5 | 74 | ble.gap().startScan(advertisementCallback); |
rgrover1 | 0:332983584a9c | 75 | |
rgrover1 | 0:332983584a9c | 76 | while (true) { |
rgrover1 | 0:332983584a9c | 77 | ble.waitForEvent(); |
rgrover1 | 0:332983584a9c | 78 | } |
rgrover1 | 0:332983584a9c | 79 | } |