-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathopenocd.cpp
47 lines (42 loc) · 1.62 KB
/
openocd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "openocd.h"
OpenOCD::OpenOCD(QObject *parent) : QObject(parent)
{
process=new QProcess();
connect(process,&QProcess::readyReadStandardError,[=]{
QString error=process->readAllStandardError();
if(error.contains("Error:"))//错误信息中含有Error项,则发送信号
{
emit onErrorOccur(error);
}
});
}
OpenOCD::~OpenOCD()
{
delete process;
}
//启动OCD进程并设定调试器类型、芯片类型、gdb端口号
void OpenOCD::start(const QString &chosenInterface,const QString &chosenTarget,const QString &extraParam,int gdbPort)
{
process->setWorkingDirectory(QCoreApplication::applicationDirPath()+"/openocd/bin");//设置工作路径
process->setProgram(QCoreApplication::applicationDirPath()+"/openocd/bin/openocd.exe");//设置程序路径
process->setNativeArguments(
QString("-f interface/%1 -f target/%2 -c \"gdb_port %3\" -c \"tcl_port disabled;telnet_port disabled;%4\"")
.arg(chosenInterface).arg(chosenTarget).arg(gdbPort).arg(extraParam));//设置参数为所选的调试器、目标芯片和gdb端口
process->start();
}
//结束OCD进程
void OpenOCD::stop()
{
if(process->state()==QProcess::NotRunning)
return;
QProcess killProcess(0);//创建新进程,用taskkill强行结束ocd进程
killProcess.setProgram("taskkill");
killProcess.setNativeArguments(QString("/F /PID %1").arg(process->pid()->dwProcessId));
killProcess.start();
killProcess.waitForFinished();
}
//返回当前OCD进程是否正在运行
bool OpenOCD::isRunning()
{
return process->state()==QProcess::Running;
}