diff --git a/README.md b/README.md index 5707a00..1d4796f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,21 @@ ros2 run tutorial publisher cd example/subscriber flutter run -d linux ``` +### Subscribe using roslibdart +``` +ros = Ros(url: 'ws://127.0.0.1:9090'); +chatter = Topic(ros: ros, name: '/topic', type: "std_msgs/String", reconnectOnClose: true, queueLength: 10, queueSize: 10); +ros.connect(); +await chatter.subscribe(subscribeHandler); + +Future subscribeHandler(Map msg) async { + msgReceived = json.encode(msg); + setState(() {}); +} +``` + + + ## Testing subscriber ### Run topic subscriber ``` @@ -54,8 +69,16 @@ ros2 run tutorial subscriber ``` cd example/publisher flutter run -d linux - ``` +### Publish using roslibdart +``` +ros = Ros(url: 'ws://127.0.0.1:9090'); +chatter = Topic(ros: ros, name: '/topic', type: "std_msgs/String", reconnectOnClose: true, queueLength: 10, queueSize: 10); +ros.connect(); +Map json = {"data": msgToPublished.toString()}; +await chatter.publish(json); +``` + ## Testing call ### Run tutorial addtwoint service ``` @@ -65,18 +88,46 @@ ros2 run tutorial service cd example/client flutter run -d linux ``` - - +### Call a service using roslibdart +``` +ros = Ros(url: 'ws://127.0.0.1:9090'); +service = Service(name: 'add_two_ints', ros: ros, type: "tutorial_interfaces/AddTwoInts"); +ros.connect(); +Map json = {"a": 1, "b": 2}; +Map result = await service.call(json); +msgToPublished = result['sum']; +``` ## Testing providing service ### Fire up flutter service - - +``` +cd example/service +flutter run -d linux +``` +### Run tutorial call +``` +ros2 run tutorial client +``` ### Run the client from shell ``` ros2 run tutorial client 2 3 ``` +### Provide service using roslibdart +``` +ros = Ros(url: 'ws://127.0.0.1:9090'); +service = Service(name: 'add_two_ints', ros: ros, type: "tutorial_interfaces/AddTwoInts"); +ros.connect(); +await service.advertise(serviceHandler); + +Future>? serviceHandler(Map args) async { + Map response = {}; + response['sum'] = args['a'] + args['b']; + return response; +} +``` + ## Links - [ROSBridge Protocol v2.0](https://github.com/biobotus/rosbridge_suite/blob/master/ROSBRIDGE_PROTOCOL.md). - [Original roslib library from Conrad Heidebrecht](https://github.com/Eternali/roslib) - [RosBridge server implementation](https://github.com/RobotWebTools/rosbridge_suite) +- [roslibjs example](https://github.com/RobotWebTools/roslibjs/blob/develop/examples/simple.html) diff --git a/example/client/README.md b/example/caller/README.md similarity index 98% rename from example/client/README.md rename to example/caller/README.md index 0e9e60a..9318f93 100644 --- a/example/client/README.md +++ b/example/caller/README.md @@ -1,4 +1,4 @@ -# client +# caller A new Flutter project. diff --git a/example/client/analysis_options.yaml b/example/caller/analysis_options.yaml similarity index 100% rename from example/client/analysis_options.yaml rename to example/caller/analysis_options.yaml diff --git a/example/client/android/.gitignore b/example/caller/android/.gitignore similarity index 100% rename from example/client/android/.gitignore rename to example/caller/android/.gitignore diff --git a/example/client/android/app/build.gradle b/example/caller/android/app/build.gradle similarity index 97% rename from example/client/android/app/build.gradle rename to example/caller/android/app/build.gradle index f6a2138..5884b0e 100644 --- a/example/client/android/app/build.gradle +++ b/example/caller/android/app/build.gradle @@ -43,7 +43,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.client" + applicationId "com.example.caller" minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() diff --git a/example/client/android/app/src/debug/AndroidManifest.xml b/example/caller/android/app/src/debug/AndroidManifest.xml similarity index 89% rename from example/client/android/app/src/debug/AndroidManifest.xml rename to example/caller/android/app/src/debug/AndroidManifest.xml index 58a48c7..b79cde6 100644 --- a/example/client/android/app/src/debug/AndroidManifest.xml +++ b/example/caller/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.example.caller"> diff --git a/example/client/android/app/src/main/AndroidManifest.xml b/example/caller/android/app/src/main/AndroidManifest.xml similarity index 96% rename from example/client/android/app/src/main/AndroidManifest.xml rename to example/caller/android/app/src/main/AndroidManifest.xml index fc7c7bd..c601cf7 100644 --- a/example/client/android/app/src/main/AndroidManifest.xml +++ b/example/caller/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="com.example.caller"> + package="com.example.caller"> diff --git a/example/client/android/build.gradle b/example/caller/android/build.gradle similarity index 100% rename from example/client/android/build.gradle rename to example/caller/android/build.gradle diff --git a/example/client/android/gradle.properties b/example/caller/android/gradle.properties similarity index 100% rename from example/client/android/gradle.properties rename to example/caller/android/gradle.properties diff --git a/example/client/android/gradle/wrapper/gradle-wrapper.properties b/example/caller/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from example/client/android/gradle/wrapper/gradle-wrapper.properties rename to example/caller/android/gradle/wrapper/gradle-wrapper.properties diff --git a/example/client/android/settings.gradle b/example/caller/android/settings.gradle similarity index 100% rename from example/client/android/settings.gradle rename to example/caller/android/settings.gradle diff --git a/example/client/ios/.gitignore b/example/caller/ios/.gitignore similarity index 100% rename from example/client/ios/.gitignore rename to example/caller/ios/.gitignore diff --git a/example/client/ios/Flutter/AppFrameworkInfo.plist b/example/caller/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from example/client/ios/Flutter/AppFrameworkInfo.plist rename to example/caller/ios/Flutter/AppFrameworkInfo.plist diff --git a/example/client/ios/Flutter/Debug.xcconfig b/example/caller/ios/Flutter/Debug.xcconfig similarity index 100% rename from example/client/ios/Flutter/Debug.xcconfig rename to example/caller/ios/Flutter/Debug.xcconfig diff --git a/example/client/ios/Flutter/Release.xcconfig b/example/caller/ios/Flutter/Release.xcconfig similarity index 100% rename from example/client/ios/Flutter/Release.xcconfig rename to example/caller/ios/Flutter/Release.xcconfig diff --git a/example/client/ios/Runner.xcodeproj/project.pbxproj b/example/caller/ios/Runner.xcodeproj/project.pbxproj similarity index 99% rename from example/client/ios/Runner.xcodeproj/project.pbxproj rename to example/caller/ios/Runner.xcodeproj/project.pbxproj index a8f01d4..8676c37 100644 --- a/example/client/ios/Runner.xcodeproj/project.pbxproj +++ b/example/caller/ios/Runner.xcodeproj/project.pbxproj @@ -294,7 +294,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.client; + PRODUCT_BUNDLE_IDENTIFIER = com.example.caller; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -422,7 +422,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.client; + PRODUCT_BUNDLE_IDENTIFIER = com.example.caller; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -444,7 +444,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.client; + PRODUCT_BUNDLE_IDENTIFIER = com.example.caller; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/example/client/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/caller/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/client/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to example/caller/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/example/client/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/caller/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/client/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/caller/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/client/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/caller/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/client/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to example/caller/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/example/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/caller/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from example/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to example/caller/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/example/client/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/caller/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/client/ios/Runner.xcworkspace/contents.xcworkspacedata rename to example/caller/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/example/client/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/caller/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/client/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to example/caller/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/client/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/caller/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/client/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to example/caller/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/example/client/ios/Runner/AppDelegate.swift b/example/caller/ios/Runner/AppDelegate.swift similarity index 100% rename from example/client/ios/Runner/AppDelegate.swift rename to example/caller/ios/Runner/AppDelegate.swift diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to example/caller/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from example/client/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to example/caller/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/example/client/ios/Runner/Base.lproj/LaunchScreen.storyboard b/example/caller/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from example/client/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to example/caller/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/example/client/ios/Runner/Base.lproj/Main.storyboard b/example/caller/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from example/client/ios/Runner/Base.lproj/Main.storyboard rename to example/caller/ios/Runner/Base.lproj/Main.storyboard diff --git a/example/client/ios/Runner/Info.plist b/example/caller/ios/Runner/Info.plist similarity index 96% rename from example/client/ios/Runner/Info.plist rename to example/caller/ios/Runner/Info.plist index 60e295c..bbbd784 100644 --- a/example/client/ios/Runner/Info.plist +++ b/example/caller/ios/Runner/Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName - Client + Caller CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,7 +13,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - client + caller CFBundlePackageType APPL CFBundleShortVersionString diff --git a/example/client/ios/Runner/Runner-Bridging-Header.h b/example/caller/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from example/client/ios/Runner/Runner-Bridging-Header.h rename to example/caller/ios/Runner/Runner-Bridging-Header.h diff --git a/example/client/lib/main.dart b/example/caller/lib/main.dart similarity index 92% rename from example/client/lib/main.dart rename to example/caller/lib/main.dart index 01ce45d..6b34acf 100644 --- a/example/client/lib/main.dart +++ b/example/caller/lib/main.dart @@ -14,11 +14,11 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Roslibdart Client Example', + title: 'Roslibdart Caller Example', theme: ThemeData( primarySwatch: Colors.blue, ), - home: const MyHomePage(title: 'Roslibdart Client Example'), + home: const MyHomePage(title: 'Roslibdart Caller Example'), ); } } @@ -54,10 +54,6 @@ class _MyHomePageState extends State { }); } - void initConnection() async { - setState(() {}); - } - void destroyConnection() async { await ros.close(); setState(() {}); diff --git a/example/client/linux/.gitignore b/example/caller/linux/.gitignore similarity index 100% rename from example/client/linux/.gitignore rename to example/caller/linux/.gitignore diff --git a/example/client/linux/CMakeLists.txt b/example/caller/linux/CMakeLists.txt similarity index 98% rename from example/client/linux/CMakeLists.txt rename to example/caller/linux/CMakeLists.txt index dc26588..fdea4d4 100644 --- a/example/client/linux/CMakeLists.txt +++ b/example/caller/linux/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) -set(BINARY_NAME "client") -set(APPLICATION_ID "com.example.client") +set(BINARY_NAME "caller") +set(APPLICATION_ID "com.example.caller") cmake_policy(SET CMP0063 NEW) diff --git a/example/client/linux/flutter/CMakeLists.txt b/example/caller/linux/flutter/CMakeLists.txt similarity index 100% rename from example/client/linux/flutter/CMakeLists.txt rename to example/caller/linux/flutter/CMakeLists.txt diff --git a/example/client/linux/flutter/generated_plugin_registrant.cc b/example/caller/linux/flutter/generated_plugin_registrant.cc similarity index 100% rename from example/client/linux/flutter/generated_plugin_registrant.cc rename to example/caller/linux/flutter/generated_plugin_registrant.cc diff --git a/example/client/linux/flutter/generated_plugin_registrant.h b/example/caller/linux/flutter/generated_plugin_registrant.h similarity index 100% rename from example/client/linux/flutter/generated_plugin_registrant.h rename to example/caller/linux/flutter/generated_plugin_registrant.h diff --git a/example/client/linux/flutter/generated_plugins.cmake b/example/caller/linux/flutter/generated_plugins.cmake similarity index 100% rename from example/client/linux/flutter/generated_plugins.cmake rename to example/caller/linux/flutter/generated_plugins.cmake diff --git a/example/client/linux/main.cc b/example/caller/linux/main.cc similarity index 100% rename from example/client/linux/main.cc rename to example/caller/linux/main.cc diff --git a/example/client/linux/my_application.cc b/example/caller/linux/my_application.cc similarity index 97% rename from example/client/linux/my_application.cc rename to example/caller/linux/my_application.cc index 2ba2836..e3e26b8 100644 --- a/example/client/linux/my_application.cc +++ b/example/caller/linux/my_application.cc @@ -40,11 +40,11 @@ static void my_application_activate(GApplication* application) { if (use_header_bar) { GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); - gtk_header_bar_set_title(header_bar, "client"); + gtk_header_bar_set_title(header_bar, "caller"); gtk_header_bar_set_show_close_button(header_bar, TRUE); gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); } else { - gtk_window_set_title(window, "client"); + gtk_window_set_title(window, "caller"); } gtk_window_set_default_size(window, 1280, 720); diff --git a/example/client/linux/my_application.h b/example/caller/linux/my_application.h similarity index 100% rename from example/client/linux/my_application.h rename to example/caller/linux/my_application.h diff --git a/example/client/pubspec.yaml b/example/caller/pubspec.yaml similarity index 100% rename from example/client/pubspec.yaml rename to example/caller/pubspec.yaml diff --git a/example/client/test/widget_test.dart b/example/caller/test/widget_test.dart similarity index 96% rename from example/client/test/widget_test.dart rename to example/caller/test/widget_test.dart index 5a5aaab..f6bd989 100644 --- a/example/client/test/widget_test.dart +++ b/example/caller/test/widget_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:client/main.dart'; +import 'package:caller/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { diff --git a/example/client/web/favicon.png b/example/caller/web/favicon.png similarity index 100% rename from example/client/web/favicon.png rename to example/caller/web/favicon.png diff --git a/example/client/web/icons/Icon-192.png b/example/caller/web/icons/Icon-192.png similarity index 100% rename from example/client/web/icons/Icon-192.png rename to example/caller/web/icons/Icon-192.png diff --git a/example/client/web/icons/Icon-512.png b/example/caller/web/icons/Icon-512.png similarity index 100% rename from example/client/web/icons/Icon-512.png rename to example/caller/web/icons/Icon-512.png diff --git a/example/client/web/icons/Icon-maskable-192.png b/example/caller/web/icons/Icon-maskable-192.png similarity index 100% rename from example/client/web/icons/Icon-maskable-192.png rename to example/caller/web/icons/Icon-maskable-192.png diff --git a/example/client/web/icons/Icon-maskable-512.png b/example/caller/web/icons/Icon-maskable-512.png similarity index 100% rename from example/client/web/icons/Icon-maskable-512.png rename to example/caller/web/icons/Icon-maskable-512.png diff --git a/example/client/web/index.html b/example/caller/web/index.html similarity index 97% rename from example/client/web/index.html rename to example/caller/web/index.html index ba445b1..549633b 100644 --- a/example/client/web/index.html +++ b/example/caller/web/index.html @@ -23,13 +23,13 @@ - + - client + caller diff --git a/example/client/web/manifest.json b/example/caller/web/manifest.json similarity index 94% rename from example/client/web/manifest.json rename to example/caller/web/manifest.json index 554b75e..e23ed3d 100644 --- a/example/client/web/manifest.json +++ b/example/caller/web/manifest.json @@ -1,6 +1,6 @@ { - "name": "client", - "short_name": "client", + "name": "caller", + "short_name": "caller", "start_url": ".", "display": "standalone", "background_color": "#0175C2", diff --git a/example/service/lib/main.dart b/example/service/lib/main.dart index 0234c34..cd31c30 100644 --- a/example/service/lib/main.dart +++ b/example/service/lib/main.dart @@ -49,10 +49,6 @@ class _MyHomePageState extends State { }); } - void initConnection() async { - setState(() {}); - } - void destroyConnection() async { await ros.close(); setState(() {}); @@ -81,7 +77,7 @@ class _MyHomePageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text('return answer ' + msgToPublished.toString()), + Text('Service returns answer ' + msgToPublished.toString()), ], ), ), diff --git a/example/subscriber/lib/main.dart b/example/subscriber/lib/main.dart index b0018c3..d8693e9 100644 --- a/example/subscriber/lib/main.dart +++ b/example/subscriber/lib/main.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:roslibdart/roslibdart.dart'; +import 'dart:async'; +import 'dart:convert'; void main() { runApp(const ExampleApp()); @@ -37,12 +39,11 @@ class _HomePageState extends State { queueLength: 10, queueSize: 10); super.initState(); - } - - void initConnection() async { ros.connect(); - await chatter.subscribe(); - setState(() {}); + Timer(const Duration(seconds: 3), () async { + await chatter.subscribe(subscribeHandler); + // await chatter.subscribe(); + }); } void destroyConnection() async { @@ -51,51 +52,28 @@ class _HomePageState extends State { setState(() {}); } + String msgReceived = ''; + Future subscribeHandler(Map msg) async { + msgReceived = json.encode(msg); + setState(() {}); + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Roslibdart Subscriber Example'), ), - body: StreamBuilder( - stream: ros.statusStream, - builder: (context, snapshot) { - return Center( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - StreamBuilder>( - stream: chatter.subscription, - builder: (BuildContext context2, - AsyncSnapshot> snapshot2) { - if (snapshot2.hasData && snapshot2.data != null) { - return Text('${snapshot2.data!['msg']}'); - } else { - return const CircularProgressIndicator(); - } - }, - ), - ActionChip( - label: Text(snapshot.data == Status.connected - ? 'DISCONNECT' - : 'CONNECT'), - backgroundColor: snapshot.data == Status.connected - ? Colors.green[300] - : Colors.grey[300], - onPressed: () { - // print(snapshot.data); - if (snapshot.data != Status.connected) { - initConnection(); - } else { - destroyConnection(); - } - }, - ), - ], - ), - ); - }), + body: Center( + // Center is a layout widget. It takes a single child and positions it + // in the middle of the parent. + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(msgReceived + ' received'), + ], + ), + ), ); } } diff --git a/lib/core/topic.dart b/lib/core/topic.dart index abe7bf6..0af2b38 100644 --- a/lib/core/topic.dart +++ b/lib/core/topic.dart @@ -4,6 +4,9 @@ import 'dart:async'; import 'ros.dart'; import 'request.dart'; +// Receiver function to handle requests when the service is advertising. +typedef SubscribeHandler = Future Function(Map args); + /// Wrapper to interact with ROS topics. class Topic { Topic({ @@ -72,7 +75,7 @@ class Topic { /// /// Defaults to true. bool reconnectOnClose; - + /* /// Subscribe to the topic if not already subscribed. Future subscribe() async { if (subscribeId == null) { @@ -91,6 +94,30 @@ class Topic { )); } } + */ + + Future subscribe(SubscribeHandler subscribeHandler) async { + if (subscribeId == null) { + // Create the listenable broadcast subscription stream. + subscription = ros.stream; + subscribeId = ros.requestSubscriber(name); + await safeSend(Request( + op: 'subscribe', + id: subscribeId, + type: type, + topic: name, + compression: compression, + throttleRate: throttleRate, + queueLength: queueLength, + )); + subscription!.listen((Map message) async { + if (message['topic'] != name) { + return; + } + await subscribeHandler(message['msg']); + }); + } + } /// Unsubscribe from the topic. Future unsubscribe() async { diff --git a/rospackage/tutorial/tutorial/client.py b/rospackage/tutorial/tutorial/caller.py similarity index 100% rename from rospackage/tutorial/tutorial/client.py rename to rospackage/tutorial/tutorial/caller.py