Ejemplo n.º 1
0
        // Here is where mode actions are taken.
        public void UpdateMode(byte mode, byte id)
        {
            if (Application.Current.Dispatcher.CheckAccess())
            {
                if (Controller != null && !IsClosing && mode < (byte)RecorderModeKinds.RecorderModeNum)
                {
                    RecorderMode = (RecorderModeKinds)mode;
                    if (LastRecorderMode == RecorderMode)
                    {
                        if ((RecorderMode != RecorderModeKinds.RecorderModeLocalOnly) &&
                            (RecorderMode != RecorderModeKinds.RecorderModeIdle) &&
                            (RecorderMode != RecorderModeKinds.RecorderModeIdleStopped)
                            )
                        {
                            return;
                        }
                        if (id == LastSystemModeId)
                        {
                            return;
                        }
                    }
                    LastSystemModeId = id;
                    lock (Controller.SchedulerLock) {
                        Controller.PlayIsSignalled   = false;
                        Controller.RecordIsSignalled = false;
                        switch (RecorderMode)
                        {
                        case RecorderModeKinds.RecorderModeLocalOnly:
                        case RecorderModeKinds.RecorderModeIdle:
                            // Switch chart back to normal mode.
                            // Reset chart cache.
                            RecorderScope.ResetCache();
                            RecorderScope.ResetSeries();
                            Controller.ResetTriggers();
                            // Reset timeline?
                            break;

                        case RecorderModeKinds.RecorderModePlayStandby:
                            // Copy pvt cache to chart cache setting actual pos to zero.
                            // Show static chart of current pvtCache.
                            Controller.CurrentPlayPVTCacheIndex = 0;
                            Controller.LastChartCacheIndex      = 0;
                            Controller.LastChartCacheTime       = 0.0;
                            Controller.LastStoppedTime          = 0.0;
                            RecorderScope.ResetCache();
                            RecorderScope.ResetSeries();
                            RecorderScope.ChartCache.DeepCopy(Controller.PVTCache);
                            RecorderScope.ChartCache.ZeroElements(1, AxesController.FIELDS_PER_AXIS);     // time,actual,target.
                            RecorderScope.ChartCache.RefreshMinMax();
                            RecorderScope.RenewChart();
                            Controller.ResetTriggers();
                            break;

                        case RecorderModeKinds.RecorderModePlaying:
                            // Start playback.
                            // TODO: unless resuming from a pause.
                            Controller.PlayIsSignalled = true;
                            break;

                        case RecorderModeKinds.RecorderModeRecordStandby:
                            // Reset chart cache & pvt cache?
                            // Reset timeline?
                            Controller.CurrentRecordStartTime = 0.0;
                            RecorderScope.ResetCache();
                            RecorderScope.ResetSeries();
                            Controller.PVTCache.Reset();
                            Controller.ResetTriggers();
                            break;

                        case RecorderModeKinds.RecorderModeRecording:
                            Controller.RecordIsSignalled = true;
                            // Make sure iso sending is active.
                            Controller.CheckMonitoringActive(true);
                            break;

                        case RecorderModeKinds.RecorderModeIdleStopped:
                            break;

                        case RecorderModeKinds.RecorderModePlayStopped:
                            // Rewind CurrentPlayPVTCacheIndex to LastStoppedTime.
                            Controller.RewindCurrentPlayPVTCacheIndex();
                            break;

                        case RecorderModeKinds.RecorderModeRecordStopped:
                            Controller.CurrentRecordStartTime = Controller.LastStoppedTime;
                            break;
                        }
                    }
                    LastRecorderMode          = RecorderMode;
                    RecorderStatus.Text       = RecorderModeMessages[(int)mode];
                    RecorderStatus.Background = RecorderModeBrushes[(int)mode];
                }
            }
            else
            {
                Application.Current.Dispatcher.Invoke((Action)(() => { UpdateMode(mode, id); }));
            }
        }