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:
Vincent Coubard
Date:
Tue Jul 26 14:40:25 2016 +0100
Revision:
0:4c8f8bf32a99
Child:
1:9db4d46bb63f
Update example at tag mbed-os-5.0.1-rc1

Who changed what in which revision?

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