コード例 #1
0
 /// <summary>
 /// Get the public key from the sender.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void GetPubKeyPortion(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     if (ArdPubKeyStr.Length < 136)
     {
         ArdPubKeyStr += e.Characteristic.StringValue;
     }
 }
コード例 #2
0
        //Event that is called when the value of the characteristic is changed
        private void CharacteristicEvent_ValueChanged(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args)
        {
            var buffer    = args.Characteristic.Value;
            var charEvent = new CharacteristicEvent(buffer);

            ValueChanged?.Invoke(sender, charEvent);
        }
コード例 #3
0
        /// <summary>
        /// Event raised when the bluettoth device notify a value change
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCharacteristicValueChangeEvent(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            if (this.eventAggregator == null)
            {
                eventAggregator = (IEventAggregator)App.Current.Container.Resolve(typeof(IEventAggregator));
            }

            DialogBehaviourHolder beahaviour = FreeStyleLibreUtils.RespondToPacketBehaviour(e.Characteristic.Value);

            switch (beahaviour.ResponseType)
            {
            case PacketResponseType.Accept:
                eventAggregator.GetEvent <MeasureChangeEvent>().Publish(beahaviour.ReceivedData);
                this.MeasureServiceState = MeasureServiceState.RECEIVING_DATA;
                break;

            case PacketResponseType.AnswerBack:
                WriteCharacteristicAsync(MiaoMiaoProtocol.NRF_UART_RX, beahaviour.Response);
                break;

            case PacketResponseType.Refuse:
                this.MeasureServiceState = MeasureServiceState.REFUSED_DATA_THEN_WAIT;
                break;

            case PacketResponseType.Ignore:
            default:
                this.MeasureServiceState = MeasureServiceState.WAITING_DATA;
                break;
            }
        }
コード例 #4
0
        //Event that is called when the value of the characteristic is changed
        private void CharacteristicEvent_ValueChanged(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args)
        {
            Debug.WriteLine("CharateristicEvent : " + args.ToString());

            if (args == null)
            {
                Debug.WriteLine("Args is null.");
            }
            if (args.Characteristic == null)
            {
                Debug.WriteLine("Args.Characteristic is null.");
            }
            if (args.Characteristic.Value == null)
            {
                Debug.WriteLine("Args.Characteristic.Value is null.");
            }
            if (_ValueChanged == null)
            {
                Debug.WriteLine("ValueChanged is null.");
            }

            var buffer    = args.Characteristic.Value;
            var charEvent = new CharacteristicEvent(buffer);

            _ValueChanged?.Invoke(sender, charEvent);
        }
コード例 #5
0
        /// <summary>
        /// This is the event handler that runs every time the Arduino sends a new message.
        /// It parses the message to an array and sends the values to both the graph
        /// and the SaMi object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Characteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            string valueString = Encoding.Default.GetString(e.Characteristic.Value);
            int    count       = valueString.Length - valueString.Replace(",", "").Length;

            if (count != 5 || valueString[0] == ',')
            {
                return;
            }
            double[] values;

            /*This part is wrapped in a try/catch because BLE messages can be a bit jumbled when
             * connection has just been established. Jumbled message won't parse, of course,
             * so they get skipped.*/
            try
            {
                values = Array.ConvertAll(valueString.Split(','), Double.Parse);
            }
            catch
            {
                return;
            }
            SenProReading newReading = new SenProReading {
                DateTime = DateTime.Now, Values = values
            };
            double dateTimePlot = DateTimeAxis.ToDouble(newReading.DateTime);

            (plot.Model.Series[0] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[0]));
            (plot.Model.Series[1] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[1]));
            (plot.Model.Series[2] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[2]));
            (plot.Model.Series[3] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[3]));
            (plot.Model.Series[4] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[4]));
            (plot.Model.Series[5] as LineSeries).Points.Add(new DataPoint(dateTimePlot, newReading.Values[5]));

            if ((plot.Model.Series[0] as LineSeries).Points.Count > 15)
            {
                (plot.Model.Series[0] as LineSeries).Points.RemoveAt(0);
                (plot.Model.Series[1] as LineSeries).Points.RemoveAt(0);
                (plot.Model.Series[2] as LineSeries).Points.RemoveAt(0);
                (plot.Model.Series[3] as LineSeries).Points.RemoveAt(0);
                (plot.Model.Series[4] as LineSeries).Points.RemoveAt(0);
                (plot.Model.Series[5] as LineSeries).Points.RemoveAt(0);
            }

            plot.Model.Axes[0].Maximum = DateTimeAxis.ToDouble(newReading.DateTime.AddSeconds(2));
            plot.Model.Axes[0].Minimum = DateTimeAxis.ToDouble(newReading.DateTime.AddSeconds(-8));

            samiClient.AddMeasurement(newReading);

            if (samiClient.MeasurementMinuteCheck())
            {
                samiClient.SaveResults();
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                plot.InvalidatePlot();
            });
        }
