Created
July 20, 2016 10:34
-
-
Save aw3s0me/d78a15ed4b15acc0dcd018dcc8802fd9 to your computer and use it in GitHub Desktop.
Parsing advertisement js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseAdvertisingData(buffer) { | |
| var length, type, data, i = 0, advertisementData = {}; | |
| var bytes = new Uint8Array(buffer); | |
| while (length !== 0) { | |
| length = bytes[i] & 0xFF; | |
| i++; | |
| // decode type constants from https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile | |
| type = bytes[i] & 0xFF; | |
| i++; | |
| data = bytes.slice(i, i + length - 1).buffer; // length includes type byte, but not length byte | |
| i += length - 2; // move to end of data | |
| i++; | |
| advertisementData[asHexString(type)] = data; | |
| } | |
| return advertisementData; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment