示例#1
0
        // BluetoothLEAdvertisementWatcher

        private void OnWatcherReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs args)
        {
            // Utils.Info("OnWatcherReceived: {0}", args.Advertisement.ManufacturerData.Count);

            lock (mLockObject)
            {
                if (mStatus != Status.Scan)
                {
                    Utils.Error("invalid status: {0}", mStatus.ToString());
                    return;
                }

                if (mDiscoveredPeripherals.Exists(ctx => ctx.Address == args.BluetoothAddress))
                {
                    return;
                }

                string deviceName = args.Advertisement.LocalName;
                if (string.IsNullOrEmpty(deviceName))
                {
                    // HACK: ScanResponseが取得できないので暫定
                    deviceName = args.BluetoothAddress.ToString();

                    /*
                     * Utils.Error("device-name not exists");
                     * return;
                     */
                }

                var context = new PeripheralContext(args.BluetoothAddress, mNextPeripheralId++, deviceName);
                mDiscoveredPeripherals.Add(context);

                Utils.Info("discover deviceName: {0} deviceId: {1}", context.Name, context.Id);

                mCallback.OnDiscover(context.Name, context.Id);
            }
        }