コード例 #6
0
        //블루투스로 데이터 계속 옴
        private void Character_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            var         bytes    = e.Characteristic.Value;
            GBGProtocol protocol = new GBGProtocol();
            string      retData  = "";

            if (bytes.Length > 1)
            {
                recvData = protocol.DeviceToApp_ParseRecvData(bytes.ToList(), int.Parse(protocolVer.Text));
                JObject j = JObject.Parse(recvData);
                if (!j.HasValues)
                {
                    return;
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    lblRecvValue.Text = recvData;
                    if (j.HasValues)
                    {
                        if (j["type"] != null)
                        {
                            if (j["type"].ToString() == "KGAIR" && j["result"].ToString() == "SUCCESS")
                            {
                                if (j["subType"].ToString() == "PM25/PM10/VOC/CO2/TEMP/HUMI")
                                {
                                    /*
                                     * kgAirPage.SetJsonData(recvData);
                                     * if (!Navigation.NavigationStack.Contains(kgAirPage))
                                     * {
                                     *  Navigation.PushAsync(kgAirPage);
                                     * }
                                     */
                                    dgMain2.setAirValue(j.ToString());
                                }
                                else if (j["subType"].ToString() == "KG/LB/FAT/VFAT")
                                {
                                    dgMain.setFat(j["FAT"].ToString());
                                }
                                else if (j["subType"].ToString() == "WATER/MUSCLE")
                                {
                                    dgMain.setWater(j["WATER"].ToString());
                                    dgMain.setMuscle(j["MUSCLE"].ToString());
                                }
                                else if (j["subType"].ToString() == "BONE/KCAL/BMI")
                                {
                                    dgMain.setKcal(j["KCAL"].ToString());
                                    dgMain.setBone(j["BONE"].ToString());
                                }
                            }
                            else if (j["type"].ToString() == "ONLYKG" && j["result"].ToString() == "SUCCESS")
                            {
                                dgMain.setWeight(j["KG"].ToString());
                            }
                        }
                    }
                });
            }
        }
コード例 #7
0
 private void CharLevel_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         showLevel();
         BtnRefresh.IsEnabled = true;
     });
 }
コード例 #8
0
ファイル: AudioViewer.cs プロジェクト: ingchips/INGdemo
 private void CharOutput_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     if (Decoder != null)
     {
         Decoder.Decode(e.Characteristic.Value);
     }
     Device.BeginInvokeOnMainThread(() =>
                                    label.Text = Utils.ByteArrayToString(e.Characteristic.Value)
                                    );
 }
コード例 #9
0
        private void TX_Updated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            string stringValue = e.Characteristic.StringValue;

            string[] split       = stringValue.Split(',');
            string   floatString = new string(split[1].Where(x => char.IsDigit(x) || x == '.').ToArray());
            float    val         = float.Parse(floatString);

            Console.WriteLine(val);
        }
コード例 #10
0
ファイル: BleManager.cs プロジェクト: versx/Suota-Go-Plus
        private void KeyChar_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            Guid uuid = e.Characteristic.Id;

            byte[] value  = e.Characteristic.Value;
            string valStr = Helper.ByteArrayToString(value);

            _logger.Log($"Characteristic updated {uuid}; New value {valStr}", Category.Info, Priority.None);
            var charValue = new CharacteristicUpdate(uuid, value);

            _aggregator.GetEvent <PrismEvents.CharacteristicUpdatedEvent>().Publish(charValue);
        }
コード例 #11
0
        /// <summary>
        /// Gets the encrypted message from the Bluetooth sender.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void GetEncryptedMessagePortion(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            if (EncryptedMsg.Length < 64)
            {
                EncryptedMsg += e.Characteristic.StringValue;
            }

            if (EncryptedMsg.Length == 64)
            {
                await Task.Run(() => DecryptMessageAndNotify(EncryptedMsg));
            }
        }
コード例 #12
0
        private async void characteristicValueChange(Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args, ICharacteristic characteristic1, IDevice device)
        {
            string x = args.Characteristic.StringValue;

            System.Diagnostics.Debug.WriteLine(x);
            await characteristic1.StopUpdatesAsync();

            await CrossBluetoothLE.Current.Adapter.DisconnectDeviceAsync(device);

            deviceToggle.IsToggled = x[0] == '1';
            return;
        }
コード例 #13
0
ファイル: ConsoleView.cs プロジェクト: ingchips/INGdemo
        private void CharOutput_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            var b = charOutput.Value;

            if (b == null)
            {
                return;
            }
            b = b.Select((v) => v != 0 ? v : (byte)10).ToArray();
            Device.BeginInvokeOnMainThread(() =>
            {
                DataLog.Text = DataLog.Text + Encoding.UTF8.GetString(b);
            });
        }
コード例 #14
0
 private void ReadCharacteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     try
     {
         if (e.Characteristic?.Value is object)
         {
             RcvdDataString = Encoding.UTF8.GetString(e.Characteristic.Value);
             RcvdDataHandler.Invoke(this, null);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Error recieving data - {ex.Message}");
     }
 }
