예제 #1
0
        /// <summary>
        /// Gets the length of the signal.
        /// </summary>
        /// <param name="unisensxml">The unisensxml.</param>
        /// <param name="selectedsignals">The selectedsignals.</param>
        /// <returns>length of the signal</returns>
        private static double GetSignalLength(XDocument unisensxml, IEnumerable <XElement> selectedsignals)
        {
            double length = -1;

            try
            {
                XElement unisens = unisensxml.Root;
                if (unisens != null)
                {
                    XAttribute duration = unisens.Attribute("duration");
                    length = double.Parse(duration.Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }
            catch (Exception)
            {
                foreach (XElement xe in selectedsignals)
                {
                    // no DURATION attribut existent -> calculate duration (in seconds) with length of signal entry
                    switch (xe.Name.LocalName)
                    {
                    case "signalEntry":
                    case "valuesEntry":
                    case "customEntry":
                        // length = length_of_file / (bytes_per_sample * number_of_channels * sample_rate)
                        if (SignalEntry.GetFileFormat(xe) == FileFormat.Bin)
                        {
                            length = new FileInfo(SignalEntry.GetId(xe)).Length /
                                     (SignalEntry.GetDataTypeBytes(SignalEntry.GetBinDataType(xe)) *
                                      MeasurementEntry.GetNumChannels(xe) *
                                      MeasurementEntry.GetSampleRate(xe));
                        }

                        break;
                    }

                    // Exit the foreach loop when length is calculated
                    if (length > 0)
                    {
                        break;
                    }
                }
            }

            if (length < 0)
            {
                throw new Exception("Cannot cut a file without duration information");
            }

            return(length);
        }
예제 #2
0
        private static double GetMaxSampleRate(IEnumerable <XElement> selectedsignals)
        {
            double max = 0.0;

            foreach (XElement xe in selectedsignals)
            {
                double sr = MeasurementEntry.GetSampleRate(xe);

                if (sr > max)
                {
                    max = sr;
                }
            }
            return(max);
        }
예제 #3
0
        public static double GetSignalLength(XDocument unisensxml, IEnumerable <XElement> selectedsignals)
        {
            double length = 0;

            try
            {
                XElement xUnisens = unisensxml.Root;
                if (xUnisens != null)
                {
                    length = double.Parse(xUnisens.Attribute("duration").Value);
                }
            }
            catch (Exception e)
            {
                foreach (XElement xe in selectedsignals)
                {
                    // no DURATION attribut existent -> calculate duration (in seconds) with length of signal entry
                    switch (xe.Name.LocalName)
                    {
                    case "signalEntry":
                        // length = length_of_file / (bytes_per_sample * number_of_channels * sample_rate)
                        length = new FileInfo(SignalEntry.GetId(xe)).Length /
                                 (SignalEntry.GetDataTypeBytes(SignalEntry.GetBinDataType(xe)) *
                                  MeasurementEntry.GetNumChannels(xe) *
                                  MeasurementEntry.GetSampleRate(xe));
                        break;
                    }

                    // Exit the foreach loop when length is calculated
                    if (length > 0)
                    {
                        break;
                    }
                }
            }

            return(length);
        }
예제 #4
0
        /// <summary>
        /// Main function for plug-ins, called by UnisensViewer.
        /// </summary>
        /// <param name="unisensxml">unisens.xml file.</param>
        /// <param name="selectedsignals">All information from unisens.xml of the selected signals.</param>
        /// <param name="path">Path of the current unisens.xml file.</param>
        /// <param name="time_cursor">Time in seconds of current cursor position. Is 0, if the plug-in is called via plug-in menu.</param>
        /// <param name="time_start">Time in seconds of start of the current selection. Is 0, when no selection exists.</param>
        /// <param name="time_end">Time in seconds of end of the current selection. Is 0, when no selection exists.</param>
        /// <param name="parameter">Additional parameter of the key bindings.</param>
        /// <returns>
        /// Returned signals have to be described by the corresponding Unisens XML element (e.g. signalEntry or eventEntry). UnisensViewer displays the returned signals directly.
        /// </returns>
        public IEnumerable <XElement> Main(XDocument unisensxml, IEnumerable <XElement> selectedsignals, string path, double time_cursor, double time_start, double time_end, string parameter)
        {
            int    sample_start   = 0;
            int    sample_end     = 0;
            double sampleValueMin = 0;
            double sampleValueMax = 0;
            string clipboard      = string.Empty;
            int    i = 1;

            // When time_cursor is used (context menu or hot key), read data from cursor position. Otherwise read data from selection.
            if (time_cursor != 0)
            {
                time_start = time_cursor;
                time_end   = time_cursor;
            }

            foreach (XElement xe in selectedsignals)
            {
                switch (xe.Name.LocalName)
                {
                case "signalEntry":
                case "valuesEntry":

                    sample_start = (int)Math.Floor(MeasurementEntry.GetSampleRate(xe) * time_start);
                    time_start   = sample_start / MeasurementEntry.GetSampleRate(xe);
                    sample_end   = (int)Math.Ceiling(MeasurementEntry.GetSampleRate(xe) * time_end);
                    time_end     = sample_end / MeasurementEntry.GetSampleRate(xe);

                    clipboard += "unisensViewer(" + i + ").cursorTime = [datenum('" + time_start + "', 'SS.FFF'), datenum('" + time_end + "', 'SS.FFF'), ];\n";
                    clipboard += "unisensViewer(" + i + ").sampleIndex = ['" + sample_start + "', '" + sample_end + "'];\n";
                    clipboard += "unisensViewer(" + i + ").unit = '" + MeasurementEntry.GetUnit(xe) + "';\n";

                    ////TODO: Read values at position positionSampleStart and positionSampleEnd
                    sampleValueMin = 1;
                    sampleValueMax = 2;
                    clipboard     += "unisensViewer(" + i + ").physicalValue = [" + ((sampleValueMin - MeasurementEntry.GetBaseline(xe)) * MeasurementEntry.GetLsbValue(xe)) + ", " + ((sampleValueMax - MeasurementEntry.GetBaseline(xe)) * MeasurementEntry.GetLsbValue(xe)) + "];\n";
                    clipboard     += "unisensViewer(" + i + ").sampleValue = [" + sampleValueMin + ", " + sampleValueMax + "];\n";

                    i++;
                    break;
                }
            }

            Clipboard.SetDataObject(clipboard, true);
            MessageBox.Show("Cursor data at sample " + sample_start + " copied to clipbaord (Matlab style).\n" + clipboard, "Copy to Clipboard");

            // Example (Matlab style):
            // unisensViewer(1).cursorTime = ['00:00:00.123', '00:00:01.123'];
            // unisensViewer(1).sampleIndex = [532, 2343];
            // unisensViewer(1).physicalValue = [5.4384, 5.4385];
            // unisensViewer(1).Unit = 'g';
            // unisensViewer(1).sampleValue = [23452, 23453];

            // Example (Excel style):
            //     cursor time    sample index
            // from    00:00:00.123    532
            // to    00:00:01.123    2343
            //
            //     physical value    sample value
            // min    5.4384g    23452
            // max    5.4385g    23453

            // Example (plain text):
            // cursor time
            // from 00:00:00.123
            // to 00:00:01.123
            //
            // sample index
            // from 532
            // to 2343
            //
            // physical value
            // min 5.4384g
            // max 5.4385g
            //
            // sample value
            // min 23452
            // max 23453
            ////

            return(null);
        }