private void ResetValues() { _abortRequest = false; EcuList.Clear(); Vin = null; GroupSgdb = null; BnType = VehicleInfoBmw.BnType.UNKNOWN; ModelSeries = null; Series = null; ConstructYear = null; ConstructMonth = null; }
public bool DetectVehicleBmwFast() { ResetValues(); HashSet <string> invalidSgbdSet = new HashSet <string>(); try { List <Dictionary <string, EdiabasNet.ResultData> > resultSets; string detectedVin = null; foreach (Tuple <string, string, string> job in ReadVinJobsBmwFast) { if (_abortRequest) { return(false); } try { _ediabas.ResolveSgbdFile(job.Item1); _ediabas.ArgString = string.Empty; _ediabas.ArgBinaryStd = null; _ediabas.ResultsRequests = string.Empty; _ediabas.ExecuteJob(job.Item2); resultSets = _ediabas.ResultSets; if (resultSets != null && resultSets.Count >= 2) { if (detectedVin == null) { detectedVin = string.Empty; } Dictionary <string, EdiabasNet.ResultData> resultDict = resultSets[1]; if (resultDict.TryGetValue(job.Item3, out EdiabasNet.ResultData resultData)) { string vin = resultData.OpData as string; // ReSharper disable once AssignNullToNotNullAttribute if (!string.IsNullOrEmpty(vin) && _vinRegex.IsMatch(vin)) { detectedVin = vin; _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected VIN: {0}", detectedVin); break; } } } } catch (Exception) { invalidSgbdSet.Add(job.Item1); _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "No VIN response"); // ignored } } if (string.IsNullOrEmpty(detectedVin)) { return(false); } Vin = detectedVin; string vehicleType = null; string modelSeries = null; DateTime?cDate = null; foreach (Tuple <string, string, string> job in ReadIdentJobsBmwFast) { if (_abortRequest) { return(false); } _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Read BR job: {0},{1}", job.Item1, job.Item2); if (invalidSgbdSet.Contains(job.Item1)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Job ignored: {0}", job.Item1); continue; } try { bool readFa = string.Compare(job.Item2, "C_FA_LESEN", StringComparison.OrdinalIgnoreCase) == 0; _ediabas.ResolveSgbdFile(job.Item1); _ediabas.ArgString = string.Empty; _ediabas.ArgBinaryStd = null; _ediabas.ResultsRequests = string.Empty; _ediabas.ExecuteJob(job.Item2); resultSets = _ediabas.ResultSets; if (resultSets != null && resultSets.Count >= 2) { Dictionary <string, EdiabasNet.ResultData> resultDict = resultSets[1]; if (resultDict.TryGetValue(job.Item3, out EdiabasNet.ResultData resultData)) { if (readFa) { string fa = resultData.OpData as string; if (!string.IsNullOrEmpty(fa)) { _ediabas.ResolveSgbdFile("FA"); _ediabas.ArgString = "1;" + fa; _ediabas.ArgBinaryStd = null; _ediabas.ResultsRequests = string.Empty; _ediabas.ExecuteJob("FA_STREAM2STRUCT"); List <Dictionary <string, EdiabasNet.ResultData> > resultSetsFa = _ediabas.ResultSets; if (resultSetsFa != null && resultSetsFa.Count >= 2) { Dictionary <string, EdiabasNet.ResultData> resultDictFa = resultSetsFa[1]; if (resultDictFa.TryGetValue("BR", out EdiabasNet.ResultData resultDataBa)) { string br = resultDataBa.OpData as string; if (!string.IsNullOrEmpty(br)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected BR: {0}", br); string vtype = VehicleInfoBmw.GetVehicleTypeFromBrName(br, _ediabas); if (!string.IsNullOrEmpty(vtype)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected vehicle type: {0}", vtype); modelSeries = br; vehicleType = vtype; } } } if (resultDictFa.TryGetValue("C_DATE", out EdiabasNet.ResultData resultDataCDate)) { string cDateStr = resultDataCDate.OpData as string; if (!string.IsNullOrEmpty(cDateStr)) { if (DateTime.TryParseExact(cDateStr, "MMyy", null, DateTimeStyles.None, out DateTime dateTime)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected construction date: {0}", dateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); cDate = dateTime; } } } if (vehicleType != null) { break; } } } } else { string br = resultData.OpData as string; if (!string.IsNullOrEmpty(br)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected BR: {0}", br); string vtype = VehicleInfoBmw.GetVehicleTypeFromBrName(br, _ediabas); if (!string.IsNullOrEmpty(vtype)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected vehicle type: {0}", vtype); modelSeries = br; vehicleType = vtype; break; } } } } } } catch (Exception) { _ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "No BR response"); // ignored } } ModelSeries = modelSeries; Series = vehicleType; if (cDate.HasValue) { ConstructYear = cDate.Value.ToString("yyyy", CultureInfo.InvariantCulture); ConstructMonth = cDate.Value.ToString("MM", CultureInfo.InvariantCulture); } string groupSgbd = VehicleInfoBmw.GetGroupSgbdFromVehicleType(vehicleType, detectedVin, cDate, _ediabas, out VehicleInfoBmw.BnType bnType); if (string.IsNullOrEmpty(groupSgbd)) { _ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "No group SGBD found"); return(false); } _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Group SGBD: {0}", groupSgbd); GroupSgdb = groupSgbd; BnType = bnType; if (_abortRequest) { return(false); } try { _ediabas.ResolveSgbdFile(groupSgbd); _ediabas.ArgString = string.Empty; _ediabas.ArgBinaryStd = null; _ediabas.ResultsRequests = string.Empty; _ediabas.ExecuteJob("IDENT_FUNKTIONAL"); EcuList.Clear(); resultSets = _ediabas.ResultSets; if (resultSets != null && resultSets.Count >= 2) { int dictIndex = 0; foreach (Dictionary <string, EdiabasNet.ResultData> resultDict in resultSets) { if (dictIndex == 0) { dictIndex++; continue; } string ecuName = string.Empty; Int64 ecuAdr = -1; string ecuDesc = string.Empty; string ecuSgbd = string.Empty; string ecuGroup = string.Empty; // ReSharper disable once InlineOutVariableDeclaration EdiabasNet.ResultData resultData; if (resultDict.TryGetValue("ECU_GROBNAME", out resultData)) { if (resultData.OpData is string) { ecuName = (string)resultData.OpData; } } if (resultDict.TryGetValue("ID_SG_ADR", out resultData)) { if (resultData.OpData is Int64) { ecuAdr = (Int64)resultData.OpData; } } if (resultDict.TryGetValue("ECU_NAME", out resultData)) { if (resultData.OpData is string) { ecuDesc = (string)resultData.OpData; } } if (resultDict.TryGetValue("ECU_SGBD", out resultData)) { if (resultData.OpData is string) { ecuSgbd = (string)resultData.OpData; } } if (resultDict.TryGetValue("ECU_GRUPPE", out resultData)) { if (resultData.OpData is string) { ecuGroup = (string)resultData.OpData; } } if (!string.IsNullOrEmpty(ecuName) && ecuAdr >= 0 && !string.IsNullOrEmpty(ecuSgbd)) { PdszDatabase.EcuInfo ecuInfo = new PdszDatabase.EcuInfo(ecuName, ecuAdr, ecuDesc, ecuSgbd, ecuGroup); EcuList.Add(ecuInfo); } dictIndex++; } } } catch (Exception) { _ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "No ident response"); return(false); } string iLevelShip = null; string iLevelCurrent = null; string iLevelBackup = null; foreach (Tuple <string, string> job in ReadILevelJobsBmwFast) { if (_abortRequest) { return(false); } _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Read ILevel job: {0},{1}", job.Item1, job.Item2); if (invalidSgbdSet.Contains(job.Item1)) { _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Job ignored: {0}", job.Item1); continue; } try { _ediabas.ResolveSgbdFile(job.Item1); _ediabas.ArgString = string.Empty; _ediabas.ArgBinaryStd = null; _ediabas.ResultsRequests = string.Empty; _ediabas.ExecuteJob(job.Item2); resultSets = _ediabas.ResultSets; if (resultSets != null && resultSets.Count >= 2) { if (detectedVin == null) { detectedVin = string.Empty; } Dictionary <string, EdiabasNet.ResultData> resultDict = resultSets[1]; if (resultDict.TryGetValue("STAT_I_STUFE_WERK", out EdiabasNet.ResultData resultData)) { string iLevel = resultData.OpData as string; if (!string.IsNullOrEmpty(iLevel) && iLevel.Length >= 4 && string.Compare(iLevel, VehicleInfoBmw.ResultUnknown, StringComparison.OrdinalIgnoreCase) != 0) { iLevelShip = iLevel; _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected ILevel ship: {0}", iLevelShip); } } if (!string.IsNullOrEmpty(iLevelShip)) { if (resultDict.TryGetValue("STAT_I_STUFE_HO", out resultData)) { string iLevel = resultData.OpData as string; if (!string.IsNullOrEmpty(iLevel) && iLevel.Length >= 4 && string.Compare(iLevel, VehicleInfoBmw.ResultUnknown, StringComparison.OrdinalIgnoreCase) != 0) { iLevelCurrent = iLevel; _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected ILevel current: {0}", iLevelCurrent); } } if (string.IsNullOrEmpty(iLevelCurrent)) { iLevelCurrent = iLevelShip; } if (resultDict.TryGetValue("STAT_I_STUFE_HO_BACKUP", out resultData)) { string iLevel = resultData.OpData as string; if (!string.IsNullOrEmpty(iLevel) && iLevel.Length >= 4 && string.Compare(iLevel, VehicleInfoBmw.ResultUnknown, StringComparison.OrdinalIgnoreCase) != 0) { iLevelBackup = iLevel; _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "Detected ILevel backup: {0}", iLevelBackup); } } break; } } } catch (Exception) { _ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "No ILevel response"); // ignored } } if (string.IsNullOrEmpty(iLevelShip)) { _ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "ILevel not found"); return(false); } _ediabas.LogFormat(EdiabasNet.EdLogLevel.Ifh, "ILevel: Ship={0}, Current={1}, Backup={2}", iLevelShip, iLevelCurrent, iLevelBackup); ILevelShip = iLevelShip; ILevelCurrent = iLevelCurrent; ILevelBackup = iLevelBackup; if (_abortRequest) { return(false); } return(true); } catch (Exception) { return(false); } }