uid.py
 1  # The MIT License (MIT)
 2  #
 3  # Copyright (c) 2020 Scott Shawcroft for Adafruit Industries LLC
 4  #
 5  # Permission is hereby granted, free of charge, to any person obtaining a copy
 6  # of this software and associated documentation files (the "Software"), to deal
 7  # in the Software without restriction, including without limitation the rights
 8  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9  # copies of the Software, and to permit persons to whom the Software is
10  # furnished to do so, subject to the following conditions:
11  #
12  # The above copyright notice and this permission notice shall be included in
13  # all copies or substantial portions of the Software.
14  #
15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  # THE SOFTWARE.
22  """
23  `adafruit_ble_eddystone.uid`
24  ================================================================================
25  
26  Static Eddystone UID advertisement. Documented by Google here:
27  https://github.com/google/eddystone/tree/master/eddystone-uid
28  
29  """
30  
31  from . import EddystoneAdvertisement, EddystoneFrameStruct, EddystoneFrameBytes
32  
33  __version__ = "0.0.0-auto.0"
34  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_Eddystone.git"
35  
36  
37  class EddystoneUID(EddystoneAdvertisement):
38      """Static Eddystone unique identifier.
39  
40         :param bytes instance_id: instance component of the id. 10 bytes long
41         :param bytes namespace_id: namespace component of the id. 6 bytes long
42         :param int tx_power: TX power at the beacon
43      """
44  
45      match_prefixes = (b"\x03\xaa\xfe", b"\x16\xaa\xfe\x00")
46      frame_type = b"\x00"
47  
48      tx_power = EddystoneFrameStruct("<B", offset=0)
49      """TX power at the beacon in dBm"""
50  
51      namespace_id = EddystoneFrameBytes(length=10, offset=1)
52      """10 byte namespace id"""
53  
54      instance_id = EddystoneFrameBytes(length=6, offset=11)
55      """6 byte instance id"""
56  
57      reserved = EddystoneFrameBytes(length=2, offset=17)
58  
59      def __init__(self, instance_id, *, namespace_id=b"CircuitPy!", tx_power=0):
60          super().__init__(minimum_size=20)
61          if self.mutable:
62              self.tx_power = tx_power
63              self.namespace_id = namespace_id
64              self.instance_id = instance_id