public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
            {
                if (destType == typeof(string) && value is AFRMeasurement)
                {
                    // Cast the value to an Employee type
                    AFRMeasurement pp = (AFRMeasurement)value;

                    return(pp.AfrValue);
                }
                return(base.ConvertTo(context, culture, value, destType));
            }
示例#2
0
        internal void HandleRealtimeData(float afr, float rpm, float airmass)
        {
            double currentLoad = airmass;
            //currentLoad += 1;
            //currentLoad /= 0.01;
            int rpmindex = LookUpIndexAxisRPMMap(rpm);
            int mapindex = LookUpIndexAxisMap(currentLoad);
            //logger.Debug("rpm index: " + rpmindex.ToString() + " loadindex: " + mapindex.ToString());
            //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
                _afrMeasurements.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)
                {
                    AFRMeasurement _measurement = new AFRMeasurement();
                    _measurement.AfrValue = afr;
                    _afrMeasurements.Add(_measurement);
                    long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds;

                    if (elapsed_ms > _CellStableTime_ms)
                    {

                        // check afr against target afr
                        // get the average AFR from the collection
                        float average_afr_in_cell = (float)GetAverageFromMeasurements();
                        float targetafr_currentcell = (float)targetmap.GetValue((rpmindex * 18) + mapindex);
                        // calculate the difference in percentage
                        float _afr_diff_percentage = Math.Abs(((targetafr_currentcell - average_afr_in_cell) / targetafr_currentcell) * 100);
                        if (_afr_diff_percentage > _AcceptableTargetErrorPercentage)
                        {

                            // afr is outside of limits (difference > set percentage).. now what?
                            // is the afr lower or higher than the target?
                            // we should correct with the set percentage _CorrectionPercentage
                            // but no more than _MaximumAdjustmentPerCyclePercentage of the original fuelmap value
                            float afr_diff_to_correct = Math.Abs(_afr_diff_percentage);
                            afr_diff_to_correct *= _CorrectionPercentage;
                            afr_diff_to_correct /= 100;
                            // cap it to _MaximumAdjustmentPerCyclePercentage
                            if (afr_diff_to_correct > _MaximumAdjustmentPerCyclePercentage)
                            {
                                afr_diff_to_correct = _MaximumAdjustmentPerCyclePercentage;
                            }
                            logger.Debug("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString() + " " + _afr_diff_percentage.ToString() + " " + afr_diff_to_correct.ToString());
                            // get the current fuel map value for the given cell
                            // get the number of changes that have been made already to this cell
                            // if the number of changes > x then don't do changes anymore and notify the user
                            int _fuelcorrectionvalue = (int)fuelmap[(rpmindex * 18) + mapindex];

                            if (average_afr_in_cell > targetafr_currentcell)
                            {
                                // we're running too lean, so we need to increase the fuelmap value by afr_diff_to_correct %
                                // get the current fuelmap value
                                // correct it with the percentage
                                logger.Debug("running lean");
                                _fuelcorrectionvalue *= (int)(100 + afr_diff_to_correct);
                                _fuelcorrectionvalue /= 100;
                                if (_fuelcorrectionvalue > 254) _fuelcorrectionvalue = 254;
                                // save it to the map

                            }
                            else
                            {
                                // we're running too rich, so we need to decrease the fuelmap value by afr_diff_to_correct %
                                // correct it with the percentage
                                logger.Debug("running rich");
                                _fuelcorrectionvalue *= (int)(100 - afr_diff_to_correct);
                                _fuelcorrectionvalue /= 100;
                                // don't go under 25, seems to be some kind of boundary!
                                // <GS-28102010> changed for testing purposes, if problems occur, revert back to 25 as boundary
                                if (_fuelcorrectionvalue < 1) _fuelcorrectionvalue = 1;

                                // save it to the map
                            }
                            if (fuelmap[(rpmindex * 18) + mapindex] != (byte)_fuelcorrectionvalue)
                            {
                                // if autowrite to ECU
                                if (_AutoUpdateFuelMap)
                                {
                                    // if the user should be notified, do so now, ask permission to alter the fuel map
                                    logger.Debug("Altering rpmidx: " + rpmindex.ToString() + " mapidx: " + mapindex.ToString() + " from value: " + fuelmap[(rpmindex * 18) + mapindex].ToString() + " to value: " + _fuelcorrectionvalue.ToString());
                                    fuelmap[(rpmindex * 18) + mapindex] = (byte)_fuelcorrectionvalue;
                                    // increase counter
                                    fuelcorrectioncountermap[(rpmindex * 18) + mapindex]++;
                                    // cast an event that will write the data into the ECU (?)
                                    CastFuelmapCellChangedEvent((rpmindex * 18) + mapindex, (byte)_fuelcorrectionvalue);
                                }
                                else
                                {
                                    // keep track of the changes in the fuelmapinfo
                                    m_FuelMapInformation.UpdateFuelMap(mapindex, rpmindex, _fuelcorrectionvalue);
                                }
                                //<GS-09082010> play an optional PING sound here!
                                CastCellLockedEvent();
                            }
                            //now we reset the stopwatch and wait for another event to occur
                            _afrMeasurements.Clear(); // clear average collection
                            _cellDurationMonitor.Stop();
                            _cellDurationMonitor.Reset();
                            _cellDurationMonitor.Start();

                        }
                        else
                        {
                            //what to do if AFR is correct (within limits), should we reset the stopwatch?
                            _afrMeasurements.Clear(); // clear average collection
                            _cellDurationMonitor.Stop();
                            _cellDurationMonitor.Reset();
                            _cellDurationMonitor.Start();
                        }
                    }
                }
                else
                {
                    // nothing, invalid index from map
                    _afrMeasurements.Clear(); // clear average collection
                    _cellDurationMonitor.Stop();
                    _cellDurationMonitor.Reset();
                    _cellDurationMonitor.Start();
                }
            }
        }
