public PerformanceResults Calculate(string filename, SymbolCollection symbols)
        {
            // do the math!
            PerformanceResults pr = new PerformanceResults();
            FillComboBoxBankSelection();

            SymbolHelper driverWishHelper = GetSymbolLike(symbols, "Driver wish", selectedBank);
            int[] pedalrequestmap = readIntdatafromfile(filename, (int)driverWishHelper.Flash_start_address, driverWishHelper.Length);
            limitermap = new int[pedalrequestmap.Length];
            int[] resulttable = new int[pedalrequestmap.Length]; // result

            rows = driverWishHelper.Y_axis_length;
            columns = driverWishHelper.X_axis_length;

            int[] pedalXAxis = readIntdatafromfile(filename, driverWishHelper.Y_axis_address, driverWishHelper.Y_axis_length * 2);
            int[] pedalYAxis = readIntdatafromfile(filename, driverWishHelper.X_axis_address, driverWishHelper.X_axis_length * 2);
            y_axisvalues = pedalYAxis;
            x_axisvalues = pedalXAxis;
            for (int colcount = 0; colcount < columns; colcount++)
            {
                for (int rowcount = 0; rowcount < rows; rowcount++)
                {
                    // get the current value from the request map
                    if (_ECUType.Contains("EDC16"))
                    {
                        int requestedTorque = (int)pedalrequestmap.GetValue((colcount * rows) + rowcount);
                        limitType limiterType = limitType.None;
                        int resultingAirMass = CalculateMaxAirmassforcell(symbols, filename, (int)pedalXAxis.GetValue(rowcount), ((int)pedalYAxis.GetValue(colcount)), requestedTorque, checkEdit1.Checked, out limiterType, true);
                        resulttable.SetValue(resultingAirMass, (colcount * rows) + rowcount);
                        limitermap.SetValue(limiterType, (colcount * rows) + rowcount);
                    }
                    else
                    {
                        int InjectedQuantity = (int)pedalrequestmap.GetValue((colcount * rows) + rowcount);
                        limitType limiterType = limitType.None;
                        int resultingAirMass = CalculateMaxAirmassforcell(symbols, filename, (int)pedalXAxis.GetValue(rowcount), ((int)pedalYAxis.GetValue(colcount)), InjectedQuantity, checkEdit1.Checked, out limiterType, false);
                        resulttable.SetValue(resultingAirMass, (colcount * rows) + rowcount);
                        limitermap.SetValue(limiterType, (colcount * rows) + rowcount);
                    }
                }
            }
            // now show resulttable
            DataTable dt = new DataTable();
            foreach (int xvalue in pedalYAxis)
            {
                dt.Columns.Add(xvalue.ToString());
            }
            // now fill the table rows
            m_MaxValueInTable = 0;
            for (int r = 0; r < pedalXAxis.Length ; r++)
            {
                object[] values = new object[columns];
                for (int t = 0; t < pedalYAxis.Length; t++)
                {
                    int currValue = (int)resulttable.GetValue( (((t + 1) * rows) - 1) - r  );
                    if (currValue > m_MaxValueInTable) m_MaxValueInTable = currValue;
                    values.SetValue(currValue, t);
                }
                dt.Rows.Add(values);
            }
            gridControl1.DataSource = dt;

            if (xtraTabControl1.SelectedTabPage.Name == xtraTabPage2.Name)
            {
                LoadGraphWithDetails();
            }
            try
            {
                for (int i = 0; i < dt.Rows[0].ItemArray.Length; i++)
                {
                    double o = Convert.ToDouble(dt.Rows[0].ItemArray.GetValue(i));
                    // convert to hp
                    int rpm = Convert.ToInt32(y_axisvalues.GetValue(i));
                    int torque = Tools.Instance.IQToTorque(Convert.ToInt32(o), rpm, m_numberCylinders);
                    if (_ECUType.Contains("EDC16"))
                    {
                        torque = Convert.ToInt32(o);
                        torque *= 10; // correction to keep the code identical from here
                        double temptorque = torque * Tools.Instance.GetCorrectionFactorForRpm(rpm, m_numberCylinders);
                        torque = Convert.ToInt32(temptorque);
                    }
                    int horsepower = Tools.Instance.TorqueToPower(torque, rpm);

                   // if (checkEdit5.Checked) horsepower = Tools.Instance.TorqueToPowerkW(torque, rpm);
                   // if (checkEdit6.Checked) torque = Tools.Instance.IQToTorque(Convert.ToInt32(o), rpm, m_numberCylinders);//AirmassToTorqueLbft(Convert.ToInt32(o), rpm);

                    horsepower /= 100;
                    torque /= 100;
                    if (torque > pr.Torque) pr.Torque = torque;
                    if (horsepower > pr.Horsepower) pr.Horsepower = horsepower;
                }
            }
            catch (Exception)
            {

            }
            return pr;
        }
