Пример #1
0
        void _bluettothServerCallback_NotificationSent(object sender, BleEventArgs e)
        {
            var user = JsonConvert.DeserializeObject <UserProfile>(Settings.User);


            _characteristic.SetValue(user.Id);

            _bluetoothServer.NotifyCharacteristicChanged(e.Device, _characteristic, false);
            //if (_count == 0)
            //    {
            //        _sw = new Stopwatch();
            //        _sw.Start();
            //    }

            //    if (_count < 1000)
            //    {


            //        _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);
            //    }
        }
Пример #2
0
        void _bluettothServerCallback_CharacteristicReadRequest(object sender, BleEventArgs e)
        {
            var user = JsonConvert.DeserializeObject <UserProfile>(Settings.User);

            e.Characteristic.SetValue(user.Id);
            if (_readRequestCount == 5)
            {
                _notificationsStarted = !_notificationsStarted;
                _readRequestCount     = 0;
            }
            else
            {
                _readRequestCount++;
                Console.WriteLine("Read req {0}", _readRequestCount);

                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                                              e.Characteristic.GetValue());
                _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
                return;
            }

            if (_notificationsStarted)
            {
                _count = 0;

                Console.WriteLine("Started notifcations!");

                _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("stopped Notifications");
                _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset,
                                              e.Characteristic.GetValue());
            }
        }