Пример #1
0
        /// <summary>
        /// This will read fake data from the CSV files based off of the initialization. If the sensor is "initialized" (not null),
        /// then it will read in CSV data for it. Otherwise, it will stay null.
        /// </summary>
        private void ReadFakeDataFromCSV()
        {
            if (ElevationTempData != null)
            {
                double dbl;

                var values = File.ReadAllLines(DataDirectory + "TestElTemp.csv")
                             .SelectMany(a => a.Split(',')
                                         .Select(str => double.TryParse(str, out dbl) ? dbl : 0));

                ElevationTempData = values.ToArray();
            }

            if (AzimuthTempData != null)
            {
                double dbl;

                var values = File.ReadAllLines(DataDirectory + "TestAzTemp.csv")
                             .SelectMany(a => a.Split(',')
                                         .Select(str => double.TryParse(str, out dbl) ? dbl : 0));

                AzimuthTempData = values.ToArray();
            }

            if (AzimuthAccData != null)
            {
                int tempInt;

                int[] xData = File.ReadAllLines(DataDirectory + "TestAzAccX.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] yData = File.ReadAllLines(DataDirectory + "TestAzAccY.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] zData = File.ReadAllLines(DataDirectory + "TestAzAccZ.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                // Find which axis has the lowest number, which we will use as the size for the overall array
                int lowest = xData.Length;
                if (lowest > yData.Length)
                {
                    lowest = yData.Length;
                }
                if (lowest > zData.Length)
                {
                    lowest = zData.Length;
                }

                AzimuthAccData = new RawAccelerometerData[lowest];

                // Populate raw accelerometer data with individual axes
                for (int i = 0; i < lowest; i++)
                {
                    AzimuthAccData[i].X = xData[i];
                    AzimuthAccData[i].Y = yData[i];
                    AzimuthAccData[i].Z = zData[i];
                }
            }

            if (ElevationAccData != null)
            {
                int tempInt;

                int[] xData = File.ReadAllLines(DataDirectory + "TestElAccX.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] yData = File.ReadAllLines(DataDirectory + "TestElAccY.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] zData = File.ReadAllLines(DataDirectory + "TestElAccZ.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                // Find which axis has the lowest number, which we will use as the size for the overall array
                int lowest = xData.Length;
                if (lowest > yData.Length)
                {
                    lowest = yData.Length;
                }
                if (lowest > zData.Length)
                {
                    lowest = zData.Length;
                }

                ElevationAccData = new RawAccelerometerData[lowest];

                // Populate raw accelerometer data with individual axes
                for (int i = 0; i < lowest; i++)
                {
                    ElevationAccData[i].X = xData[i];
                    ElevationAccData[i].Y = yData[i];
                    ElevationAccData[i].Z = zData[i];
                }
            }

            if (CounterbalanceAccData != null)
            {
                int tempInt;

                int[] xData = File.ReadAllLines(DataDirectory + "TestCbAccX.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] yData = File.ReadAllLines(DataDirectory + "TestCbAccY.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                int[] zData = File.ReadAllLines(DataDirectory + "TestCbAccZ.csv")
                              .SelectMany(a => a.Split(',')
                                          .Select(str => int.TryParse(str, out tempInt) ? tempInt : 0)).ToArray();

                // Find which axis has the lowest number, which we will use as the size for the overall array
                int lowest = xData.Length;
                if (lowest > yData.Length)
                {
                    lowest = yData.Length;
                }
                if (lowest > zData.Length)
                {
                    lowest = zData.Length;
                }

                CounterbalanceAccData = new RawAccelerometerData[lowest];

                // Populate raw accelerometer data with individual axes
                for (int i = 0; i < lowest; i++)
                {
                    CounterbalanceAccData[i].X = xData[i];
                    CounterbalanceAccData[i].Y = yData[i];
                    CounterbalanceAccData[i].Z = zData[i];
                }
            }

            if (ElevationEncoderData != null)
            {
                double dbl;

                var values = File.ReadAllLines(DataDirectory + "TestElEnc.csv")
                             .SelectMany(a => a.Split(',')
                                         .Select(str => double.TryParse(str, out dbl) ? dbl : 0));

                ElevationEncoderData = values.ToArray();
            }

            if (AzimuthEncoderData != null)
            {
                double dbl;

                var values = File.ReadAllLines(DataDirectory + "TestAzEnc.csv")
                             .SelectMany(a => a.Split(',')
                                         .Select(str => double.TryParse(str, out dbl) ? dbl : 0));

                AzimuthEncoderData = values.ToArray();
            }
        }
Пример #2
0
        /// <summary>
        /// This is used to set the initialization of the sensors. Any non-initialized sensors will not be encoded.
        /// </summary>
        /// <param name="init">Sensor initialization we receive from the SensorNetworkServer's InitializationClient</param>
        private void InitializeSensors(byte[] init)
        {
            if (init[(int)SensorInitializationEnum.ElevationTemp] == 0)
            {
                ElevationTempData = null;
            }
            else
            {
                ElevationTempData = new double[0];
            }

            if (init[(int)SensorInitializationEnum.AzimuthTemp] == 0)
            {
                AzimuthTempData = null;
            }
            else
            {
                AzimuthTempData = new double[0];
            }

            if (init[(int)SensorInitializationEnum.ElevationEncoder] == 0)
            {
                ElevationEncoderData = null;
            }
            else
            {
                ElevationEncoderData = new double[0];
            }

            if (init[(int)SensorInitializationEnum.AzimuthEncoder] == 0)
            {
                AzimuthEncoderData = null;
            }
            else
            {
                AzimuthEncoderData = new double[0];
            }

            if (init[(int)SensorInitializationEnum.AzimuthAccelerometer] == 0)
            {
                AzimuthAccData = null;
            }
            else
            {
                AzimuthAccData = new RawAccelerometerData[0];
            }

            if (init[(int)SensorInitializationEnum.ElevationAccelerometer] == 0)
            {
                ElevationAccData = null;
            }
            else
            {
                ElevationAccData = new RawAccelerometerData[0];
            }

            if (init[(int)SensorInitializationEnum.CounterbalanceAccelerometer] == 0)
            {
                CounterbalanceAccData = null;
            }
            else
            {
                CounterbalanceAccData = new RawAccelerometerData[0];
            }
        }