Beispiel #1
0
        private void StartOnlineMode()
        {
            if (!_ecuConnection.Opened)
            {
                StartECUConnection();
            }
            /*if (Environment.MachineName == "PC-GUIDO" && _ecuConnection.Opened)
            {
                _ecuConnection.SetMemorySyncDate(DateTime.Now);
            }*/
            if (_ecuConnection.Opened && _APPmode == OperationMode.ModeOffline)
            {
                ctrlRealtime1.AppSettings = m_appSettings;
                ctrlRealtime1.WideBandAFRSymbol = m_appSettings.WidebandLambdaSymbol;
                ctrlRealtime1.AcceptableTargetErrorPercentage = m_appSettings.AcceptableTargetErrorPercentage;
                ctrlRealtime1.AreaCorrectionPercentage = m_appSettings.AreaCorrectionPercentage;
                ctrlRealtime1.AutoUpdateFuelMap = m_appSettings.AutoUpdateFuelMap;
                ctrlRealtime1.CellStableTime_ms = m_appSettings.CellStableTime_ms;
                ctrlRealtime1.CorrectionPercentage = m_appSettings.CorrectionPercentage;
                ctrlRealtime1.DiscardClosedThrottleMeasurements = m_appSettings.DiscardClosedThrottleMeasurements;
                ctrlRealtime1.DiscardFuelcutMeasurements = m_appSettings.DiscardFuelcutMeasurements;
                ctrlRealtime1.EnrichmentFilter = m_appSettings.EnrichmentFilter;
                ctrlRealtime1.FuelCutDecayTime_ms = m_appSettings.FuelCutDecayTime_ms;
                ctrlRealtime1.MaximumAdjustmentPerCyclePercentage = m_appSettings.MaximumAdjustmentPerCyclePercentage;
                ctrlRealtime1.MaximumAFRDeviance = m_appSettings.MaximumAFRDeviance;
                ctrlRealtime1.MinimumAFRMeasurements = m_appSettings.MinimumAFRMeasurements;
                ctrlRealtime1.AutoLoggingEnabled = m_appSettings.AutoLoggingEnabled;
                ctrlRealtime1.AutoLogStartSign = m_appSettings.AutoLogStartSign;
                ctrlRealtime1.AutoLogStartValue = m_appSettings.AutoLogStartValue;
                ctrlRealtime1.AutoLogStopSign = m_appSettings.AutoLogStopSign;
                ctrlRealtime1.AutoLogStopValue = m_appSettings.AutoLogStopValue;
                ctrlRealtime1.AutoLogTriggerStartSymbol = m_appSettings.AutoLogTriggerStartSymbol;
                ctrlRealtime1.AutoLogTriggerStopSymbol = m_appSettings.AutoLogTriggerStopSymbol;

                ctrlRealtime1.MapSensor = m_trionicFile.GetMapSensorType(m_appSettings.AutoDetectMapsensorType);
                ctrlRealtime1.Fuelxaxis = m_trionicFile.GetMapXaxisValues(m_trionicFileInformation.GetInjectionMap());
                ctrlRealtime1.Fuelyaxis = m_trionicFile.GetMapYaxisValues(m_trionicFileInformation.GetInjectionMap());
                ctrlRealtime1.Ignitionxaxis = m_trionicFile.GetMapXaxisValues(m_trionicFileInformation.GetIgnitionMap());
                ctrlRealtime1.Ignitionyaxis = m_trionicFile.GetMapYaxisValues(m_trionicFileInformation.GetIgnitionMap());
                _APPmode = OperationMode.ModeOnline; // we're in online mode
                UpdateOnlineOffLineTexts();
                SetOnlineButtons(true);
                // start a new panel that fills everything with tabs like the dashboard which enables users to
                // monitor, edit and save data and logs (sessions) until they decide to go offline again
                dockSymbols.Visibility = DockVisibility.AutoHide;
                dockSymbols.HideImmediately();

                // never show symbollist in online mode?
                // also minimize the menu in this mode
                ribbonControl1.Minimized = true;
                //TODO: <GS-06042010> set realtime panel floating if screen resolution is very high to make
                // the gauge more readable
                /*if (IsHighResolutionScreen())
                {
                    // make the panel floating!
                }*/
                ctrlRealtime1.EnableAdvancedMode = m_appSettings.EnableAdvancedMode;
                dockRealtime.Visibility = DockVisibility.Visible;

                ctrlRealtime1.UpdateProgramModeButtons(_ecuConnection.ReadSymbolData("Pgm_mod!", (uint)m_trionicFileInformation.GetSymbolAddressSRAM("Pgm_mod!"), (uint)m_trionicFileInformation.GetSymbolLength("Pgm_mod!")));
                dockRealtime.Width = dockManager1.Form.ClientSize.Width - 20; //?
                // and set correct tabpage

                FillRealtimePool(RealtimeMonitoringType.Fuel, true);
                Thread.Sleep(100);
                DateTime dt_ecu = _ecuConnection.GetMemorySyncDate();
                Thread.Sleep(100);
                DateTime dt_file = m_trionicFile.GetMemorySyncDate();
                DateTime now = DateTime.Now;
                if (dt_ecu.Year == 2000 && dt_ecu.Month == 1 && dt_ecu.Day == 1 && dt_ecu.Hour == 0 && dt_ecu.Minute == 0 && dt_ecu.Second == 0)
                {
                    dt_ecu = now;
                    _ecuConnection.SetMemorySyncDate(dt_ecu);
                }
                if (dt_file.Year == 2000 && dt_file.Month == 1 && dt_file.Day == 1 && dt_file.Hour == 0 && dt_file.Minute == 0 && dt_file.Second == 0)
                {
                    dt_file = now;
                    //_ecuConnection.SetMemorySyncDate(dt_ecu);
                    m_trionicFile.SetMemorySyncDate(dt_file);
                }
                if (!_syncAskedForECUConnect)
                {
                    if (dt_ecu > dt_file)
                    {
                        Console.WriteLine("Sync when start online mode: ECU to bin");
                        frmSyncFileECU syncdlg = new frmSyncFileECU();
                        syncdlg.SetTimeStamps(dt_file, dt_ecu);
                        syncdlg.SetInformation("Proposed sync: ECU to binary");
                        DialogResult dr = syncdlg.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            // sync ecu to file without changing sync dates
                            SyncMaps(SyncOption.ToFile);
                            m_trionicFile.SetMemorySyncDate(dt_ecu);
                        }
                        else if (dr == DialogResult.Retry)
                        {
                            SyncMaps(SyncOption.ToECU);
                            _ecuConnection.SetMemorySyncDate(dt_file);
                        }
                    }
                    else if (dt_file > dt_ecu)
                    {
                        Console.WriteLine("Sync when start online mode: bin to ECU");
                        frmSyncFileECU syncdlg = new frmSyncFileECU();
                        syncdlg.SetTimeStamps(dt_file, dt_ecu);
                        syncdlg.SetInformation("Proposed sync: binary to ECU");
                        DialogResult dr = syncdlg.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            // sync file to ecu without changing sync dates
                            SyncMaps(SyncOption.ToECU);
                            _ecuConnection.SetMemorySyncDate(dt_file);
                        }
                        else if (dr == DialogResult.Retry)
                        {
                            SyncMaps(SyncOption.ToFile);
                            m_trionicFile.SetMemorySyncDate(dt_ecu);
                        }
                    }
                }
                _syncAskedForECUConnect = false;

                // realtime always starts in fuel mode
                _ecuConnection.StartECUMonitoring();
            }
            else if (_ecuConnection.Opened && _APPmode == OperationMode.ModeOnline)
            {
                // dan?
                StopOnlineMode();
                _APPmode = OperationMode.ModeOffline;
                barStaticItem5.Caption = "Mode: online";
                btnSwitchMode.Caption = "Go offline";
                UpdateOnlineOffLineTexts();
                SetOnlineButtons(true);
            }
            else if(!_ecuConnection.Opened)
            {
                btnSwitchMode.Caption = "Go online";
                barStaticItem5.Caption = "Mode: offline";
                _APPmode = OperationMode.ModeOffline;
                _ECUmode = OperationMode.ModeOffline;
                SetOnlineButtons(false);
                UpdateOnlineOffLineTexts();
                Application.DoEvents();
                frmInfoBox info = new frmInfoBox("Failed to open canbus connection!");
            }
        }