コード例 #15
0
ファイル: DirFindingViewer.cs プロジェクト: ingchips/INGdemo
        private void CharOutput_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
        {
            var b = charIQ.Value;

            if (b?.Length < 17)
            {
                return;
            }

            double angle = Estimator.Estimate(b[0], b.Skip(1).Select(x => (sbyte)x).ToArray());

            Device.BeginInvokeOnMainThread(() =>
            {
                AngleLable.Text    = string.Format("{0:F1} Deg", 360 * angle / (2 * Math.PI));
                Indicator.AngleRad = angle;
            });
        }
コード例 #16
0
 void Characteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     string uuid = e.Characteristic.Uuid.ToUpper();
     Android.Util.Log.Debug("BLE", "Notify Received. " + e.Characteristic.Value[0].ToString() + " (" + uuid + ")");
     TextView text = FindViewById<TextView>(Resource.Id.textView1);
     this.RunOnUiThread(() =>
     {
         if (e.Characteristic.Value[0] == 0)
         {
             text.Text = "OFF";
         }
         else
         {
             text.Text = "ON";
         }
     });
 }
コード例 #17
0
        private async void CharacteristicHR_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args)
        {
            // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
            // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml

            try
            {
                int heartValue;
                var bytes = args.Characteristic.Value;

                heartValue = bytes[1];

                if (_currentValue == null)
                {
                    _currentValue = new HeartRateData();
                }

                _currentValue.Value     = bytes[1];
                _currentValue.Timestamp = DateTime.Now;


                if (_characteristicBatteryLevel != null)
                {
                    if (_currentValue.TimestampBatteryLevel == null ||
                        (DateTime.Now - _currentValue.TimestampBatteryLevel).Value.Minutes > 1)
                    {
                        _currentValue.BatteryLevel = null;

                        var batteryLevelByte = await _characteristicBatteryLevel?.ReadAsync();

                        _currentValue.TimestampBatteryLevel = DateTime.Now;
                        _currentValue.BatteryLevel          = batteryLevelByte[0];
                    }
                }

                _log("CharacteristicHR_ValueUpdated", $"Device {_currentValue.Value}");
            }
            catch (Exception e)
            {
                _log("CharacteristicHR_ValueUpdated", e.Message);
            }
        }
コード例 #18
0
        private async void CharacteristicHR_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs args)
        {
            // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
            // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml

            try
            {
                int heartValue;
                var bytes = args.Characteristic.Value;

                byte flags = bytes[0];
                int  header;

                if ((flags & 0x1) == 0x1)
                {
                    // HB data is 16 bits (bytes[2]bytes[1] since it's LSB first)
                    header     = (bytes[2] >> 4);                    // First 4 bits
                    heartValue = bytes[1] | ((0xF & bytes[2]) << 8); // Next 12

                    if (heartValue == 0xFFF)
                    {
                        heartValue = -1;
                    }

                    if (_update_func != null)
                    {
                        await _update_func(header, heartValue);
                    }
                }
                else
                {
                    header     = 0;
                    heartValue = bytes[1];

                    if (_update_func != null)
                    {
                        await _update_func(header, heartValue);
                    }
                }

                if (_currentValue == null)
                {
                    _currentValue = new HeartRateData();
                }

                _currentValue.Value     = bytes[1];
                _currentValue.Timestamp = DateTime.Now;


                if (_characteristicBatteryLevel != null)
                {
                    if (_currentValue.TimestampBatteryLevel == null ||
                        (DateTime.Now - _currentValue.TimestampBatteryLevel).Value.Minutes > 1)
                    {
                        _currentValue.BatteryLevel = null;

                        var batteryLevelByte = await _characteristicBatteryLevel?.ReadAsync();

                        _currentValue.TimestampBatteryLevel = DateTime.Now;
                        _currentValue.BatteryLevel          = batteryLevelByte[0];
                    }
                }

                _log("CharacteristicHR_ValueUpdated", $"Device {_currentValue.Value}");
            }
            catch (Exception e)
            {
                _log("CharacteristicHR_ValueUpdated", e.Message);
            }
        }
コード例 #19
0
ファイル: CgmPageViewModel.cs プロジェクト: xians78/eDroplet
 private void DataReadCharacteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     Debug.WriteLine("Data: " + General.ByteArrayToString(e.Characteristic.Value));
 }
コード例 #20
0
ファイル: CgmPageViewModel.cs プロジェクト: xians78/eDroplet
 private void BatteryVoltageCharacteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     dialogScr.Toast("Battery voltage: " + e.Characteristic.Value[0].ToString() + " %");
 }
コード例 #21
0
 void MinorCharacteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     minor.Text = ByteArrayToString(e.Characteristic.Value);
 }
コード例 #22
0
 private void CharOutput_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     S2MByteCounter += (int)charOutput.Value?.Length;
 }
コード例 #23
0
ファイル: Thermometer.cs プロジェクト: ingchips/INGdemo
 private void CharMeasValue_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     Device.BeginInvokeOnMainThread(() => {
         ShowMeasValue(charMeasValue.Value);
     });
 }
コード例 #24
0
 private void RxCharacteristic_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
 {
     TextRx += Encoding.ASCII.GetString(e.Characteristic.Value);
 }