public static void Initialize(Btu_DatabaseContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.User.Any()) { return; // DB has been seeded } var users = new User[] { new User { FirstName = "Carson", LastName = "Alexander", Password = "******", Email = "*****@*****.**", Privilege = "tester" } }; foreach (User s in users) { context.User.Add(s); } var ecu = new Ecu[] { new Ecu { EcuModel = "Tester" } }; foreach (Ecu s in ecu) { context.Ecu.Add(s); } var simulators = new Simulator[] { new Simulator { EcuId = 0 } }; foreach (Simulator s in simulators) { context.Simulator.Add(s); } var batches = new Batch[] { new Batch { AuthorUserId = 0, TesterUserId = 0, SimId = 0, Name = "Hello", Status = "Queued", DateCreated = DateTime.Now, Display = 1 } }; foreach (Batch s in batches) { context.Batch.Add(s); } context.SaveChanges(); return; }
public static long ReadNumberOfDTCs(Ecu ecu) { using (Request reqReadFaultMemory = ecu.CreateRequest("FaultMemory_ReadAllIdentified")) { Parameter statusOfDTC = reqReadFaultMemory.GetParameter("DtcStatusbyte"); if (statusOfDTC != null) { statusOfDTC.Value.Set(2); } else { return(-1); } using (SendResult result = reqReadFaultMemory.Send()) { if (SendStatus.Ok != result.Status) { return(-3); } else { Parameter listOfDTC = result.Response.GetParameter("ListOfDTC"); return((listOfDTC != null) ? listOfDTC.Parameters.Count : -4); } } } }
public ActionResult UpdateEcu(Ecu updatedEcu) { var ecu = ecuData.Update(updatedEcu); if (ecu == null) { return(NotFound()); } return(Ok(ecu)); }
public Ecu Update(Ecu updatedEcu) { var ecu = ecus.FirstOrDefault(e => e.Id == updatedEcu.Id); if (ecu != null) { ecu.Type = updatedEcu.Type; ecu.Description = updatedEcu.Description; } return(ecu); }
/// <summary> /// Load ecu for reading /// </summary> public void LoadCurrentEcu() { int countPids = 0; List <Ecu> ecus = this.comamnds.GetEcus(); Ecu selectedEcu = null; foreach (Ecu ecu in ecus) { if (countPids < ecu.CountOfPidsSupported) { countPids = ecu.CountOfPidsSupported; selectedEcu = ecu; } } reporter.ReportEcu(selectedEcu); this.current = selectedEcu; }
/// <summary> /// Check if pid is supported for ecu /// </summary> /// <param name="ecu"></param> /// <param name="pid"></param> /// <returns></returns> public Boolean IsPidSupportedForEcu(Ecu ecu, OdbPid pid) { if (supportedPids.ContainsKey(ecu.EcuId)) { var modes = supportedPids[ecu.EcuId]; if (modes.ContainsKey(OdbPids.ATSP0)) { var pids = modes[OdbPids.ATSP0]; return(pids.Contains(pid.GetPidIdInDecimal())); } if (modes.ContainsKey(pid.Mode)) { var pids = modes[pid.Mode]; return(pids.Contains(pid.GetPidIdInDecimal())); } } return(false); }
public static long ClearFaultMemory(Ecu ecu) { using (Request reqClearFaultMemory = ecu.CreateRequest("FaultMemory_Clear")) { if (reqClearFaultMemory == null) { return(-1); } using (SendResult result = reqClearFaultMemory.Send()) { if (result.Status != SendStatus.Ok) { return(-2); } if (result.Response == null || !result.Response.IsPositive) { return(-3); } } } return(0); }
/// <summary> /// Get all supported ecus /// </summary> /// <returns></returns> public List <Ecu> GetEcus() { List <Ecu> ecus = new List <Ecu>(); foreach (KeyValuePair <int, Dictionary <OdbPid, List <int> > > ecuData in supportedPids) { Ecu ecu = new Ecu(); ecu.EcuId = ecuData.Key; ecu.Modes = new List <EcuModes>(); ecu.CountOfPidsSupported = 0; foreach (KeyValuePair <OdbPid, List <int> > pidsData in ecuData.Value) { EcuModes modes = new EcuModes(); modes.Mode = pidsData.Key; modes.SupportedPids = pidsData.Value; ecu.CountOfPidsSupported += pidsData.Value.Count; ecu.Modes.Add(modes); } ecus.Add(ecu); } return(ecus); }
public Ecu Create(Ecu newEcu) { newEcu.Id = ecus.Max(r => r.Id) + 1; ecus.Add(newEcu); return(newEcu); }
public IActionResult CreateEcu(Ecu newEcu) { var ecu = ecuData.Create(newEcu); return(Ok(ecu)); }
public static void Initialize(Btu_DatabaseContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.User.Any()) { return; // DB has been seeded } var users = new User[] { new User { FirstName = "Carson", LastName = "Alexander", Password = "******", Email = "*****@*****.**", Privilege = "Admin" } }; foreach (User s in users) { context.User.Add(s); } var ecu = new Ecu[] { new Ecu { EcuId = 0, EcuModel = "Model A" }, new Ecu { EcuId = 1, EcuModel = "Model B" }, new Ecu { EcuId = 2, EcuModel = "Model C" } }; foreach (Ecu s in ecu) { context.Ecu.Add(s); } var simulators = new Simulator[] { new Simulator { SimId = 0, EcuId = 0 }, new Simulator { SimId = 1, EcuId = 1 }, new Simulator { SimId = 2, EcuId = 2 } }; foreach (Simulator s in simulators) { context.Simulator.Add(s); } var batches = new Batch[] { new Batch { BatchId = 0, BatchVersion = 0, AuthorUserId = 1, SimId = 0, Name = "Default", Status = "Made", DateCreated = DateTime.Now, Display = 0 } }; foreach (Batch s in batches) { context.Batch.Add(s); } var procedures = new Procedure[] { new Procedure { ProcId = 0, Description = "Take Off", Name = "Take Off", Script = "take_off.py" }, new Procedure { ProcId = 1, Description = "Cruise", Name = "Cruise", Script = "cruise.py" }, new Procedure { ProcId = 2, Description = "Land", Name = "Land", Script = "land.py" } }; foreach (Procedure s in procedures) { context.Procedure.Add(s); } context.SaveChanges(); return; }
public static void TC_AmbiguousKeyUpDown(int engineRunning) { // Initialize the system Report.TestStep("Initialize the system..."); KeyUp.Value = 0; KeyDown.Value = 0; EngineRunning.Value = engineRunning; // Retrieve the ECU by asking the application object Report.TestStep("Query ECU..."); Ecu ecu = Application.GetEcu("SUT"); if (null == ecu) { Report.TestStepFail("Cannot find ECU 'SUT'. Aborting."); return; } Report.TestStepPass("ECU 'SUT' found."); // Make sure the fault memory is clear, clear it when necessary Report.TestStep("Check fault memory status and clear it if not empty yet..."); long numberOfDTCs = BasicDiagnostics.ReadNumberOfDTCs(ecu); switch (numberOfDTCs) { case 0: // Fault memory is already empty Report.TestStepPass("Empty fault memory."); break; case 1: // There is a DTC in the fault memory Report.TestStep("Entry found in fault memory, therefore clearing it."); if (0 > BasicDiagnostics.ClearFaultMemory(ecu) || 0 != BasicDiagnostics.ReadNumberOfDTCs(ecu)) { Report.TestStepFail("Clearing fault memory failed."); return; } break; default: // Error reading fault memory, aborting Report.TestStepFail("Cannot confirm that fault memory is empty."); return; } // Provoke an error by concurrently setting lock request to 'lock' and 'unlock'. Report.TestStep("Provoke entry in fault memory"); KeyUp.Value = 1; KeyDown.Value = 1; Execution.Wait(100); // There should be a DTC in the fault memory now. Report.TestStep("Check presence of DTC in fault memory..."); if (BasicDiagnostics.ReadNumberOfDTCs(ecu) == 1) { Report.TestStepPass("DTC stored as expected."); } else { Report.TestStepFail("DTC not reported."); } // Reset fault memory Report.TestStep("Reset fault memory..."); BasicDiagnostics.ClearFaultMemory(ecu); // Reset signals Report.TestStep("Reset all signals..."); KeyUp.Value = 0; KeyDown.Value = 0; }