BLE EddystoneService example

This example is a fork of the following mbed-os example:

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/

Please read the documentation in this page.

Committer:
mbed_official
Date:
Thu Jul 28 23:14:36 2016 +0100
Revision:
1:9db4d46bb63f
Parent:
0:4c8f8bf32a99
Child:
2:9ee673e0b86a
Merge branch 'master' of https://github.com/ARMmbed/mbed-os-example-ble


Commit copied from ./src/github.com/ARMmbed/mbed-os-example-ble

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 1:9db4d46bb63f 1 /* mbed Microcontroller Library
mbed_official 1:9db4d46bb63f 2 * Copyright (c) 2006-2015 ARM Limited
mbed_official 1:9db4d46bb63f 3 *
mbed_official 1:9db4d46bb63f 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 1:9db4d46bb63f 5 * you may not use this file except in compliance with the License.
mbed_official 1:9db4d46bb63f 6 * You may obtain a copy of the License at
mbed_official 1:9db4d46bb63f 7 *
mbed_official 1:9db4d46bb63f 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 1:9db4d46bb63f 9 *
mbed_official 1:9db4d46bb63f 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 1:9db4d46bb63f 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 1:9db4d46bb63f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 1:9db4d46bb63f 13 * See the License for the specific language governing permissions and
mbed_official 1:9db4d46bb63f 14 * limitations under the License.
mbed_official 1:9db4d46bb63f 15 */
mbed_official 1:9db4d46bb63f 16
mbed_official 1:9db4d46bb63f 17 #include "UIDFrame.h"
mbed_official 1:9db4d46bb63f 18
mbed_official 1:9db4d46bb63f 19 UIDFrame::UIDFrame(void)
mbed_official 1:9db4d46bb63f 20 {
mbed_official 1:9db4d46bb63f 21 memset(uidNamespaceID, 0, sizeof(UIDNamespaceID_t));
mbed_official 1:9db4d46bb63f 22 memset(uidInstanceID, 0, sizeof(UIDInstanceID_t));
mbed_official 1:9db4d46bb63f 23 }
mbed_official 1:9db4d46bb63f 24
mbed_official 1:9db4d46bb63f 25 UIDFrame::UIDFrame(const UIDNamespaceID_t uidNamespaceIDIn, const UIDInstanceID_t uidInstanceIDIn)
mbed_official 1:9db4d46bb63f 26 {
mbed_official 1:9db4d46bb63f 27 memcpy(uidNamespaceID, uidNamespaceIDIn, sizeof(UIDNamespaceID_t));
mbed_official 1:9db4d46bb63f 28 memcpy(uidInstanceID, uidInstanceIDIn, sizeof(UIDInstanceID_t));
mbed_official 1:9db4d46bb63f 29 }
mbed_official 1:9db4d46bb63f 30
mbed_official 1:9db4d46bb63f 31 void UIDFrame::setUIDData(const UIDNamespaceID_t &uidNamespaceIDIn, const UIDInstanceID_t &uidInstanceIDIn)
mbed_official 1:9db4d46bb63f 32 {
mbed_official 1:9db4d46bb63f 33 memcpy(uidNamespaceID, uidNamespaceIDIn, sizeof(UIDNamespaceID_t));
mbed_official 1:9db4d46bb63f 34 memcpy(uidInstanceID, uidInstanceIDIn, sizeof(UIDInstanceID_t));
mbed_official 1:9db4d46bb63f 35 }
mbed_official 1:9db4d46bb63f 36
mbed_official 1:9db4d46bb63f 37 void UIDFrame::constructUIDFrame(uint8_t *rawFrame, int8_t advPowerLevel)
mbed_official 1:9db4d46bb63f 38 {
mbed_official 1:9db4d46bb63f 39 size_t index = 0;
mbed_official 1:9db4d46bb63f 40
mbed_official 1:9db4d46bb63f 41 rawFrame[index++] = EDDYSTONE_UUID[0]; // 16-bit Eddystone UUID
mbed_official 1:9db4d46bb63f 42 rawFrame[index++] = EDDYSTONE_UUID[1];
mbed_official 1:9db4d46bb63f 43 rawFrame[index++] = FRAME_TYPE_UID; // 1B Type
mbed_official 1:9db4d46bb63f 44 rawFrame[index++] = advPowerLevel; // 1B Power @ 0meter
mbed_official 1:9db4d46bb63f 45
mbed_official 1:9db4d46bb63f 46 memcpy(rawFrame + index, uidNamespaceID, sizeof(UIDNamespaceID_t)); // 10B Namespace ID
mbed_official 1:9db4d46bb63f 47 index += sizeof(UIDNamespaceID_t);
mbed_official 1:9db4d46bb63f 48 memcpy(rawFrame + index, uidInstanceID, sizeof(UIDInstanceID_t)); // 6B Instance ID
mbed_official 1:9db4d46bb63f 49 index += sizeof(UIDInstanceID_t);
mbed_official 1:9db4d46bb63f 50
mbed_official 1:9db4d46bb63f 51 memset(rawFrame + index, 0, 2 * sizeof(uint8_t)); // 2B RFU, which are unused
mbed_official 1:9db4d46bb63f 52 }
mbed_official 1:9db4d46bb63f 53
mbed_official 1:9db4d46bb63f 54 size_t UIDFrame::getRawFrameSize(void) const
mbed_official 1:9db4d46bb63f 55 {
mbed_official 1:9db4d46bb63f 56 return FRAME_SIZE_UID + EDDYSTONE_UUID_SIZE;
mbed_official 1:9db4d46bb63f 57 }
mbed_official 1:9db4d46bb63f 58
mbed_official 1:9db4d46bb63f 59 uint8_t* UIDFrame::getUIDNamespaceID(void)
mbed_official 1:9db4d46bb63f 60 {
mbed_official 1:9db4d46bb63f 61 return uidNamespaceID;
mbed_official 1:9db4d46bb63f 62 }
mbed_official 1:9db4d46bb63f 63
mbed_official 1:9db4d46bb63f 64 uint8_t* UIDFrame::getUIDInstanceID(void)
mbed_official 1:9db4d46bb63f 65 {
mbed_official 1:9db4d46bb63f 66 return uidInstanceID;
mbed_official 1:9db4d46bb63f 67 }