Compare commits
3 Commits
627c1c925a
...
ba2369623b
Author | SHA1 | Date | |
---|---|---|---|
|
ba2369623b | ||
|
f831233c09 | ||
|
b2c3e6a743 |
@ -119,33 +119,43 @@ class Topic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Unsubscribe from the topic.
|
/// Unsubscribe from the topic.
|
||||||
Future<void> unsubscribe() async {
|
Future<void> unsubscribe() async {
|
||||||
if (subscribeId != null) {
|
if (subscribeId != null) {
|
||||||
// Send the request and reset the subscription variables.
|
// Send the request and reset the subscription variables.
|
||||||
await safeSend(Request(
|
await safeSend(unsubscribeReq());
|
||||||
op: 'unsubscribe',
|
|
||||||
id: subscribeId,
|
|
||||||
topic: name,
|
|
||||||
));
|
|
||||||
// await ros.requestUnsubscribe(id);
|
// await ros.requestUnsubscribe(id);
|
||||||
subscription = null;
|
subscription = null;
|
||||||
subscribeId = null;
|
subscribeId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request unsubscribeReq() {
|
||||||
|
return Request(
|
||||||
|
op: 'unsubscribe',
|
||||||
|
id: subscribeId,
|
||||||
|
topic: name,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Publish a [message] to the topic.
|
/// Publish a [message] to the topic.
|
||||||
Future<void> publish(dynamic message) async {
|
Future<void> publish(dynamic message) async {
|
||||||
// Advertise the topic and then send the publish request.
|
// Advertise the topic and then send the publish request.
|
||||||
await advertise();
|
await advertise();
|
||||||
publishId = ros.requestPublisher(name);
|
publishId = ros.requestPublisher(name);
|
||||||
await safeSend(Request(
|
await safeSend(publishReq(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
Request publishReq(dynamic message) {
|
||||||
|
return Request(
|
||||||
op: 'publish',
|
op: 'publish',
|
||||||
topic: name,
|
topic: name,
|
||||||
id: publishId,
|
id: publishId,
|
||||||
msg: message,
|
msg: message,
|
||||||
latch: latch,
|
latch: latch,
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advertise the topic.
|
/// Advertise the topic.
|
||||||
@ -153,17 +163,21 @@ class Topic {
|
|||||||
if (!isAdvertised) {
|
if (!isAdvertised) {
|
||||||
// Send the advertisement request.
|
// Send the advertisement request.
|
||||||
advertiseId = ros.requestAdvertiser(name);
|
advertiseId = ros.requestAdvertiser(name);
|
||||||
await safeSend(Request(
|
await safeSend(advertiseReq());
|
||||||
|
// If the ROS connection closes show that we're not advertising anymore.
|
||||||
|
watchForClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Request advertiseReq() {
|
||||||
|
return Request(
|
||||||
op: 'advertise',
|
op: 'advertise',
|
||||||
id: advertiseId,
|
id: advertiseId,
|
||||||
type: type,
|
type: type,
|
||||||
topic: name,
|
topic: name,
|
||||||
latch: latch,
|
latch: latch,
|
||||||
queueSize: queueSize,
|
queueSize: queueSize,
|
||||||
));
|
);
|
||||||
// If the ROS connection closes show that we're not advertising anymore.
|
|
||||||
watchForClose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for the connection to close and then reset advertising variables.
|
/// Wait for the connection to close and then reset advertising variables.
|
||||||
@ -187,6 +201,8 @@ class Topic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Safely send a [message] to ROS.
|
/// Safely send a [message] to ROS.
|
||||||
Future<void> safeSend(Request message) async {
|
Future<void> safeSend(Request message) async {
|
||||||
// Send the message but if we're not connected and the [reconnectOnClose] flag
|
// Send the message but if we're not connected and the [reconnectOnClose] flag
|
||||||
|
Loading…
Reference in New Issue
Block a user