public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { if (destType == typeof(string) && value is IgnitionMeasurement) { // Cast the value to an Employee type IgnitionMeasurement pp = (IgnitionMeasurement)value; return(pp.IgnitionValue); } return(base.ConvertTo(context, culture, value, destType)); }
public bool Contains(IgnitionMeasurement value) { // If value is not of type Int16, this will return false. return(List.Contains(value)); }
public void Insert(int index, IgnitionMeasurement value) { List.Insert(index, value); }
public void Remove(IgnitionMeasurement value) { List.Remove(value); }
public int Add(IgnitionMeasurement value) { return(List.Add(value)); }
public int IndexOf(IgnitionMeasurement value) { return(List.IndexOf(value)); }
public void HandleRealtimeData(double rpm, double tps, double boost, double ignitionadvance, bool isKnocking) { if (_isAutoMappingActive && !_holdUntilKnockIsGone) // _holdUuntilKnockIsGone indicates we should ignore measurements until knock is over { if (rpm > _MinimumEngineSpeedForIgnitionTuning) { // only handle this stuff if automapping is active // first off, get the index in the ignition map for the given engine speed and load double currentLoad = boost; currentLoad += 1; currentLoad /= 0.01; int rpmindex = LookUpIndexAxisRPMMap(rpm, "Ign_map_0_y_axis!", 1); int mapindex = LookUpIndexAxisMap(currentLoad, "Ign_map_0_x_axis!"); // we need to be higher in boost than what knock_press_tab tells us, because below these pressure, knock will not // be detected int boostLimit = knockPressTab[rpmindex]; double dLimit = (double)boostLimit; dLimit *= mapsensorfactor; //EDIT: We made a slight mistake here... we need to start altering one column HIGHER in boost because // if we change the column directly when boost > knockPressTab[..] we will still influence ignition advance // because of T5 table interpolation. So, we need to skip ONE extra column // how can we do this? ... get the index for boostLimit as well int mapMinimumIndex = LookUpIndexAxisMap(boostLimit, "Ign_map_0_x_axis!"); if (dLimit > currentLoad) { return; } if (mapindex <= mapMinimumIndex + 1) { return; // we're not allowed to alter this column because it will cause interpolation issues } //so we now know in what cell we are // if the cell changed, we need to restart the stopwatch // if the cell is unchanged we need to check the stopwatchduration against the settings if (rpmindex != _monitoringCellRPMIndex || mapindex != _monitoringCellMAPIndex) { // set both values _ignitionMeasurements.Clear(); // clear average collection _monitoringCellRPMIndex = rpmindex; _monitoringCellMAPIndex = mapindex; // reset stopwatch _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { // appearantly we are in the same cell if (_monitoringCellMAPIndex >= 0 && _monitoringCellRPMIndex >= 0) { IgnitionMeasurement _measurement = new IgnitionMeasurement(); _measurement.IgnitionValue = ignitionadvance; _ignitionMeasurements.Add(_measurement); long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds; if (elapsed_ms > _CellStableTime_ms) { //Console.WriteLine("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString()); float average_ignition_in_cell = (float)GetAverageFromMeasurements(); int ignitionAdvanceValueFromMap = ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]; // TODO: if knocking, retard ignition by 1 full degree and lock the cell. // TODO: if NOT knocking, advance ignition by m_IgnitionAdvancePerCycle (0.1 by default) degrees but ONLY if the boost is higher than the knock detection limit AND knock detection is turned on // If we make a change we need to reset the monitor time and the measurements if (isKnocking) { _holdUntilKnockIsGone = true; if (IsCellLocked(_monitoringCellMAPIndex, _monitoringCellRPMIndex)) { ignitionAdvanceValueFromMap -= Convert.ToInt32(m_IgnitionRetardFurtherKnocks * 10); // might be knocking based on previous cell.. now what // only update stuff AFTER knock has disappeared again AddLogEntry("Decreasing by " + m_IgnitionRetardFurtherKnocks.ToString() + " degrees because locked cell still knocked rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); if (ignitionAdvanceValueFromMap <= 0) { ignitionAdvanceValueFromMap = 0; } ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); } else { ignitionAdvanceValueFromMap -= Convert.ToInt32(m_IgnitionRetardFirstKnock * 10); if (ignitionAdvanceValueFromMap <= 0) { ignitionAdvanceValueFromMap = 0; } AddLogEntry("Decreasing by " + m_IgnitionRetardFirstKnock.ToString() + " degrees because non-locked cell knocked rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); LockCell(_monitoringCellMAPIndex, _monitoringCellRPMIndex); } _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { _holdUntilKnockIsGone = false; if (!IsCellLocked(_monitoringCellMAPIndex, _monitoringCellRPMIndex)) { //increase ignition by m_IgnitionAdvancePerCycle (0.1 by default) degrees IF the cell is not locked, otherwise leave it be //Cast event to increase ignition // check against m_MaxumimIgnitionAdvancePerSession int originalAdvance = originalignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]; double advanceThisSession = Convert.ToDouble(ignitionAdvanceValueFromMap - originalAdvance); advanceThisSession /= 10; if (advanceThisSession >= m_MaxumimIgnitionAdvancePerSession) { AddLogEntry("Maximum advance increase reached for rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); if (ignitionAdvanceValueFromMap > Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)) { ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10); // cap CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)); } } else { ignitionAdvanceValueFromMap += Convert.ToInt32(m_IgnitionAdvancePerCycle * 10); if (ignitionAdvanceValueFromMap >= Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)) { ignitionAdvanceValueFromMap = Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10); // max @ 40 degrees advance } AddLogEntry("Increasing by " + m_IgnitionAdvancePerCycle.ToString() + " degrees because non-locked cell did not knock rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); } } _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } else { // nothing, invalid index from map _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } } else if (!isKnocking) { _holdUntilKnockIsGone = false; } }
public void HandleRealtimeData(double rpm, double tps, double boost, double ignitionadvance, bool isKnocking) { if (_isAutoMappingActive && !_holdUntilKnockIsGone) // _holdUuntilKnockIsGone indicates we should ignore measurements until knock is over { if (rpm > _MinimumEngineSpeedForIgnitionTuning) { // only handle this stuff if automapping is active // first off, get the index in the ignition map for the given engine speed and load double currentLoad = boost; currentLoad += 1; currentLoad /= 0.01; int rpmindex = LookUpIndexAxisRPMMap(rpm, "Ign_map_0_y_axis!", 1); int mapindex = LookUpIndexAxisMap(currentLoad, "Ign_map_0_x_axis!"); // we need to be higher in boost than what knock_press_tab tells us, because below these pressure, knock will not // be detected int boostLimit = knockPressTab[rpmindex]; double dLimit = (double)boostLimit; dLimit *= mapsensorfactor; //EDIT: We made a slight mistake here... we need to start altering one column HIGHER in boost because // if we change the column directly when boost > knockPressTab[..] we will still influence ignition advance // because of T5 table interpolation. So, we need to skip ONE extra column // how can we do this? ... get the index for boostLimit as well int mapMinimumIndex = LookUpIndexAxisMap(boostLimit, "Ign_map_0_x_axis!"); if (dLimit > currentLoad) return; if (mapindex <= mapMinimumIndex + 1) return; // we're not allowed to alter this column because it will cause interpolation issues //so we now know in what cell we are // if the cell changed, we need to restart the stopwatch // if the cell is unchanged we need to check the stopwatchduration against the settings if (rpmindex != _monitoringCellRPMIndex || mapindex != _monitoringCellMAPIndex) { // set both values _ignitionMeasurements.Clear(); // clear average collection _monitoringCellRPMIndex = rpmindex; _monitoringCellMAPIndex = mapindex; // reset stopwatch _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { // appearantly we are in the same cell if (_monitoringCellMAPIndex >= 0 && _monitoringCellRPMIndex >= 0) { IgnitionMeasurement _measurement = new IgnitionMeasurement(); _measurement.IgnitionValue = ignitionadvance; _ignitionMeasurements.Add(_measurement); long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds; if (elapsed_ms > _CellStableTime_ms) { //Console.WriteLine("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString()); float average_ignition_in_cell = (float)GetAverageFromMeasurements(); int ignitionAdvanceValueFromMap = ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]; // TODO: if knocking, retard ignition by 1 full degree and lock the cell. // TODO: if NOT knocking, advance ignition by m_IgnitionAdvancePerCycle (0.1 by default) degrees but ONLY if the boost is higher than the knock detection limit AND knock detection is turned on // If we make a change we need to reset the monitor time and the measurements if (isKnocking) { _holdUntilKnockIsGone = true; if (IsCellLocked(_monitoringCellMAPIndex, _monitoringCellRPMIndex)) { ignitionAdvanceValueFromMap -= Convert.ToInt32(m_IgnitionRetardFurtherKnocks * 10); // might be knocking based on previous cell.. now what // only update stuff AFTER knock has disappeared again AddLogEntry("Decreasing by " + m_IgnitionRetardFurtherKnocks.ToString() + " degrees because locked cell still knocked rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); if (ignitionAdvanceValueFromMap <= 0) ignitionAdvanceValueFromMap = 0; ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); } else { ignitionAdvanceValueFromMap -= Convert.ToInt32(m_IgnitionRetardFirstKnock * 10); if (ignitionAdvanceValueFromMap <= 0) ignitionAdvanceValueFromMap = 0; AddLogEntry("Decreasing by " + m_IgnitionRetardFirstKnock.ToString() + " degrees because non-locked cell knocked rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); LockCell(_monitoringCellMAPIndex, _monitoringCellRPMIndex); } _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { _holdUntilKnockIsGone = false; if (!IsCellLocked(_monitoringCellMAPIndex, _monitoringCellRPMIndex)) { //increase ignition by m_IgnitionAdvancePerCycle (0.1 by default) degrees IF the cell is not locked, otherwise leave it be //Cast event to increase ignition // check against m_MaxumimIgnitionAdvancePerSession int originalAdvance = originalignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]; double advanceThisSession = Convert.ToDouble(ignitionAdvanceValueFromMap - originalAdvance); advanceThisSession /= 10; if (advanceThisSession >= m_MaxumimIgnitionAdvancePerSession) { AddLogEntry("Maximum advance increase reached for rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); if (ignitionAdvanceValueFromMap > Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)) { ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10); // cap CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)); } } else { ignitionAdvanceValueFromMap += Convert.ToInt32(m_IgnitionAdvancePerCycle * 10); if (ignitionAdvanceValueFromMap >= Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10)) ignitionAdvanceValueFromMap = Convert.ToInt32(m_GlobalMaximumIgnitionAdvance * 10); // max @ 40 degrees advance AddLogEntry("Increasing by " + m_IgnitionAdvancePerCycle.ToString() + " degrees because non-locked cell did not knock rpm: " + rpm.ToString() + " boost: " + boost.ToString() + " adjusted to " + ignitionAdvanceValueFromMap.ToString()); ignitionmap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex] = ignitionAdvanceValueFromMap; ignitioncorrectioncountermap[_monitoringCellRPMIndex * 18 + _monitoringCellMAPIndex]++; CastIgnitionmapCellChangedEvent((rpmindex * 18) + mapindex, ignitionAdvanceValueFromMap); } } _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } else { // nothing, invalid index from map _ignitionMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } } else if (!isKnocking) { _holdUntilKnockIsGone = false; } }
public bool Contains(IgnitionMeasurement value) { // If value is not of type Int16, this will return false. return (List.Contains(value)); }
public int Add(IgnitionMeasurement value) { return (List.Add(value)); }
public int IndexOf(IgnitionMeasurement value) { return (List.IndexOf(value)); }