Example #1
0
        private async Task StartRRIntervalStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.RRInterval);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = nameof(this.bandClient.SensorManager.RRInterval);
            //var channelCode = this.channels[channelName.ToUpper()];
            await stream.Buffer(new TimeSpan(0, 0, Interval)).Select(
                async readings =>
            {
                if (!readings.Any())
                {
                    return;
                }

                var rr     = readings.Average(reading => reading.SensorReading.Interval);
                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(), rr.ToString(CultureInfo.InvariantCulture));
                //var sampleValue = new DataSampleDC
                //{
                //    SensorType = channelCode,
                //    Values = new Dictionary<string, string>
                //                                    { { channelCode, gsr.ToString(CultureInfo.InvariantCulture) } }
                //};
                await this.SendNewSample(sample);
            });
        }
Example #2
0
        private void RabbitPublisher()
        {
            var connectionFactory = new ConnectionFactory();

            connectionFactory.HostName = "localhost";
            connectionFactory.UserName = "******";
            connectionFactory.Password = "******";

            try
            {
                using (var connection = connectionFactory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare("WBA_HealthStatus_Trigger", "fanout");
                        String fullmsg = "Band," + BandController.GetUnixTimeStamp() + "," + heartbeatmed;
                        var    body    = Encoding.UTF8.GetBytes(fullmsg);
                        channel.BasicPublish("WBA_HealthStatus_Trigger_Response", "", null, body);
                        channel.Close();
                    }
            }
            catch (Exception)
            {
                // do stuff
            }
        }
Example #3
0
        private async Task StartUVIndexStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.UV);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = $"{nameof(this.bandClient.SensorManager.UV)}Index";
            //var channelCode = this.channels[channelName];
            await stream.Buffer(new TimeSpan(0, 0, Interval)).Select(
                async readings =>
            {
                if (!readings.Any())
                {
                    return;
                }

                var indexLevel =
                    readings.GroupBy(reading => reading.SensorReading.IndexLevel)
                    .OrderByDescending(gr => gr.Count())
                    .Select(gr => gr.Key)
                    .First();
                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(), indexLevel.ToString());
                //var sampleValue = new DataSampleDC
                //{
                //    SensorType = channelCode,
                //    Values = new Dictionary<string, string>
                //                                    { { channelCode, indexLevel.ToString() } }
                //};
                await this.SendNewSample(sample);
            });
        }
Example #4
0
        private async Task StartContactStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.Contact);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = nameof(this.bandClient.SensorManager.Contact);
            //var channelCode = this.channels[channelName];
            await stream.Buffer(new TimeSpan(0, 0, Interval)).Select(
                async readings =>
            {
                if (!readings.Any())
                {
                    return;
                }

                var worn   = readings.All(reading => reading.SensorReading.State == BandContactState.Worn);
                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(), worn.ToString());
                //var sampleValue = new DataSampleDC
                //{
                //    SensorType = channelCode,
                //    Values = new Dictionary<string, string>
                //                                  { { channelCode, worn.ToString() } }
                //};
                await this.SendNewSample(sample);
            });
        }
Example #5
0
        private async Task StartAccelerometerStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.Accelerometer);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = nameof(this.bandClient.SensorManager.Accelerometer);
            ////var channelCodes = new List<string>
            ////{
            ////    this.channels[$"{channelName}X"],
            ////    this.channels[$"{channelName}Y"],
            ////    this.channels[$"{channelName}Z"]
            ////};
            //var sensorType = channelCodes[0].Split('-').FirstOrDefault();
            await stream.Buffer(new TimeSpan(0, 0, HighOutputInterval)).Select(
                async readings =>
            {
                var accelerationX = string.Join(Separator,
                                                readings.Select(
                                                    reading => reading.SensorReading.AccelerationX.ToString(CultureInfo.InvariantCulture)));
                var accelerationY = string.Join(Separator,
                                                readings.Select(
                                                    reading => reading.SensorReading.AccelerationY.ToString(CultureInfo.InvariantCulture)));
                var accelerationZ = string.Join(Separator,
                                                readings.Select(
                                                    reading => reading.SensorReading.AccelerationZ.ToString(CultureInfo.InvariantCulture)));

                if (string.IsNullOrEmpty(accelerationX) &&
                    string.IsNullOrEmpty(accelerationY) &&
                    string.IsNullOrEmpty(accelerationZ))
                {
                    return;
                }

                var message = accelerationX + " , " + accelerationY + " , " + accelerationZ;

                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(), message);

                //var sampleValues = new DataSampleDC
                //{
                //    SensorType = sensorType,
                //    Values = new Dictionary<string, string>
                //                              {
                //                                  { channelCodes[0], accelerationX.ToString() },
                //                                  { channelCodes[1], accelerationY.ToString() },
                //                                  { channelCodes[2], accelerationZ.ToString() }
                //                              }
                //};
                await this.SendNewSample(sample);
            });
        }
