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