/// <summary> /// Report selected ecu /// </summary> /// <param name="selectedEcu"></param> public void ReportEcu(Ecu selectedEcu) { if (!OdbClient.OBD_REPORTER_ENABLED) { return; } if (selectedEcu != null) { Debug.WriteLine(InfoPrefix + "Using car ECU with id '{0}' and {1} supporteds pids.", selectedEcu.EcuId, selectedEcu.CountOfPidsSupported); } else { Debug.WriteLine(ErrorPrefix + "There is not compatible ECU for your car."); } }
/// <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> /// 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; }
/// <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(pid.Mode)) { var pids = modes[pid.Mode]; return pids.Contains(pid.GetPidIdInDecimal()); } } return false; }