Example #6
0
        private async Task StartHeartRateStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.HeartRate);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = nameof(this.bandClient.SensorManager.HeartRate);
            //var channelCode = this.channels[channelName];
            await stream.Buffer(new TimeSpan(0, 0, Interval)).Select(
                async readings =>
            {
                var lockedReadings =
                    readings.Where(reading => reading.SensorReading.Quality == HeartRateQuality.Locked);
                if (!lockedReadings.Any())
                {
                    return;
                }

                var avg       = lockedReadings.Average(reading => reading.SensorReading.HeartRate);
                var min       = lockedReadings.Min(y => y.SensorReading.HeartRate);
                var max       = lockedReadings.Max(y => y.SensorReading.HeartRate);
                var avgdouble = Math.Round(avg, 2);
                var message   = min.ToString() + " , " + avgdouble.ToString() + " , " + max.ToString();



                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(), message);
                //var sampleValue = new DataSampleDC
                //{
                //    SensorType = channelCode,
                //    Values = new Dictionary<string, string>
                //                                      { { channelCode, avg.ToString(CultureInfo.InvariantCulture) } }
                //};
                await this.SendNewSample(sample);
            });
        }
Example #7
0
        private async Task StartPedometerStream()
        {
            var stream = await this.GetSensorStream(this.bandClient.SensorManager.Pedometer);

            if (stream == null)
            {
                return;
            }

            this.disposableStreams.Add(stream.Subscribe());
            var channelName = nameof(this.bandClient.SensorManager.Pedometer);
            //var channelCode = this.channels[channelName];
            await stream.Buffer(new TimeSpan(0, 0, Interval)).Select(
                async readings =>
            {
                if (!readings.Any())
                {
                    return;
                }

                var steps = readings.Max(reading => reading.SensorReading.TotalSteps);

                if (isFirstStepsReading)
                {
                    isFirstStepsReading = false;
                    firstStepsReading   = steps;
                }
                var sample = new SensorReadingDC(channelName, BandController.GetUnixTimeStamp(),
                                                 (steps - firstStepsReading).ToString(CultureInfo.InvariantCulture));
                //var sampleValue = new DataSampleDC
                //{
                //    SensorType = channelCode,
                //    Values = new Dictionary<string, string>
                //                                  { { channelCode, (steps - firstStepsReading).ToString(CultureInfo.InvariantCulture) } }
                //};
                await
                this.SendNewSample(sample);
            });
        }
Example #8
0
        private async void CheckCaloriesCycle()
        {
            var Calstream = await bandHelper.GetTotalCal();

            long currCal = await Calstream.FirstAsync();

            long diff = currCal - totalCal;

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                CaloriesDisplay.Text = " Calories: " + diff;

                await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + CaloriesDisplay.Text);
            }).AsTask();
        }
