Exemplo n.º 1
0
        public StreamRenderer(XElement signalentry, double guisignaldisplaywidth, int imagewidth)
            : base(signalentry)
        {
            this.channels = SignalEntry.GetNumChannels(signalentry);

            switch (SignalEntry.GetFileFormat(signalentry))
            {
            case FileFormat.Bin:
                this.datatype         = SignalEntry.GetBinDataType(signalentry);
                this.samplestructsize = this.channels * (int)SignalEntry.GetDataTypeBytes(this.datatype);
                break;

            case FileFormat.Csv:
                this.datatype         = StreamDataType.Ieee754_Single;
                this.samplestructsize = this.channels * (int)SignalEntry.GetDataTypeBytes(this.datatype);
                break;

            default:
                throw new Exception("Dateiformat noch nicht unterstützt.");
            }

            this.Baseline      = (float)SignalEntry.GetBaseline(signalentry);
            this.Lsbvalue      = (float)SignalEntry.GetLsbValue(signalentry);
            this.Unit          = SignalEntry.GetUnit(signalentry);
            this.samplespersec = SignalEntry.GetSampleRate(signalentry);

            this.imageheight = (int)guisignaldisplaywidth;
            this.imagewidth  = imagewidth;
            //this.imageheight = 100;
            this.dirtyrect = new Int32Rect(0, 0, this.imagewidth, this.imageheight);

            this.physicaldata = new SampleD[this.channels];

            this.ReOpen();
        }
Exemplo n.º 2
0
        public static unsafe void CropBinary(XElement signalentry, double time_start, double time_end)
        {
            StreamDataType datatype         = SignalEntry.GetBinDataType(signalentry);
            int            channels         = SignalEntry.GetNumChannels(signalentry);
            int            samplestructsize = channels * (int)SignalEntry.GetDataTypeBytes(datatype);
            double         samplespersec    = SignalEntry.GetSampleRate(signalentry);



            MapFile mapfile = new MapFile(SignalEntry.GetId(signalentry), false);

            // Hier Dateigröße und Anzahl der Samples nochmal ausrechnen.
            // Kann ja sein, dass die Datei am Ende ein bissel kaputt ist.
            // (Datei wird dann auf ganze Sampleanzahl abgeschnitten)
            Int64 filesamples = mapfile.filesize / samplestructsize;
            Int64 filesize    = filesamples * samplestructsize;


            Int64 sample_start = (Int64)(time_start * samplespersec);
            Int64 sample_end   = (Int64)(time_end * samplespersec);


            if (sample_start >= filesamples)
            {
                return;
            }


            if (sample_end > filesamples)
            {
                sample_end = filesamples;
            }


            Int64 srcoffs = sample_start * samplestructsize;
            Int64 size    = (Int64)((sample_end - sample_start) * samplestructsize);


            // Sampledaten nach vorne kopieren
            if (sample_start > 0)
            {
                mapfile.MemMove(0, (int)srcoffs, (int)size);    // XXX memmove gibts gibts nur als 32bit version??
            }
            mapfile.Dispose();
            mapfile = null;


            // Datei hinten abschneiden (truncate)
            if (size < filesize)
            {
                FileStream fs = new FileStream(SignalEntry.GetId(signalentry), FileMode.Open, FileAccess.Write);
                fs.SetLength(size);
                fs.Close();
                fs.Dispose();
                fs = null;
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Crops the binary.
        /// </summary>
        /// <param name="signalentry">The signalentry.</param>
        /// <param name="time_start">The time_start.</param>
        /// <param name="time_end">The time_end.</param>
        private static unsafe void CropBinary(XElement signalentry, double time_start, double time_end)
        {
            String         fileName         = SignalEntry.GetId(signalentry);
            StreamDataType datatype         = SignalEntry.GetBinDataType(signalentry);
            int            channels         = SignalEntry.GetNumChannels(signalentry);
            int            samplestructsize = channels * (int)SignalEntry.GetDataTypeBytes(datatype);
            double         samplespersec    = SignalEntry.GetSampleRate(signalentry);

            FileInfo fileInfo = new FileInfo(fileName);
            // Hier Dateigröße und Anzahl der Samples nochmal ausrechnen.
            // Kann ja sein, dass die Datei am Ende ein bissel kaputt ist.
            // (Datei wird dann auf ganze Sampleanzahl abgeschnitten)
            long filesamples  = fileInfo.Length / samplestructsize;
            long filesize     = filesamples * samplestructsize;
            long sample_start = (long)(time_start * samplespersec);
            long sample_end   = (long)(time_end * samplespersec);

            if (sample_start >= filesamples)
            {
                return;
            }

            if (sample_end > filesamples)
            {
                sample_end = filesamples;
            }

            long size = (long)((sample_end - sample_start) * samplestructsize);

            // Datei vorne abschneiden
            if (sample_start > 0)
            {
                long srcoffs = sample_start * samplestructsize;
                try //Try it first with fast memory mapping
                {
                    MapFile mapfile = new MapFile(fileName, false);
                    mapfile.MemMove(0, (int)srcoffs, (int)size); // XXX memmove gibts gibts nur als 32bit version??
                    mapfile.Dispose();
                    mapfile = null;
                }
                catch (Exception) //If file is too large for memory mapping do it manually
                {
                    FileStream inFile    = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    FileStream outFile   = new FileStream(fileName + ".tmp", FileMode.OpenOrCreate, FileAccess.Write);
                    int        blocksize = 10240;

                    inFile.Seek(srcoffs, SeekOrigin.Begin);
                    while (true)
                    {
                        byte[] buffer = new byte[blocksize];
                        int    data   = inFile.Read(buffer, 0, blocksize);
                        if (data <= 0)
                        {
                            break; //
                        }
                        outFile.Write(buffer, 0, data);
                        if (data < blocksize)
                        {
                            break;
                        }
                    }
                    inFile.Close();
                    outFile.Close();
                    File.Delete(fileName);
                    File.Move(fileName + ".tmp", fileName);
                }
            }

            // Datei hinten abschneiden (truncate)
            if (size < filesize)
            {
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write);
                fs.SetLength(size);
                fs.Close();
                fs.Dispose();
                fs = null;
            }
        }