public class Ros extends Object
Topic, are used.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_HOSTNAME
The default hostname used if none is provided.
|
static int |
DEFAULT_PORT
The default port used if none is provided.
|
| Constructor and Description |
|---|
Ros()
Create a connection to ROS with the default hostname and port.
|
Ros(String hostname)
Create a connection to ROS with the given hostname and default port.
|
Ros(String hostname,
int port)
Create a connection to ROS with the given hostname and port.
|
Ros(String hostname,
int port,
JRosbridge.WebSocketType protocol)
Create a connection to ROS with the given hostname and port.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRosHandler(RosHandler handler)
Add a handler to this connection.
|
void |
authenticate(String mac,
String client,
String dest,
String rand,
int t,
String level,
int end)
Sends an authorization request to the server.
|
boolean |
connect()
Attempt to establish a connection to rosbridge.
|
void |
deregisterCallServiceCallback(String serviceName)
Deregister a callback for a given incoming service request.
|
void |
deregisterTopicCallback(String topic,
TopicCallback cb)
Deregister a callback for a given topic.
|
boolean |
disconnect()
Disconnect the connection to rosbridge.
|
String |
getHostname()
Get the hostname associated with this connection.
|
int |
getPort()
Get the port associated with this connection.
|
JRosbridge.WebSocketType |
getProtocol()
Get the type of WebSocket protocol being used.
|
String |
getURL()
Get the full URL this client is connecting to.
|
boolean |
isConnected()
Check if there is a connection to rosbridge.
|
long |
nextId()
Get the next unique ID number for this connection.
|
void |
onClose(javax.websocket.Session session)
This function is called once a successful disconnection is made.
|
void |
onError(javax.websocket.Session session,
Throwable t)
This function is called if an error occurs.
|
void |
onMessage(String message)
This method is called once an entire message has been read in by the
connection from rosbridge.
|
void |
onOpen(javax.websocket.Session session)
This function is called once a successful connection is made.
|
void |
registerCallServiceCallback(String serviceName,
CallServiceCallback cb)
Register a callback for a given incoming service request.
|
void |
registerServiceCallback(String serviceCallId,
ServiceCallback cb)
Register a callback for a given outgoing service call.
|
void |
registerTopicCallback(String topic,
TopicCallback cb)
Register a callback for a given topic.
|
boolean |
send(javax.json.JsonObject jsonObject)
Send the given JSON object to rosbridge.
|
public static final String DEFAULT_HOSTNAME
public static final int DEFAULT_PORT
public Ros()
public Ros(String hostname)
hostname - The hostname to connect to.public Ros(String hostname, int port)
hostname - The hostname to connect to.port - The port to connect to.public Ros(String hostname, int port, JRosbridge.WebSocketType protocol)
hostname - The hostname to connect to.port - The port to connect to.protocol - The WebSocket protocol to use.public String getHostname()
public int getPort()
public JRosbridge.WebSocketType getProtocol()
public String getURL()
public long nextId()
public void addRosHandler(RosHandler handler)
handler - The handler to add.public boolean connect()
public boolean disconnect()
public boolean isConnected()
public void onOpen(javax.websocket.Session session)
session - The session associated with the connection.public void onClose(javax.websocket.Session session)
session - The session associated with the disconnection.public void onError(javax.websocket.Session session,
Throwable t)
session - The session for the error.session - The session for the error.public void onMessage(String message)
message - The incoming JSON message from rosbridge.public boolean send(javax.json.JsonObject jsonObject)
jsonObject - The JSON object to send to rosbridge.public void authenticate(String mac, String client, String dest, String rand, int t, String level, int end)
mac - The MAC (hash) string given by the trusted source.client - The IP of the client.dest - The IP of the destination.rand - The random string given by the trusted source.t - The time of the authorization request.level - The user level as a string given by the client.end - The end time of the client's session.public void registerTopicCallback(String topic, TopicCallback cb)
topic - The topic to register this callback with.cb - The callback that will be called when messages come in for the
associated topic.public void deregisterTopicCallback(String topic, TopicCallback cb)
topic - The topic associated with the callback.cb - The callback to remove.public void registerServiceCallback(String serviceCallId, ServiceCallback cb)
serviceCallId - The unique ID of the service call.cb - The callback that will be called when a service response comes
back for the associated request.public void registerCallServiceCallback(String serviceName, CallServiceCallback cb)
serviceName - The unique name of the service call.cb - The callback that will be called when a service request comes
in for the associated request.public void deregisterCallServiceCallback(String serviceName)
serviceName - The unique name of the service call.Copyright © 2014. All rights reserved.