Beispiel #2
0
        private bool StartECUConnection()
        {
            bool retval = false;
            // user wants to connect to an ECU
            // while connected, disable this button
            //_ecuConnection = new ECUConnection();

            /*if (m_appSettings.DebugMode && Environment.MachineName == "PC-GUIDO") //<GS-29032010>
            {
                // set from binary sram dump in stead of live data
                _ecuConnection.SramDumpFile = Application.StartupPath + "\\workbin.RAM";
                Console.WriteLine("Loaded working.RAM");
            }*/
            btnSwitchMode.Caption = "Connecting...";
            Application.DoEvents();
            if (m_appSettings.CanDevice == "Lawicel")
            {
                CheckCanwakeup();
            }
            _ecuConnection.AppSettings = m_appSettings;
            _ecuConnection.OpenECUConnection();
            if (_ecuConnection.Opened)
            {
                if (m_trionicFileInformation != null)
                {
                    if (m_trionicFileInformation.Filelength == 0x20000)
                    {
                        _ecuConnection.IsT52 = true;
                    }
                    else
                    {
                        _ecuConnection.IsT52 = false;
                    }
                }

                retval = true;
                _ECUmode = OperationMode.ModeOnline;
                SetOnlineButtons(true);

                string swversion = _ecuConnection.GetSoftwareVersion();
                btnSwitchMode.Caption = "Connected: " + swversion;
                Application.DoEvents();
                Console.WriteLine("SW version: " + swversion);
                if (swversion == "")
                {
                    // special case, no ECU connected
                    retval = false;
                    btnSwitchMode.Caption = "Not connected";
                    _ecuConnection.CloseECUConnection(true);
                    _ECUmode = OperationMode.ModeOffline;
                    _APPmode = OperationMode.ModeOffline;
                    SetOnlineButtons(false);
                    Application.DoEvents();
                    return retval;
                }
                if (m_trionicFile != null)
                {
                    if (m_trionicFile.GetSoftwareVersion() != swversion)
                    {
                        SetStatusText("Getting symboltable...");
                        DataTable _symboltable = _ecuConnection.GetSymbolTable();
                        //_symboltable.WriteXml(Application.StartupPath + "\\" + _ecuConnection.Swversion + ".xml");

                        FillRealtimePool(RealtimeMonitoringType.Fuel, true);
                        _ecuConnection.StopECUMonitoring();
                        Thread.Sleep(50);
                        FillRealtimePool(RealtimeMonitoringType.Fuel, true);

                        _ecuConnection.StartECUMonitoring();// start monitoring, it's for free!
                        SetStatusText("Monitoring...");

                    }
                }
                else
                {
                    SetStatusText("Getting symboltable...");
                    DataTable _symboltable = _ecuConnection.GetSymbolTable();
                    //_symboltable.WriteXml(Application.StartupPath + "\\" + _ecuConnection.Swversion + ".xml");
                    FillRealtimePool(RealtimeMonitoringType.Fuel, true);
                    _ecuConnection.StopECUMonitoring();
                    Thread.Sleep(50);
                    SetStatusText("Idle");
                }
                barStaticItem1.Caption = " ECU: " + swversion;
                barStaticItem1.Enabled = true;
                // clear default filters to allow access to sram symbols as well.
                gridViewSymbols.ActiveFilterEnabled = false;
                // check for counter values
                Thread.Sleep(100);
                DateTime dt_ecu = _ecuConnection.GetMemorySyncDate();
                Thread.Sleep(100);
                DateTime dt_file = m_trionicFile.GetMemorySyncDate();
                DateTime now = DateTime.Now;
                if (dt_ecu.Year == 2000 && dt_ecu.Month == 1 && dt_ecu.Day == 1 && dt_ecu.Hour == 0 && dt_ecu.Minute == 0 && dt_ecu.Second == 0)
                {
                    dt_ecu = now;
                    _ecuConnection.SetMemorySyncDate(dt_ecu);
                }
                if (dt_file.Year == 2000 && dt_file.Month == 1 && dt_file.Day == 1 && dt_file.Hour == 0 && dt_file.Minute == 0 && dt_file.Second == 0)
                {
                    dt_file = now;
                    //_ecuConnection.SetMemorySyncDate(dt_ecu);
                    m_trionicFile.SetMemorySyncDate(dt_file);
                }
                if (dt_ecu > dt_file)
                {
                    Console.WriteLine("Sync when start ECU connection: ECU to bin");
                    frmSyncFileECU syncdlg = new frmSyncFileECU();
                    syncdlg.SetTimeStamps(dt_file, dt_ecu);
                    syncdlg.SetInformation("Proposed sync: ECU to binary");
                    DialogResult dr = syncdlg.ShowDialog();
                    _syncAskedForECUConnect = true;

                    if (dr == DialogResult.OK)
                    {
                        // sync ecu to file without changing sync dates
                        SyncMaps(SyncOption.ToFile);
                        m_trionicFile.SetMemorySyncDate(dt_ecu);
                    }
                    else if (dr == DialogResult.Retry)
                    {
                        SyncMaps(SyncOption.ToECU);
                        _ecuConnection.SetMemorySyncDate(dt_file);
                    }
                }
                else if (dt_file > dt_ecu)
                {
                    Console.WriteLine("Sync when start ECU connection: bin to ECU");
                    frmSyncFileECU syncdlg = new frmSyncFileECU();
                    syncdlg.SetTimeStamps(dt_file, dt_ecu);
                    syncdlg.SetInformation("Proposed sync: binary to ECU");
                    DialogResult dr = syncdlg.ShowDialog();
                    _syncAskedForECUConnect = true;
                    if (dr == DialogResult.OK)
                    {
                        // sync file to ecu without changing sync dates
                        SyncMaps(SyncOption.ToECU);
                        _ecuConnection.SetMemorySyncDate(dt_file);
                    }
                    else if (dr == DialogResult.Retry)
                    {
                        SyncMaps(SyncOption.ToFile);
                        m_trionicFile.SetMemorySyncDate(dt_ecu);
                    }
                }
            }
            return retval;
        }