Пример #1
0
        /// <summary>
        /// The extension method that retries to transmit a data specified amount of times.
        /// </summary>
        /// <param name="bluetoothConnection">The parameter that represents a current <see cref="IBluetoothConnection"/> instance.</param>
        /// <param name="buffer">The parameter that represents a <see cref="Memory{byte}" /> buffer to transmit.</param>
        /// <param name="retriesCount">The parameter that represents a retries count.</param>
        /// <returns>Returns the <see cref="Task{bool}"/> instance with true if get transmitted otherwise false.</returns>
        public static async Task <bool> RetryTransmitAsync(this IBluetoothConnection bluetoothConnection,
                                                           Memory <byte> buffer,
                                                           CancellationToken cancellationToken = default,
                                                           int retriesCount = 3)
        {
            while (retriesCount > 0)
            {
                try
                {
                    await bluetoothConnection.TransmitAsync(buffer, cancellationToken);

                    return(Success);
                }
                catch (BluetoothDataTransferUnitException)
                {
                    retriesCount--;
                }
                catch
                {
                    throw;
                }
            }

            return(Failed);
        }
Пример #2
0
        /// <summary>
        /// The extension method that retries to transmit a data specified amount of times.
        /// </summary>
        /// <param name="bluetoothConnection">The parameter that represents a current <see cref="IBluetoothConnection"/> instance.</param>
        /// <param name="buffer">The parameter that represents a <see cref="buffer[]"/> to transmit.</param>
        /// <param name="offset">The parameter that represents a buffer offset.</param>
        /// <param name="count">The parameter that represents a cound of bytes to trnasmit.</param>
        /// <param name="retriesCount">The parameter that represents a retries count.</param>
        /// <returns>Returns the <see cref="Task{bool}"/> instance with true if get transmitted otherwise false.</returns>
        public static async Task <bool> RetryTransmitAsync(this IBluetoothConnection bluetoothConnection,
                                                           byte[] buffer,
                                                           int offset,
                                                           int count,
                                                           int retriesCount = 3)
        {
            while (retriesCount > 0)
            {
                try
                {
                    await bluetoothConnection.TransmitAsync(buffer, offset, count);

                    return(Success);
                }
                catch (BluetoothDataTransferUnitException)
                {
                    retriesCount--;
                }
                catch
                {
                    throw;
                }
            }

            return(Failed);
        }