Example #9
0
        private async void ManageBand(BandReativeExtensionsWrapper bandHelper)
        {
            bandHelper.SendMessage("Testing Messages");

            var streamHR = await bandHelper.GetHeartRateStream();

            var streamCal = await bandHelper.GetCaloriesStream();

            var streamSkin = await bandHelper.GetSkinTemperatureStream();

            var streamUV = await bandHelper.GetUltravioletStream();

            var streamPed = await bandHelper.GetPedometerStream();

            var streamAcce = await bandHelper.GetAccelerometerStream();

            var currCalstream = await bandHelper.GetTotalCal();

            totalCal = await currCalstream.FirstAsync();

            await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + "Ciclo de trabalho iniciado. Calorias desde o ultimo factory reset: " + totalCal);



            var hrSubscription = streamHR
                                 .Where(x => x.SensorReading.Quality == Microsoft.Band.Sensors.HeartRateQuality.Locked)
                                 .Buffer(new TimeSpan(0, 0, interv))
                                 .Select(async x =>
            {
                var avg = x.Average(y => y.SensorReading.HeartRate);
                var min = x.Min(y => y.SensorReading.HeartRate);
                var max = x.Max(y => y.SensorReading.HeartRate);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    HeartRateDisplay.Text = " HeartRate Med: " + Math.Round(avg, 2) + " Min: " + min + " Max: " + max;

                    await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandHRLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + HeartRateDisplay.Text);
                }).AsTask();
                return(avg);
            })
                                 .Subscribe(x =>
            {
                Debug.WriteLine(x);
                if (x.IsFaulted)
                {
                    btrange = true;
                }
            });



            //var calSubscription = streamCal
            //                .Where(x => x.SensorReading.Calories != 0)
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var value = x.Select(y => y.SensorReading.Calories);
            //                   long cal = value.Last() - totalCal;

            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       CaloriesDisplay.Text = "Calories: " + cal;

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + CaloriesDisplay.Text);
            //                   }).AsTask();
            //                   return cal;
            //               })
            //               .Subscribe(x =>
            //               {

            //                   Debug.WriteLine(x);

            //               });

            var skinSubscription = streamSkin
                                   .Buffer(new TimeSpan(0, 0, interv))
                                   .Select(async x =>
            {
                var avg = x.Average(y => y.SensorReading.Temperature);
                var min = x.Min(y => y.SensorReading.Temperature);
                var max = x.Max(y => y.SensorReading.Temperature);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    SkinTemperatureDisplay.Text = " Temperature Med: " + Math.Round(avg, 2) + " Min: " + min + " Max: " + max;

                    await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandTemperatureLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + SkinTemperatureDisplay.Text);
                }).AsTask();
                return(avg);
            })
                                   .Subscribe(x =>
            {
                Debug.WriteLine(x);
            });

            //var pedSubscription = streamPed
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var total = x.Select(y => y.SensorReading.TotalSteps);
            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       PedometerDisplay.Text = "Steps: " + total;

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandStepsLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + PedometerDisplay.Text);
            //                   }).AsTask();
            //                   return total;
            //               })
            //               .Subscribe(x =>
            //               {
            //                   Debug.WriteLine(x);

            //               });

            //var uvSubscription = streamUV
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var index = x.Select(y => y.SensorReading.IndexLevel);
            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       UVDisplay.Text = " UV: " + index.Last().ToString();

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandUVLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + UVDisplay.Text);
            //                   }).AsTask();
            //                   return index;
            //               })
            //               .Subscribe(x =>
            //               {
            //                   Debug.WriteLine(x);

            //               });

            //var accSubscription = streamAcce
            //              .Buffer(new TimeSpan(0, 0, interv))
            //              .Select(async x =>
            //              {
            //                  var pointX = x.Select(y => y.SensorReading.AccelerationX);
            //                  var pointY = x.Select(y => y.SensorReading.AccelerationY);
            //                  var pointZ = x.Select(y => y.SensorReading.AccelerationZ);


            //                  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                  {
            //                      AcceDisplay.Text = "Point X: " + pointX + "  Point Y: " + pointY + "  PointZ: " + pointZ;

            //                      await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandAccellLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + AcceDisplay.Text);
            //                  }).AsTask();
            //                  return pointX;
            //              })
            //              .Subscribe(x =>
            //              {
            //                  Debug.WriteLine(x);

            //              });
            //var streamAcc

            //if (_bandClient != null)
            //    return;

            //var bands = await BandClientManager.Instance.GetBandsAsync();
            //_bandInfo = bands.First();

            //_bandClient = await BandClientManager.Instance.ConnectAsync(_bandInfo);

            //var uc = _bandClient.SensorManager.HeartRate.GetCurrentUserConsent();
            //bool isConsented = false;
            //if (uc == UserConsent.NotSpecified)
            //{
            //    isConsented = await _bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
            //}

            //if (isConsented || uc == UserConsent.Granted)
            //{

            //    IEnumerable<TimeSpan> supportedHeartBeatReportingIntervals = _bandClient.SensorManager.HeartRate.SupportedReportingIntervals;
            //    foreach(var ri in supportedHeartBeatReportingIntervals)
            //    {

            //    }



            //    _bandClient.SensorManager.HeartRate.ReadingChanged += async (obj, ev) =>
            //    {
            //        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            //                            {
            //                                HeartRateDisplay.Text = ev.SensorReading.HeartRate.ToString();
            //                                HeartRateState.Text = ev.SensorReading.Quality.ToString();
            //                                //await c.saveStringToLocalFile("BandHRLogs.txt", "HeartRate: " + ev.SensorReading.HeartRate);
            //                            }).AsTask();
            //    };
            //    await _bandClient.SensorManager.HeartRate.StartReadingsAsync();
            //}
        }