static public void SaveECUData(String fName, List <ECUData> ECUDataRecords) { CsvFile cf = new CsvFile(); CsvWriter cw = new CsvWriter(); foreach (ECUData rec in ECUDataRecords) { CsvRecord cr = new CsvRecord(); //Get a new CSV Record List <String> dataStringList = rec.GetDataValueStringList(); foreach (String item in dataStringList) { cr.Fields.Add(item); } cf.Records.Add(cr); } cf.Headers.Clear(); List <String> dataNameList = ECUData.GetDataValueNameList(); foreach (String s in dataNameList) { cf.Headers.Add(s); } cw.WriteCsv(cf, fName, Encoding.ASCII); //Write The CSV File }
public ECUData ParseFrame(Byte[] frame) { ECUData eData = new ECUData(); eData.ProgramVersion = frame[0]; eData.PromVersion = frame[1]; eData.ACRequest = frame[2]; eData.MAP = (frame[3] / 9.13) + 3.1; eData.CTS = (frame[4] / 0.888) - 40.0; eData.IAT = (frame[5] / 0.888) - 40.0; eData.Volts = frame[6] / 16.24; eData.Lambda = frame[7] / 51.2; UInt16 t = frame[9]; t <<= 8; t += frame[8]; if (t == 0) { eData.RPM = 0; } else { Int32 r = 19850000 / t; eData.RPM = (UInt16)r; } eData.TPS = frame[12] / 2.55; eData.SparkAdvance = frame[13]; eData.InitialMAP = (frame[16] / 9.3) + 3.1; eData.LoopStatusExhaust = frame[18]; eData.InjPulseMs = frame[19] / 7.79; eData.fuelsync = frame[21]; eData.STFuelTrim = frame[24]; eData.LTFuelTrim = frame[26]; eData.Knock = frame[27]; ECUData.CalcECUItems(ref eData); //Handle Calculated Properties return(eData); }
private void SaveLogFile() { DialogResult result; bool bAppend = false;; saveFileDialogLogging.AddExtension = true; saveFileDialogLogging.DefaultExt = "csv"; saveFileDialogLogging.OverwritePrompt = false; if (saveFileDialogLogging.ShowDialog() != DialogResult.OK) { return; } String fname = saveFileDialogLogging.FileName; if ((System.IO.File.Exists(fname))) { result = MessageBox.Show("File Exists - Append to Existing file?", "File Check", MessageBoxButtons.YesNoCancel); switch (result) { case DialogResult.Yes: bAppend = true; break; case DialogResult.No: bAppend = false; break; default: return; break; } } //If time to write the CSV file LogFile.Headers.Clear(); List <String> dataNameList = ECUData.GetDataValueNameList(); foreach (String s in dataNameList) { LogFile.Headers.Add(s); } CsvWriter cw = new CsvWriter(); cw.WriteCsv(LogFile, fname, Encoding.ASCII, bAppend); //Write The CSV File needSave = false; }
public static bool ReadECUData(ref ECUData ECUVars, String url) { ECUData tempecu; bool retval = false; url = "http://" + url + "/ecu"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(url); try { HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; if (result == null) { return(false); } if (result == "") { return(false); } tempecu = JsonConvert.DeserializeObject <ECUData>(result); //Now we have name value pairs of ECU variables. Need to calculate a few remaining ones // ECUData.CalcECUItems(ref tempecu); Obsolete ObjectCopier.CopyShallow <ECUData>(tempecu, ECUVars); //Now ensure we've copied the Relay Status retval = true; } } catch (Exception e) { Console.WriteLine(e.Message); } return(retval); }
private void SaveparsedCSVFile() { List <ECUData> ECUDataRecords = new List <ECUData>(); DialogResult result = dlgCSVSave.ShowDialog(); JeepECUData ecu = new JeepECUData(); if (result == DialogResult.OK) { //parse all data from raw Readings into Data Frames //Parse Data One Byte at a time into frames for (int x = 0; x < rawEngineData.Count; x++) { ecu.ReceiveDataFrame(rawEngineData[x].data); if (ecu.bufferError == 1) { ++BadFrameErrors; } if (ecu.FrameCompleteFlag) { //Note Reading the frame Buffer resets the complete flag and allows parsing //to continue ECUData rec = ecu.ParseFrame(ecu.frameBuffer); if (ecu.bufferCount >= 27) { //Get a date/time stamp for this //use last byte in frame. Add to recors and //save the record rec.LogTime = rawEngineData[x].timeStamp; ECUDataRecords.Add(rec); } else { ++ShortFrameErrors; } } } JeepECUData.SaveECUData(dlgCSVSave.FileName, ECUDataRecords); } }
//Given an ECU Data data structure, calculates the proper values for //Throttle Position Sensor,ECU Mode, Lean/Rich Indicator, and Vaccum //from the pit positions in the ECU data public static void CalcECUItems(ref ECUData ECUInfo) { //Calc Absolute Manifold Pressure double VacHg = (ECUInfo.InitialMAP - ECUInfo.MAP) / 9.13; ECUInfo.sVacHg = VacHg.ToString(); //Calc if we're lean or rich Byte lr = ECUInfo.LoopStatusExhaust; lr = (Byte)(lr >> 7); if (lr == 1) { ECUInfo.O2State = "Rich"; } else { ECUInfo.O2State = "Lean"; } //Figure out which mode the ECU is in lr = ECUInfo.LoopStatusExhaust; lr = (Byte)(lr >> 1); lr = (Byte)(lr & 0x01); if (lr == 1) { ECUInfo.ECUMode = "Decel"; } else { lr = ECUInfo.LoopStatusExhaust; lr = (Byte)(lr >> 6); lr = (Byte)(lr & 0x01); if (lr == 1) { ECUInfo.ECUMode = "Closed"; } else { ECUInfo.ECUMode = "Open"; } } //figure out throttle position //Get Bit Positions 1 and 3 Byte tpsB1 = (Byte)(ECUInfo.fuelsync >> 1); Byte tpsB3 = (Byte)(ECUInfo.fuelsync >> 3); tpsB1 &= 0x01; tpsB3 &= 0x01; if ((tpsB1 ^ tpsB3) == 1) { //One or the other is set (But not Both) if (tpsB1 == 1) { ECUInfo.ThrottlePos = "Closed"; } else { ECUInfo.ThrottlePos = "Wide Open"; } } else { ECUInfo.ThrottlePos = "Partial"; } }