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