Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
source/UIDFrame.cpp@0:1c7da5f83647, 2016-11-29 (annotated)
- Committer:
- sarahmarshy
- Date:
- Tue Nov 29 06:29:10 2016 +0000
- Revision:
- 0:1c7da5f83647
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sarahmarshy | 0:1c7da5f83647 | 1 | /* |
| sarahmarshy | 0:1c7da5f83647 | 2 | * Copyright (c) 2006-2016 Google Inc, All Rights Reserved |
| sarahmarshy | 0:1c7da5f83647 | 3 | * |
| sarahmarshy | 0:1c7da5f83647 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| sarahmarshy | 0:1c7da5f83647 | 5 | * you may not use this file except in compliance with the License. |
| sarahmarshy | 0:1c7da5f83647 | 6 | * You may obtain a copy of the License at |
| sarahmarshy | 0:1c7da5f83647 | 7 | * |
| sarahmarshy | 0:1c7da5f83647 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| sarahmarshy | 0:1c7da5f83647 | 9 | * |
| sarahmarshy | 0:1c7da5f83647 | 10 | * Unless required by applicable law or agreed to in writing, software |
| sarahmarshy | 0:1c7da5f83647 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| sarahmarshy | 0:1c7da5f83647 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| sarahmarshy | 0:1c7da5f83647 | 13 | * See the License for the specific language governing permissions and |
| sarahmarshy | 0:1c7da5f83647 | 14 | * limitations under the License. |
| sarahmarshy | 0:1c7da5f83647 | 15 | */ |
| sarahmarshy | 0:1c7da5f83647 | 16 | |
| sarahmarshy | 0:1c7da5f83647 | 17 | #include "UIDFrame.h" |
| sarahmarshy | 0:1c7da5f83647 | 18 | |
| sarahmarshy | 0:1c7da5f83647 | 19 | UIDFrame::UIDFrame(void) { |
| sarahmarshy | 0:1c7da5f83647 | 20 | } |
| sarahmarshy | 0:1c7da5f83647 | 21 | |
| sarahmarshy | 0:1c7da5f83647 | 22 | void UIDFrame::clearFrame(uint8_t* frame) { |
| sarahmarshy | 0:1c7da5f83647 | 23 | frame[FRAME_LEN_OFFSET] = 0; // Set frame length to zero to clear it |
| sarahmarshy | 0:1c7da5f83647 | 24 | } |
| sarahmarshy | 0:1c7da5f83647 | 25 | |
| sarahmarshy | 0:1c7da5f83647 | 26 | void UIDFrame::setData(uint8_t *rawFrame, int8_t advTxPower, const uint8_t* uidData) { |
| sarahmarshy | 0:1c7da5f83647 | 27 | size_t index = 0; |
| sarahmarshy | 0:1c7da5f83647 | 28 | rawFrame[index++] = UID_HEADER_LEN + UID_LENGTH; // UID length + overhead of four bytes below |
| sarahmarshy | 0:1c7da5f83647 | 29 | rawFrame[index++] = EDDYSTONE_UUID[0]; // LSB 16-bit Eddystone UUID (little endian) |
| sarahmarshy | 0:1c7da5f83647 | 30 | rawFrame[index++] = EDDYSTONE_UUID[1]; // MSB |
| sarahmarshy | 0:1c7da5f83647 | 31 | rawFrame[index++] = FRAME_TYPE_UID; // 1B Type |
| sarahmarshy | 0:1c7da5f83647 | 32 | rawFrame[index++] = advTxPower; // 1B Power @ 0meter |
| sarahmarshy | 0:1c7da5f83647 | 33 | |
| sarahmarshy | 0:1c7da5f83647 | 34 | memcpy(rawFrame + index, uidData, UID_LENGTH); // UID = 10B NamespaceID + 6B InstanceID |
| sarahmarshy | 0:1c7da5f83647 | 35 | } |
| sarahmarshy | 0:1c7da5f83647 | 36 | |
| sarahmarshy | 0:1c7da5f83647 | 37 | uint8_t* UIDFrame::getData(uint8_t* rawFrame) { |
| sarahmarshy | 0:1c7da5f83647 | 38 | return &(rawFrame[UID_DATA_OFFSET]); |
| sarahmarshy | 0:1c7da5f83647 | 39 | } |
| sarahmarshy | 0:1c7da5f83647 | 40 | |
| sarahmarshy | 0:1c7da5f83647 | 41 | uint8_t UIDFrame::getDataLength(uint8_t* rawFrame) |
| sarahmarshy | 0:1c7da5f83647 | 42 | { |
| sarahmarshy | 0:1c7da5f83647 | 43 | return rawFrame[FRAME_LEN_OFFSET] - EDDYSTONE_UUID_LEN; |
| sarahmarshy | 0:1c7da5f83647 | 44 | } |
| sarahmarshy | 0:1c7da5f83647 | 45 | |
| sarahmarshy | 0:1c7da5f83647 | 46 | uint8_t* UIDFrame::getAdvFrame(uint8_t* rawFrame) |
| sarahmarshy | 0:1c7da5f83647 | 47 | { |
| sarahmarshy | 0:1c7da5f83647 | 48 | return &(rawFrame[ADV_FRAME_OFFSET]); |
| sarahmarshy | 0:1c7da5f83647 | 49 | } |
| sarahmarshy | 0:1c7da5f83647 | 50 | |
| sarahmarshy | 0:1c7da5f83647 | 51 | uint8_t UIDFrame::getAdvFrameLength(uint8_t* rawFrame) |
| sarahmarshy | 0:1c7da5f83647 | 52 | { |
| sarahmarshy | 0:1c7da5f83647 | 53 | return rawFrame[FRAME_LEN_OFFSET]; |
| sarahmarshy | 0:1c7da5f83647 | 54 | } |
| sarahmarshy | 0:1c7da5f83647 | 55 | |
| sarahmarshy | 0:1c7da5f83647 | 56 | uint8_t* UIDFrame::getUid(uint8_t* rawFrame) |
| sarahmarshy | 0:1c7da5f83647 | 57 | { |
| sarahmarshy | 0:1c7da5f83647 | 58 | return &(rawFrame[UID_VALUE_OFFSET]); |
| sarahmarshy | 0:1c7da5f83647 | 59 | } |
| sarahmarshy | 0:1c7da5f83647 | 60 | |
| sarahmarshy | 0:1c7da5f83647 | 61 | uint8_t UIDFrame::getUidLength(uint8_t* rawFrame) |
| sarahmarshy | 0:1c7da5f83647 | 62 | { |
| sarahmarshy | 0:1c7da5f83647 | 63 | return rawFrame[FRAME_LEN_OFFSET] - UID_HEADER_LEN; |
| sarahmarshy | 0:1c7da5f83647 | 64 | } |
| sarahmarshy | 0:1c7da5f83647 | 65 | |
| sarahmarshy | 0:1c7da5f83647 | 66 | void UIDFrame::setAdvTxPower(uint8_t* rawFrame, int8_t advTxPower) |
| sarahmarshy | 0:1c7da5f83647 | 67 | { |
| sarahmarshy | 0:1c7da5f83647 | 68 | rawFrame[UID_TXPOWER_OFFSET] = advTxPower; |
| sarahmarshy | 0:1c7da5f83647 | 69 | } |