-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrostopic.cpp
115 lines (103 loc) · 2.36 KB
/
rostopic.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* @Author: Tfly6 2085488186@qq.com
* @Date: 2023-07-22 21:50:11
* @LastEditors: Tfly6 2085488186@qq.com
* @LastEditTime: 2023-07-23 21:27:32
* @Description: rostopic 命令
*/
#include "rostopic.h"
#include <QDebug>
Rostopic::Rostopic(QObject *parent) : MyCommand(parent)
{
modeFlag = MODENULL;
echoFlag = false;
connect(process,&QProcess::readyReadStandardOutput,this,&Rostopic::onReOut);
}
void Rostopic::onReOut()
{
QString line = process->readAll(); // 读取命令输出的内容
if(line.isEmpty())
{
qDebug() <<"error: " ;
}
QStringList con = line.split("\n",QString::SkipEmptyParts);
if(modeFlag == MODELIST)
{
content = con;
emit readOut(modeFlag,content);
}
if(modeFlag == MODEINFO)
{
content = con;
emit readOut(modeFlag,content);
}
if(modeFlag == MODEECHO)
{
content << con;
emit readOut(modeFlag,content);
}
if(modeFlag == MODEPUB)
{
content << con;
emit readOut(modeFlag,content);
}
if(modeFlag == MODEKILLCMD)
{
//qDebug() << "kill";
doKill(con);
}
}
void Rostopic::list()
{
writeCmd("rostopic list\n");
modeFlag = MODELIST;
//qDebug()<<"rostopic list";
}
void Rostopic::info(QString topic)
{
writeCmd("rostopic info "+topic+"\n");
modeFlag = MODEINFO;
//qDebug()<<"rostopic info";
}
void Rostopic::echo(QString topic,QString arg)
{
writeCmd("rostopic echo "+arg+topic+"\n");
modeFlag = MODEECHO;
echoFlag = true;
//qDebug()<<"rostopic echo";
}
void Rostopic::pub(QString topic ,QString type ,QString con ,QString arg)
{
if(type.isEmpty())
{
type = "std_msgs/String";
}
if(con.isEmpty())
{
con = "hello";
}
if(arg.isEmpty())
{
arg = "-1";
}
content = QStringList()<<"pub data: "+con;
// qDebug()<<topic;
// qDebug()<<type;
// qDebug()<<arg;
// qDebug()<<con;
// 判断con 是否为数字
if(con.contains(QRegExp("[+-]?(0|([1-9]\\d*))(\\.\\d+)?")))
{
con = "\"'"+con+"'\"";
}
writeCmd("rostopic pub "+arg+" "+topic+" "+type+" "+con+"\n");
modeFlag = MODEPUB;
//qDebug()<<"rostopic pub";
}
void Rostopic::killEcho()
{
killCmd("rostopic echo");
modeFlag = MODEKILLCMD;
echoFlag = false;
//qDebug()<<"kill rostopic echo";
}