Exemplo n.º 1
0
        public void LogData(HeartRateServiceData data)
        {
            String line = "";

            if (!File.Exists(filename))
            {
                line += HeartRateServiceData.GetCsVHeader() + Environment.NewLine;
            }
            line += data.ToString();
            using (var streamWriter = new StreamWriter(filename, true))
            {
                streamWriter.WriteLine(line);
            }
        }
Exemplo n.º 2
0
        private void HeartRate_ValueChanged(
            GattCharacteristic sender,
            GattValueChangedEventArgs args)
        {
            var value = args.CharacteristicValue;

            if (value.Length == 0)
            {
                return;
            }

            using (var reader = DataReader.FromBuffer(value))
            {
                byte[] data = new byte[value.Length];
                reader.ReadBytes(data);
                var bpm           = -1;
                var flags         = data[0];
                var isshort       = (flags & 1) == 1; // 1 == UINT16
                var contactSensor = (ContactSensorStatus)((flags >> 1) & 3);
                var minLength     = isshort ? 3 : 2;

                if (value.Length < minLength)
                {
                    Debug.WriteLine($"Buffer was too small. Got {value.Length}, expected {minLength}.");
                    return;
                }

                HeartRateServiceData hrsd = new HeartRateServiceData(data);
                LogData(hrsd);

                bpm = hrsd.HeartRateMeasurement;

                Debug.WriteLine($"Read {flags.ToString("X")} {contactSensor} {bpm}");
                foreach (var rr in hrsd.RRIntervals)
                {
                    Debug.WriteLine($"RR Interval {rr}");
                }

                HeartRateUpdated?.Invoke(contactSensor, bpm);
            }
        }