forked from michaeljenkin/unityros
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathROSBridgeMsg.cs
77 lines (62 loc) · 2.58 KB
/
ROSBridgeMsg.cs
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
using System.Collections;
using System.Text;
using SimpleJSON;
/**
* This (mostly empty) class is the parent class for all RosBridgeMsg's (the actual message) from
* ROS. As the message can be empty....
* <p>
* This could be omitted I suppose, but it is retained here as (i) it nicely parallels the
* ROSBRidgePacket class which encapsulates the top of the ROSBridge messages which are not
* empty, and (ii) someday ROS may actually define a minimal message.
*
* Version History
* 3.1 - changed methods to start with an upper case letter to be more consistent with c#
* style.
* 3.0 - modification from hand crafted version 2.0
*
* @author Michael Jenkin, Robert Codd-Downey and Andrew Speers
* @version 3.1
*/
public class ROSBridgeMsg {
public ROSBridgeMsg() {}
public virtual string ToYAMLString() {
StringBuilder x = new StringBuilder();
x.Append("{");
x.Append("}");
return x.ToString();
}
public static string Advertise(string messageTopic, string messageType) {
return "{\"op\": \"advertise\", \"topic\": \"" + messageTopic + "\", \"type\": \"" + messageType + "\"}";
}
public static string UnAdvertise(string messageTopic) {
return "{\"op\": \"unadvertise\", \"topic\": \"" + messageTopic + "\"}";
}
public static string Publish(string messageTopic, string message) {
return "{\"op\": \"publish\", \"topic\": \"" + messageTopic + "\", \"msg\": " + message + "}";
}
public static string Subscribe(string messageTopic) {
return "{\"op\": \"subscribe\", \"topic\": \"" + messageTopic + "\"}";
}
public static string Subscribe(string messageTopic, string messageType) {
return "{\"op\": \"subscribe\", \"topic\": \"" + messageTopic + "\", \"type\": \"" + messageType + "\"}";
}
public static string UnSubscribe(string messageTopic) {
return "{\"op\": \"unsubscribe\", \"topic\": \"" + messageTopic + "\"}";
}
public static string CallService(string service, string id, string args)
{
if ((id == null) || id.Equals(""))
return CallService(service, args);
else
return "{\"op\": \"call_service\", \"service\": \"" + service + "\", \"id\": \"" + id + "\", \"args\" : " + args + "}";
}
public static string CallService(string service, string args) {
if ((args == null) || args.Equals(""))
return CallService(service);
else
return "{\"op\": \"call_service\", \"service\": \"" + service + "\", \"args\" : " + args + "}";
}
public static string CallService(string service) {
return "{\"op\": \"call_service\", \"service\": \"" + service + "\"}";
}
}