示例#3
0
        internal void HandleRealtimeData(float afr, float rpm, float airmass)
        {
            double currentLoad = airmass;
            //currentLoad += 1;
            //currentLoad /= 0.01;
            int rpmindex = LookUpIndexAxisRPMMap(rpm);
            int mapindex = LookUpIndexAxisMap(currentLoad);

            //logger.Debug("rpm index: " + rpmindex.ToString() + " loadindex: " + mapindex.ToString());
            //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
                _afrMeasurements.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)
                {
                    AFRMeasurement _measurement = new AFRMeasurement();
                    _measurement.AfrValue = afr;
                    _afrMeasurements.Add(_measurement);
                    long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds;

                    if (elapsed_ms > _CellStableTime_ms)
                    {
                        // check afr against target afr
                        // get the average AFR from the collection
                        float average_afr_in_cell   = (float)GetAverageFromMeasurements();
                        float targetafr_currentcell = (float)targetmap.GetValue((rpmindex * 18) + mapindex);
                        // calculate the difference in percentage
                        float _afr_diff_percentage = Math.Abs(((targetafr_currentcell - average_afr_in_cell) / targetafr_currentcell) * 100);
                        if (_afr_diff_percentage > _AcceptableTargetErrorPercentage)
                        {
                            // afr is outside of limits (difference > set percentage).. now what?
                            // is the afr lower or higher than the target?
                            // we should correct with the set percentage _CorrectionPercentage
                            // but no more than _MaximumAdjustmentPerCyclePercentage of the original fuelmap value
                            float afr_diff_to_correct = Math.Abs(_afr_diff_percentage);
                            afr_diff_to_correct *= _CorrectionPercentage;
                            afr_diff_to_correct /= 100;
                            // cap it to _MaximumAdjustmentPerCyclePercentage
                            if (afr_diff_to_correct > _MaximumAdjustmentPerCyclePercentage)
                            {
                                afr_diff_to_correct = _MaximumAdjustmentPerCyclePercentage;
                            }
                            logger.Debug("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString() + " " + _afr_diff_percentage.ToString() + " " + afr_diff_to_correct.ToString());
                            // get the current fuel map value for the given cell
                            // get the number of changes that have been made already to this cell
                            // if the number of changes > x then don't do changes anymore and notify the user
                            int _fuelcorrectionvalue = (int)fuelmap[(rpmindex * 18) + mapindex];

                            if (average_afr_in_cell > targetafr_currentcell)
                            {
                                // we're running too lean, so we need to increase the fuelmap value by afr_diff_to_correct %
                                // get the current fuelmap value
                                // correct it with the percentage
                                logger.Debug("running lean");
                                _fuelcorrectionvalue *= (int)(100 + afr_diff_to_correct);
                                _fuelcorrectionvalue /= 100;
                                if (_fuelcorrectionvalue > 254)
                                {
                                    _fuelcorrectionvalue = 254;
                                }
                                // save it to the map
                            }
                            else
                            {
                                // we're running too rich, so we need to decrease the fuelmap value by afr_diff_to_correct %
                                // correct it with the percentage
                                logger.Debug("running rich");
                                _fuelcorrectionvalue *= (int)(100 - afr_diff_to_correct);
                                _fuelcorrectionvalue /= 100;
                                // don't go under 25, seems to be some kind of boundary!
                                // <GS-28102010> changed for testing purposes, if problems occur, revert back to 25 as boundary
                                if (_fuelcorrectionvalue < 1)
                                {
                                    _fuelcorrectionvalue = 1;
                                }

                                // save it to the map
                            }
                            if (fuelmap[(rpmindex * 18) + mapindex] != (byte)_fuelcorrectionvalue)
                            {
                                // if autowrite to ECU
                                if (_AutoUpdateFuelMap)
                                {
                                    // if the user should be notified, do so now, ask permission to alter the fuel map
                                    logger.Debug("Altering rpmidx: " + rpmindex.ToString() + " mapidx: " + mapindex.ToString() + " from value: " + fuelmap[(rpmindex * 18) + mapindex].ToString() + " to value: " + _fuelcorrectionvalue.ToString());
                                    fuelmap[(rpmindex * 18) + mapindex] = (byte)_fuelcorrectionvalue;
                                    // increase counter
                                    fuelcorrectioncountermap[(rpmindex * 18) + mapindex]++;
                                    // cast an event that will write the data into the ECU (?)
                                    CastFuelmapCellChangedEvent((rpmindex * 18) + mapindex, (byte)_fuelcorrectionvalue);
                                }
                                else
                                {
                                    // keep track of the changes in the fuelmapinfo
                                    m_FuelMapInformation.UpdateFuelMap(mapindex, rpmindex, _fuelcorrectionvalue);
                                }
                                //<GS-09082010> play an optional PING sound here!
                                CastCellLockedEvent();
                            }
                            //now we reset the stopwatch and wait for another event to occur
                            _afrMeasurements.Clear(); // clear average collection
                            _cellDurationMonitor.Stop();
                            _cellDurationMonitor.Reset();
                            _cellDurationMonitor.Start();
                        }
                        else
                        {
                            //what to do if AFR is correct (within limits), should we reset the stopwatch?
                            _afrMeasurements.Clear(); // clear average collection
                            _cellDurationMonitor.Stop();
                            _cellDurationMonitor.Reset();
                            _cellDurationMonitor.Start();
                        }
                    }
                }
                else
                {
                    // nothing, invalid index from map
                    _afrMeasurements.Clear(); // clear average collection
                    _cellDurationMonitor.Stop();
                    _cellDurationMonitor.Reset();
                    _cellDurationMonitor.Start();
                }
            }
        }
 public bool Contains(AFRMeasurement value)
 {
     // If value is not of type Int16, this will return false.
     return (List.Contains(value));
 }
 public int Add(AFRMeasurement value)
 {
     return (List.Add(value));
 }
 public void Remove(AFRMeasurement value)
 {
     List.Remove(value);
 }
 public void Insert(int index, AFRMeasurement value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(AFRMeasurement value)
 {
     return (List.IndexOf(value));
 }
 public bool Contains(AFRMeasurement value)
 {
     // If value is not of type Int16, this will return false.
     return(List.Contains(value));
 }
 public void Remove(AFRMeasurement value)
 {
     List.Remove(value);
 }
 public void Insert(int index, AFRMeasurement value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(AFRMeasurement value)
 {
     return(List.IndexOf(value));
 }
 public int Add(AFRMeasurement value)
 {
     return(List.Add(value));
 }