コード例 #1
0
    def __init__(self, characteristic=None, instance=None):
        try:
            super().__init__()
        except:
            super(OSXBLEDescriptor, self).__init__()
        self.characteristic = characteristic
        self.instance = instance
        self.UUID = ""
        self._value = None
        # callback
        self.update_userdescription = None
        if not instance:
            return

        uuidBytes = instance._.UUID._.data
        if len(uuidBytes) == 2:
            self.name = str(instance._.UUID)
            if self.name.startswith("Unknown"):
                self.name = "UNKNOWN"
            self.UUID = CBUUID2String(uuidBytes)
        elif len(uuidBytes) == 16:
            self.UUID = str(uuid.UUID(bytes=uuidBytes)).upper()
        else:
            # invalid UUID size
            pass
コード例 #2
0
ファイル: peripheral.py プロジェクト: ucoluk/PyBLEWrapper
 def findCharacteristicByDescriptorInstance(self, instance):
     service = self.findServiceByDescriptorInstance(instance)
     uuidBytes = instance._.characteristic._.UUID._.data
     for c in service.characteristics:
         if str(c.UUID) == CBUUID2String(uuidBytes):
             return c
     return None
コード例 #3
0
    def __init__(self, peripheral=None, instance=None):
        try:
            super().__init__()
        except:
            super(OSXBLEService, self).__init__()
        # which peripheral own this service
        self.instance = instance
        self.peripheral = peripheral
        self.UUID = ""
        self.isPrimary = False
        if not instance:
            return

        uuidBytes = instance._.UUID._.data
        if len(uuidBytes) == 2:
            self.name = str(instance._.UUID)
            if self.name.startswith("Unknown"):
                self.name = "UNKNOWN"
            self.UUID = CBUUID2String(uuidBytes)
        elif len(uuidBytes) == 16:
            self.UUID = str(uuid.UUID(bytes=uuidBytes)).upper()
        else:
            # invalid UUID size
            pass
        self.isPrimary = (instance._.isPrimary == YES)
コード例 #4
0
ファイル: gatt.py プロジェクト: bgromov/PyBLEWrapper
    def __init__(self, service=None, profile=None, instance=None):
        try:
            super().__init__(service=service, profile=profile)
        except:
            super(OSXBLECharacteristic, self).__init__(service=service,
                                                       profile=profile)
        self._description = ""
        self.properties = {
            "broadcast": False,  # 0x0001
            "read": False,  # 0x0002
            "writeWithoutResponse": False,  # 0x0004
            "write": False,  # 0x0008
            "notify": False,  # 0x0010
            "indicate": False,  # 0x0020
            "authenticatedSignedWrites": False,  # 0x0040
            "extendedProperties": False,  # 0x0080
            "notifyEncryptionRequired": False,  # 0x0100
            "indicateEncryptionRequired": False  # 0x0200
        }
        self._instance = None
        self.service = service
        self.profile = profile
        self.UUID = ""
        self._notify = False
        if not instance:
            return

        # update basic info
        self.instance = instance
        uuidBytes = instance._.UUID._.data
        if len(uuidBytes) == 2:
            self.name = str(instance._.UUID)
            if self.name.startswith("Unknown"):
                self.name = "UNKNOWN"
            self.UUID = CBUUID2String(uuidBytes)
        elif len(uuidBytes) == 16:
            self.UUID = str(uuid.UUID(bytes=uuidBytes)).upper()
        else:
            # invalid UUID size
            pass
コード例 #5
0
ファイル: peripheral.py プロジェクト: ucoluk/PyBLEWrapper
 def findServiceByDescriptorInstance(self, instance):
     uuidBytes = instance._.characteristic._.service._.UUID._.data
     for s in self.services:
         if str(s.UUID) == CBUUID2String(uuidBytes):
             return s
     return None
コード例 #6
0
ファイル: peripheral.py プロジェクト: ucoluk/PyBLEWrapper
 def findServiceByServiceInstance(self, instance):
     uuidBytes = instance._.UUID._.data
     for s in self.services:
         if str(s.UUID) == CBUUID2String(uuidBytes):
             return s
     return None
コード例 #7
0
 def getCharacteristicByInstance(self, instance):
     for c in self.characteristics:
         if str(c.UUID) == CBUUID2String(instance._.UUID._.data):
             return c
     return None
コード例 #8
0
 def findDescriptorByInstance(self, instance):
     for d in self.descriptors:
         if str(d.UUID) == CBUUID2String(instance._.UUID._.data):
             return d
     return None
コード例 #9
0
    def didDiscoverPeripheral(self, central, peripheral, advertisementData,
                              rssi):
        temp = OSXPeripheral.alloc().init()
        idx = -1
        p = None
        try:
            idx = self.scanedList.index(temp)
        except ValueError:
            idx = -1
        except Exception as e:
            self.logger.error(str(e))
        if idx >= 0:
            p = self.scanedList[idx]
        else:
            p = temp

        p.instance = peripheral
        p.UUID = uuid.UUID(peripheral._.identifier.UUIDString())
        p.name = peripheral._.name
        # handle advertisement data
        #   local name
        if CBAdvertisementDataLocalNameKey in advertisementData:
            p.advLocalName = advertisementData[CBAdvertisementDataLocalNameKey]
        #   manufacturer data
        if CBAdvertisementDataManufacturerDataKey in advertisementData:
            p.advManufacturerData = advertisementData[
                CBAdvertisementDataManufacturerDataKey]
        #   provided services UUIDs
        if CBAdvertisementDataServiceUUIDsKey in advertisementData:
            p.advServiceUUIDS = []
            UUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey]
            for UUID in UUIDs:
                p.advServiceUUIDs.append(CBUUID2String(UUID._.data))
        #   Tx Power Level
        if CBAdvertisementDataTxPowerLevelKey in advertisementData:
            p.advTxPowerLevel = int(
                advertisementData[CBAdvertisementDataTxPowerLevelKey])
        #   ServiceData
        if CBAdvertisementDataServiceDataKey in advertisementData:
            p.advServiceData = advertisementData[
                CBAdvertisementDataServiceDataKey]
        #   OverflowServiceUUIDs
        if CBAdvertisementDataOverflowServiceUUIDsKey in advertisementData:
            p.advOverflowServiceUUIDs = []
            UUIDs = advertisementData[
                CBAdvertisementDataOverflowServiceUUIDsKey]
            for UUID in UUIDs:
                p.advOverflowServiceUUIDs.append(CBUUID2String(UUID._.data))
        #   IsConnectable
        if CBAdvertisementDataIsConnectable in advertisementData:
            p.advIsConnectable = advertisementData[
                CBAdvertisementDataIsConnectable]
        #   SolicitedServiceUUIDs
        if CBAdvertisementDataSolicitedServiceUUIDsKey in advertisementData:
            p.advSolicitedServiceUUIDs = []
            UUIDs = advertisementData[
                CBAdvertisementDataSolicitedServiceUUIDsKey]
            for UUID in UUIDs:
                p.advSolicitedServiceUUIDs.append(CBUUID2String(UUID._.data))
        # RSSI
        p.rssi = rssi

        if p not in self.scanedList:
            self.scanedList.append(p)
            self.logger.info("Found Peripheral %s", peripheral._.name)
            self.logger.info("RSSI: %d", rssi)
            self.logger.info("UUID: %s", peripheral._.identifier.UUIDString())
            self.logger.info("State: %s", peripheral._.state)

        # update lists
        self.updateAvailableList()