private void GenerateCSVFromRaw(string path) { string filename = Path.GetFileNameWithoutExtension(path); if (filename == null && File.Exists(path)) { Console.WriteLine("Path: {0} was not a file", path); return; } string directoryPath = Path.GetDirectoryName(path); string newFileName = filename.Replace("raw_", "gen_"); string newFilePath = Path.Combine(directoryPath, newFileName) + ".csv"; using (FileStream fs = File.OpenRead(path)) { byte[] start = { 0xFD, 0xFF, 0xFF, 0xFF, 0xFF }; byte[] end = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF }; Protocol protocol = new Protocol(start, end); byte[] b = new byte[1024]; while (fs.Read(b, 0, b.Length) > 0) { protocol.Add(b); } List <DataPacket> frames = protocol.FindFrames(); ComponentMapping mapping = new TestStandMapping(); Session session = new Session(mapping); using (StreamWriter sw = new StreamWriter(newFilePath)) { string header = FormatPretty.PrettyHeader(session.Mapping.Loggables()); sw.WriteLine(header); foreach (DataPacket dp in frames) { session.UpdateComponents(dp.Bytes); string pretty = FormatPretty.PrettyLine(session.SystemTime, session.Mapping.Loggables()); sw.WriteLine(pretty); } } } }
private void OnSelectFilePressed(object sender, EventArgs e) { string fileName = OpenFileDialog(); if (fileName != null) { _fileLabel.Text = (fileName.Length > 30) ? "..." + fileName.Substring(fileName.Length - 30 - 1) : fileName; StreamReader file = new StreamReader(fileName); _data = FormatPretty.PrettyToData(file); _sensorStore.Clear(); foreach (KeyValuePair <string, List <float> > sensor in _data.Values) { _sensorStore.AppendValues(sensor.Key); } _sensorDropdown.Sensitive = true; } else { } }