Inheritance: System.EventArgs
Esempio n. 1
0
        void _bluettothServerCallback_NotificationSent(object sender, BleEventArgs e)
        {
            if (_count == 0)
            {
                _sw = new Stopwatch();
                _sw.Start();
            }

            if (_count < 1000)
            {
                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 20)
                        .Select(s => s[random.Next(s.Length)])
                        .ToArray());
                _characteristic.SetValue(result);

                _bluetoothServer.NotifyCharacteristicChanged(e.Device, _characteristic, false);

                _count++;

            }
            else
            {
                _sw.Stop();
                Console.WriteLine("Sent # {0} notifcations. Total kb:{2}. Time {3}(s). Throughput {1} bytes/s", _count,
                    _count * 20.0f / _sw.Elapsed.TotalSeconds, _count * 20 / 1000, _sw.Elapsed.TotalSeconds);
            }
        }
Esempio n. 2
0
        void _bluettothServerCallback_NotificationSent(object sender, BleEventArgs e)
        {
            if (_count == 0)
            {
                _sw = new Stopwatch();
                _sw.Start();
            }

            if (_count < 1000)
            {
                var chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                var result = new string(
                    Enumerable.Repeat(chars, 20)
                    .Select(s => s[random.Next(s.Length)])
                    .ToArray());
                _characteristic.SetValue(result);

                _bluetoothServer.NotifyCharacteristicChanged(e.Device, _characteristic, false);

                _count++;
            }
            else
            {
                _sw.Stop();
                Console.WriteLine("Sent # {0} notifcations. Total kb:{2}. Time {3}(s). Throughput {1} bytes/s", _count,
                                  _count * 20.0f / _sw.Elapsed.TotalSeconds, _count * 20 / 1000, _sw.Elapsed.TotalSeconds);
            }
        }
Esempio n. 3
0
        void _bluettothServerCallback_CharacteristicReadRequest(object sender, BleEventArgs e)
        {
            if (_readRequestCount == 5)
            {
                _notificationsStarted = !_notificationsStarted;
                _readRequestCount     = 0;
            }
            else
            {
                _readRequestCount++;
                Console.WriteLine("Read req {0}", _readRequestCount);
                e.Characteristic.SetValue(String.Format("Right on {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                                              e.Characteristic.GetValue());
                return;
            }

            if (_notificationsStarted)
            {
                _count = 0;

                Console.WriteLine("Started notifcations!");

                e.Characteristic.SetValue(String.Format("Start {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                                              e.Characteristic.GetValue());
                _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
            }
            else
            {
                Console.WriteLine("Stopped notifcations!");
                e.Characteristic.SetValue(String.Format("Stop {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                                              e.Characteristic.GetValue());
                _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
            }
        }
Esempio n. 4
0
        void _bluettothServerCallback_CharacteristicReadRequest(object sender, BleEventArgs e)
        {
            if (_readRequestCount == 5)
            {
                _notificationsStarted = !_notificationsStarted;
                _readRequestCount = 0;

            }
            else
            {
                _readRequestCount++;
                Console.WriteLine("Read req {0}", _readRequestCount);
                e.Characteristic.SetValue(String.Format("Right on {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                    e.Characteristic.GetValue());
                return;
            }

            if (_notificationsStarted)
            {
                _count = 0;

                Console.WriteLine("Started notifcations!");

                e.Characteristic.SetValue(String.Format("Start {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                    e.Characteristic.GetValue());
                _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
            }
            else
            {
                Console.WriteLine("Stopped notifcations!");
                e.Characteristic.SetValue(String.Format("Stop {0}!", _readRequestCount));
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                    e.Characteristic.GetValue());
                _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
            }
        }
 void _bluettothServerCallback_CharacteristicReadRequest(object sender, BleEventArgs e)
 {
     e.Characteristic.SetValue(_data);
     _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset, e.Characteristic.GetValue());
 }