topic
This commit is contained in:
parent
b38c834818
commit
b2c3e6a743
@ -5,6 +5,9 @@
|
|||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
)
|
||||||
|
|
||||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||||
|
|
||||||
foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
||||||
@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
|||||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
||||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
||||||
endforeach(plugin)
|
endforeach(plugin)
|
||||||
|
|
||||||
|
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
|
||||||
|
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
|
||||||
|
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
|
||||||
|
endforeach(ffi_plugin)
|
||||||
|
19
lib/attach/topic2.dart
Normal file
19
lib/attach/topic2.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// import 'package:roslibdart/core/request.dart';
|
||||||
|
|
||||||
|
// class Topic2 {
|
||||||
|
// String name;
|
||||||
|
// String type;
|
||||||
|
|
||||||
|
// Topic2({required this.name, required this.type});
|
||||||
|
|
||||||
|
// String publish(dynamic message) {
|
||||||
|
// var req = Request(
|
||||||
|
// op: "publish",
|
||||||
|
// id:
|
||||||
|
// topic: name,
|
||||||
|
// msg: message,
|
||||||
|
// );
|
||||||
|
// return req.toString();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
@ -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,19 +163,23 @@ 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());
|
||||||
op: 'advertise',
|
|
||||||
id: advertiseId,
|
|
||||||
type: type,
|
|
||||||
topic: name,
|
|
||||||
latch: latch,
|
|
||||||
queueSize: queueSize,
|
|
||||||
));
|
|
||||||
// If the ROS connection closes show that we're not advertising anymore.
|
// If the ROS connection closes show that we're not advertising anymore.
|
||||||
watchForClose();
|
watchForClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request advertiseReq() {
|
||||||
|
return Request(
|
||||||
|
op: 'advertise',
|
||||||
|
id: advertiseId,
|
||||||
|
type: type,
|
||||||
|
topic: name,
|
||||||
|
latch: latch,
|
||||||
|
queueSize: queueSize,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Wait for the connection to close and then reset advertising variables.
|
/// Wait for the connection to close and then reset advertising variables.
|
||||||
Future<void> watchForClose() async {
|
Future<void> watchForClose() async {
|
||||||
if (!reconnectOnClose) {
|
if (!reconnectOnClose) {
|
||||||
@ -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