Beispiel #2
0
        private void LoadFiles()
        {
            loading               = true;
            simpleButton1.Text    = "Cancel";
            simpleButton2.Enabled = false;
            SetProgressVisibility(true);
            SetScanProgress("scanning...", 0);
            Application.DoEvents();
            ctrlAirmassResult   airmassResult = new ctrlAirmassResult();
            partNumberConverter pnc           = new partNumberConverter();
            List <ScannedFile>  detectedFiles = new List <ScannedFile>();
            int fileCounter = 0;

            if (Directory.Exists(buttonEdit1.Text))
            {
                string[] files = Directory.GetFiles(buttonEdit1.Text, "*.*", SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    fileCounter++;
                    int percentage = (fileCounter * 100) / files.Length;
                    SetScanProgress("importing...", percentage);

                    if (cancelLoad)
                    {
                        cancelLoad = false;
                        break;
                    }
                    FileInfo fi = new FileInfo(file);
                    this.Text = "Library builder - " + Path.GetFileNameWithoutExtension(file);
                    Application.DoEvents();
                    if (IsValidLength(fi.Length))
                    {
                        IEDCFileParser    parser          = Tools.Instance.GetParserForFile(file, false);
                        byte[]            allBytes        = File.ReadAllBytes(file);
                        string            boschPartnumber = parser.ExtractBoschPartnumber(allBytes);
                        List <CodeBlock>  newCodeBlocks   = new List <CodeBlock>();
                        List <AxisHelper> newAxisHelpers  = new List <AxisHelper>();
                        if (boschPartnumber != string.Empty)
                        {
                            //string additionalInfo = parser.ExtractInfo(allBytes);
                            SymbolCollection sc   = parser.parseFile(file, out newCodeBlocks, out newAxisHelpers);
                            ECUInfo          info = pnc.ConvertPartnumber(boschPartnumber, allBytes.Length);

                            ScannedFile newFile = new ScannedFile();
                            newFile.CarMake      = info.CarMake;
                            newFile.CarType      = info.CarType;
                            newFile.EcuType      = info.EcuType;
                            newFile.EngineType   = info.EngineType;
                            newFile.FuellingType = info.FuellingType;
                            newFile.FuelType     = info.FuelType;
                            newFile.HP           = info.HP;
                            newFile.PartNumber   = info.PartNumber;
                            newFile.SoftwareID   = info.SoftwareID;
                            newFile.TQ           = info.TQ;

                            if (info.EcuType.Contains("EDC15P-6"))
                            {
                                newFile.Filetype = EDCFileType.EDC15P6;
                            }
                            else if (info.EcuType.Contains("EDC15P"))
                            {
                                newFile.Filetype = EDCFileType.EDC15P;
                            }
                            else if (info.EcuType.Contains("EDC15M"))
                            {
                                newFile.Filetype = EDCFileType.EDC15M;
                            }
                            else if (info.EcuType.Contains("EDC15V-5."))
                            {
                                newFile.Filetype = EDCFileType.MSA15;
                            }
                            else if (info.EcuType.Contains("EDC15V"))
                            {
                                newFile.Filetype = EDCFileType.EDC15V;
                            }
                            else if (info.EcuType.Contains("EDC15C"))
                            {
                                newFile.Filetype = EDCFileType.EDC15C;
                            }
                            else if (info.EcuType.Contains("EDC16"))
                            {
                                newFile.Filetype = EDCFileType.EDC16;
                            }
                            else if (info.EcuType.Contains("EDC17"))
                            {
                                newFile.Filetype = EDCFileType.EDC17;
                            }
                            else if (info.EcuType.Contains("MSA15"))
                            {
                                newFile.Filetype = EDCFileType.MSA15;
                            }
                            else if (info.EcuType.Contains("MSA12"))
                            {
                                newFile.Filetype = EDCFileType.MSA12;
                            }
                            else if (info.EcuType.Contains("MSA11"))
                            {
                                newFile.Filetype = EDCFileType.MSA11;
                            }
                            else if (info.EcuType.Contains("MSA6"))
                            {
                                newFile.Filetype = EDCFileType.MSA6;
                            }

                            else if (boschPartnumber != string.Empty)
                            {
                                if (fi.Length == 1024 * 1024 * 2)
                                {
                                    newFile.Filetype = EDCFileType.EDC17;
                                }
                                else if (boschPartnumber.StartsWith("EDC17"))
                                {
                                    newFile.Filetype = EDCFileType.EDC17;
                                }
                                else
                                {
                                    newFile.Filetype = EDCFileType.EDC15V;
                                }
                            }
                            else
                            {
                                newFile.Filetype = EDCFileType.EDC16; // default to EDC16???
                            }
                            newFile.Filename = file;
                            newFile.Filesize = (int)fi.Length;

                            ChecksumResultDetails crd = Tools.Instance.UpdateChecksum(file, true);

                            string chkType = string.Empty;
                            if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41)
                            {
                                chkType = "VAG EDC15P V4.1";
                            }
                            else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41V2)
                            {
                                chkType = "VAG EDC15P V4.1v2";
                            }
                            else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41_2002)
                            {
                                chkType = "VAG EDC15P V4.1 2002+";
                            }
                            newFile.ChecksumType        = chkType;
                            newFile.ChecksumResult      = crd.CalculationResult.ToString();
                            newFile.NumberChecksums     = crd.NumberChecksumsTotal;
                            newFile.NumberChecksumsFail = crd.NumberChecksumsFail;
                            newFile.NumberChecksumsOk   = crd.NumberChecksumsOk;

                            newFile.NumberMapsDetected = sc.Count;
                            string _message = string.Empty;
                            newFile.MapsOk   = CheckMajorMapsPresent(sc, newFile.Filetype, out _message);
                            newFile.Messages = _message;
                            foreach (SymbolHelper sh in sc)
                            {
                                if (!sh.Varname.StartsWith("3D") && !sh.Varname.StartsWith("2D"))
                                {
                                    newFile.NumberMapsRecognized++;
                                }
                            }

                            try
                            {
                                airmassResult.Currentfile      = file;
                                airmassResult.Symbols          = sc;
                                airmassResult.Currentfile_size = (int)fi.Length;
                                string additionalInfo = parser.ExtractInfo(allBytes);
                                airmassResult.NumberCylinders = pnc.GetNumberOfCylinders(info.EngineType, additionalInfo);
                                airmassResult.ECUType         = info.EcuType;
                                PerformanceResults pr = airmassResult.Calculate(file, sc);
                                newFile.RealHP = pr.Horsepower;
                                newFile.RealTQ = pr.Torque;
                            }
                            catch (Exception)
                            {
                            }

                            detectedFiles.Add(newFile);
                        }
                        else if (file.ToUpper().EndsWith(".BIN") || file.ToUpper().EndsWith(".ORI"))
                        {
                            Console.WriteLine("Missed " + file);
                            // add it as well
                            if (checkEdit1.Checked)
                            {
                                ScannedFile newFile = new ScannedFile();
                                newFile.CarMake              = "";
                                newFile.CarType              = "";
                                newFile.EcuType              = "Unknown";
                                newFile.EngineType           = "";
                                newFile.FuellingType         = "";
                                newFile.FuelType             = "";
                                newFile.HP                   = 0;
                                newFile.PartNumber           = "";
                                newFile.SoftwareID           = "";
                                newFile.TQ                   = 0;
                                newFile.Filetype             = EDCFileType.Unknown;
                                newFile.Filename             = file;
                                newFile.Filesize             = (int)fi.Length;
                                newFile.ChecksumType         = "";
                                newFile.ChecksumResult       = "";
                                newFile.NumberChecksums      = 0;
                                newFile.NumberChecksumsFail  = 0;
                                newFile.NumberChecksumsOk    = 0;
                                newFile.NumberMapsDetected   = 0;
                                newFile.MapsOk               = false;
                                newFile.Messages             = "";
                                newFile.NumberMapsRecognized = 0;
                                detectedFiles.Add(newFile);
                            }
                        }
                    }
                }
                gridControl1.DataSource = detectedFiles;
            }
            loading = false;
            SetScanProgress("done", 100);
            SetProgressVisibility(false);
            this.Text             = "Library builder";
            simpleButton1.Text    = "Close";
            simpleButton2.Enabled = true;
            Application.DoEvents();
        }