コード例 #1
0
        public MockEmpaticaHandler()
        {
            Console.WriteLine("MockEmpaticaHandler");

            _devices = new List <EmpaticaDevice>
            {
                new EmpaticaDevice("1", "1", "1", "1", "1"),
                new EmpaticaDevice("2", "2", "2", "2", "2")
            };

            var random = new Random();

            _observer = Observable.Interval(TimeSpan.FromSeconds(1))
                        .ObserveOn(RxApp.MainThreadScheduler)
                        .Where(_ => _isCapturing)
                        .Do(_ =>
            {
                var time = DateTimeOffset.Now.ToUnixTimeSeconds() - _startedTime;
                var bvp  = new Bvp(2 * (float)random.NextDouble(), time);
                BvpAction?.Invoke(bvp);

                var ibi = new Ibi(750 + 100 * (float)random.NextDouble(), time);
                IbiAction?.Invoke(ibi);

                var gsr = new Gsr((float)random.NextDouble(), time);
                GsrAction?.Invoke(gsr);

                var temperature = new Temperature(35.5f + (float)random.NextDouble(), time);
                TemperatureAction?.Invoke(temperature);
            });
        }
コード例 #2
0
        // Called everytime that have response from EmpaticaBLEServer
        private static void HandleResponseFromEmpaticaBLEServer(string response)
        {
            //Console.Write(response);
            string[] sensor_type = response.Split(' ');

            if (sensor_type[0] == "E4_Acc")
            {
                //Write Acc to csv
                //Console.WriteLine("This is ACC.");
                Acc each_acc = new Acc()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    ax           = sensor_type[2],
                    ay           = sensor_type[3],
                    az           = sensor_type[4].Split('\n')[0]
                };
                acc_list.Add(each_acc);
            }

            else if (sensor_type[0] == "E4_Bvp")
            {
                //Write Bvp to csv
                //Console.WriteLine("This is BVP.");
                Bvp each_bvp = new  Bvp()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    bvp          = sensor_type[2].Split('\n')[0]
                };
                bvp_list.Add(each_bvp);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Gsr")
            {
                //Write Gsr to csv
                //Console.WriteLine("This is GSR.");
                Gsr each_gsr = new  Gsr()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    gsr          = sensor_type[2].Split('\n')[0]
                };
                gsr_list.Add(each_gsr);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Temperature")
            {
                //Write Temp to csv
                //Console.WriteLine("This is TEMP.");
                Temp each_temp = new  Temp()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    tmp          = sensor_type[2].Split('\n')[0]
                };
                temp_list.Add(each_temp);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Ibi")
            {
                //Write Ibi to csv
                //Console.WriteLine("This is IBI.");
                Ibi each_ibi = new Ibi()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    ibi          = sensor_type[2].Split('\n')[0]
                };
                ibi_list.Add(each_ibi);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Hr")
            {
                //Write Hr to csv
                //Console.WriteLine("This is HR.");
                Heartbeat each_hr = new  Heartbeat()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    hr           = sensor_type[2].Split('\n')[0]
                };
                hr_list.Add(each_hr);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Battery")
            {
                //Write Batter to csv
                //Console.WriteLine("This is BATTERYLEVEL.");

                BatteryLevel each_battery = new  BatteryLevel()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                    battery      = sensor_type[2].Split('\n')[0]
                };
                battery_list.Add(each_battery);   // Write each record to .csv file stream.
            }

            else if (sensor_type[0] == "E4_Tag")
            {
                //Write Tag to csv
                //Console.WriteLine("This is TAG.");
                Tag each_tag = new  Tag()
                {
                    timefromempt = sensor_type[1],
                    timestamp    = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(),
                };
                tag_list.Add(each_tag);   // Write each record to .csv file stream.
            }
        }