Пример #3
0
        /// <summary>
        /// The extension method that retries to recive a data specified amount of times.
        /// </summary>
        /// <param name="bluetoothConnection">The parameter that represents a current <see cref="IBluetoothConnection"/> instance.</param>
        /// <param name="buffer">The parameter that represents a <see cref="buffer[]"/> to recive.</param>
        /// <param name="offset">The parameter that represents a recive buffer offset.</param>
        /// <param name="count">The parameter that represents a cound of bytes to trnasmit.</param>
        /// <param name="cancellationToken">The parameter that represents a <see cref="CancellationToken"/> instance.</param>
        /// <param name="retriesCount">The parameter that represents a retries count.</param>
        /// <returns>Returns the <see cref="Task{(bool Succeeded, int Count)}"/> instance.</returns>
        public static async Task <(bool Succeeded, int Count)> RetryReciveAsync(this IBluetoothConnection bluetoothConnection,
                                                                                byte[] buffer,
                                                                                int offset,
                                                                                int count,
                                                                                CancellationToken cancellationToken,
                                                                                int retriesCount = 3)
        {
            while (retriesCount > 0)
            {
                try
                {
                    int result = await bluetoothConnection.ReciveAsync(buffer, offset, count, cancellationToken);

                    return(Success, result);
                }
                catch (BluetoothDataTransferUnitException)
                {
                    retriesCount--;
                }
                catch
                {
                    throw;
                }

                return(Failed, default);
            }

            return(default);
Пример #4
0
        /// <summary> Create a new Pebble connection </summary>
        /// <param name="connection"></param>
        public PebbleProtocol(IBluetoothConnection connection)
        {
            _blueToothConnection = connection;

            _blueToothConnection.DataReceived += SerialPortDataReceived;
            //TODO: Push this on to the clients.... do we even care if there is an error?
            //_BlueToothPort.ErrorReceived += serialPortErrorReceived;
        }
Пример #5
0
        /// <summary> Create a new Pebble connection </summary>
        /// <param name="connection"></param>
        public PebbleProtocol( IBluetoothConnection connection )
        {
            _blueToothConnection = connection;

            _blueToothConnection.DataReceived += SerialPortDataReceived;
            //TODO: Push this on to the clients.... do we even care if there is an error?
            //_BlueToothPort.ErrorReceived += serialPortErrorReceived;
        }
Пример #6
0
        /// <summary>
        ///     Create a new Pebble
        /// </summary>
        /// <param name="connection">The port to use to connect to the pebble</param>
        /// <param name="pebbleId">
        ///     The four-character Pebble ID, based on its BT address.
        ///     Nothing explodes when it's incorrect, it's merely used for identification.
        /// </param>
        public Pebble(IBluetoothConnection connection, string pebbleId)
        {
            ResponseTimeout = TimeSpan.FromSeconds(5);
            PebbleID        = pebbleId;

            _callbackHandlers = new Dictionary <Type, List <CallbackContainer> >();

            _PebbleProt = new PebbleProtocol(connection);
            _PebbleProt.RawMessageReceived += RawMessageReceived;
        }
Пример #7
0
        /// <summary>
        ///     Create a new Pebble
        /// </summary>
        /// <param name="connection">The port to use to connect to the pebble</param>
        /// <param name="pebbleId">
        ///     The four-character Pebble ID, based on its BT address.
        ///     Nothing explodes when it's incorrect, it's merely used for identification.
        /// </param>
        protected Pebble(IBluetoothConnection connection, string pebbleId)
        {
            ResponseTimeout = TimeSpan.FromSeconds(5);
            PebbleID        = pebbleId;
            BlobDBClient    = new BlobDBClient(this);
            PutBytesClient  = new PutBytesClient(this);
            InstallClient   = new InstallClient(this);

            _callbackHandlers = new Dictionary <Type, List <CallbackContainer> >();

            _PebbleProt = new PebbleProtocol(connection);
            _PebbleProt.RawMessageReceived += RawMessageReceived;

            RegisterCallback <AppMessagePacket>(OnApplicationMessageReceived);
        }
Пример #8
0
        /***
         * This method is always called when the screen is appearing (right before it happens).
         * sets the bluetooth's connectionName depending on the value of currPlayer.
         * tries to connect to the device which was set.
         */
        protected override void OnAppearing()
        {
            btConnection = DependencyService.Get <IBluetoothConnection>();
            string connectTo;

            if (currPlayer == "player1")
            {
                connectTo = "spinit";
            }
            else
            {
                connectTo = "spinit2";
            }
            btConnection.SetConnectionName(connectTo);
            connectToBT();
        }
Пример #9
0
        private BoxConnection()
        {
            Debug.WriteLine("BoxConnection");

            try
            {
                _bluetoothConnection = DependencyService.Get <IBluetoothConnection>();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.InnerException?.Message);
                Debug.WriteLine(e.InnerException?.StackTrace);
            }

            Debug.WriteLine("Bluetooth service: " + _bluetoothConnection);

            if (_bluetoothConnection.IsConnected() != BluetoothStatus.CONNECTED)
            {
                _bluetoothConnection.RequestBluetoothConnection();
            }
        }
Пример #10
0
        /// <summary>
        /// The extension method that retries to connect to the remote device a specified amount of times.
        /// </summary>
        /// <param name="bluetoothConnection">The parameter that represents a current <see cref="IBluetoothConnection"/> instance.</param>
        /// <param name="retriesCount">The parameter that represents a retries count.</param>
        /// <returns>Returns the <see cref="Task{bool}"/> instance with true if get connected otherwise false.</returns>
        public static async Task <bool> RetryConnectAsync(this IBluetoothConnection bluetoothConnection,
                                                          int retriesCount = 3)
        {
            while (retriesCount > 0)
            {
                try
                {
                    await bluetoothConnection.ConnectAsync();

                    return(Success);
                }
                catch (BluetoothConnectionException)
                {
                    retriesCount--;
                }
                catch
                {
                    throw;
                }
            }

            return(Failed);
        }
Пример #11
0
 public TestPebble(IBluetoothConnection connection, string pebbleId)
     : base(connection, pebbleId)
 {
 }
Пример #12
0
 public TestPebble( IBluetoothConnection connection, string pebbleId )
     : base( connection, pebbleId )
 {
 }