Пример #1
0
        /// <summary>
        /// Full Constructor with all options
        /// </summary>
        /// <param name="bdAddr">Bluetooth device address</param>
        /// <param name="latencyMode">Latency mode</param>
        /// <param name="autoDisconnectTime">Auto disconnect time</param>
        public ButtonConnectionChannel(Bdaddr bdAddr, LatencyMode latencyMode, short autoDisconnectTime)
        {
            if (bdAddr == null)
            {
                throw new ArgumentNullException(nameof(bdAddr));
            }

            BdAddr              = bdAddr;
            _latencyMode        = latencyMode;
            _autoDisconnectTime = autoDisconnectTime;
        }
Пример #2
0
        protected override void ParseInternal(BinaryReader reader)
        {
            BdAddr = new Bdaddr(reader);
            var uuidBytes = reader.ReadBytes(16);

            if (uuidBytes.Length != 16)
            {
                throw new EndOfStreamException();
            }
            var sb = new StringBuilder(32);

            for (var i = 0; i < 16; i++)
            {
                sb.Append(string.Format("{0:x2}", uuidBytes[i]));
            }
            Uuid = sb.ToString();
            if (Uuid == "00000000000000000000000000000000")
            {
                Uuid = null;
            }

            if (reader.PeekChar() == -1)
            {
                // For old protocol
                return;
            }
            int colorLen   = reader.ReadByte();
            var colorBytes = new byte[colorLen];

            for (var i = 0; i < colorLen; i++)
            {
                colorBytes[i] = reader.ReadByte();
            }
            for (var i = colorLen; i < 16; i++)
            {
                reader.ReadByte();
            }
            Color = colorLen == 0 ? null : Encoding.UTF8.GetString(colorBytes);

            int serialNumberLen   = reader.ReadByte();
            var serialNumberBytes = new byte[serialNumberLen];

            for (var i = 0; i < serialNumberLen; i++)
            {
                serialNumberBytes[i] = reader.ReadByte();
            }
            for (var i = serialNumberLen; i < 16; i++)
            {
                reader.ReadByte();
            }
            SerialNumber    = serialNumberLen == 0 ? null : Encoding.UTF8.GetString(serialNumberBytes);
            FlicVersion     = reader.ReadByte();
            FirmwareVersion = reader.ReadUInt32();
        }
Пример #3
0
        /// <summary>
        /// Forces disconnect of a button.
        /// All connection channels among all clients the server has for this button will be removed.
        /// </summary>
        /// <param name="bdAddr">Bluetooth device address</param>
        public void ForceDisconnect(Bdaddr bdAddr)
        {
            if (bdAddr == null)
            {
                throw new ArgumentNullException(nameof(bdAddr));
            }

            SendPacket(new CmdForceDisconnect {
                BdAddr = bdAddr
            });
        }
Пример #4
0
        /// <summary>
        /// Requests info for a button.
        /// A null UUID will be sent to the callback if the button was not verified before.
        /// </summary>
        /// <param name="bdAddr">Bluetooth device address</param>
        /// <param name="callback">Callback to be invoked when the response arrives</param>
        public void GetButtonInfo(Bdaddr bdAddr, GetButtonInfoResponseCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            lock (_getButtonInfoResponseCallbackQueue)
            {
                _getButtonInfoResponseCallbackQueue.Enqueue(callback);
                SendPacket(new CmdGetButtonInfo {
                    BdAddr = bdAddr
                });
            }
        }
        protected override void ParseInternal(BinaryReader reader)
        {
            ScanWizardId = reader.ReadUInt32();
            BdAddr       = new Bdaddr(reader);
            int nameLen = reader.ReadByte();
            var bytes   = new byte[nameLen];

            for (var i = 0; i < nameLen; i++)
            {
                bytes[i] = reader.ReadByte();
            }
            for (var i = nameLen; i < 16; i++)
            {
                reader.ReadByte();
            }
            Name = Encoding.UTF8.GetString(bytes);
        }
        protected override void ParseInternal(BinaryReader reader)
        {
            BluetoothControllerState = (BluetoothControllerState)reader.ReadByte();
            MyBdAddr                         = new Bdaddr(reader);
            MyBdAddrType                     = (BdAddrType)reader.ReadByte();
            MaxPendingConnections            = reader.ReadByte();
            MaxConcurrentlyConnectedButtons  = reader.ReadInt16();
            CurrentPendingConnections        = reader.ReadByte();
            CurrentlyNoSpaceForNewConnection = reader.ReadBoolean();
            var nbVerifiedButtons = reader.ReadUInt16();

            BdAddrOfVerifiedButtons = new Bdaddr[nbVerifiedButtons];
            for (var i = 0; i < nbVerifiedButtons; i++)
            {
                BdAddrOfVerifiedButtons[i] = new Bdaddr(reader);
            }
        }
        protected override void ParseInternal(BinaryReader reader)
        {
            ScanId = reader.ReadUInt32();
            BdAddr = new Bdaddr(reader);
            int nameLen = reader.ReadByte();
            var bytes   = new byte[nameLen];

            for (var i = 0; i < nameLen; i++)
            {
                bytes[i] = reader.ReadByte();
            }
            for (var i = nameLen; i < 16; i++)
            {
                reader.ReadByte();
            }
            Name            = Encoding.UTF8.GetString(bytes);
            Rssi            = reader.ReadSByte();
            IsPrivate       = reader.ReadBoolean();
            AlreadyVerified = reader.ReadBoolean();
        }
        protected override void ParseInternal(BinaryReader reader)
        {
            BdAddr = new Bdaddr(reader);
            var uuidBytes = reader.ReadBytes(16);

            if (uuidBytes.Length != 16)
            {
                throw new EndOfStreamException();
            }
            var sb = new StringBuilder(32);

            for (var i = 0; i < 16; i++)
            {
                sb.Append(string.Format("{0:x2}", uuidBytes[i]));
            }
            Uuid = sb.ToString();
            if (Uuid == "00000000000000000000000000000000")
            {
                Uuid = null;
            }
        }
Пример #9
0
 /// <summary>
 /// Constructor that uses default values of latency mode (normal latency) and auto disconnect time (disable auto disconnect mechanism)
 /// </summary>
 /// <param name="bdAddr">Bluetooth device address</param>
 public ButtonConnectionChannel(Bdaddr bdAddr) : this(bdAddr, LatencyMode.NormalLatency, 0x1ff)
 {
 }
Пример #10
0
 protected override void ParseInternal(BinaryReader reader)
 {
     BdAddr = new Bdaddr(reader);
 }
Пример #11
0
 protected override void ParseInternal(BinaryReader reader)
 {
     BdAddr = new Bdaddr(reader);
     DeletedByThisClient = reader.ReadBoolean();
 }