public AccelerometerPage()
        {
            Model = new AccelerometerModel
            {
                IsSupported = Accelerometer.IsSupported,
                SensorCount = Accelerometer.Count
            };

            InitializeComponent();

            if (Model.IsSupported)
            {
                Accelerometer              = new Accelerometer();
                Accelerometer.DataUpdated += Accelerometer_DataUpdated;

                canvas.Series = new List <Series>()
                {
                    new Series()
                    {
                        Color         = SKColors.Red,
                        Name          = "X",
                        FormattedText = "X={0:f2}m/s^2",
                    },
                    new Series()
                    {
                        Color         = SKColors.Green,
                        Name          = "Y",
                        FormattedText = "Y={0:f2}m/s^2",
                    },
                    new Series()
                    {
                        Color         = SKColors.Blue,
                        Name          = "Z",
                        FormattedText = "Z={0:f2}m/s^2",
                    },
                };
            }
        }
Beispiel #2
0
        private void initCampaignDataSources()
        {
            #region Assign sensor model references
            accelerometerModel = new AccelerometerModel
            {
                IsSupported = Accelerometer.IsSupported,
                SensorCount = Accelerometer.Count
            };
            gravityModel = new GravityModel
            {
                IsSupported = GravitySensor.IsSupported,
                SensorCount = GravitySensor.Count
            };
            gyroscopeModel = new GyroscopeModel
            {
                IsSupported = Gyroscope.IsSupported,
                SensorCount = Gyroscope.Count
            };
            hRMModel = new HRMModel
            {
                IsSupported = HeartRateMonitor.IsSupported,
                SensorCount = HeartRateMonitor.Count
            };
            humidityModel = new HumidityModel
            {
                IsSupported = HumiditySensor.IsSupported,
                SensorCount = HumiditySensor.Count
            };
            lightModel = new LightModel
            {
                IsSupported = LightSensor.IsSupported,
                SensorCount = LightSensor.Count
            };
            linearAccelerationModel = new LinearAccelerationModel
            {
                IsSupported = LinearAccelerationSensor.IsSupported,
                SensorCount = LinearAccelerationSensor.Count
            };
            magnetometerModel = new MagnetometerModel
            {
                IsSupported = Magnetometer.IsSupported,
                SensorCount = Magnetometer.Count
            };
            orientationModel = new OrientationModel
            {
                IsSupported = OrientationSensor.IsSupported,
                SensorCount = OrientationSensor.Count
            };
            pressureModel = new PressureModel
            {
                IsSupported = PressureSensor.IsSupported,
                SensorCount = PressureSensor.Count
            };
            proximityModel = new ProximityModel
            {
                IsSupported = ProximitySensor.IsSupported,
                SensorCount = ProximitySensor.Count
            };
            temperatureModel = new TemperatureModel
            {
                IsSupported = TemperatureSensor.IsSupported,
                SensorCount = TemperatureSensor.Count
            };
            ultravioletModel = new UltravioletModel
            {
                IsSupported = UltravioletSensor.IsSupported,
                SensorCount = UltravioletSensor.Count
            };
            #endregion

            #region Assign sensor references and sensor measurement event handlers
            if (accelerometerModel.IsSupported)
            {
                accelerometer                  = new Accelerometer();
                accelerometer.PausePolicy      = SensorPausePolicy.None;
                accelerometer.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                accelerometer.DataUpdated     += storeAccelerometerDataCallback;
                sensorMap[Tools.ACCELEROMETER] = accelerometer;
            }
            if (gravityModel.IsSupported)
            {
                gravity                  = new GravitySensor();
                gravity.PausePolicy      = SensorPausePolicy.None;
                gravity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                gravity.DataUpdated     += storeGravitySensorDataCallback;
                sensorMap[Tools.GRAVITY] = gravity;
            }
            if (gyroscopeModel.IsSupported)
            {
                gyroscope                  = new Gyroscope();
                gyroscope.PausePolicy      = SensorPausePolicy.None;
                gyroscope.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                gyroscope.DataUpdated     += storeGyroscopeDataCallback;
                sensorMap[Tools.GYROSCOPE] = gyroscope;
            }
            if (hRMModel.IsSupported)
            {
                hRM                  = new HeartRateMonitor();
                hRM.PausePolicy      = SensorPausePolicy.None;
                hRM.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                hRM.DataUpdated     += storeHeartRateMonitorDataCallback;
                sensorMap[Tools.HRM] = hRM;
            }
            if (humidityModel.IsSupported)
            {
                humidity                  = new HumiditySensor();
                humidity.PausePolicy      = SensorPausePolicy.None;
                humidity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                humidity.DataUpdated     += storeHumiditySensorDataCallback;
                sensorMap[Tools.HUMIDITY] = humidity;
            }
            if (lightModel.IsSupported)
            {
                light                  = new LightSensor();
                light.PausePolicy      = SensorPausePolicy.None;
                light.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                light.DataUpdated     += storeLightSensorDataCallback;
                sensorMap[Tools.LIGHT] = light;
            }
            if (linearAccelerationModel.IsSupported)
            {
                linearAcceleration                  = new LinearAccelerationSensor();
                linearAcceleration.PausePolicy      = SensorPausePolicy.None;
                linearAcceleration.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                linearAcceleration.DataUpdated     += storeLinearAccelerationSensorDataCallback;
                sensorMap[Tools.LINEARACCELERATION] = linearAcceleration;
            }
            if (magnetometerModel.IsSupported)
            {
                magnetometer                  = new Magnetometer();
                magnetometer.PausePolicy      = SensorPausePolicy.None;
                magnetometer.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                magnetometer.DataUpdated     += storeMagnetometerDataCallback;
                sensorMap[Tools.MAGNETOMETER] = magnetometer;
            }
            if (orientationModel.IsSupported)
            {
                orientation                  = new OrientationSensor();
                orientation.PausePolicy      = SensorPausePolicy.None;
                orientation.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                orientation.DataUpdated     += storeOrientationSensorDataCallback;
                sensorMap[Tools.ORIENTATION] = orientation;
            }
            if (pressureModel.IsSupported)
            {
                pressure                  = new PressureSensor();
                pressure.PausePolicy      = SensorPausePolicy.None;
                pressure.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                pressure.DataUpdated     += storePressureSensorDataCallback;
                sensorMap[Tools.PRESSURE] = pressure;
            }
            if (proximityModel.IsSupported)
            {
                proximity                  = new ProximitySensor();
                proximity.PausePolicy      = SensorPausePolicy.None;
                proximity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                proximity.DataUpdated     += storeProximitySensorDataCallback;
                sensorMap[Tools.PROXIMITY] = proximity;
            }
            if (temperatureModel.IsSupported)
            {
                temperature                  = new TemperatureSensor();
                temperature.PausePolicy      = SensorPausePolicy.None;
                temperature.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                temperature.DataUpdated     += storeTemperatureSensorDataCallback;
                sensorMap[Tools.TEMPERATURE] = temperature;
            }
            if (ultravioletModel.IsSupported)
            {
                ultraviolet                  = new UltravioletSensor();
                ultraviolet.PausePolicy      = SensorPausePolicy.None;
                ultraviolet.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                ultraviolet.DataUpdated     += storeUltravioletSensorDataCallback;
                sensorMap[Tools.ULTRAVIOLET] = ultraviolet;
            }
            #endregion

            loadCampaignSettings();
        }
