public Advertisement(Peripheral device, NSDictionary advertisementData, NSNumber rssi)
 {
     _peripheral = device;
     _rssi       = rssi.Int32Value;
     if (advertisementData[CBAdvertisement.DataLocalNameKey] is NSString name)
     {
         _localName = Encoding.UTF8.GetBytes(name);
     }
     if (advertisementData[CBAdvertisement.DataManufacturerDataKey] is NSData data)
     {
         _manufacturerData = data.ToArray();
     }
     if (advertisementData[CBAdvertisement.DataTxPowerLevelKey] is NSNumber number)
     {
         _txPower = number.Int32Value;
     }
     if (advertisementData[CBAdvertisement.DataServiceUUIDsKey] is NSArray services)
     {
         _services = ExtractServiceUuids(services);
     }
     if (advertisementData["kCBAdvDataTimestamp"] is NSNumber stamp)
     {
         _timestamp = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(stamp.DoubleValue);
     }
     else
     {
         _timestamp = DateTime.UtcNow;
     }
 }
 public PeripheralConnection(Peripheral device, int num)
 {
     _device     = device;
     _adapter    = device.Adapter;
     _peripheral = device.CBPeripheral;
     _central    = _adapter.CentralManager;
     _loggerId   = $"BLEConnection:{device.Uuid}:{num}";
     _logger     = _adapter._loggerFactory.CreateLogger(_loggerId);
     _q          = new OperationQueue(_logger);
 }
예제 #3
0
        Peripheral GetPeripheral(CBPeripheral peripheral)
        {
            var uuid = peripheral.Identifier.ToUuid();

            if (_devices.TryGetValue(uuid, out var bleDevice))
            {
                bleDevice.UpdateCBPeripheral(peripheral);
                return(bleDevice);
            }

            return(_devices[uuid] = new Peripheral(this, uuid, peripheral));
        }