def retrievePeriphersWithIdentifiers(self, identifiers):
     if not isinstance(identifiers, list) and isinstance(identifiers, str):
         identifiers = list(identifiers.split())
     known_identifiers = NSMutableArray.alloc().init()
     for identifier in identifiers:
         UUID = NSUUID.alloc().UUIDWithString_(identifer)
         if UUID is not nil:
             known_identifiers.addObject_(UUID)
     peripherals = self.manager.retrievePeripheralsWithIdentifiers_(known_identifiers)
     for p in peripherals:
         if not self.findPeripheralFromList(p, self.scanedList):
             temp = OSXPeripheral.alloc().init()
             temp.instance = p
             temp.UUID = uuid.UUID(p._.identifier.UUIDString())
             temp.name=p._.name
             self.scanedList.append(temp)
     # update lists
     self.updateAvailableList()
 def retrieveConnectedPeripheralsWithServices(self, services):
     if not isinstance(services, list) and isinstance(services, str):
         services = list(services.split())
     known_services = NSMutableArray.alloc().init()
     for service in services:
         UUID = CBUUID.UUIDWithString_(service)
         if UUID is not nil:
             known_services.addObject_(UUID)
     peripherals = self.manager.retrieveConnectedPeripheralsWithServices_(known_services)
     for p in peripherals:
         if not self.findPeripheralFromList(p, self.scanedList):
             temp = OSXPeripheral.alloc().init()
             temp.instance = p
             temp.UUID = uuid.UUID(p._.identifier.UUIDString())
             temp.name=p._.name
             self.scanedList.append(temp)
     # update lists
     self.updateAvailableList()
Beispiel #3
0
 def retrievePeriphersWithIdentifiers(self, identifiers):
     if not isinstance(identifiers, list) and isinstance(identifiers, str):
         identifiers = list(identifiers.split())
     known_identifiers = NSMutableArray.alloc().init()
     for identifier in identifiers:
         UUID = NSUUID.alloc().UUIDWithString_(identifer)
         if UUID is not nil:
             known_identifiers.addObject_(UUID)
     peripherals = self.manager.retrievePeripheralsWithIdentifiers_(
         known_identifiers)
     for p in peripherals:
         if not self.findPeripheralFromList(p, self.scanedList):
             temp = OSXPeripheral.alloc().init()
             temp.instance = p
             temp.UUID = uuid.UUID(p._.identifier.UUIDString())
             temp.name = p._.name
             self.scanedList.append(temp)
     # update lists
     self.updateAvailableList()
Beispiel #4
0
 def retrieveConnectedPeripheralsWithServices(self, services):
     if not isinstance(services, list) and isinstance(services, str):
         services = list(services.split())
     known_services = NSMutableArray.alloc().init()
     for service in services:
         UUID = CBUUID.UUIDWithString_(service)
         if UUID is not nil:
             known_services.addObject_(UUID)
     peripherals = self.manager.retrieveConnectedPeripheralsWithServices_(
         known_services)
     for p in peripherals:
         if not self.findPeripheralFromList(p, self.scanedList):
             temp = OSXPeripheral.alloc().init()
             temp.instance = p
             temp.UUID = uuid.UUID(p._.identifier.UUIDString())
             temp.name = p._.name
             self.scanedList.append(temp)
     # update lists
     self.updateAvailableList()
    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()
Beispiel #6
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()