/// <summary> /// Decode a file of all the samples. A sample is made up of a /// group of Real and Imaginary data samples. This will create a list /// of all samples found in the file. /// </summary> /// <param name="file">File to decode.</param> /// <returns>List of all the samples found in the list.</returns> public List <Sample> Decode(string file) { List <Sample> samples = new List <Sample>(); List <byte> buffer = new List <byte>(); // Placeholder for real data while waiting for imaginary data RealData realData = null; // Open file to read using (FileStream strm = File.OpenRead(file)) { for (int x = 0; x < strm.Length; x++) { // Read in a byte int strmReadByte = strm.ReadByte(); // Verify the byte is good if (strmReadByte >= 0) { // Add it to the list buffer.Add((byte)strmReadByte); // If the list has 4 bytes // verify we have a good sample // if we do not have a good sample, // drop the first byte. If we good have a // good sample, remove the sample from the list // and decode the sample if (buffer.Count == 4) { // Create an array for the data byte[] data = buffer.ToArray(); if (ValidRealData(buffer)) { realData = new RealData(data); buffer.Clear(); } else if (ValidImaginaryData(buffer)) { ImaginaryData imgData = new ImaginaryData(data); // If a Real data has already been set // Create a sample and add it to the list //if (realData != null && imgData.BoardId <= 1) if (realData != null) { samples.Add(new Sample() { RealDataSample = realData, ImaginaryDataSample = imgData }); } // Reset values buffer.Clear(); realData = null; } else { buffer.RemoveAt(0); realData = null; } } } } } return(samples); }
/// <summary> /// Decode a file of all the samples. A sample is made up of a /// group of Real and Imaginary data samples. This will create a list /// of all samples found in the file. /// </summary> /// <param name="file">File to decode.</param> /// <returns>List of all the samples found in the list.</returns> public List<Sample> Decode(string file) { List<Sample> samples = new List<Sample>(); List<byte> buffer = new List<byte>(); // Placeholder for real data while waiting for imaginary data RealData realData = null; // Open file to read using (FileStream strm = File.OpenRead(file)) { for (int x = 0; x < strm.Length; x++) { // Read in a byte int strmReadByte = strm.ReadByte(); // Verify the byte is good if (strmReadByte >= 0) { // Add it to the list buffer.Add((byte)strmReadByte); // If the list has 4 bytes // verify we have a good sample // if we do not have a good sample, // drop the first byte. If we good have a // good sample, remove the sample from the list // and decode the sample if (buffer.Count == 4) { // Create an array for the data byte[] data = buffer.ToArray(); if (ValidRealData(buffer)) { realData = new RealData(data); buffer.Clear(); } else if (ValidImaginaryData(buffer)) { ImaginaryData imgData = new ImaginaryData(data); // If a Real data has already been set // Create a sample and add it to the list //if (realData != null && imgData.BoardId <= 1) if (realData != null) { samples.Add(new Sample() { RealDataSample = realData, ImaginaryDataSample = imgData }); } // Reset values buffer.Clear(); realData = null; } else { buffer.RemoveAt(0); realData = null; } } } } } return samples; }