This repository was archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRosbridgeHandler.java
More file actions
72 lines (59 loc) · 1.8 KB
/
RosbridgeHandler.java
File metadata and controls
72 lines (59 loc) · 1.8 KB
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
package com.roboeaters.grantbot;
// tweak to suit rosbridge
import android.util.Log;
import de.tavendo.autobahn.WebSocketConnectionHandler;
public class RosbridgeHandler extends WebSocketConnectionHandler {
ROSBridge ros_thread;
final static String TAG = "ROSBridgeHandler";
public RosbridgeHandler(ROSBridge r_t) {
ros_thread = r_t;
}
/**
* Fired when the WebSockets connection has been established.
* After this happened, messages may be sent.
*/
public void onOpen() {
Log.d(TAG, "Status: Connected to ws://" + ros_thread.hostName + ":" + ros_thread.portNumber);
ros_thread.canMessage = true;
}
/**
* Fired when the WebSockets connection has deceased (or could
* not established in the first place).
*
* @param code Close code.
* @param reason Close reason (human-readable).
*/
public void onClose(int code, String reason) {
Log.d(TAG, "Connection lost.");
ros_thread.canMessage = false;
}
/**
* Fired when a text message has been received (and text
* messages are not set to be received raw).
*
* @param payload Text message payload or null (empty payload).
*/
public void onTextMessage(String payload) {
// receives JSONs in string form from ROS
Log.d(TAG, "onTextMessage: " + payload);
}
/**
* Fired when a text message has been received (and text
* messages are set to be received raw).
*
* @param payload Text message payload as raw UTF-8 or null (empty payload).
*/
public void onRawTextMessage(byte[] payload) {
// unused
Log.d(TAG, "onRawTextMessage: " + payload.toString());
}
/**
* Fired when a binary message has been received.
*
* @param payload Binar message payload or null (empty payload).
*/
public void onBinaryMessage(byte[] payload) {
// unused
Log.d(TAG, "onBinaryMessage: " + payload.toString());
}
}