Beispiel #1
0
        void SetupWrite()
        {
            if (this.onWrite == null)
            {
                return;
            }

            this.context
            .CharacteristicWrite
            .Where(x => x.Characteristic.Equals(this.Native))
            .Subscribe(ch =>
            {
                var peripheral = new Peripheral(ch.Device);
                var request    = new WriteRequest(this, peripheral, ch.Value, ch.Offset, ch.ResponseNeeded);
                var state      = this.onWrite(request);

                if (request.IsReplyNeeded)
                {
                    this.context.Server.SendResponse(
                        ch.Device,
                        ch.RequestId,
                        state.ToNative(),
                        ch.Offset,
                        ch.Value
                        );
                }
            })
            .DisposedBy(this.disposer);
        }
Beispiel #2
0
        void SetupRead()
        {
            if (this.onRead == null)
            {
                return;
            }

            this.context
            .CharacteristicRead
            .Where(x => x.Characteristic.Equals(this.Native))
            .Subscribe(ch =>
            {
                var peripheral = new Peripheral(ch.Device);
                var request    = new ReadRequest(this, peripheral, ch.Offset);
                var result     = this.onRead(request);

                this.context.Server.SendResponse
                (
                    ch.Device,
                    ch.RequestId,
                    result.Status.ToNative(),
                    ch.Offset,
                    result.Data
                );
            })
            .DisposedBy(this.disposer);
        }
Beispiel #3
0
        IPeripheral GetOrAdd(BluetoothDevice native)
        {
            lock (this.subscribers)
            {
                if (this.subscribers.ContainsKey(native.Address))
                {
                    return(this.subscribers[native.Address]);
                }

                var device = new Peripheral(native);
                this.subscribers.Add(native.Address, device);
                return(device);
            }
        }