Compare commits
39 Commits
@ -1,15 +0,0 @@
|
|||||||
*.iml
|
|
||||||
.gradle
|
|
||||||
/local.properties
|
|
||||||
/.idea/caches
|
|
||||||
/.idea/libraries
|
|
||||||
/.idea/modules.xml
|
|
||||||
/.idea/workspace.xml
|
|
||||||
/.idea/navEditor.xml
|
|
||||||
/.idea/assetWizardSettings.xml
|
|
||||||
.DS_Store
|
|
||||||
/build
|
|
||||||
/captures
|
|
||||||
.externalNativeBuild
|
|
||||||
.cxx
|
|
||||||
local.properties
|
|
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1 +0,0 @@
|
|||||||
Hamburger
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="11" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetDropDown">
|
|
||||||
<targetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="C:\Users\Lenovo\.android\avd\Pixel_XL_API_30.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</targetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2022-10-25T13:49:43.646135700Z" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
||||||
<component name="GradleSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<GradleProjectSettings>
|
|
||||||
<option name="testRunner" value="GRADLE" />
|
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="modules">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
<option value="$PROJECT_DIR$/app" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectType">
|
|
||||||
<option name="id" value="Android" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1 +0,0 @@
|
|||||||
/build
|
|
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<GradleProjectSettings>
|
|
||||||
<option name="testRunner" value="GRADLE" />
|
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectType">
|
|
||||||
<option name="id" value="Android" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,44 +0,0 @@
|
|||||||
# For more information about using CMake with Android Studio, read the
|
|
||||||
# documentation: https://d.android.com/studio/projects/add-native-code.html
|
|
||||||
|
|
||||||
# Sets the minimum version of CMake required to build the native library.
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.4.1)
|
|
||||||
|
|
||||||
# Creates and names a library, sets it as either STATIC
|
|
||||||
# or SHARED, and provides the relative paths to its source code.
|
|
||||||
# You can define multiple libraries, and CMake builds them for you.
|
|
||||||
# Gradle automatically packages shared libraries with your APK.
|
|
||||||
|
|
||||||
add_library( # Sets the name of the library.
|
|
||||||
native-test
|
|
||||||
|
|
||||||
# Sets the library as a shared library.
|
|
||||||
SHARED
|
|
||||||
|
|
||||||
# Provides a relative path to your source file(s).
|
|
||||||
src/main/jni/native-test.c )
|
|
||||||
|
|
||||||
# Searches for a specified prebuilt library and stores the path as a
|
|
||||||
# variable. Because CMake includes system libraries in the search path by
|
|
||||||
# default, you only need to specify the name of the public NDK library
|
|
||||||
# you want to add. CMake verifies that the library exists before
|
|
||||||
# completing its build.
|
|
||||||
|
|
||||||
find_library( # Sets the name of the path variable.
|
|
||||||
log-lib
|
|
||||||
|
|
||||||
# Specifies the name of the NDK library that
|
|
||||||
# you want CMake to locate.
|
|
||||||
log )
|
|
||||||
|
|
||||||
# Specifies libraries CMake should link to your target library. You
|
|
||||||
# can link multiple libraries, such as libraries you define in this
|
|
||||||
# build script, prebuilt third-party libraries, or system libraries.
|
|
||||||
|
|
||||||
target_link_libraries( # Specifies the target library.
|
|
||||||
native-test
|
|
||||||
|
|
||||||
# Links the target library to the log library
|
|
||||||
# included in the NDK.
|
|
||||||
${log-lib} )
|
|
@ -1,75 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'com.android.application'
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace 'com.example.hamburger'
|
|
||||||
compileSdk 32
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "com.example.hamburger"
|
|
||||||
minSdk 21
|
|
||||||
targetSdk 32
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
cppFlags ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
path "CMakeLists.txt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
buildFeatures {
|
|
||||||
viewBinding true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
|
||||||
implementation 'com.google.android.material:material:1.5.0'
|
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
|
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
|
|
||||||
implementation 'androidx.navigation:navigation-fragment:2.4.1'
|
|
||||||
implementation 'androidx.navigation:navigation-ui:2.4.1'
|
|
||||||
implementation files('libs\\mysql-connector-java-5.1.49.jar')
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
|
||||||
|
|
||||||
implementation 'com.jakewharton:butterknife:10.0.0'
|
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
|
|
||||||
//noinspection GradleCompatible
|
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
|
||||||
//noinspection GradleCompatible
|
|
||||||
//implementation 'com.android.support:recyclerview-v7:28.0.0'
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
|
||||||
//noinspection DuplicatePlatformClasses
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
|
||||||
implementation files('libs/json-simple-1.1.jar')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
# Add project specific ProGuard rules here.
|
|
||||||
# You can control the set of applied configuration files using the
|
|
||||||
# proguardFiles setting in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.example.hamburger;
|
||||||
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import com.example.hamburger.dao.UserDao;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import com.example.hamburger.dao.UserDao;
|
||||||
|
import com.example.hamburger.entity.User;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class Mtest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void text_1() {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
assertEquals("com.example.hamburger", appContext.getPackageName());
|
||||||
|
|
||||||
|
new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
UserDao userDao = new UserDao();
|
||||||
|
int msg = userDao.login("1","1");
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void text_2() {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
assertEquals("com.example.hamburger", appContext.getPackageName());
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
|
||||||
|
user.setUserAccount("11");
|
||||||
|
user.setUserPassword("11");
|
||||||
|
user.setUserName("11");
|
||||||
|
user.setUserType(1);
|
||||||
|
user.setUserState(0);
|
||||||
|
user.setUserDel(0);
|
||||||
|
|
||||||
|
new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
int msg = 0;
|
||||||
|
|
||||||
|
UserDao userDao = new UserDao();
|
||||||
|
|
||||||
|
User uu = userDao.findUser(user.getUserAccount());
|
||||||
|
if(uu != null){
|
||||||
|
msg = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
boolean flag = userDao.register(user);
|
||||||
|
if(flag){
|
||||||
|
msg = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 372 KiB |
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 58 KiB |
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="ic_launcher_background">#0E3B53</color>
|
|
||||||
</resources>
|
|
@ -1,60 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
<application
|
|
||||||
android:allowBackup="true"
|
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
|
||||||
android:fullBackupContent="@xml/backup_rules"
|
|
||||||
android:icon="@mipmap/ic_launcher"
|
|
||||||
android:label="@string/app_name"
|
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
|
||||||
android:supportsRtl="true"
|
|
||||||
android:theme="@style/Theme.Hamburger"
|
|
||||||
tools:targetApi="31">
|
|
||||||
<activity
|
|
||||||
android:name=".MainActivity2"
|
|
||||||
android:exported="false"
|
|
||||||
android:label="@string/title_activity_main2">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.lib_name"
|
|
||||||
android:value="" />
|
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name=".MainActivity"
|
|
||||||
android:exported="true">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.lib_name"
|
|
||||||
android:value="" />
|
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name=".main_window"
|
|
||||||
android:exported="true" />
|
|
||||||
<activity
|
|
||||||
android:name=".register"
|
|
||||||
android:exported="true" />
|
|
||||||
<activity
|
|
||||||
android:name=".notifications"
|
|
||||||
android:exported="true" />
|
|
||||||
<activity android:name="com.example.dadac.testrosbridge.TransferSta"
|
|
||||||
android:exported="true">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name="com.dadac.testrosbridge.RosBridgeActivity"/>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
</manifest>
|
|
@ -1,42 +0,0 @@
|
|||||||
package com.dadac.testrosbridge;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import com.jilk.ros.rosbridge.ROSBridgeClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ Create by dadac on 2018/10/8.
|
|
||||||
* @Function:
|
|
||||||
* @Return:
|
|
||||||
*/
|
|
||||||
public class RCApplication extends Application {
|
|
||||||
|
|
||||||
|
|
||||||
ROSBridgeClient client;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTerminate() {
|
|
||||||
if (client != null)
|
|
||||||
client.disconnect();
|
|
||||||
super.onTerminate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ROSBridgeClient getRosClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRosClient(ROSBridgeClient client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
|||||||
package com.example.dadac.testrosbridge;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ Create by dadac on 2018/10/8.
|
|
||||||
* @Function: 存放所有的 JNI 调用的文件
|
|
||||||
* @Return:
|
|
||||||
*/
|
|
||||||
public class JNICallAll {
|
|
||||||
|
|
||||||
// Used to load the 'native-lib' library on application startup.
|
|
||||||
static {
|
|
||||||
System.loadLibrary("native-test");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A native method that is implemented by the 'native-lib' native library,
|
|
||||||
* which is packaged with this application.
|
|
||||||
*/
|
|
||||||
public native String stringFromJNI();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package com.example.dadac.testrosbridge;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
//import android.support.v7.app.AppCompatActivity;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import com.dadac.testrosbridge.RosBridgeActivity;
|
|
||||||
import com.example.hamburger.R;
|
|
||||||
|
|
||||||
public class TransferSta extends AppCompatActivity {
|
|
||||||
|
|
||||||
private Button DC_Button_JumpToRos;
|
|
||||||
|
|
||||||
/* @Override
|
|
||||||
/*protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.fragment_dashboard);
|
|
||||||
DC_Button_JumpToRos = (Button) findViewById(R.id.DC_Button_JumpToRos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void JumpToActivity(View view) {
|
|
||||||
Intent myIntentRos = new Intent(TransferSta.this, RosBridgeActivity.class);
|
|
||||||
startActivity(myIntentRos);
|
|
||||||
}*/
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package com.example.hamburger;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import com.example.hamburger.R;
|
|
||||||
import com.example.hamburger.notifications;
|
|
||||||
import com.example.hamburger.ui.notifications.NotificationsFragment;
|
|
||||||
|
|
||||||
public class add extends AppCompatActivity {
|
|
||||||
|
|
||||||
EditText mytext;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_add);
|
|
||||||
mytext = findViewById(R.id.mt);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Confirm() {
|
|
||||||
Button button = (Button) findViewById(R.id.conf);
|
|
||||||
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setClass(add.this, NotificationsFragment.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.example.hamburger.entity;
|
||||||
|
|
||||||
|
public class IsolationUser {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String gender;
|
||||||
|
private String idnumber;
|
||||||
|
private int roomnumber;
|
||||||
|
private String checkin_time;
|
||||||
|
|
||||||
|
|
||||||
|
public IsolationUser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public IsolationUser(String name, String gender, String idnumber, int roomnumber, String checkin_time) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.gender = gender;
|
||||||
|
this.idnumber = idnumber;
|
||||||
|
this.roomnumber = roomnumber;
|
||||||
|
this.checkin_time = checkin_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getname() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setname(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGender() {
|
||||||
|
return gender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGender(String gender) {
|
||||||
|
this.gender = gender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdnumber() {
|
||||||
|
return idnumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdnumber(String idnumber) {
|
||||||
|
this.idnumber = idnumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoomnumber() {
|
||||||
|
return roomnumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoomnumber(int roomnumber) {
|
||||||
|
this.roomnumber = roomnumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCheckin_time() {
|
||||||
|
return checkin_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckin_time(String checkin_time) {
|
||||||
|
this.checkin_time = checkin_time;
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
package com.example.hamburger;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
public class main_window extends AppCompatActivity {
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
//这个是获取布局文件的,这里是你下一个页面的布局文件//注意这个是跳转界面的不能设置错,应该是第一个
|
|
||||||
setContentView(R.layout.main_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package com.example.hamburger;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class notifications extends AppCompatActivity {
|
|
||||||
|
|
||||||
private TextView tv;
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.fragment_notifications);
|
|
||||||
|
|
||||||
Button button = (Button) findViewById(R.id.btn1);
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setClass(notifications.this, add.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.example.hamburger.ui.dashboard;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import com.example.hamburger.databinding.FragmentDashboardBinding;
|
|
||||||
|
|
||||||
public class DashboardFragment extends Fragment {
|
|
||||||
|
|
||||||
private FragmentDashboardBinding binding;
|
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
DashboardViewModel dashboardViewModel =
|
|
||||||
new ViewModelProvider(this).get(DashboardViewModel.class);
|
|
||||||
|
|
||||||
binding = FragmentDashboardBinding.inflate(inflater, container, false);
|
|
||||||
View root = binding.getRoot();
|
|
||||||
|
|
||||||
final TextView textView = binding.v1;
|
|
||||||
dashboardViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
binding = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.hamburger.ui.dashboard;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
public class DashboardViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private final MutableLiveData<String> mText;
|
|
||||||
|
|
||||||
public DashboardViewModel() {
|
|
||||||
mText = new MutableLiveData<>();
|
|
||||||
mText.setValue("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<String> getText() {
|
|
||||||
return mText;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.example.hamburger.ui.home;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import com.example.hamburger.databinding.FragmentHomeBinding;
|
|
||||||
|
|
||||||
public class HomeFragment extends Fragment {
|
|
||||||
|
|
||||||
private FragmentHomeBinding binding;
|
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
HomeViewModel homeViewModel =
|
|
||||||
new ViewModelProvider(this).get(HomeViewModel.class);
|
|
||||||
|
|
||||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
|
||||||
View root = binding.getRoot();
|
|
||||||
|
|
||||||
final TextView textView = binding.TextView1;
|
|
||||||
homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
binding = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.hamburger.ui.home;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
public class HomeViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private final MutableLiveData<String> mText;
|
|
||||||
|
|
||||||
public HomeViewModel() {
|
|
||||||
mText = new MutableLiveData<>();
|
|
||||||
mText.setValue("This is home fragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<String> getText() {
|
|
||||||
return mText;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,101 @@
|
|||||||
|
package com.example.hamburger.ui.home;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.hamburger.R;
|
||||||
|
import com.example.hamburger.dao.UserDao;
|
||||||
|
import com.example.hamburger.entity.IsolationUser;
|
||||||
|
|
||||||
|
public class Inform_input extends AppCompatActivity{
|
||||||
|
|
||||||
|
private static final String TAG = "mysql-party-register";
|
||||||
|
EditText name = null;
|
||||||
|
EditText gender = null;
|
||||||
|
EditText idnumber = null;
|
||||||
|
EditText roomnumber = null;
|
||||||
|
EditText checkin_time = null;
|
||||||
|
|
||||||
|
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.infor_input);
|
||||||
|
|
||||||
|
name = findViewById(R.id.name);
|
||||||
|
gender = findViewById(R.id.gender);
|
||||||
|
idnumber = findViewById(R.id.ID_number);
|
||||||
|
roomnumber = findViewById(R.id.roomnumber);
|
||||||
|
checkin_time = findViewById(R.id.checkin_time);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInfor(View view){
|
||||||
|
String name1 = name.getText().toString();
|
||||||
|
String gender1 = gender.getText().toString();
|
||||||
|
String idnumber1 = idnumber.getText().toString();
|
||||||
|
int roomnumber1 = Integer.parseInt(roomnumber.getText().toString());
|
||||||
|
String checkin_time1 = checkin_time.getText().toString();
|
||||||
|
|
||||||
|
IsolationUser user=new IsolationUser();
|
||||||
|
|
||||||
|
user.setname(name1);
|
||||||
|
user.setGender(gender1);
|
||||||
|
user.setIdnumber(idnumber1);
|
||||||
|
user.setRoomnumber(roomnumber1);
|
||||||
|
user.setCheckin_time(checkin_time1);
|
||||||
|
|
||||||
|
new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
int msg = 0;
|
||||||
|
|
||||||
|
UserDao userDao = new UserDao();
|
||||||
|
|
||||||
|
IsolationUser uu = userDao.findUser_(user.getname());
|
||||||
|
if(uu != null){
|
||||||
|
msg = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
boolean flag = userDao.LogInfor(user);
|
||||||
|
if(flag){
|
||||||
|
msg = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hand.sendEmptyMessage(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("HandlerLeak")
|
||||||
|
final Handler hand = new Handler()
|
||||||
|
{
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
if(msg.what == 0) {
|
||||||
|
Toast.makeText(getApplicationContext(),"录入失败",Toast.LENGTH_LONG).show();
|
||||||
|
} else if(msg.what == 1) {
|
||||||
|
Toast.makeText(getApplicationContext(),"该信息已经存在,请重新录入",Toast.LENGTH_LONG).show();
|
||||||
|
} else if(msg.what == 2) {
|
||||||
|
Toast.makeText(getApplicationContext(), "录入成功", Toast.LENGTH_LONG).show();
|
||||||
|
Intent intent = new Intent();
|
||||||
|
//将想要传递的数据用putExtra封装在intent中
|
||||||
|
intent.putExtra("a","录入");
|
||||||
|
setResult(RESULT_CANCELED,intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public void findInfor(View view){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
package com.example.hamburger.ui.notifications;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import com.example.hamburger.R;
|
|
||||||
import com.example.hamburger.databinding.FragmentNotificationsBinding;
|
|
||||||
|
|
||||||
public class NotificationsFragment extends Fragment{
|
|
||||||
|
|
||||||
private FragmentNotificationsBinding binding;
|
|
||||||
|
|
||||||
private NotificationsViewModel notificationsViewModel;
|
|
||||||
|
|
||||||
private TextView tv;
|
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
NotificationsViewModel notificationsViewModel =
|
|
||||||
new ViewModelProvider(this).get(NotificationsViewModel.class);
|
|
||||||
|
|
||||||
binding = FragmentNotificationsBinding.inflate(inflater, container, false);
|
|
||||||
View root = binding.getRoot();
|
|
||||||
|
|
||||||
final TextView textView = binding.textNotifications;
|
|
||||||
notificationsViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
|
||||||
|
|
||||||
final Button button=root.findViewById(R.id.btn1);
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setClass(getActivity(), add.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return root;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
binding = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.hamburger.ui.notifications;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
public class NotificationsViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private final MutableLiveData<String> mText;
|
|
||||||
|
|
||||||
public NotificationsViewModel() {
|
|
||||||
mText = new MutableLiveData<>();
|
|
||||||
mText.setValue("This is notifications fragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<String> getText() {
|
|
||||||
return mText;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.example.hamburger.ui.notifications;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import com.example.hamburger.R;
|
|
||||||
import com.example.hamburger.notifications;
|
|
||||||
|
|
||||||
public class add extends AppCompatActivity {
|
|
||||||
|
|
||||||
EditText mytext;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_add);
|
|
||||||
mytext = findViewById(R.id.mt);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Confirm() {
|
|
||||||
Button button = (Button) findViewById(R.id.conf);
|
|
||||||
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setClass(add.this, NotificationsFragment.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Clock;
|
|
||||||
import com.jilk.ros.message.Log;
|
|
||||||
import com.jilk.ros.rosapi.message.Empty;
|
|
||||||
import com.jilk.ros.rosapi.message.GetTime;
|
|
||||||
import com.jilk.ros.rosapi.message.MessageDetails;
|
|
||||||
import com.jilk.ros.rosapi.message.Type;
|
|
||||||
import com.jilk.ros.rosbridge.ROSBridgeClient;
|
|
||||||
|
|
||||||
public class Example {
|
|
||||||
|
|
||||||
public Example() {}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ROSBridgeClient client = new ROSBridgeClient("ws://10.8.87.23:9090");
|
|
||||||
client.connect();
|
|
||||||
//testTopic(client);
|
|
||||||
try {
|
|
||||||
testService(client);
|
|
||||||
}
|
|
||||||
catch (RuntimeException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testService(ROSBridgeClient client) {
|
|
||||||
try {
|
|
||||||
Service<Empty, GetTime> timeService =
|
|
||||||
new Service<Empty, GetTime>("/rosapi/get_time", Empty.class, GetTime.class, client);
|
|
||||||
timeService.verify();
|
|
||||||
//System.out.println("Time (secs): " + timeService.callBlocking(new Empty()).time.sec);
|
|
||||||
|
|
||||||
Service<com.jilk.ros.rosapi.message.Service, Type> serviceTypeService =
|
|
||||||
new Service<com.jilk.ros.rosapi.message.Service, Type>("/rosapi/service_type",
|
|
||||||
com.jilk.ros.rosapi.message.Service.class, Type.class, client);
|
|
||||||
serviceTypeService.verify();
|
|
||||||
String type = serviceTypeService.callBlocking(new com.jilk.ros.rosapi.message.Service("/rosapi/service_response_details")).type;
|
|
||||||
|
|
||||||
Service<Type, MessageDetails> serviceDetails =
|
|
||||||
new Service<Type, MessageDetails>("/rosapi/service_response_details",
|
|
||||||
Type.class, MessageDetails.class, client);
|
|
||||||
serviceDetails.verify();
|
|
||||||
//serviceDetails.callBlocking(new Type(type)).print();
|
|
||||||
|
|
||||||
com.jilk.ros.Topic<Log> logTopic =
|
|
||||||
new com.jilk.ros.Topic<Log>("/rosout", Log.class, client);
|
|
||||||
logTopic.verify();
|
|
||||||
|
|
||||||
/*
|
|
||||||
System.out.println("Nodes");
|
|
||||||
for (String s : client.getNodes())
|
|
||||||
System.out.println(" " + s);
|
|
||||||
System.out.println("Topics");
|
|
||||||
for (String s : client.getTopics()) {
|
|
||||||
System.out.println(s + ":");
|
|
||||||
client.getTopicMessageDetails(s).print();
|
|
||||||
}
|
|
||||||
System.out.println("Services");
|
|
||||||
for (String s : client.getServices()) {
|
|
||||||
System.out.println(s + ":");
|
|
||||||
client.getServiceRequestDetails(s).print();
|
|
||||||
System.out.println("-----------------");
|
|
||||||
client.getServiceResponseDetails(s).print();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {
|
|
||||||
System.out.println("Process was interrupted.");
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Service<Empty, Topics> topicService =
|
|
||||||
new Service<Empty, Topics>("/rosapi/topics", Empty.class, Topics.class, client);
|
|
||||||
Service<Topic, Type> typeService =
|
|
||||||
new Service<Topic, Type>("/rosapi/topic_type", Topic.class, Type.class, client);
|
|
||||||
Service<Type, MessageDetails> messageService =
|
|
||||||
new Service<Type, MessageDetails>("/rosapi/message_details", Type.class, MessageDetails.class, client);
|
|
||||||
try {
|
|
||||||
Topics topics = topicService.callBlocking(new Empty());
|
|
||||||
for (String topicString : topics.topics) {
|
|
||||||
Topic topic = new Topic();
|
|
||||||
topic.topic = topicString;
|
|
||||||
Type type = typeService.callBlocking(topic);
|
|
||||||
MessageDetails details = messageService.callBlocking(type);
|
|
||||||
System.out.println("Topic: " + topic.topic + " Type: " + type.type);
|
|
||||||
details.print();
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
Type type = new Type();
|
|
||||||
type.type = "time";
|
|
||||||
System.out.print("Single type check on \'time\': ");
|
|
||||||
messageService.callBlocking(type).print();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {
|
|
||||||
System.out.println("testService: process was interrupted.");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testTopic(ROSBridgeClient client) {
|
|
||||||
com.jilk.ros.Topic<Clock> clockTopic = new com.jilk.ros.Topic<Clock>("/clock", Clock.class, client);
|
|
||||||
clockTopic.subscribe();
|
|
||||||
try {
|
|
||||||
Thread.sleep(20000);} catch(InterruptedException ex) {}
|
|
||||||
Clock cl = null;
|
|
||||||
try {
|
|
||||||
cl = clockTopic.take(); // just gets one
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {}
|
|
||||||
cl.print();
|
|
||||||
cl.clock.nsecs++;
|
|
||||||
clockTopic.unsubscribe();
|
|
||||||
clockTopic.advertise();
|
|
||||||
clockTopic.publish(cl);
|
|
||||||
clockTopic.unadvertise();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
|
|
||||||
public interface MessageHandler<T extends Message> {
|
|
||||||
public void onMessage(T message);
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.rosapi.message.TypeDef;
|
|
||||||
import com.jilk.ros.rosbridge.FullMessageHandler;
|
|
||||||
import com.jilk.ros.rosbridge.ROSBridgeClient;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Operation;
|
|
||||||
|
|
||||||
public abstract class ROSClient {
|
|
||||||
|
|
||||||
public ROSClient() {}
|
|
||||||
|
|
||||||
public static ROSClient create(String uriString) {
|
|
||||||
// if we ever implement other ROSClient types, we'll key off the URI protocol (e.g., ws://)
|
|
||||||
// we'd also have to abstract out Topic and Service since they depend on the ROSBridge operations
|
|
||||||
return new ROSBridgeClient(uriString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean connect();
|
|
||||||
public abstract boolean connect(ConnectionStatusListener listener);
|
|
||||||
public abstract void disconnect();
|
|
||||||
public abstract void send(Operation operation);
|
|
||||||
public abstract void send(String json);
|
|
||||||
public abstract void register(Class<? extends Operation> c,
|
|
||||||
String s,
|
|
||||||
Class<? extends Message> m,
|
|
||||||
FullMessageHandler h);
|
|
||||||
public abstract void unregister(Class<? extends Operation> c, String s);
|
|
||||||
public abstract void setDebug(boolean debug);
|
|
||||||
public abstract String[] getNodes() throws InterruptedException;
|
|
||||||
public abstract String[] getTopics() throws InterruptedException;
|
|
||||||
public abstract String[] getServices() throws InterruptedException;
|
|
||||||
public abstract TypeDef getTopicMessageDetails(String topic) throws InterruptedException;
|
|
||||||
public abstract TypeDef[] getTopicMessageList(String topic) throws InterruptedException;
|
|
||||||
public abstract TypeDef getServiceRequestDetails(String service) throws InterruptedException;
|
|
||||||
public abstract TypeDef[] getServiceRequestList(String service) throws InterruptedException;
|
|
||||||
public abstract TypeDef getServiceResponseDetails(String service) throws InterruptedException;
|
|
||||||
public abstract TypeDef[] getServiceResponseList(String service) throws InterruptedException;
|
|
||||||
public abstract TypeDef getTypeDetails(String type) throws InterruptedException;
|
|
||||||
public abstract TypeDef[] getTypeList(String type) throws InterruptedException;
|
|
||||||
public abstract void typeMatch(TypeDef t, Class<? extends Message> c) throws InterruptedException;
|
|
||||||
public abstract Object getUnderlyingClient(); // for debugging
|
|
||||||
|
|
||||||
public interface ConnectionStatusListener {
|
|
||||||
public void onConnect();
|
|
||||||
public void onDisconnect(boolean normal, String reason, int code);
|
|
||||||
public void onError(Exception ex);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.rosbridge.FullMessageHandler;
|
|
||||||
import com.jilk.ros.rosbridge.operation.CallService;
|
|
||||||
import com.jilk.ros.rosbridge.operation.ServiceResponse;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
public class Service<CallType extends Message, ResponseType extends Message> extends Message implements FullMessageHandler {
|
|
||||||
private String service;
|
|
||||||
private Class<? extends ResponseType> responseType;
|
|
||||||
private Class<? extends CallType> callType;
|
|
||||||
private ROSClient client;
|
|
||||||
private Map<String, CallRecord> calls;
|
|
||||||
|
|
||||||
public Service(String service, Class<? extends CallType> callType,
|
|
||||||
Class<? extends ResponseType> responseType, ROSClient client) {
|
|
||||||
this.service = service;
|
|
||||||
this.client = client;
|
|
||||||
this.responseType = responseType;
|
|
||||||
this.callType = callType;
|
|
||||||
calls = new HashMap<String, CallRecord>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// A result can only be returned once; it is cleared from the hash before
|
|
||||||
// being sent/returned. This is to ensure that results do not accumulate
|
|
||||||
// indefinitely. If callers need to keep these around they can set up their
|
|
||||||
// own hash.
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String id, Message response) {
|
|
||||||
//System.out.print("Service.onMessage: ");
|
|
||||||
//response.print();
|
|
||||||
CallRecord call = calls.get(id);
|
|
||||||
if(call == null) {
|
|
||||||
System.out.print("No caller service response");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (call.handler != null) {
|
|
||||||
calls.remove(id);
|
|
||||||
call.handler.onMessage((ResponseType) response);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
call.result = (ResponseType) response;
|
|
||||||
call.latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String call(CallType args) {
|
|
||||||
return callImpl(args, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void callWithHandler(CallType args, MessageHandler<ResponseType> responseHandler) {
|
|
||||||
callImpl(args, responseHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType callBlocking(CallType args) throws InterruptedException {
|
|
||||||
return take(call(args));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String callImpl(CallType args, MessageHandler<ResponseType> responseHandler) {
|
|
||||||
client.register(ServiceResponse.class, service, responseType, this); // do this once on creation?
|
|
||||||
CallService messageCallService = new CallService(service, args);
|
|
||||||
String id = messageCallService.id;
|
|
||||||
CallRecord callRecord = new CallRecord(responseHandler);
|
|
||||||
calls.put(id, callRecord);
|
|
||||||
client.send(messageCallService);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType poll(String id) {
|
|
||||||
CallRecord call = calls.get(id);
|
|
||||||
if (call.result != null)
|
|
||||||
calls.remove(id);
|
|
||||||
return call.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType take(String id) throws InterruptedException {
|
|
||||||
CallRecord call = calls.get(id);
|
|
||||||
call.latch.await();
|
|
||||||
calls.remove(id);
|
|
||||||
return call.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void verify() throws InterruptedException {
|
|
||||||
|
|
||||||
boolean hasService = false;
|
|
||||||
for (String s : client.getServices()) {
|
|
||||||
if (s.equals(service)) {
|
|
||||||
hasService = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasService)
|
|
||||||
throw new RuntimeException("Service \'" + service + "\' not available.");
|
|
||||||
|
|
||||||
client.typeMatch(client.getServiceRequestDetails(service), callType);
|
|
||||||
client.typeMatch(client.getServiceResponseDetails(service), responseType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CallRecord {
|
|
||||||
public ResponseType result;
|
|
||||||
public CountDownLatch latch;
|
|
||||||
public MessageHandler<ResponseType> handler;
|
|
||||||
|
|
||||||
public CallRecord(MessageHandler<ResponseType> handler) {
|
|
||||||
this.result = null;
|
|
||||||
this.latch = new CountDownLatch(1);
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,144 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.rosbridge.FullMessageHandler;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Advertise;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Operation;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Publish;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Subscribe;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Unadvertise;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Unsubscribe;
|
|
||||||
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
|
|
||||||
public class Topic<T extends Message> extends LinkedBlockingQueue<T> implements FullMessageHandler {
|
|
||||||
protected String topic;
|
|
||||||
private Class<? extends T> type;
|
|
||||||
private String messageType;
|
|
||||||
private ROSClient client;
|
|
||||||
private Thread handlerThread;
|
|
||||||
|
|
||||||
public Topic(String topic, Class<? extends T> type, ROSClient client) {
|
|
||||||
this.topic = topic;
|
|
||||||
this.client = client;
|
|
||||||
this.type = type;
|
|
||||||
messageType = Message.getMessageType(type);
|
|
||||||
handlerThread = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String id, Message message) {
|
|
||||||
add((T) message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// warning: there is a delay between the completion of this method and
|
|
||||||
// the completion of the subscription; it takes longer than
|
|
||||||
// publishing multiple other messages, for example.
|
|
||||||
public void subscribe(MessageHandler<T> handler) {
|
|
||||||
startRunner(handler);
|
|
||||||
subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void subscribe() {
|
|
||||||
client.register(Publish.class, topic, type, this);
|
|
||||||
send(new Subscribe(topic, messageType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unsubscribe() {
|
|
||||||
// need to handle race conditions in incoming message handler
|
|
||||||
// so that once unsubscribe has happened the handler gets no more
|
|
||||||
// messages
|
|
||||||
send(new Unsubscribe(topic));
|
|
||||||
client.unregister(Publish.class, topic);
|
|
||||||
stopRunner();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startRunner(MessageHandler<T> handler) {
|
|
||||||
stopRunner();
|
|
||||||
handlerThread = new Thread(new MessageRunner(handler));
|
|
||||||
handlerThread.setName("Message handler for " + topic);
|
|
||||||
handlerThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopRunner() {
|
|
||||||
if (handlerThread != null) {
|
|
||||||
handlerThread.interrupt();
|
|
||||||
clear();
|
|
||||||
handlerThread = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void advertise() {
|
|
||||||
send(new Advertise(topic, messageType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void publish(T message) {
|
|
||||||
send(new Publish(topic, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unadvertise() {
|
|
||||||
send(new Unadvertise(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void send(Operation operation) {
|
|
||||||
client.send(operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void verify() throws InterruptedException {
|
|
||||||
|
|
||||||
boolean hasTopic = false;
|
|
||||||
for (String s : client.getTopics()) {
|
|
||||||
if (s.equals(topic)) {
|
|
||||||
hasTopic = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasTopic)
|
|
||||||
throw new RuntimeException("Topic \'" + topic + "\' not available.");
|
|
||||||
|
|
||||||
client.typeMatch(client.getTopicMessageDetails(topic), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MessageRunner implements Runnable {
|
|
||||||
private MessageHandler<T> handler;
|
|
||||||
|
|
||||||
public MessageRunner(MessageHandler<T> handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (!Thread.interrupted()) {
|
|
||||||
try {
|
|
||||||
handler.onMessage(take());
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by xxhong on 16-11-17.
|
|
||||||
*/
|
|
||||||
@MessageType(string = "std_msgs/Int16MultiArray")
|
|
||||||
public class AudioMsg extends Message {
|
|
||||||
public short[] data;
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "rosgraph_msgs/Clock")
|
|
||||||
public class Clock extends Message {
|
|
||||||
public TimePrimitive clock;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "std_msgs/Duration")
|
|
||||||
public class Duration extends DurationPrimitive {
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "duration")
|
|
||||||
public class DurationPrimitive extends TimePrimitive {
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "std_srvs/Empty")
|
|
||||||
public class Empty extends Message {
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "std_msgs/Header")
|
|
||||||
public class Header extends Message {
|
|
||||||
public long seq;
|
|
||||||
public TimePrimitive stamp;
|
|
||||||
public String frame_id;
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "rosgraph_msgs/Log")
|
|
||||||
public class Log extends Message {
|
|
||||||
public Header header;
|
|
||||||
public byte level;
|
|
||||||
public String name;
|
|
||||||
public String msg;
|
|
||||||
public String file;
|
|
||||||
public String function;
|
|
||||||
public long line;
|
|
||||||
public String[] topics;
|
|
||||||
}
|
|
@ -1,202 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@MessageType(string = "message")
|
|
||||||
public abstract class Message {
|
|
||||||
|
|
||||||
// Some requirements about message types:
|
|
||||||
// - It must have a MessageType declaration to be recognized on inbound messages
|
|
||||||
// - Every field must be explicitly designated as public
|
|
||||||
// - Every field that is not a primitive or near-primitive must be another Message class
|
|
||||||
// - If there is a non-empty constructor, you must also have an empty constructor
|
|
||||||
// - If it is set up as an inner class, it needs an explicit nullary constructor
|
|
||||||
// (note: I have seen an inner class otherwise fail, I have not tested it with the explicit constructor)
|
|
||||||
|
|
||||||
public static void register(Class c, Map<String, Class> messageClasses) {
|
|
||||||
try {
|
|
||||||
typecheck(c);
|
|
||||||
|
|
||||||
// Must register the class and not have duplicate
|
|
||||||
// This is not recursive because only the top level message class
|
|
||||||
// needs to be determined from the string - others are top-down.
|
|
||||||
String messageString = getMessageType(c);
|
|
||||||
Class existingClass = messageClasses.get(messageString);
|
|
||||||
if (existingClass != null && !existingClass.equals(c))
|
|
||||||
throw new MessageException("Message String \'" + messageString +
|
|
||||||
"\' is assigned to two different classes (" +
|
|
||||||
c.getName() + " and " + existingClass.getName() + ")");
|
|
||||||
messageClasses.put(messageString, c);
|
|
||||||
}
|
|
||||||
catch (MessageException ex) {
|
|
||||||
// should be changed to be a hooked method to give library user control
|
|
||||||
System.out.println(ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMessageType(Class c) {
|
|
||||||
return ((MessageType) c.getAnnotation(MessageType.class)).string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// this has never been used or tested but kind of belongs here
|
|
||||||
// commented out because it uses ReflectiveOperationException which is not available on Android
|
|
||||||
/*
|
|
||||||
public static Message newInstance(String className) {
|
|
||||||
try {
|
|
||||||
Class messageClass = Class.forName(className);
|
|
||||||
if (Message.class.isAssignableFrom(messageClass))
|
|
||||||
return (Message) messageClass.newInstance();
|
|
||||||
else throw new ClassCastException();
|
|
||||||
}
|
|
||||||
catch (ReflectiveOperationException ex) {
|
|
||||||
throw new RuntimeException("Unable to create message of class \'" + className + "\'.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Could probably do more checking here, but not sure what right now
|
|
||||||
private static void typecheck(Class c) throws MessageException {
|
|
||||||
|
|
||||||
// Must inherit from Message
|
|
||||||
if (!Message.class.isAssignableFrom(c))
|
|
||||||
throw new MessageException("Class \'" + c.getName() +
|
|
||||||
"\' does not extend Message");
|
|
||||||
|
|
||||||
// Must have the MessageType annotation
|
|
||||||
if (getMessageType(c) == null)
|
|
||||||
throw new MessageException("Class \'" + c.getName() +
|
|
||||||
"\' is missing the MessageType annotation");
|
|
||||||
|
|
||||||
// All fields must also be valid Message classes
|
|
||||||
// Note that this also serves to force-load all the message classes
|
|
||||||
// so that they get registered
|
|
||||||
for (Field f : c.getFields()) {
|
|
||||||
Class fc = f.getType();
|
|
||||||
if (fc.isArray()) {
|
|
||||||
Class ac = fc.getComponentType();
|
|
||||||
if (!isPrimitive(ac))
|
|
||||||
typecheck(ac);
|
|
||||||
}
|
|
||||||
else if (!isPrimitive(fc))
|
|
||||||
typecheck(fc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void print() {
|
|
||||||
printMessage(this, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printMessage(Object o, String indent) {
|
|
||||||
for (Field f : o.getClass().getFields()) {
|
|
||||||
Class c = f.getType();
|
|
||||||
Object fieldObject = getFieldObject(f, o);
|
|
||||||
if (fieldObject != null) {
|
|
||||||
if (isPrimitive(c))
|
|
||||||
System.out.println(indent + f.getName() + ": " + fieldObject);
|
|
||||||
else if (c.isArray()) {
|
|
||||||
System.out.println(indent + f.getName() + ": [");
|
|
||||||
printArray(fieldObject, indent + " ");
|
|
||||||
System.out.println(indent + "]");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.out.println(indent + f.getName() + ":");
|
|
||||||
printMessage(fieldObject, indent + " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printArray(Object array, String indent) {
|
|
||||||
Class arrayClass = array.getClass().getComponentType();
|
|
||||||
for (int i = 0; i < Array.getLength(array); i++) {
|
|
||||||
Object elementObject = Array.get(array, i);
|
|
||||||
if (elementObject != null) {
|
|
||||||
if (isPrimitive(arrayClass))
|
|
||||||
System.out.println(indent + i + ": " + elementObject);
|
|
||||||
else if (arrayClass.isArray()) { // this is not actually allowed in ROS
|
|
||||||
System.out.println(indent + i + ": [");
|
|
||||||
printArray(elementObject, indent + " ");
|
|
||||||
System.out.println(indent + "]");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.out.println(indent + i + ":");
|
|
||||||
printMessage(elementObject, indent + " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// remember to print array indices
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isPrimitive(Class c) {
|
|
||||||
return (c.isPrimitive() ||
|
|
||||||
c.equals(String.class) ||
|
|
||||||
Number.class.isAssignableFrom(c) ||
|
|
||||||
c.equals(Boolean.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Copied from com.jilk.ros.rosbridge.JSON
|
|
||||||
private static Object getFieldObject(Field f, Object o) {
|
|
||||||
Object fo = null;
|
|
||||||
try {
|
|
||||||
fo = f.get(o);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return fo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyFrom(Message source) {
|
|
||||||
try {
|
|
||||||
if (source.getClass() != getClass())
|
|
||||||
throw new RuntimeException("Attempt to copy non-matching classes");
|
|
||||||
for (Field f : getClass().getFields()) {
|
|
||||||
Class fc = f.getType();
|
|
||||||
if (fc.isArray())
|
|
||||||
throw new RuntimeException("copyFrom - array types not implemented");
|
|
||||||
else if (!isPrimitive(fc))
|
|
||||||
((Message) f.get(this)).copyFrom((Message) f.get(source));
|
|
||||||
else {
|
|
||||||
Object value = f.get(source);
|
|
||||||
f.set(this, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException ex) {
|
|
||||||
throw new RuntimeException("copyFrom error", ex);
|
|
||||||
}
|
|
||||||
catch (ClassCastException ex) {
|
|
||||||
throw new RuntimeException("copyFrom error", ex);
|
|
||||||
}
|
|
||||||
// ReflectiveOperationException is not available on Android (Java 1.6)
|
|
||||||
/*
|
|
||||||
catch (ReflectiveOperationException ex) {
|
|
||||||
throw new RuntimeException ("copyFrom error", ex);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
public class MessageException extends Exception {
|
|
||||||
|
|
||||||
public MessageException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface MessageType {
|
|
||||||
String string() default "";
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by xxhong on 16-11-17.
|
|
||||||
*/
|
|
||||||
@MessageType(string = "std_msgs/String")
|
|
||||||
public class SemanticRequest extends Message {
|
|
||||||
public SemanticRequest(String args) {
|
|
||||||
jsonStr = args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String jsonStr;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by xxhong on 16-11-17.
|
|
||||||
*/
|
|
||||||
@MessageType(string = "std_msgs/String")
|
|
||||||
public class SemanticResponse extends Message {
|
|
||||||
public String result;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by xxhong on 16-11-17.
|
|
||||||
*/
|
|
||||||
@MessageType(string = "std_msgs/String")
|
|
||||||
public class StdMsg extends Message {
|
|
||||||
public String data;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "std_msgs/Time")
|
|
||||||
public class Time extends TimePrimitive {
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.message;
|
|
||||||
|
|
||||||
@MessageType(string = "time")
|
|
||||||
public class TimePrimitive extends Message {
|
|
||||||
public int secs; // when requesting this format from ROSbridge, it uses 'sec' (no 's')
|
|
||||||
public int nsecs; // when requesting this format from ROSbridge, it uses 'nsec'
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "std_msgs/Empty")
|
|
||||||
public class Empty extends Message {
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
import com.jilk.ros.message.TimePrimitive;
|
|
||||||
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/GetTimeResponse")
|
|
||||||
public class GetTime extends Message {
|
|
||||||
public TimePrimitive time;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/MessageDetails")
|
|
||||||
public class MessageDetails extends Message {
|
|
||||||
public TypeDef[] typedefs;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Nodes")
|
|
||||||
public class Nodes extends Message {
|
|
||||||
public String[] nodes;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Service")
|
|
||||||
public class Service extends Message {
|
|
||||||
public String service;
|
|
||||||
|
|
||||||
public Service() {}
|
|
||||||
|
|
||||||
public Service(String service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Services")
|
|
||||||
public class Services extends Message {
|
|
||||||
public String[] services;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Topic")
|
|
||||||
public class Topic extends Message {
|
|
||||||
public String topic;
|
|
||||||
|
|
||||||
public Topic() {}
|
|
||||||
|
|
||||||
public Topic(String topic) {
|
|
||||||
this.topic = topic;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Topics")
|
|
||||||
public class Topics extends Message {
|
|
||||||
public String[] topics;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/Type")
|
|
||||||
public class Type extends Message {
|
|
||||||
public String type;
|
|
||||||
|
|
||||||
public Type() {}
|
|
||||||
|
|
||||||
public Type(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosapi.message;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
|
|
||||||
@MessageType(string = "rosapi/TypeDef")
|
|
||||||
public class TypeDef extends Message {
|
|
||||||
public String type;
|
|
||||||
public String[] fieldnames;
|
|
||||||
public String[] fieldtypes;
|
|
||||||
public int[] fieldarraylen;
|
|
||||||
public String[] examples;
|
|
||||||
|
|
||||||
public static boolean match(String type, Class c) {
|
|
||||||
boolean result = false;
|
|
||||||
if (
|
|
||||||
(type.equals("bool") && ((boolean.class.equals(c)) || (Boolean.class.equals(c)))) ||
|
|
||||||
(type.equals("int8") && ((byte.class.equals(c)) || (Byte.class.equals(c)))) ||
|
|
||||||
(type.equals("byte") && ((byte.class.equals(c)) || (Byte.class.equals(c)))) || // deprecated
|
|
||||||
(type.equals("uint8") && ((short.class.equals(c)) || (Short.class.equals(c)))) ||
|
|
||||||
(type.equals("char") && ((short.class.equals(c)) || (Short.class.equals(c)))) || // deprecated
|
|
||||||
(type.equals("int16") && ((short.class.equals(c)) || (Short.class.equals(c)))) ||
|
|
||||||
(type.equals("uint16") && ((int.class.equals(c)) || (Integer.class.equals(c)))) ||
|
|
||||||
(type.equals("int32") && ((int.class.equals(c)) || (Integer.class.equals(c)))) ||
|
|
||||||
(type.equals("uint32") && ((long.class.equals(c)) || (Long.class.equals(c)))) ||
|
|
||||||
(type.equals("int64") && ((long.class.equals(c)) || (Long.class.equals(c)))) ||
|
|
||||||
(type.equals("float32") && ((float.class.equals(c)) || (Float.class.equals(c)))) ||
|
|
||||||
(type.equals("float64") && ((double.class.equals(c)) || (Double.class.equals(c)))) ||
|
|
||||||
(type.equals("uint64") && (java.math.BigInteger.class.equals(c))) ||
|
|
||||||
(type.equals("string") && (String.class.equals(c)))
|
|
||||||
)
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosbridge;
|
|
||||||
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
|
|
||||||
public interface FullMessageHandler<T extends Message> {
|
|
||||||
public void onMessage(String id, T message);
|
|
||||||
}
|
|
@ -1,260 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014 Jilk Systems, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of the Java ROSBridge Client.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Java ROSBridge Client is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the Java ROSBridge Client. If not, see http://www.gnu.org/licenses/.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.jilk.ros.rosbridge;
|
|
||||||
|
|
||||||
import com.jilk.ros.ROSClient;
|
|
||||||
import com.jilk.ros.Service;
|
|
||||||
import com.jilk.ros.message.Message;
|
|
||||||
import com.jilk.ros.message.MessageType;
|
|
||||||
import com.jilk.ros.rosapi.message.Empty;
|
|
||||||
import com.jilk.ros.rosapi.message.MessageDetails;
|
|
||||||
import com.jilk.ros.rosapi.message.Nodes;
|
|
||||||
import com.jilk.ros.rosapi.message.Services;
|
|
||||||
import com.jilk.ros.rosapi.message.Topic;
|
|
||||||
import com.jilk.ros.rosapi.message.Topics;
|
|
||||||
import com.jilk.ros.rosapi.message.Type;
|
|
||||||
import com.jilk.ros.rosapi.message.TypeDef;
|
|
||||||
import com.jilk.ros.rosbridge.implementation.ROSBridgeWebSocketClient;
|
|
||||||
import com.jilk.ros.rosbridge.operation.Operation;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class ROSBridgeClient extends ROSClient {
|
|
||||||
String uriString;
|
|
||||||
ROSBridgeWebSocketClient client;
|
|
||||||
|
|
||||||
public ROSBridgeClient(String uriString) {
|
|
||||||
this.uriString = uriString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean connect() {
|
|
||||||
return connect(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean connect(ROSClient.ConnectionStatusListener listener) {
|
|
||||||
boolean result = false;
|
|
||||||
client = ROSBridgeWebSocketClient.create(uriString);
|
|
||||||
if (client != null) {
|
|
||||||
client.setListener(listener);
|
|
||||||
try {
|
|
||||||
result = client.connectBlocking();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnect() {
|
|
||||||
try {
|
|
||||||
client.closeBlocking();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Operation operation) {
|
|
||||||
client.send(operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(String json) {
|
|
||||||
client.send(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(Class<? extends Operation> c,
|
|
||||||
String s,
|
|
||||||
Class<? extends Message> m,
|
|
||||||
FullMessageHandler h) {
|
|
||||||
client.register(c, s, m, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unregister(Class<? extends Operation> c, String s) {
|
|
||||||
client.unregister(c, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDebug(boolean debug) {
|
|
||||||
client.setDebug(debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getNodes() throws InterruptedException {
|
|
||||||
Service<Empty, Nodes> nodeService =
|
|
||||||
new Service<Empty, Nodes>("/rosapi/nodes", Empty.class, Nodes.class, this);
|
|
||||||
return nodeService.callBlocking(new Empty()).nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getTopics() throws InterruptedException {
|
|
||||||
Service<Empty, Topics> topicsService =
|
|
||||||
new Service<Empty, Topics>("/rosapi/topics", Empty.class, Topics.class, this);
|
|
||||||
return topicsService.callBlocking(new Empty()).topics;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getServices() throws InterruptedException {
|
|
||||||
Service<Empty, Services> servicesService =
|
|
||||||
new Service<Empty, Services>("/rosapi/services", Empty.class, Services.class, this);
|
|
||||||
return servicesService.callBlocking(new Empty()).services;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef getTopicMessageDetails(String topic) throws InterruptedException {
|
|
||||||
return getTypeDetails(getTopicType(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef[] getTopicMessageList(String topic) throws InterruptedException {
|
|
||||||
return getTypeList(getTopicType(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef getServiceRequestDetails(String service) throws InterruptedException {
|
|
||||||
return getTypeDetails(getServiceType(service), "Request", "/rosapi/service_request_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef[] getServiceRequestList(String service) throws InterruptedException {
|
|
||||||
return getTypeList(getServiceType(service), "Request", "/rosapi/service_request_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef getServiceResponseDetails(String service) throws InterruptedException {
|
|
||||||
return getTypeDetails(getServiceType(service), "Response", "/rosapi/service_response_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef[] getServiceResponseList(String service) throws InterruptedException {
|
|
||||||
return getTypeList(getServiceType(service), "Response", "/rosapi/service_response_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef[] getTypeList(String type) throws InterruptedException {
|
|
||||||
return getTypeList(type, "", "/rosapi/message_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeDef getTypeDetails(String type) throws InterruptedException {
|
|
||||||
return getTypeDetails(type, "", "/rosapi/message_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef[] getTypeList(String type, String suffix, String serviceName) throws InterruptedException {
|
|
||||||
Service<Type, MessageDetails> messageDetailsService =
|
|
||||||
new Service<Type, MessageDetails>(serviceName,
|
|
||||||
Type.class, MessageDetails.class, this);
|
|
||||||
return messageDetailsService.callBlocking(new Type(type)).typedefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef getTypeDetails(String type, String suffix, String serviceName) throws InterruptedException {
|
|
||||||
Service<Type, MessageDetails> messageDetailsService =
|
|
||||||
new Service<Type, MessageDetails>(serviceName,
|
|
||||||
Type.class, MessageDetails.class, this);
|
|
||||||
return findType(type + suffix, messageDetailsService.callBlocking(new Type(type)).typedefs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTopicType(String topic) throws InterruptedException {
|
|
||||||
Service<Topic, Type> topicTypeService =
|
|
||||||
new Service<Topic, Type>("/rosapi/topic_type",
|
|
||||||
Topic.class, Type.class, this);
|
|
||||||
return topicTypeService.callBlocking(new Topic(topic)).type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getServiceType(String service) throws InterruptedException {
|
|
||||||
Service<com.jilk.ros.rosapi.message.Service, Type> serviceTypeService =
|
|
||||||
new Service<com.jilk.ros.rosapi.message.Service, Type>("/rosapi/service_type",
|
|
||||||
com.jilk.ros.rosapi.message.Service.class, Type.class, this);
|
|
||||||
return serviceTypeService.callBlocking(new com.jilk.ros.rosapi.message.Service(service)).type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef findType(String type, TypeDef[] types) {
|
|
||||||
TypeDef result = null;
|
|
||||||
for (TypeDef t : types) {
|
|
||||||
if (t.type.equals(type)) {
|
|
||||||
result = t;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("ROSBridgeClient.findType: ");
|
|
||||||
//result.print();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void typeMatch(TypeDef t, Class<? extends Message> c) throws InterruptedException {
|
|
||||||
if (c == null)
|
|
||||||
throw new RuntimeException("No registered message type found for: " + t.type);
|
|
||||||
Field[] fields = c.getFields();
|
|
||||||
for (int i = 0; i < t.fieldnames.length; i++) {
|
|
||||||
|
|
||||||
// Field names
|
|
||||||
String classFieldName = fields[i].getName();
|
|
||||||
String typeFieldName = t.fieldnames[i];
|
|
||||||
if (!classFieldName.equals(typeFieldName))
|
|
||||||
typeMatchError(t, c, "field name", typeFieldName, classFieldName);
|
|
||||||
|
|
||||||
// Array type of field
|
|
||||||
boolean typeIsArray = (t.fieldarraylen[i] >= 0);
|
|
||||||
boolean fieldIsArray = fields[i].getType().isArray();
|
|
||||||
if (typeIsArray != fieldIsArray)
|
|
||||||
typeMatchError(t, c, "array mismatch", typeFieldName, classFieldName);
|
|
||||||
|
|
||||||
// Get base type of field
|
|
||||||
Class fieldClass = fields[i].getType();
|
|
||||||
if (fieldIsArray)
|
|
||||||
fieldClass = fields[i].getType().getComponentType();
|
|
||||||
String type = t.fieldtypes[i];
|
|
||||||
|
|
||||||
// Field type for primitivesclient
|
|
||||||
if (Message.isPrimitive(fieldClass)) {
|
|
||||||
if (!TypeDef.match(type, fieldClass))
|
|
||||||
typeMatchError(t, c, "type mismatch", type, fieldClass.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Field type for non-primitive classes, and recurse
|
|
||||||
else {
|
|
||||||
if (!Message.class.isAssignableFrom(fieldClass))
|
|
||||||
throw new RuntimeException("Member " + classFieldName +
|
|
||||||
" of class " + fieldClass.getName() + " does not extend Message.");
|
|
||||||
String fieldClassString = ((MessageType) fieldClass.getAnnotation(MessageType.class)).string();
|
|
||||||
if (!type.equals(fieldClassString))
|
|
||||||
typeMatchError(t, c, "message type mismatch", type, fieldClassString);
|
|
||||||
typeMatch(getTypeDetails(type), fieldClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void typeMatchError(TypeDef t, Class<? extends Message> c,
|
|
||||||
String error, String tString, String cString) {
|
|
||||||
throw new RuntimeException("Type match error between " +
|
|
||||||
t.type + " and " + c.getName() + ": " +
|
|
||||||
error + ": \'" + tString + "\' does not match \'" + cString + "\'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getUnderlyingClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|