Beispiel #3
0
        public static void ConvertAccelDataNoAnalysis()
        {
            string filename = Path.Combine("Data", "Accelerometer.binary");
            string fileDir  = Path.Combine("Converted", "Accelerometer");

            Directory.CreateDirectory("Converted");

            DateTime initialTime       = DateTime.Now;
            DateTime currentTime       = DateTime.Now;
            bool     isInitialDateTime = true;

            int fileCounter    = 0; //current files found and navigated
            int newFileCounter = 0; //current number of files converted based on fileLineSize

            long index         = 1;
            long fileLineIndex = 0; //tracks amount of lines in current file
            long count         = 0; //keep track of records

            const int fileLineSize = 1000000;

            string searchFile = $"{filename}{fileCounter++}";
            string resultFile = $"{fileDir}{newFileCounter++}.csv";

            StreamWriter sw = File.CreateText(resultFile);

            //get all accel binary files
            while (File.Exists(searchFile))
            {
                using (FileStream fs = new FileStream(searchFile, FileMode.Open, FileAccess.Read))
                {
                    int accelBytes         = 12;
                    int rtcBytes           = 8;
                    int cpuBytes           = 8;
                    int accelSegmentLength = accelBytes + rtcBytes + cpuBytes;

                    byte[] bytes = new byte[accelBytes + rtcBytes + cpuBytes];

                    const string header = "ID,SECOND,X_RAW,Y_RAW,Z_RAW,X,Y,X,TIMESTAMP,CPU_TEMP";

                    sw.WriteLine(header);

                    while (fs.Read(bytes) != 0)
                    {
                        Span <byte> data         = bytes;
                        Span <byte> accelSegment = data.Slice(0, accelBytes);
                        Span <byte> rtcSegment   = data.Slice(accelBytes, rtcBytes);
                        Span <byte> cpuSegment   = data.Slice(accelBytes + rtcBytes, cpuBytes);

                        currentTime = new DateTime(BitConverter.ToInt64(rtcSegment));

                        if (isInitialDateTime)
                        {
                            initialTime       = currentTime;
                            isInitialDateTime = false;
                        }


                        string csvLine = $"{index++},";

                        csvLine += (currentTime - initialTime).TotalSeconds.ToString("F3") + ",";



                        int[] acelValues         = System.Runtime.InteropServices.MemoryMarshal.Cast <byte, int>(accelSegment).ToArray();
                        AccelerometerModel model = new AccelerometerModel(acelValues);

                        csvLine += $"{model.X_Raw},{model.Y_Raw},{model.Z_Raw},{model.X},{model.Y},{model.Z},";

                        csvLine += currentTime.ToString("HH:mm:ss") + ",";
                        csvLine += BitConverter.ToDouble(cpuSegment).ToString();

                        if (fileLineIndex >= fileLineSize)
                        {
                            //generate new csv file
                            fileLineIndex = 0;
                            resultFile    = $"{fileDir}{newFileCounter++}.csv";

                            sw.Flush();
                            sw.Close();
                            sw.Dispose();
                            sw = File.CreateText(resultFile);
                        }

                        sw.WriteLine(csvLine);
                        count++;
                        fileLineIndex++;
                    }
                }
                sw.Flush();
                searchFile = $"{filename}{fileCounter++}";
            }
            sw.Dispose();

            using (var writer = LogFile.AppendText())
            {
                writer.WriteLine("-------------------------------------------------------------------------------");
                writer.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")} - Accelerometer Records converted: {count}");
                writer.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")} - Accelerometer Files found: {fileCounter}");
                writer.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")} - Accelerometer Converted Files created: {newFileCounter}");
                writer.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")} - Accelerometer TotalSeconds: {(currentTime - initialTime).TotalSeconds.ToString("F3")}");
                writer.WriteLine();
            }
        }