예제 #1
0
        private int LookUpIndexAxisRPMMap(double value, string symbolname, int multiplywith)
        {
            int    return_index   = -1;
            double min_difference = 10000000;

            byte[] axisvalues = m_TrionicFile.ReadData((uint)m_TrionicFile.GetFileInfo().GetSymbolAddressFlash(symbolname), (uint)m_TrionicFile.GetFileInfo().GetSymbolLength(symbolname));
            if (m_TrionicFile.GetFileInfo().isSixteenBitTable(symbolname))
            {
                for (int t = 0; t < axisvalues.Length; t += 2)
                {
                    int b = (int)(byte)axisvalues.GetValue(t) * 256;
                    b += (int)(byte)axisvalues.GetValue(t + 1);
                    b *= multiplywith;
                    double diff = Math.Abs((double)b - value);
                    if (min_difference > diff)
                    {
                        min_difference = diff;
                        // this is our index
                        return_index = t / 2;
                        // Console.WriteLine("Difference was: " + diff.ToString() + " at index " + return_index.ToString());
                    }
                }
            }
            else
            {
                for (int t = 0; t < axisvalues.Length; t++)
                {
                    int b = (int)(byte)axisvalues.GetValue(t);
                    b *= multiplywith;
                    double diff = Math.Abs((double)b - value);
                    if (min_difference > diff)
                    {
                        min_difference = diff;
                        // this is our index
                        return_index = t;
                    }
                }
            }
            return(return_index);
        }
예제 #2
0
 private void IncreaseByteVariableWith140Percent(IECUFile m_File, string symbol)
 {
     // read value
     byte[] data = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash(symbol), (uint)m_File.GetFileInfo().GetSymbolLength(symbol));
     for (int t = 0; t < data.Length; t++)
     {
         double dval = Convert.ToDouble(data[t]);
         dval *= 1.4;
         data[t] = Convert.ToByte(dval);
     }
     m_File.WriteData(data, (uint)m_File.GetFileInfo().GetSymbolAddressFlash(symbol));
 }
예제 #3
0
        private void GenerateAndSaveNewIgnitionMap(IECUFile m_File, bool runsE85)
        {
            //TODO: Implement
            // get the axis
            TuningReferenceMaps _referenceMaps = new TuningReferenceMaps();
            byte[] pressure_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0_x_axis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Ign_map_0_x_axis!"));
            byte[] rpm_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0_y_axis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Ign_map_0_y_axis!"));
            byte[] new_ignition_map = new byte[16 * 18 * 2];
            int ign_map_index = 0;
            for (int rpm_index = rpm_axis.Length-2; rpm_index >=0; rpm_index -= 2)
            {
                for (int pressure_index = 0; pressure_index < pressure_axis.Length; pressure_index += 2)
                {

                    int irpm = Convert.ToInt32(rpm_axis[rpm_index]) * 256;
                    irpm += Convert.ToInt32(rpm_axis[rpm_index+1]);
                    int ipressure = Convert.ToInt32(pressure_axis[pressure_index]) * 256;
                    ipressure += Convert.ToInt32(pressure_axis[pressure_index + 1]);
                    double correctionFactor = 1;
                    double pressure = ipressure;
                    MapSensorType mapsensor = m_File.GetMapSensorType(false);
                    if (mapsensor == MapSensorType.MapSensor30) correctionFactor = 1.2;
                    else if (mapsensor == MapSensorType.MapSensor35) correctionFactor = 1.4;
                    else if (mapsensor == MapSensorType.MapSensor40) correctionFactor = 1.6;
                    else if (mapsensor == MapSensorType.MapSensor50) correctionFactor = 2.0;
                    pressure *= correctionFactor;
                    pressure -= 100;
                    pressure /= 100;
                    double ignition_advance = _referenceMaps.GetIgnitionAdvanceForPressureRpm(pressure, (double)irpm);
                    if (runsE85) ignition_advance = _referenceMaps.GetIgnitionAdvanceE85ForPressureRpm(pressure, (double)irpm);
                    // write ignition advance into the map
                    ignition_advance *= 10; // correction factor
                    Int32 iAdvance = Convert.ToInt32(ignition_advance);
                    byte v1 = (byte)(iAdvance / 256);
                    byte v2 = (byte)(iAdvance - (int)v1 * 256);
                    //Console.WriteLine("Writing data rpmidx : " + rpm_index.ToString() + " mapidx: " + pressure_index.ToString() + " ignidx: " + ign_map_index.ToString());
                    new_ignition_map[ign_map_index++] = v1;
                    new_ignition_map[ign_map_index++] = v2;
                }
            }
            // now save the map
            m_File.WriteData(new_ignition_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_0!"));
            m_File.WriteData(new_ignition_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Ign_map_4!")); // save as warmup map as well
        }
예제 #4
0
        private void GenerateAndSaveNewFuelMap(IECUFile m_File)
        {
            TuningReferenceMaps _referenceMaps = new TuningReferenceMaps();
            byte[] pressure_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_map_xaxis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Fuel_map_xaxis!"));
            byte[] rpm_axis = m_File.ReadData((uint)m_File.GetFileInfo().GetSymbolAddressFlash("Fuel_map_yaxis!"), (uint)m_File.GetFileInfo().GetSymbolLength("Fuel_map_yaxis!"));
            byte[] new_fuel_map = new byte[16 * 16];
            int fuel_map_index = 0;
            for (int rpm_index = rpm_axis.Length - 2; rpm_index >= 0; rpm_index -= 2)
            {
                for (int pressure_index = 0; pressure_index < pressure_axis.Length; pressure_index ++)
                {

                    int irpm = Convert.ToInt32(rpm_axis[rpm_index]) * 256;
                    irpm += Convert.ToInt32(rpm_axis[rpm_index + 1]);
                    irpm *= 10;
                    int ipressure = Convert.ToInt32(pressure_axis[pressure_index]);
                    double correctionFactor = 1;
                    double pressure = ipressure;
                    MapSensorType mapsensor = m_File.GetMapSensorType(false);
                    if (mapsensor == MapSensorType.MapSensor30) correctionFactor = 1.2;
                    else if (mapsensor == MapSensorType.MapSensor35) correctionFactor = 1.4;
                    else if (mapsensor == MapSensorType.MapSensor40) correctionFactor = 1.6;
                    else if (mapsensor == MapSensorType.MapSensor50) correctionFactor = 2.0;
                    pressure *= correctionFactor;
                    pressure -= 100;
                    pressure /= 100;
                    double fuel_correction = _referenceMaps.FuelCorrectionForPressureRpm(pressure, (double)irpm);
                    // write ignition advance into the map
                    fuel_correction -= 0.5;
                    fuel_correction /= 0.00390625;

                    Int32 icorrection = Convert.ToInt32(fuel_correction);
                    if (icorrection > 255) icorrection = 255;
                    new_fuel_map[fuel_map_index++] = (byte)icorrection;
                }
            }
            // now save the map
            m_File.WriteData(new_fuel_map, (uint)m_File.GetFileInfo().GetSymbolAddressFlash("Insp_mat!"));
        }