示例#1
0
        public JLinkSettingsFormViewModel(IProject model) : base(model)
        {
            settings = model.GetDebuggerSettings <JLinkSettings>();

            interfaceSelectedIndex = (int)settings.Interface;
            interfaceType          = settings.Interface;
            _download          = settings.Download;
            _reset             = settings.Reset;
            _useRemote         = settings.UseRemote;
            _ipAddress         = settings.RemoteIPAddress;
            _postDownloadReset = settings.PostDownloadReset;
            _run             = settings.Run;
            _selectedVersion = settings.Version;

            speedSelectedIndex = SpeedOptions.IndexOf(settings.SpeedkHz.ToString());

            speed = settings.SpeedkHz.ToString();

            string devPath = Path.Combine(JLinkDebugger.GetBaseDirectory(settings.Version), "devices.csv");

            deviceList = new ObservableCollection <JLinkTargetDeviceViewModel>();

            LoadDeviceList(devPath);
        }
示例#2
0
        protected override void OnRun(DebuggerStartInfo startInfo)
        {
            var result   = true;
            var settings = _project.GetDebuggerSettings <JLinkSettings>();

            console.Clear();
            console.WriteLine("[JLink] - Starting GDB Server...");

            string processName = "JLinkGDBServer";

            if (Platform.PlatformIdentifier != Platforms.PlatformID.Unix)
            {
                processName += "CL";
            }

            var jlinkStartInfo = new ProcessStartInfo();

            if (settings.UseRemote)
            {
                jlinkStartInfo.Arguments = string.Format($"-select IP={settings.RemoteIPAddress} -device {settings.TargetDevice} -if {Enum.GetName(typeof(JlinkInterfaceType), settings.Interface)} -speed {settings.SpeedkHz}");
            }
            else
            {
                jlinkStartInfo.Arguments = string.Format($"-select USB -device {settings.TargetDevice} -if {Enum.GetName(typeof(JlinkInterfaceType), settings.Interface)} -speed {settings.SpeedkHz}");
            }

            jlinkStartInfo.FileName = Path.Combine(JLinkDebugger.GetBaseDirectory(_project), processName + Platform.ExecutableExtension);

            if (Path.IsPathRooted(jlinkStartInfo.FileName) && !System.IO.File.Exists(jlinkStartInfo.FileName))
            {
                console.WriteLine("[JLink] - Error unable to find executable.");
                return;
            }

            // Hide console window
            jlinkStartInfo.RedirectStandardOutput = true;
            jlinkStartInfo.RedirectStandardError  = true;
            jlinkStartInfo.UseShellExecute        = false;
            jlinkStartInfo.CreateNoWindow         = true;

            var processes = Process.GetProcessesByName(processName);

            foreach (var process in processes)
            {
                process.Kill();
            }

            if (!Path.IsPathRooted(jlinkStartInfo.FileName) || File.Exists(jlinkStartInfo.FileName))
            {
                Task.Run(() =>
                {
                    using (var process = Process.Start(jlinkStartInfo))
                    {
                        jlinkProcess = process;

                        process.OutputDataReceived += (sender, e) =>
                        {
                            if (DebugMode && !string.IsNullOrEmpty(e.Data))
                            {
                                console.WriteLine("[JLink] - " + e.Data);
                            }
                        };

                        process.ErrorDataReceived += (sender, e) =>
                        {
                            if (!string.IsNullOrEmpty(e.Data))
                            {
                                console.WriteLine("[JLink] - " + e.Data);
                            }
                        };

                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();

                        process.WaitForExit();

                        Dispose();

                        console.WriteLine("[JLink] - GDB Server Closed.");

                        jlinkProcess = null;

                        result = false;

                        base.OnExit();
                    }
                });

                while (jlinkProcess == null)
                {
                    Thread.Sleep(10);
                }

                TargetExited += (sender, e) =>
                {
                    jlinkProcess?.Kill();
                    jlinkProcess = null;
                };

                if (result)
                {
                    base.OnRun(startInfo);
                    console.WriteLine("[JLink] - Connecting...");
                }
            }
            else
            {
                console.WriteLine("[JLink] - Unable to start GDBServer.");
                base.OnExit();
            }
        }