更新代码 #30

Merged
meickrq7f merged 3 commits from dev into master 3 years ago

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 98 KiB

@ -7,11 +7,11 @@
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="D:\AndroidSDK\.android\.android\avd\Pixel_2_API_31.avd" />
<value value="E:\SDK\avd\.android\avd\Pixel_XL_API_30.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-06-14T12:27:15.523840400Z" />
<timeTargetWasSelectedWithDropDown value="2022-07-10T02:39:23.302314100Z" />
</component>
</project>

@ -30,7 +30,7 @@
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/my_fragment1.xml" value="0.1" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/my_fragment2.xml" value="0.18489583333333334" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/my_fragment3.xml" value="0.2" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/pickup.xml" value="0.5" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/pickup.xml" value="0.1" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/tab1.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/top.xml" value="0.3717105263157895" />
<entry key="..\:/无人物流/xcr_se/src/Logistics/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.1" />

@ -2,10 +2,11 @@ package com.example.logistics.entity;
public class Good {
private int id;
private String phoneNum;
private int shelfNum;
private int floorNum;
private String time;
private String phoneNum;//货主手机号
private int shelfNum;//货架号
private int floorNum;//货架层号
private String time;//入库时间
public Good(){

@ -4,9 +4,9 @@ import android.provider.ContactsContract;
public class Operation {
private int id;
private String pickUpCode;
private String phoneNum;
private String time;
private String pickUpCode;//取件码
private String phoneNum;//货主手机号
private String time;//取件时间
public Operation(){

@ -2,9 +2,9 @@ package com.example.logistics.entity;
public class User {
private int userId;
private String userName;
private String passWord;
private String phoneNum;
private String userName;//用户名
private String passWord;//密码
private String phoneNum;//手机吗
public User(){

@ -25,24 +25,23 @@ public class goodManager {
Log.d(TAG, "search");
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
Connection connection = DBOpenHelper.getConn();//DBO连接数据库
int msg = 0;
try{
Log.d(TAG, "select goods");
String sql = "select * from goods where id = ?";
String sql = "select * from goods where id = ?";//搜索指定取件码(=id号的快件信息
if(connection != null){
Log.d(TAG, "connection!");
PreparedStatement ps = connection.prepareStatement(sql);
if(ps != null){
Log.e(TAG, "id: " + id);
ps.setInt(1,Integer.parseInt(id));
ResultSet rs = ps.executeQuery();
ps.setInt(1,Integer.parseInt(id));//设置sql语句中id号
ResultSet rs = ps.executeQuery();//执行sql语句并返回结果到rs
int count = rs.getMetaData().getColumnCount();
while(rs.next()){
while(rs.next()){//遍历返回结果加入map中
for(int i = 1; i <= count; i++){
String field = rs.getMetaData().getColumnName(i);
map.put(field, rs.getString(field));
@ -53,14 +52,14 @@ public class goodManager {
if(map.size() != 0){
Log.d(TAG, "map isnot null");
StringBuilder s = new StringBuilder();
for(String key:map.keySet()){
if(key.equals("phonenum")){
for(String key:map.keySet()){//搜索map中的key值
if(key.equals("phonenum")){//搜索phonenum属性
String strphone = String.valueOf(map.get(key));
Log.d(TAG, strphone);
if(phonenum.equals(strphone.substring(7,11))){
if(phonenum.equals(strphone.substring(7,11))){//如果手机尾号后四位相等
msg = 1; //phonenum correct
Log.d(TAG, "phonenum correct");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context);//弹出快件位置信息
builder.setTitle("快件位置");
builder.setMessage("\n第 "+ map.get("shelfnum")+ " 号货架\n第 " + map.get("floornum")+ " 层");
Looper.prepare();
@ -89,13 +88,14 @@ public class goodManager {
e.printStackTrace();
Log.d(TAG, "search bug: " + e.getMessage());
msg = 0;
} finally {
}
return msg;
}
public boolean delete(String pickupcode){
public boolean delete(String pickupcode){//根据取件码删除快递
Connection connection = DBOpenHelper.getConn();
try{
@ -107,9 +107,9 @@ public class goodManager {
PreparedStatement ps = connection.prepareStatement(sql);
if(ps != null){
Log.e(TAG, "pickupcode: " + pickupcode);
ps.setString(1,pickupcode);
ps.setString(1,pickupcode);//设置参数
ps.executeUpdate();
ps.executeUpdate();//删除操作
connection.close();
ps.close();
@ -132,7 +132,7 @@ public class goodManager {
return false;
}
public List<Map<String, Object>> nopick(String phonenum){
public List<Map<String, Object>> nopick(String phonenum){//根据手机号查询未取的件
Connection connection = DBOpenHelper.getConn();
Log.d(TAG, "nopick goods");
@ -167,7 +167,7 @@ public class goodManager {
map.put(field, rs.getString(field));
}
}
datalist.add(map);
datalist.add(map);//加入即将显示的列表中
}
connection.close();
ps.close();
@ -186,7 +186,7 @@ public class goodManager {
return datalist;
}
public int pickup(String pickupcode, String phonenum){
public int pickup(String pickupcode, String phonenum){//根据取件码与手机号取件
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
@ -202,7 +202,7 @@ public class goodManager {
if(ps != null){
Log.e(TAG, "pickupcode: " + pickupcode);
ps.setInt(1,Integer.parseInt(pickupcode));
ResultSet rs = ps.executeQuery();
ResultSet rs = ps.executeQuery();//获取要取的件信息
int count = rs.getMetaData().getColumnCount();
while(rs.next()){
@ -213,12 +213,12 @@ public class goodManager {
}
connection.close();
ps.close();
if(map.size() != 0){
if(map.size() != 0){//如果找不到对应快件
Log.d(TAG, "map has value");
StringBuilder s = new StringBuilder();
for(String key:map.keySet()){
if(key.equals("phonenum")){
if(phonenum.equals(map.get(key).toString().substring(7,11))){
if(phonenum.equals(map.get(key).toString().substring(7,11))){//如果手机尾号相等
msg = 1; //password correct
}else{
msg = 2; //password incorrect

@ -17,19 +17,17 @@ import java.util.Map;
public class operationManager {
private static final String TAG = "operationManager";
public boolean add(String pickupcode, String phonenum){
public boolean add(String pickupcode, String phonenum){//根据取件码与手机号添加操作记录
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
try{
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
Log.d(TAG, "add");
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");//时间格式
Date date = new Date();
String time = format1.format(date);
String time = format1.format(date);//时间格式字符串化
String sql = "insert into operations(pickupcode, phonenum, time) values (?,?,?)";
if(connection != null){
PreparedStatement ps = connection.prepareStatement(sql);
@ -59,13 +57,16 @@ public class operationManager {
}
}
public List<Map<String, Object>> history(String phonenum){
public List<Map<String, Object>> history(String phonenum){//根据手机号查询历史记录
Connection connection = DBOpenHelper.getConn();
List<Map<String, Object>> datalist;
List<Map<String, Object>> datalist;//查询结果显示列表
datalist = new ArrayList<Map<String, Object>>();
try{
Log.d(TAG, "history");
String sql = "select * from operations where phonenum = ?";
if(connection != null){

@ -16,13 +16,16 @@ public class userManager {
private static final String TAG = "userManager";
public int login(String username, String password){
public int login(String username, String password){//根据用户名与密码登录
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
int msg = 0;
try{
Log.d(TAG, "login");
String sql = "select * from users where username = ?";
if(connection != null){
@ -41,16 +44,16 @@ public class userManager {
}
connection.close();
ps.close();
password = MD5Utils.md5(password);
password = MD5Utils.md5(password);//密码md5加密
if(map.size() != 0){
StringBuilder s = new StringBuilder();
for(String key:map.keySet()){
if(key.equals("password")){
if(key.equals("password")){//查看password属性
if(password.equals(map.get(key))){
msg = 1; //password correct
msg = 1; //密码正确
}else{
msg = 2; //password incorrect
msg = 2; //密码错误
}
break;
}
@ -68,22 +71,27 @@ public class userManager {
msg = 0;
}
}catch (Exception e){
e.printStackTrace();
Log.d(TAG, "login bug: " + e.getMessage());
msg = 0;
} finally {
}
return msg;
}
public int loginByPhone(String phonenum, String password){
public int loginByPhone(String phonenum, String password){//通过手机号登录
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
int msg = 0;
try{
Log.d(TAG, "loginByPhone");
String sql = "select * from users where phonenum = ?";
if(connection != null){
@ -102,6 +110,7 @@ public class userManager {
}
connection.close();
ps.close();
password = MD5Utils.md5(password);
if(map.size() != 0){
StringBuilder s = new StringBuilder();
@ -138,11 +147,14 @@ public class userManager {
return msg;
}
public User findUser(String username){
public User findUser(String username){//查看是否已有该用户
Connection connection = DBOpenHelper.getConn();
User user = null;
try{
Log.d(TAG, "findUser");
String sql = "select * from users where username = ?";
if(connection != null){
PreparedStatement ps = connection.prepareStatement(sql);
@ -156,7 +168,7 @@ public class userManager {
String passWord = rs.getString(3);
String phoneNum = rs.getString(4);
user = new User(userId, userName, passWord, phoneNum);
user = new User(userId, userName, passWord, phoneNum);//若已有用户,生成用户类并返回
}
}
}
@ -168,11 +180,14 @@ public class userManager {
return user;
}
public boolean register(User user){
public boolean register(User user){//注册功能
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
try{
Log.d(TAG, "register");
String sql = "insert into users(username, password, phonenum) values (?,?,?)";
if(connection != null){
@ -204,13 +219,16 @@ public class userManager {
}
}
public int change(String phonenum, String password){
public int change(String phonenum, String password){//修改密码
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
int msg = 0;
try{
Log.d(TAG, "change");
String sql = "update users set password = ? where phonenum = ?";
if(connection != null){

@ -7,9 +7,9 @@ import java.sql.SQLException;
public class DBOpenHelper {
private static String diver = "com.mysql.jdbc.Driver";
//加入utf-8是为了后面往表中输入中文表中不会出现乱码的情况
private static String url = "jdbc:mysql://192.168.43.139:3306/logistics?characterEncoding=utf-8";
private static String url = "jdbc:mysql://192.168.43.203:3306/logistics?characterEncoding=utf-8";
private static String user = "root";//用户名
private static String password = "123...iamfan";//密码
private static String password = "";//密码
/*
*
* */

@ -19,7 +19,7 @@ import androidx.fragment.app.Fragment;
import com.example.logistics.R;
import com.example.logistics.manager.goodManager;
//查询快件存放地
public class FindUI extends Fragment implements View.OnClickListener{
private String TAG = "FindUI";
@ -37,8 +37,9 @@ public class FindUI extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
View view = inflater.inflate(R.layout.my_fragment1,container,false);
Log.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.frag_find,container,false);
mButton = (Button)view.findViewById(R.id.Sea_Button);
mPickUpCode = (EditText)view.findViewById(R.id.Sea_PickUpCode);
@ -67,7 +68,7 @@ public class FindUI extends Fragment implements View.OnClickListener{
@Override
public void run(){
goodManager goodManager = new goodManager();
int msg = goodManager.search(mPickUpCode.getText().toString().trim(), mPhoneNum.getText().toString().trim(), getActivity());
int msg = goodManager.search(mPickUpCode.getText().toString().trim(), mPhoneNum.getText().toString().trim(), getActivity());//查询快件位置并返回结果
Log.e("Main", "msg");
hand1.sendEmptyMessage(msg);
}
@ -78,6 +79,7 @@ public class FindUI extends Fragment implements View.OnClickListener{
final Handler hand1 = new Handler(){
@Override
public void handleMessage(Message msg){
if(msg.what == 0){
Toast.makeText(mContext, "搜索失败", Toast.LENGTH_SHORT).show();
}else if(msg.what == 2){
@ -85,6 +87,7 @@ public class FindUI extends Fragment implements View.OnClickListener{
}else if(msg.what == 3){
Toast.makeText(mContext, "取件码不存在", Toast.LENGTH_SHORT).show();
}
}
};
}

@ -28,6 +28,7 @@ import java.util.Map;
public class HistoryUI extends Activity implements OnItemClickListener, OnScrollListener, View.OnClickListener {
private String TAG = "HistoryUI";
//绑定界面元素
private ListView lv_history;
private ArrayAdapter<String> arr_adapter;
private SimpleAdapter simp_adapter;
@ -37,6 +38,9 @@ public class HistoryUI extends Activity implements OnItemClickListener, OnScroll
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
sync_his = (ImageButton) findViewById(R.id.sync_his);
@ -52,6 +56,7 @@ public class HistoryUI extends Activity implements OnItemClickListener, OnScroll
Intent intent = getIntent();
phonenum = intent.getStringExtra("user");
Log.d(TAG, "onCreate");
sync();
}
@ -66,12 +71,12 @@ public class HistoryUI extends Activity implements OnItemClickListener, OnScroll
public void onClick(View v){
switch(v.getId()){
case R.id.sync_his:
sync();
sync();//调用同步按钮同步记录
Toast.makeText(this, "同步成功", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState){
public void onScrollStateChanged(AbsListView view, int scrollState){//上下划动屏幕查看操作记录
// TODO Auto-generated method stub
switch(scrollState){
case SCROLL_STATE_FLING:
@ -94,11 +99,14 @@ public class HistoryUI extends Activity implements OnItemClickListener, OnScroll
}
public void sync(){
Log.d(TAG, "sync");
new Thread(){
@Override
public void run(){
operationManager operationManager = new operationManager();
dataList = operationManager.history(phonenum);
dataList = operationManager.history(phonenum);//调用operationManager的查询历史记录
int msg = 1;
hand1.sendEmptyMessage(msg);

@ -20,7 +20,7 @@ import android.widget.Toast;
public class LoginUI extends Activity {
private int islogin = 0;
private Button loginButton;
private Button signUpButton;
private Button forgetButton;
@ -29,6 +29,8 @@ public class LoginUI extends Activity {
private Button changeButton;
private EditText fphonenum;
private EditText fpassword;
private int islogin = 0;
int flag = 0; //flag = 0 是用户名登录;=1是手机号
// 调用Actvity
@ -36,19 +38,20 @@ public class LoginUI extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_login);
loginButton = (Button) this.findViewById(R.id.LoginButton);
signUpButton = (Button) this.findViewById(R.id.SignUpButton);
forgetButton = (Button) this.findViewById(R.id.forget);
phonenumButton = (Button) this.findViewById(R.id.phonenum);
//设置对话框引用Activity对象
AlertDialog.Builder builder = new AlertDialog.Builder(LoginUI.this);
//使用别的layout
View view2 = View.inflate(LoginUI.this, R.layout.forget, null);
builder.setTitle("取件").setView(view2);
builder.setTitle("忘记密码").setView(view2);
alert = builder.create();
@ -100,6 +103,7 @@ public class LoginUI extends Activity {
new View.OnClickListener() {
@Override
public void onClick(View view) {
//输入提示
userName.setHint("请输入手机号");
flag = 1;
}
@ -109,18 +113,22 @@ public class LoginUI extends Activity {
}
public void change(View view){
//trim() 方法用于删除字符串的头尾空白符,空白符包括:空格、制表符 tab、换行符等其他空白符等。
String phoneunm = fphonenum.getText().toString().trim();
String password = fpassword.getText().toString().trim();
new Thread() {
@Override
public void run() {
//后端用来和数据库交互
userManager userManager = new userManager();
//msg=0代表操作成功
int msg = userManager.change(phoneunm, password);
Log.d(TAG, "change");
if(msg != 1){
Log.d(TAG, "pickup,failed");
//处理异步消息int类型的msg最终会转化为hander的msg类型
hand2.sendEmptyMessage(msg);
return;
}
@ -132,6 +140,8 @@ public class LoginUI extends Activity {
}
public void login(View view){
Log.d(TAG, "login");
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
@ -148,10 +158,12 @@ public class LoginUI extends Activity {
}
Log.e("MAin", "msg");
hand1.sendEmptyMessage(msg);
//msg==1表示登录成功
if(msg == 1){
User owner = userManager.findUser(userName.getText().toString().trim());
Intent intent = new Intent(LoginUI.this, MenuActivity.class);
if(flag == 1){
//不同activity之间传递数据
intent.putExtra("user", userName.getText().toString().trim());
}else{
intent.putExtra("user", owner.getPhoneNum());

@ -1,5 +1,4 @@
package com.example.logistics.ui;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
@ -18,71 +17,73 @@ import com.example.logistics.R;
public class MenuActivity extends AppCompatActivity implements View.OnClickListener{
private String TAG = "MenuActivity";
private LinearLayout ly_one,ly_two,ly_three;
private TextView mTextView1,mTextView2,mTextView3;
private TextView mTextNum1,mTextNum2,mTextNum3;
private ImageView mImageView;
private LinearLayout ly_one,ly_two,ly_three; //线性布局变量
private TextView mTextView1,mTextView2,mTextView3; //文本框变量
private TextView mTextNum1,mTextNum2,mTextNum3; //第二类文本框变量
private ImageView mImageView; //图像视图变量
//创建一系列成员变量:
private Fragment mFrag1;
private Fragment mFrag2;
private Fragment mFrag3;
//创建Frag变量
private String owner;
private String owner; //唯一标识用户
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
super.onCreate(savedInstanceState); //调用父类的构造函数
setContentView(R.layout.activity_menu); //将类和布局文件绑定
bindView();
bindView(); //调用bindView()
Intent intent = getIntent();
owner = intent.getStringExtra("user");
selectTab(0);
}
} //类的构造函数
private void bindView() {
ly_one = (LinearLayout)findViewById(R.id.ly_tab_menu_deal);
ly_two = (LinearLayout)findViewById(R.id.ly_tab_menu_poi);
ly_three = (LinearLayout)findViewById(R.id.ly_tab_menu_more);
ly_three = (LinearLayout)findViewById(R.id.ly_tab_menu_more); //把三个布局绑定到布局变量上
mTextView1 = (TextView)findViewById(R.id.tab_menu_deal);
mTextView2 = (TextView)findViewById(R.id.tab_menu_poi);
mTextView3 = (TextView)findViewById(R.id.tab_menu_more);
mTextView3 = (TextView)findViewById(R.id.tab_menu_more); //把三个文本框绑定到变量上
mTextNum1 = (TextView)findViewById(R.id.tab_menu_deal_num);
mTextNum2 = (TextView)findViewById(R.id.tab_menu_poi_num);
mTextNum3 = (TextView)findViewById(R.id.tab_menu_more_num);
mTextNum3 = (TextView)findViewById(R.id.tab_menu_more_num); //把三个第二类文本框绑定到变量上
ly_one.setOnClickListener(this);
ly_two.setOnClickListener(this);
ly_three.setOnClickListener(this);
}
ly_three.setOnClickListener(this); //监听器:点击三个区域绑定三个功能
} //绑定变量和布局元素
//重置所有文本的选中状态
//重置所有文本的选中状态
private void setSelected() {
mTextView1.setSelected(false);
mTextView2.setSelected(false);
mTextView3.setSelected(false);
}
} //每次选中一按钮,先全设为未选中
@Override
public void onClick(View v) {
setSelected();
public void onClick(View v) { //点击某区域实现某功能
setSelected(); //全部设为未选中
switch (v.getId()) {
case R.id.ly_tab_menu_deal:
selectTab(0);
case R.id.ly_tab_menu_deal: //倘若点到这个id对应的
selectTab(0); //使第一个标签变蓝色
break;
case R.id.ly_tab_menu_poi:
selectTab(1);
break;
case R.id.ly_tab_menu_more:
selectTab(2);
break;
break; //分析已点击区域对应的功能
}
}

@ -52,23 +52,31 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
private int shelfnum = 1;
private int floornum = 1;
//后端服务器
private String ws = "ws://192.168.43.203:8080/result";
private String TAG = "PickUpUI";
int flag = 0; //flag=0:chushi
//flag = 0 代表mbutton为取件flag = 1 代表mbutton为确认
int flag = 0;
public PickUpUI(){
}
//这个注解通常用于消除空指针异常
@Nullable
//用来指定方法重写的,只能修饰方法并且只能用于方法重写,不能修饰其它的元素。它可以强制一个子类必须重写父类方法或者实现接口的方法。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment2,container,false);
View view = inflater.inflate(R.layout.pickup,container,false);
mButton = (Button)view.findViewById(R.id.Pick_Button);
mButton.setOnClickListener(this);
//获得Fragment依附的Activity对象
mContext = getActivity();
Log.i("set", "listner");
@ -78,6 +86,8 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
}
void setAlert(){
alert = new android.app.AlertDialog.Builder(mContext)
.setTitle("提醒")
@ -93,8 +103,6 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
js.put("op", "confirm");
} catch (JSONException e) {
e.printStackTrace();
} finally {
}
flag = 1;
@ -111,12 +119,10 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
JSONObject js = new JSONObject();
try {
js.put("confirm", "no");
js.put("content", "no");
js.put("op", "confirm");
} catch (JSONException e) {
e.printStackTrace();
} finally {
}
client.send(js.toString());
@ -126,53 +132,7 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
Log.d(TAG, "setAlert");
}
void setWebsocket(){
URI uri = URI.create(ws);
client = new JWebSocketClient(uri){
@Override
public void onMessage(String message) {
Log.e("JWebSocketClientService", "收到的消息:" + message);
Log.e("alert",message);
if(message.equals("confirm")){
alert.dismiss();
hand2.sendEmptyMessage(3);
Log.e("alert","show");
}
}
@Override
public void onOpen(ServerHandshake handshakedata) {
super.onOpen(handshakedata);
Log.e("JWebSocketClientService", "websocket连接成功");
};
};
connect();
}
private void connect() {
new Thread() {
@Override
public void run() {
try {
//connectBlocking多出一个等待操作会先连接再发送否则未连接发送会报错
client.connectBlocking();
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
}
}
}.start();
}
@SuppressLint("HandlerLeak")
final Handler hand2 = new Handler(){
@Override
public void handleMessage(Message msg){
alert.show();
}
};
@Override
public void onClick(View view) {
@ -189,23 +149,7 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
}
}
void confirm(){
JSONObject js = new JSONObject();
try {
js.put("op","finish");
client.send(js.toString());
flag = 0;
mButton.setText("取件");
client.onClose(1,"close",true);
Log.d("finish", "over");
} catch (JSONException jsonException) {
jsonException.printStackTrace();
} finally {
}
}
public void pickup(){
@ -214,6 +158,7 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
View view2 = View.inflate(mContext, R.layout.pickup, null);
PickUpCode = (EditText) view2.findViewById(R.id.pk_PickUp);
//尾号后四位
PhoneNum = (EditText) view2.findViewById(R.id.pk_PhoneNum);
Button button = (Button) view2.findViewById(R.id.pk_button);
@ -236,6 +181,8 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
operationManager operationManager = new operationManager();
goodManager goodManager = new goodManager();
//获取menuactivity传来的值
Bundle bundle = getArguments();
String user = bundle.getString("user");
@ -254,12 +201,9 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
boolean flag1 = operationManager.add(pickupcode, user);
boolean flag2 = goodManager.delete(pickupcode);
if (!flag1) {
msg = 2;
}
if(!flag2){
msg = 3;
boolean flag = flag1 & flag2;
if (flag) {
msg = 1;
}
hand1.sendEmptyMessage(msg);
@ -269,6 +213,81 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
});
}
void confirm(){
JSONObject js = new JSONObject();
try {
js.put("op","finish");
client.send(js.toString());
flag = 0;
mButton.setText("取件");
client.onClose(1,"close",true);
Log.d("finish", "over");
} catch (JSONException jsonException) {
jsonException.printStackTrace();
}
}
void setWebsocket(){
URI uri = URI.create(ws);
client = new JWebSocketClient(uri){
//onMessage()方法在接收到消息时调用
@Override
public void onMessage(String message) {
Log.e("JWebSocketClientService", "收到的消息:" + message);
Log.e("alert",message);
if(message.equals("confirm")){
alert.dismiss();
hand2.sendEmptyMessage(3);
Log.e("alert","show");
}
}
//onOpen()方法在websocket连接开启时调用
@Override
public void onOpen(ServerHandshake handshakedata) {
super.onOpen(handshakedata);
Log.e("JWebSocketClientService", "websocket连接成功");
}
};
connect();
}
private void connect() {
new Thread() {
@Override
public void run() {
try {
//connectBlocking多出一个等待操作会先连接再发送否则未连接发送会报错
client.connectBlocking();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
@SuppressLint("HandlerLeak")
final Handler hand2 = new Handler(){
@Override
public void handleMessage(Message msg){
alert.show();
}
};
@SuppressLint("HandlerLeak")
final Handler hand1 = new Handler() {
@Override
@ -279,9 +298,9 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
Toast.makeText(mContext, "加入队列成功", Toast.LENGTH_SHORT).show();
joinQueue();
}else if(msg.what == 2){
Toast.makeText(mContext, "出库失败", Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "手机号错误", Toast.LENGTH_SHORT).show();
}else if(msg.what == 3){
Toast.makeText(mContext, "保存记录失败", Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "取件码不存在", Toast.LENGTH_SHORT).show();
}
}
};
@ -296,6 +315,7 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
Log.d(TAG, pickupcode);
Log.d(TAG, phonenum);
//将整型数据Integer转换为基本数据类型int
con.put("code", Integer.parseInt(pickupcode));
con.put("shelf", shelfnum);
con.put("floor", floornum);
@ -304,8 +324,6 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
js.put("op", "connect");
} catch (JSONException jsonException) {
jsonException.printStackTrace();
} finally {
}
if (null != client) {

@ -25,10 +25,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SearchUI extends Activity implements OnItemClickListener, OnScrollListener, View.OnClickListener {
public class SearchUI extends Activity implements OnItemClickListener, OnScrollListener, View.OnClickListener {//查询未取快件
private String TAG = "SearchUI";
//绑定界面元素
private ListView lv_nopick;
private ArrayAdapter<String> arr_adapter;
private SimpleAdapter simp_adapter;
@ -38,8 +38,11 @@ public class SearchUI extends Activity implements OnItemClickListener, OnScrollL
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_no_pick);
setContentView(R.layout.activity_search);
dataList=new ArrayList<Map<String,Object>>();
lv_nopick = (ListView) findViewById(R.id.lv_nopick);
@ -54,7 +57,7 @@ public class SearchUI extends Activity implements OnItemClickListener, OnScrollL
Intent intent = getIntent();
phonenum = intent.getStringExtra("user");
sync();
sync();//同步未取快件信息
}
@Override
@ -97,11 +100,14 @@ public class SearchUI extends Activity implements OnItemClickListener, OnScrollL
}
public void sync(){
Log.d(TAG, "sync");
new Thread(){
@Override
public void run(){
goodManager goodManager = new goodManager();
dataList = goodManager.nopick(phonenum);
dataList = goodManager.nopick(phonenum);//掉用goodManager的查询未取件函数
int msg = 1;
hand1.sendEmptyMessage(msg);

@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -18,7 +19,7 @@ import com.example.logistics.R;
public class SetUI extends Fragment implements View.OnClickListener{
private String TAG = "SetUI";
//绑定界面元素
private LinearLayout ll_waiting;
private LinearLayout ll_history;
private LinearLayout ll_exit;
@ -32,7 +33,10 @@ public class SetUI extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment3,container,false);
Log.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.frag_set,container,false);
ll_waiting = (LinearLayout) view.findViewById(R.id.waiting);
ll_history = (LinearLayout) view.findViewById(R.id.history);
@ -54,20 +58,22 @@ public class SetUI extends Fragment implements View.OnClickListener{
public void onClick(View view) {
Intent intent;
switch(view.getId()){
case R.id.waiting:
case R.id.waiting://跳转到未取件界面
Log.d(TAG, "waiting");
intent = new Intent(mContext, SearchUI.class);
intent.putExtra("user", user);
intent.putExtra("user", user);//将用户信息一并发过去
startActivity(intent);
break;
case R.id.history:
case R.id.history://跳转到历史记录界面
Log.d(TAG, "history");
intent = new Intent(mContext, HistoryUI.class);
intent.putExtra("user", user);
intent.putExtra("user", user);//将用户信息一并发过去
startActivity(intent);
break;
case R.id.exit:
case R.id.exit://跳转到退出登录界面
Log.d(TAG, "exit");
Toast.makeText(mContext, "exit", Toast.LENGTH_SHORT).show();
intent = new Intent(mContext, LoginUI.class);
intent = new Intent(mContext, LoginUI.class);//跳转到loginUI类
startActivity(intent);
getActivity().finish();
break;

@ -6,7 +6,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -16,38 +15,35 @@ import com.example.logistics.R;
import com.example.logistics.manager.userManager;
import com.example.logistics.entity.User;
//signup UI
//UI from android
public class SignUpUI extends Activity {
private String TAG = "SignUpUI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
Button signUpButton = (Button) this.findViewById(R.id.SignUpButton);
Button backLoginButton = (Button) this.findViewById(R.id.BackLoginButton);
//注册按钮
signUpButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "SignUp:onClick");
register(v);
}
}
);
//返回按钮
// 返回登录按钮监听器
backLoginButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// 跳转到登录界面
Log.d(TAG, "BackLogin:onClick");
// 建立;跳转
Intent intent = new Intent(SignUpUI.this, LoginUI.class);
//执行
startActivity(intent);
}
}
@ -55,48 +51,32 @@ public class SignUpUI extends Activity {
}
public void register(View view){
Log.d(TAG, "register");
public void register(View view){
//获取
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
EditText passWordAgain = (EditText) this.findViewById(R.id.PassWordAgainEdit);
EditText phone = (EditText) this.findViewById(R.id.PhoneEdit);
//编辑
String strUserName = userName.getText().toString().trim();
String strPassWord = passWord.getText().toString().trim();
String strPassWordAgain = passWordAgain.getText().toString().trim();
String strPhoneNumber = phone.getText().toString().trim();
//输入判断
if (strUserName.length() > 10) {
Log.d(TAG, "username out of length");
Toast.makeText(SignUpUI.this, "用户名长度必须小于10", Toast.LENGTH_SHORT).show();
} else if (strUserName.length() == 0) {
Log.d(TAG, "username is none");
Toast.makeText(SignUpUI.this, "用户名不能为空!", Toast.LENGTH_SHORT).show();
} else if (strPassWord.length() > 16) {
Log.d(TAG, "password out of length");
Toast.makeText(SignUpUI.this, "密码长度必须小于16", Toast.LENGTH_SHORT).show();
} else if (strPassWord.length() == 0) {
Log.d(TAG, "password is none");
Toast.makeText(SignUpUI.this, "密码不能为空!", Toast.LENGTH_SHORT).show();
} else if (!strPassWord.equals(strPassWordAgain)) {
Log.d(TAG, "password is not same");
Toast.makeText(SignUpUI.this, "两次密码输入不一致!", Toast.LENGTH_SHORT).show();
} else {
Log.d(TAG, "register success");
Toast.makeText(SignUpUI.this, "注册成功!", Toast.LENGTH_SHORT).show();
User user = new User();
@ -104,30 +84,21 @@ public class SignUpUI extends Activity {
user.setPassWord(strPassWord);
user.setPhoneNum(strPhoneNumber);
//数据库查询得出msg
new Thread(){
@Override
public void run(){
Log.d(TAG, "register thread");
int msg = 0;
userManager userManager = new userManager();
User uu = userManager.findUser(user.getUserName());
if(uu != null){
Log.d(TAG, "have this account");
msg = 1; //have this account
}else{
Log.d(TAG, "have no this account");
boolean flag = userManager.register(user);
if(flag){
Log.d(TAG, "register success");
msg = 2;
}
}
hand.sendEmptyMessage(msg);
@ -136,27 +107,19 @@ public class SignUpUI extends Activity {
}
}
//根据msg显示
@SuppressLint("HandlerLeak")
final Handler hand = new Handler(){
public void handleMessage(Message msg){
Log.d(TAG, "msg is:" + msg.toString());
if(msg.what == 0){
Toast.makeText(getApplicationContext(), "注册失败", Toast.LENGTH_SHORT).show();
}else if(msg.what == 1){
Toast.makeText(getApplicationContext(), "该账号已存在,请换一个注册", Toast.LENGTH_SHORT).show();
}else if(msg.what == 2){
Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_SHORT).show();
//于是自动跳转登录界面
Intent intent = new Intent(SignUpUI.this, LoginUI.class);
startActivity(intent);
}
}
};

@ -0,0 +1,145 @@
/**
* 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.ros;
import com.jilk.ros.message.ros.message.Clock;
import com.jilk.ros.message.ros.message.Log;
import com.jilk.ros.message.ros.rosapi.message.Empty;
import com.jilk.ros.message.ros.rosapi.message.GetTime;
import com.jilk.ros.message.ros.rosapi.message.MessageDetails;
import com.jilk.ros.message.ros.rosapi.message.Type;
import com.jilk.ros.message.ros.rosbridge.ROSBridgeClient;
public class Example {
public Example() {}
public static void main(String[] args) {
ROSBridgeClient client = new ROSBridgeClient("ws://162.243.238.80: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.message.ros.rosapi.message.Service, Type> serviceTypeService =
new Service<com.jilk.ros.message.ros.rosapi.message.Service, Type>("/rosapi/service_type",
com.jilk.ros.message.ros.rosapi.message.Service.class, Type.class, client);
serviceTypeService.verify();
String type = serviceTypeService.callBlocking(new com.jilk.ros.message.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();
Topic<Log> logTopic =
new 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.");
} finally {
}
/*
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) {
Topic<Clock> clockTopic = new Topic<Clock>("/clock", Clock.class, client);
clockTopic.subscribe();
try {
Thread.sleep(20000);} catch(InterruptedException ex) {}finally {
}
Clock cl = null;
try {
cl = clockTopic.take(); // just gets one
}
catch (InterruptedException ex) {}finally {
}
cl.print();
cl.clock.nsecs++;
clockTopic.unsubscribe();
clockTopic.advertise();
clockTopic.publish(cl);
clockTopic.unadvertise();
}
}

@ -0,0 +1,26 @@
/**
* 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.ros;
import com.jilk.ros.message.ros.message.Message;
public interface MessageHandler<T extends Message> {
public void onMessage(T message);
}

@ -0,0 +1,68 @@
/**
* 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.ros;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.rosapi.message.TypeDef;
import com.jilk.ros.message.ros.rosbridge.FullMessageHandler;
import com.jilk.ros.message.ros.rosbridge.ROSBridgeClient;
import com.jilk.ros.message.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);
}
}

@ -0,0 +1,134 @@
/**
* 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.ros;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.rosbridge.FullMessageHandler;
import com.jilk.ros.message.ros.rosbridge.operation.CallService;
import com.jilk.ros.message.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;
}
}
}

@ -0,0 +1,146 @@
/**
* 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.ros;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.rosbridge.FullMessageHandler;
import com.jilk.ros.message.ros.rosbridge.operation.Advertise;
import com.jilk.ros.message.ros.rosbridge.operation.Operation;
import com.jilk.ros.message.ros.rosbridge.operation.Publish;
import com.jilk.ros.message.ros.rosbridge.operation.Subscribe;
import com.jilk.ros.message.ros.rosbridge.operation.Unadvertise;
import com.jilk.ros.message.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;
} finally {
}
}
}
}
}

@ -0,0 +1,9 @@
package com.jilk.ros.message.ros.message;
/**
* Created by xxhong on 16-11-17.
*/
@MessageType(string = "std_msgs/Int16MultiArray")
public class AudioMsg extends Message {
public short[] data;
}

@ -0,0 +1,25 @@
/**
* 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.ros.message;
@MessageType(string = "rosgraph_msgs/Clock")
public class Clock extends Message {
public TimePrimitive clock;
}

@ -0,0 +1,24 @@
/**
* 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.ros.message;
@MessageType(string = "std_msgs/Duration")
public class Duration extends DurationPrimitive {
}

@ -0,0 +1,25 @@
/**
* 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.ros.message;
@MessageType(string = "duration")
public class DurationPrimitive extends TimePrimitive {
}

@ -0,0 +1,24 @@
/**
* 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.ros.message;
@MessageType(string = "std_srvs/Empty")
public class Empty extends Message {
}

@ -0,0 +1,27 @@
/**
* 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.ros.message;
@MessageType(string = "std_msgs/Header")
public class Header extends Message {
public long seq;
public TimePrimitive stamp;
public String frame_id;
}

@ -0,0 +1,32 @@
/**
* 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.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;
}

@ -0,0 +1,210 @@
/**
* 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.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());
}finally {
}
}
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();
}
finally {
}
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);
}
finally {
}
// ReflectiveOperationException is not available on Android (Java 1.6)
/*
catch (ReflectiveOperationException ex) {
throw new RuntimeException ("copyFrom error", ex);
}
*/
}
}

@ -0,0 +1,32 @@
/**
* 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.ros.message;
public class MessageException extends Exception {
public MessageException(String message) {
super(message);
}
public MessageException(String message, Throwable cause) {
super(message, cause);
}
}

@ -0,0 +1,32 @@
/**
* 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.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 "";
}

@ -0,0 +1,13 @@
package com.jilk.ros.message.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;
}

@ -0,0 +1,9 @@
package com.jilk.ros.message.ros.message;
/**
* Created by xxhong on 16-11-17.
*/
@MessageType(string = "std_msgs/String")
public class SemanticResponse extends Message {
public String result;
}

@ -0,0 +1,9 @@
package com.jilk.ros.message.ros.message;
/**
* Created by xxhong on 16-11-17.
*/
@MessageType(string = "std_msgs/String")
public class StdMsg extends Message {
public String data;
}

@ -0,0 +1,24 @@
/**
* 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.ros.message;
@MessageType(string = "std_msgs/Time")
public class Time extends TimePrimitive {
}

@ -0,0 +1,26 @@
/**
* 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.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'
}

@ -0,0 +1,178 @@
package com.jilk.ros.message.ros.model;
import java.util.List;
/**
* Created by super_yu on 2018/1/8.
*/
public class FootPrintResult {
/**
* header : {"seq":4297,"frame_id":"odom","stamp":{"secs":1515378187,"nsecs":125325857}}
* polygon : {"points":[{"z":0,"x":0.31369608640670776,"y":-0.5355392694473267},{"z":0,"x":0.35115259885787964,"y":-0.016890067607164383},{"z":0,"x":-0.30713292956352234,"y":0.03065088950097561},{"z":0,"x":-0.3445894420146942,"y":-0.4879983365535736}]}
*/
private HeaderBean header;
private PolygonBean polygon;
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public PolygonBean getPolygon() {
return polygon;
}
public void setPolygon(PolygonBean polygon) {
this.polygon = polygon;
}
public static class HeaderBean {
/**
* seq : 4297
* frame_id : odom
* stamp : {"secs":1515378187,"nsecs":125325857}
*/
private int seq;
private String frame_id;
private StampBean stamp;
public int getSeq() {
return seq;
}
public void setSeq(int seq) {
this.seq = seq;
}
public String getFrame_id() {
return frame_id;
}
public void setFrame_id(String frame_id) {
this.frame_id = frame_id;
}
public StampBean getStamp() {
return stamp;
}
public void setStamp(StampBean stamp) {
this.stamp = stamp;
}
public static class StampBean {
/**
* secs : 1515378187
* nsecs : 125325857
*/
private int secs;
private int nsecs;
public int getSecs() {
return secs;
}
public void setSecs(int secs) {
this.secs = secs;
}
public int getNsecs() {
return nsecs;
}
public void setNsecs(int nsecs) {
this.nsecs = nsecs;
}
}
}
public static class PolygonBean {
private List<PointsBean> points;
public List<PointsBean> getPoints() {
return points;
}
public void setPoints(List<PointsBean> points) {
this.points = points;
}
public static class PointsBean {
/**
* z : 0
* x : 0.31369608640670776
* y : -0.5355392694473267
*/
private int z;
private double x;
private double y;
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
}
// {
// "header": {
// "seq": 4297,
// "frame_id": "odom",
// "stamp": {
// "secs": 1515378187,
// "nsecs": 125325857
// }
// },
// "polygon": {
// "points": [
// {
// "z": 0,
// "x": 0.31369608640670776,
// "y": -0.5355392694473267
// },
// {
// "z": 0,
// "x": 0.35115259885787964,
// "y": -0.016890067607164383
// },
// {
// "z": 0,
// "x": -0.30713292956352234,
// "y": 0.03065088950097561
// },
// {
// "z": 0,
// "x": -0.3445894420146942,
// "y": -0.4879983365535736
// }
// ]
// }
// }
}

@ -0,0 +1,274 @@
package com.jilk.ros.message.ros.model;
import java.util.ArrayList;
import java.util.List;
/**
* Created by super_yu on 2018/2/5.
*/
public class InitPoseResult {
/**
* op : publish
* topic : /initialpose
* msg : {"header":{"frame_id":"map"},"pose":{"pose":{"position":{"x":0,"y":0,"z":0},"orientation":{"x":0,"y":0,"z":0,"w":1}},"covariance":[0.25,0,0,0,0,0,0,0.25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.06853891945200942]}}
*/
private String op = "publish";
private String topic = "/initialpose";
private MsgBean msg;
public MsgBean getMsg() {
return msg;
}
public void setMsg(MsgBean msg) {
this.msg = msg;
}
public static class MsgBean {
/**
* header : {"frame_id":"map"}
* pose : {"pose":{"position":{"x":0,"y":0,"z":0},"orientation":{"x":0,"y":0,"z":0,"w":1}},"covariance":[0.25,0,0,0,0,0,0,0.25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.06853891945200942]}
*/
private HeaderBean header;
private PoseBeanX pose;
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public PoseBeanX getPose() {
return pose;
}
public void setPose(PoseBeanX pose) {
this.pose = pose;
}
public static class HeaderBean {
/**
* frame_id : map
*/
private String frame_id = "map";
}
public static class PoseBeanX {
/**
* pose : {"position":{"x":0,"y":0,"z":0},"orientation":{"x":0,"y":0,"z":0,"w":1}}
* covariance :
* 0.25,0,0,0,0,0,0,0.25,
* 0,0,0,0,0,0,0,0,0,0,0,
* 0,0,0,0,0,0,0,0,0,0,0,
* 0,0,0,0,0,0.06853891945200942
*/
private PoseBean pose;
private List<Double> covariance;
public PoseBean getPose() {
return pose;
}
public void setPose(PoseBean pose) {
this.pose = pose;
}
public void setCovariance() {
covariance = new ArrayList<Double>();
for (int i = 0; i < 36; i++) {
if (i == 0) {
covariance.add(0.25);
} else if (i == 7) {
covariance.add(0.25);
} else if (i == 35) {
covariance.add(0.06853891945200942);
} else {
covariance.add((double) 0);
}
}
}
public static class PoseBean {
/**
* position : {"x":0,"y":0,"z":0}
* orientation : {"x":0,"y":0,"z":0,"w":1}
*/
private PositionBean position;
private OrientationBean orientation;
public PositionBean getPosition() {
return position;
}
public void setPosition(PositionBean position) {
this.position = position;
}
public OrientationBean getOrientation() {
return orientation;
}
public void setOrientation(OrientationBean orientation) {
this.orientation = orientation;
}
public static class PositionBean {
/**
* x : 0
* y : 0
* z : 0
*/
private double x;
private double y;
private double z;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
}
public static class OrientationBean {
/**
* x : 0
* y : 0
* z : 0
* w : 1
*/
private double x;
private double y;
private double z;
private double w;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
public double getW() {
return w;
}
public void setW(double w) {
this.w = w;
}
}
}
}
}
// {
// "op": "publish",
// "topic": "/initialpose",
// "msg": {
// "header": {
// "frame_id": "map"
// },
// "pose": {
// "pose": {
// "position": {
// "x": 0,
// "y": 0,
// "z": 0
// },
// "orientation": {
// "x": 0,
// "y": 0,
// "z": 0,
// "w": 1
// }
// },
// "covariance": [
// 0.25,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0.25,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0.06853891945200942
// ]
// }
// }
// }
}

@ -0,0 +1,501 @@
package com.jilk.ros.message.ros.model;
/**
* Created by super_yu on 2018/1/5.
*/
import java.util.List;
/**
*
* orientation zw
* position xy
* twist x
* angular z
* Created by super_yu on 2017/9/29.
*/
public class PoiResult {
/**
* twist : {"twist":{"angular":{"z":0,"y":0,"x":0},"linear":{"z":0,"y":0,"x":0}},"covariance":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}
* child_frame_id : base_footprint
* pose : {"covariance":[0.1,0,0,0,0,0,0,0.1,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,0.2],"pose":{"position":{"z":0,"y":-0.16137039724419636,"x":0.001470031525333453},"orientation":{"w":-0.08271030624895466,"z":-0.9965736326234024,"y":"-0","x":0}}}
* header : {"seq":69712,"stamp":{"secs":1506650141,"nsecs":455670567},"frame_id":"odom"}
*/
private TwistBeanX twist;
private String child_frame_id;
private PoseBeanX pose;
private HeaderBean header;
public TwistBeanX getTwist() {
return twist;
}
public void setTwist(TwistBeanX twist) {
this.twist = twist;
}
public String getChild_frame_id() {
return child_frame_id;
}
public void setChild_frame_id(String child_frame_id) {
this.child_frame_id = child_frame_id;
}
public PoseBeanX getPose() {
return pose;
}
public void setPose(PoseBeanX pose) {
this.pose = pose;
}
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public static class TwistBeanX {
/**
* twist : {"angular":{"z":0,"y":0,"x":0},"linear":{"z":0,"y":0,"x":0}}
* covariance : [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
*/
private TwistBean twist;
private List<Integer> covariance;
public TwistBean getTwist() {
return twist;
}
public void setTwist(TwistBean twist) {
this.twist = twist;
}
public List<Integer> getCovariance() {
return covariance;
}
public void setCovariance(List<Integer> covariance) {
this.covariance = covariance;
}
public static class TwistBean {
/**
* angular : {"z":0,"y":0,"x":0}
* linear : {"z":0,"y":0,"x":0}
*/
private AngularBean angular;
private LinearBean linear;
public AngularBean getAngular() {
return angular;
}
public void setAngular(AngularBean angular) {
this.angular = angular;
}
public LinearBean getLinear() {
return linear;
}
public void setLinear(LinearBean linear) {
this.linear = linear;
}
public static class AngularBean {
/**
* z : 0
* y : 0
* x : 0
*/
private int z;
private int y;
private int x;
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
public static class LinearBean {
/**
* z : 0
* y : 0
* x : 0
*/
private int z;
private int y;
private int x;
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
}
}
public static class PoseBeanX {
/**
* covariance : [0.1,0,0,0,0,0,0,0.1,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,1.7976931348623157E308,0,0,0,0,0,0,0.2]
* pose : {"position":{"z":0,"y":-0.16137039724419636,"x":0.001470031525333453},"orientation":{"w":-0.08271030624895466,"z":-0.9965736326234024,"y":"-0","x":0}}
*/
private PoseBean pose;
private List<Double> covariance;
public PoseBean getPose() {
return pose;
}
public void setPose(PoseBean pose) {
this.pose = pose;
}
public List<Double> getCovariance() {
return covariance;
}
public void setCovariance(List<Double> covariance) {
this.covariance = covariance;
}
public static class PoseBean {
/**
* position : {"z":0,"y":-0.16137039724419636,"x":0.001470031525333453}
* orientation : {"w":-0.08271030624895466,"z":-0.9965736326234024,"y":"-0","x":0}
*/
private PositionBean position;
private OrientationBean orientation;
public PositionBean getPosition() {
return position;
}
public void setPosition(PositionBean position) {
this.position = position;
}
public OrientationBean getOrientation() {
return orientation;
}
public void setOrientation(OrientationBean orientation) {
this.orientation = orientation;
}
public static class PositionBean {
/**
* z : 0
* y : -0.16137039724419636
* x : 0.001470031525333453
*/
private int z;
private double y;
private double x;
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
}
public static class OrientationBean {
/**
* w : -0.08271030624895466
* z : -0.9965736326234024
* y : -0
* x : 0
*/
private double w;
private double z;
private String y;
private int x;
public double getW() {
return w;
}
public void setW(double w) {
this.w = w;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
}
}
public static class HeaderBean {
/**
* seq : 69712
* stamp : {"secs":1506650141,"nsecs":455670567}
* frame_id : odom
*/
private int seq;
private StampBean stamp;
private String frame_id;
public int getSeq() {
return seq;
}
public void setSeq(int seq) {
this.seq = seq;
}
public StampBean getStamp() {
return stamp;
}
public void setStamp(StampBean stamp) {
this.stamp = stamp;
}
public String getFrame_id() {
return frame_id;
}
public void setFrame_id(String frame_id) {
this.frame_id = frame_id;
}
public static class StampBean {
/**
* secs : 1506650141
* nsecs : 455670567
*/
private int secs;
private int nsecs;
public int getSecs() {
return secs;
}
public void setSecs(int secs) {
this.secs = secs;
}
public int getNsecs() {
return nsecs;
}
public void setNsecs(int nsecs) {
this.nsecs = nsecs;
}
}
}
//
// {
// "twist": {
// "twist": {
// "angular": {
// "z": 0,
// "y": 0,
// "x": 0
// },
// "linear": {
// "z": 0,
// "y": 0,
// "x": 0
// }
// },
// "covariance": [
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0
// ]
// },
// "child_frame_id": "base_footprint",
// "pose": {
// "covariance": [
// 0.1,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0.1,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 1.7976931348623157E308,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 1.7976931348623157E308,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 1.7976931348623157E308,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0.2
// ],
// "pose": {
// "position": {
// "z": 0,
// "y": -0.16137039724419636,
// "x": 0.001470031525333453
// },
// "orientation": {
// "w": -0.08271030624895466,
// "z": -0.9965736326234024,
// "y": -0,
// "x": 0
// }
// }
// },
// "header": {
// "seq": 69712,
// "stamp": {
// "secs": 1506650141,
// "nsecs": 455670567
// },
// "frame_id": "odom"
// }
// }
}

@ -0,0 +1,246 @@
package com.jilk.ros.message.ros.nav;
/**
* Created by super_yu on 27/10/2017.
*/
public class Move_Base_Goal {
/**
* msg : {"target_pose":{"header":{"frame_id":"/map"},"pose":{"w":0.72508,"x":0.00455891,"y":0.0110448,"z":-0.688561}},"base_position":{"header":{"frame_id":"/map"},"pose":{"x":-5.56034,"y":0.543951,"z":2.96803E-4}}}
* op : publish
* topic : /move_base/goal
*/
private MsgBean msg;
private String op = "publish";
private String topic = "/move_base/goal";
public MsgBean getMsg() {
return msg;
}
public void setMsg(MsgBean msg) {
this.msg = msg;
}
public String getOp() {
return op;
}
public String getTopic() {
return topic;
}
public static class MsgBean {
/**
* target_pose : {"header":{"frame_id":"/map"},"pose":{"w":0.72508,"x":0.00455891,"y":0.0110448,"z":-0.688561}}
* base_position : {"header":{"frame_id":"/map"},"pose":{"x":-5.56034,"y":0.543951,"z":2.96803E-4}}
*/
private TargetPoseBean target_pose;
private BasePositionBean base_position;
public TargetPoseBean getTarget_pose() {
return target_pose;
}
public void setTarget_pose(TargetPoseBean target_pose) {
this.target_pose = target_pose;
}
public BasePositionBean getBase_position() {
return base_position;
}
public void setBase_position(BasePositionBean base_position) {
this.base_position = base_position;
}
public static class TargetPoseBean {
/**
* header : {"frame_id":"/map"}
* pose : {"w":0.72508,"x":0.00455891,"y":0.0110448,"z":-0.688561}
*/
private HeaderBean header;
private PoseBean pose;
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public PoseBean getPose() {
return pose;
}
public void setPose(PoseBean pose) {
this.pose = pose;
}
public static class HeaderBean {
/**
* frame_id : /map
*/
private String frame_id = "/map";
public String getFrame_id() {
return frame_id;
}
}
public static class PoseBean {
/**
* w : 0.72508
* x : 0.00455891
* y : 0.0110448
* z : -0.688561
*/
private double w;
private double x;
private double y;
private double z;
public double getW() {
return w;
}
public void setW(double w) {
this.w = w;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
}
}
public static class BasePositionBean {
/**
* header : {"frame_id":"/map"}
* pose : {"x":-5.56034,"y":0.543951,"z":2.96803E-4}
*/
private HeaderBeanX header;
private PoseBeanX pose;
public HeaderBeanX getHeader() {
return header;
}
public void setHeader(HeaderBeanX header) {
this.header = header;
}
public PoseBeanX getPose() {
return pose;
}
public void setPose(PoseBeanX pose) {
this.pose = pose;
}
public static class HeaderBeanX {
/**
* frame_id : /map
*/
private String frame_id = "/map";
public String getFrame_id() {
return frame_id;
}
}
public static class PoseBeanX {
/**
* x : -5.56034
* y : 0.543951
* z : 2.96803E-4
*/
private double x;
private double y;
private double z;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
}
}
}
// {
// "op": "publish",
// "topic": "/move_base/goal",
// "msg": {
// "target_pose": {
// "header": {
// "frame_id": "/map"
// },
// "pose": {
// "z": -0.695688,
// "x": 0.000728705,
// "w": 0.71834,
// "y": 0.00213251
// }
// },
// "base_position": {
// "header": {
// "frame_id": "/map"
// },
// "pose": {
// "z": 0.00984454,
// "x": -0.0483838,
// "y": -0.00480753
// }
// }
// }
// }
}

@ -0,0 +1,219 @@
package com.jilk.ros.message.ros.nav;
import java.util.List;
/**
* Created by super_yu on 30/10/2017.
*/
public class Move_Base_Status {
/**
* status_list : [{"goal_id":{"id":"map_6_A_603","stamp":{"secs":1509348841,"nsecs":490135242}},"text":"Goal reached.","status":3},{"goal_id":{"id":"map_6_A_601","stamp":{"secs":1509348875,"nsecs":650002258}},"text":"This goal has been accepted by the simple action server","status":1}]
* header : {"seq":13516,"frame_id":"","stamp":{"secs":1509348876,"nsecs":156902566}}
*/
private HeaderBean header;
private List<StatusListBean> status_list;
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public List<StatusListBean> getStatus_list() {
return status_list;
}
public void setStatus_list(List<StatusListBean> status_list) {
this.status_list = status_list;
}
public static class HeaderBean {
/**
* seq : 13516
* frame_id :
* stamp : {"secs":1509348876,"nsecs":156902566}
*/
private int seq;
private String frame_id;
private StampBean stamp;
public int getSeq() {
return seq;
}
public void setSeq(int seq) {
this.seq = seq;
}
public String getFrame_id() {
return frame_id;
}
public void setFrame_id(String frame_id) {
this.frame_id = frame_id;
}
public StampBean getStamp() {
return stamp;
}
public void setStamp(StampBean stamp) {
this.stamp = stamp;
}
public static class StampBean {
/**
* secs : 1509348876
* nsecs : 156902566
*/
private int secs;
private int nsecs;
public int getSecs() {
return secs;
}
public void setSecs(int secs) {
this.secs = secs;
}
public int getNsecs() {
return nsecs;
}
public void setNsecs(int nsecs) {
this.nsecs = nsecs;
}
}
}
public static class StatusListBean {
/**
* goal_id : {"id":"map_6_A_603","stamp":{"secs":1509348841,"nsecs":490135242}}
* text : Goal reached.
* status : 3
*/
private GoalIdBean goal_id;
private String text;
private int status;
public GoalIdBean getGoal_id() {
return goal_id;
}
public void setGoal_id(GoalIdBean goal_id) {
this.goal_id = goal_id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public static class GoalIdBean {
/**
* id : map_6_A_603
* stamp : {"secs":1509348841,"nsecs":490135242}
*/
private String id;
private StampBeanX stamp;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public StampBeanX getStamp() {
return stamp;
}
public void setStamp(StampBeanX stamp) {
this.stamp = stamp;
}
public static class StampBeanX {
/**
* secs : 1509348841
* nsecs : 490135242
*/
private int secs;
private int nsecs;
public int getSecs() {
return secs;
}
public void setSecs(int secs) {
this.secs = secs;
}
public int getNsecs() {
return nsecs;
}
public void setNsecs(int nsecs) {
this.nsecs = nsecs;
}
}
}
}
// {
// "status_list": [
// {
// "goal_id": {
// "id": "map_6_A_603",
// "stamp": {
// "secs": 1509348841,
// "nsecs": 490135242
// }
// },
// "text": "Goal reached.",
// "status": 3
// },
// {
// "goal_id": {
// "id": "map_6_A_601",
// "stamp": {
// "secs": 1509348875,
// "nsecs": 650002258
// }
// },
// "text": "This goal has been accepted by the simple action server",
// "status": 1
// }
// ],
// "header": {
// "seq": 13516,
// "frame_id": "",
// "stamp": {
// "secs": 1509348876,
// "nsecs": 156902566
// }
// }
// }
}

@ -0,0 +1,37 @@
package com.jilk.ros.message.ros.nav;
import java.util.HashMap;
import java.util.List;
/**
*
* Created by super_yu on 27/10/2017.
*/
public class NavPublich {
private List<String> wayPointsNames;
private HashMap<String, TMove_Base_Goal> navPublishHashMap;
public List<String> getWayPointsNames() {
return wayPointsNames;
}
public void setWayPointsNames(List<String> wayPointsNames) {
this.wayPointsNames = wayPointsNames;
}
public HashMap<String, TMove_Base_Goal> getNavPublishHashMap() {
return navPublishHashMap;
}
public void setNavPublishHashMap(HashMap<String, TMove_Base_Goal> navPublishHashMap) {
this.navPublishHashMap = navPublishHashMap;
}
public void clear() {
if (wayPointsNames != null) wayPointsNames.clear();
if (navPublishHashMap != null) navPublishHashMap.clear();
}
}

@ -0,0 +1,402 @@
package com.jilk.ros.message.ros.nav;
/**
* Created by super_yu on 30/10/2017.
*/
public class TMove_Base_Goal {
/**
* op : publish
* topic : /move_base/goal
* msg : {"header":{"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"},"goal_id":{"stamp":{"secs":0,"nsecs":0},"id":"map_6_A_601"},"goal":{"target_pose":{"header":{"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"},"pose":{"position":{"z":2.96803E-4,"x":-5.56034,"y":0.543951},"orientation":{"z":-0.688561,"x":0.00455891,"w":0.72508,"y":0.0110448}}}}}
*/
private String op = "publish";
private String topic = "/move_base/goal";
private MsgBean msg;
public String getOp() {
return op;
}
public String getTopic() {
return topic;
}
public MsgBean getMsg() {
return msg;
}
public void setMsg(MsgBean msg) {
this.msg = msg;
}
public static class MsgBean {
/**
* header : {"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"}
* goal_id : {"stamp":{"secs":0,"nsecs":0},"id":"map_6_A_601"}
* goal : {"target_pose":{"header":{"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"},"pose":{"position":{"z":2.96803E-4,"x":-5.56034,"y":0.543951},"orientation":{"z":-0.688561,"x":0.00455891,"w":0.72508,"y":0.0110448}}}}
*/
private HeaderBean header;
private GoalIdBean goal_id;
private GoalBean goal;
public HeaderBean getHeader() {
return header;
}
public void setHeader(HeaderBean header) {
this.header = header;
}
public GoalIdBean getGoal_id() {
return goal_id;
}
public void setGoal_id(GoalIdBean goal_id) {
this.goal_id = goal_id;
}
public GoalBean getGoal() {
return goal;
}
public void setGoal(GoalBean goal) {
this.goal = goal;
}
public static class HeaderBean {
/**
* seq : 0
* stamp : {"secs":0,"nsecs":0}
* frame_id : map
*/
private int seq = 0;
private StampBean stamp;
private String frame_id = "map";
public int getSeq() {
return seq;
}
public StampBean getStamp() {
return stamp;
}
public void setStamp(StampBean stamp) {
this.stamp = stamp;
}
public String getFrame_id() {
return frame_id;
}
public static class StampBean {
/**
* secs : 0
* nsecs : 0
*/
private int secs = 0;
private int nsecs = 0;
public int getSecs() {
return secs;
}
public int getNsecs() {
return nsecs;
}
}
}
public static class GoalIdBean {
/**
* stamp : {"secs":0,"nsecs":0}
* id : map_6_A_601
*/
private StampBeanX stamp;
private String id;
public StampBeanX getStamp() {
return stamp;
}
public void setStamp(StampBeanX stamp) {
this.stamp = stamp;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public static class StampBeanX {
/**
* secs : 0
* nsecs : 0
*/
private int secs = 0;
private int nsecs = 0;
public int getSecs() {
return secs;
}
public int getNsecs() {
return nsecs;
}
}
}
public static class GoalBean {
/**
* target_pose : {"header":{"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"},"pose":{"position":{"z":2.96803E-4,"x":-5.56034,"y":0.543951},"orientation":{"z":-0.688561,"x":0.00455891,"w":0.72508,"y":0.0110448}}}
*/
private TargetPoseBean target_pose;
public TargetPoseBean getTarget_pose() {
return target_pose;
}
public void setTarget_pose(TargetPoseBean target_pose) {
this.target_pose = target_pose;
}
public static class TargetPoseBean {
/**
* header : {"seq":0,"stamp":{"secs":0,"nsecs":0},"frame_id":"map"}
* pose : {"position":{"z":2.96803E-4,"x":-5.56034,"y":0.543951},"orientation":{"z":-0.688561,"x":0.00455891,"w":0.72508,"y":0.0110448}}
*/
private HeaderBeanX header;
private PoseBean pose;
public HeaderBeanX getHeader() {
return header;
}
public void setHeader(HeaderBeanX header) {
this.header = header;
}
public PoseBean getPose() {
return pose;
}
public void setPose(PoseBean pose) {
this.pose = pose;
}
public static class HeaderBeanX {
/**
* seq : 0
* stamp : {"secs":0,"nsecs":0}
* frame_id : map
*/
private int seq = 0;
private StampBeanXX stamp;
private String frame_id = "map";
public int getSeq() {
return seq;
}
public StampBeanXX getStamp() {
return stamp;
}
public void setStamp(StampBeanXX stamp) {
this.stamp = stamp;
}
public String getFrame_id() {
return frame_id;
}
public static class StampBeanXX {
/**
* secs : 0
* nsecs : 0
*/
private int secs = 0;
private int nsecs = 0;
public int getSecs() {
return secs;
}
public int getNsecs() {
return nsecs;
}
}
}
public static class PoseBean {
/**
* position : {"z":2.96803E-4,"x":-5.56034,"y":0.543951}
* orientation : {"z":-0.688561,"x":0.00455891,"w":0.72508,"y":0.0110448}
*/
private PositionBean position;
private OrientationBean orientation;
public PositionBean getPosition() {
return position;
}
public void setPosition(PositionBean position) {
this.position = position;
}
public OrientationBean getOrientation() {
return orientation;
}
public void setOrientation(OrientationBean orientation) {
this.orientation = orientation;
}
public static class PositionBean {
/**
* z : 2.96803E-4
* x : -5.56034
* y : 0.543951
*/
private double z;
private double x;
private double y;
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
public static class OrientationBean {
/**
* z : -0.688561
* x : 0.00455891
* w : 0.72508
* y : 0.0110448
*/
private double z;
private double x;
private double w;
private double y;
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getW() {
return w;
}
public void setW(double w) {
this.w = w;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
}
}
}
}
// {
// "op": "publish",
// "topic": "/move_base/goal",
// "msg": {
// "header": {
// "seq": 0,
// "stamp": {
// "secs": 0,
// "nsecs": 0
// },
// "frame_id": "map"
// },
// "goal_id": {
// "stamp": {
// "secs": 0,
// "nsecs": 0
// },
// "id": "map_6_A_601"
// },
// "goal": {
// "target_pose": {
// "header": {
// "seq": 0,
// "stamp": {
// "secs": 0,
// "nsecs": 0
// },
// "frame_id": "map"
// },
// "pose": {
// "position": {
// "z": 0.000296803,
// "x": -5.56034,
// "y": 0.543951
// },
// "orientation": {
// "z": -0.688561,
// "x": 0.00455891,
// "w": 0.72508,
// "y": 0.0110448
// }
// }
// }
// }
// }
// }
}

@ -0,0 +1,22 @@
package com.jilk.ros.message.ros.net;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
/**
* Created by Administrator on 2017/5/22 0022.
*/
public class NetBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// 如果相等的话就说明网络状态发生了变化
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
int netWorkState = NetUtil.getNetWorkState(context);
}
}
}

@ -0,0 +1,49 @@
package com.jilk.ros.message.ros.net;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* Created by Administrator on 2017/5/22 0022.
*/
public class NetUtil {
/**
*
*/
private static final int NETWORK_NONE = -1;
/**
*
*/
private static final int NETWORK_MOBILE = 0;
/**
* 线
*/
private static final int NETWORK_WIFI = 1;
public static int getNetWorkState(Context context) {
// 得到连接管理器对象
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_WIFI)) {
return NETWORK_WIFI;
} else if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_MOBILE)) {
return NETWORK_MOBILE;
}
} else {
return NETWORK_NONE;
}
return NETWORK_NONE;
}
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,27 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "std_msgs/Empty")
public class Empty extends Message {
}

@ -0,0 +1,30 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.message.TimePrimitive;
@MessageType(string = "rosapi/GetTimeResponse")
public class GetTime extends Message {
public TimePrimitive time;
}

@ -0,0 +1,28 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/MessageDetails")
public class MessageDetails extends Message {
public TypeDef[] typedefs;
}

@ -0,0 +1,28 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Nodes")
public class Nodes extends Message {
public String[] nodes;
}

@ -0,0 +1,34 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Service")
public class Service extends Message {
public String service;
public Service() {}
public Service(String service) {
this.service = service;
}
}

@ -0,0 +1,28 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Services")
public class Services extends Message {
public String[] services;
}

@ -0,0 +1,34 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Topic")
public class Topic extends Message {
public String topic;
public Topic() {}
public Topic(String topic) {
this.topic = topic;
}
}

@ -0,0 +1,28 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Topics")
public class Topics extends Message {
public String[] topics;
}

@ -0,0 +1,34 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "rosapi/Type")
public class Type extends Message {
public String type;
public Type() {}
public Type(String type) {
this.type = type;
}
}

@ -0,0 +1,55 @@
/**
* 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.ros.rosapi.message;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.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;
}
}

@ -0,0 +1,26 @@
/**
* 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.ros.rosbridge;
import com.jilk.ros.message.ros.message.Message;
public interface FullMessageHandler<T extends Message> {
public void onMessage(String id, T message);
}

@ -0,0 +1,270 @@
/**
* 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.ros.rosbridge;
import com.jilk.ros.message.ros.ROSClient;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.rosapi.message.Empty;
import com.jilk.ros.message.ros.rosapi.message.MessageDetails;
import com.jilk.ros.message.ros.rosapi.message.Nodes;
import com.jilk.ros.message.ros.rosapi.message.Service;
import com.jilk.ros.message.ros.rosapi.message.Services;
import com.jilk.ros.message.ros.rosapi.message.Topic;
import com.jilk.ros.message.ros.rosapi.message.Topics;
import com.jilk.ros.message.ros.rosapi.message.Type;
import com.jilk.ros.message.ros.rosapi.message.TypeDef;
import com.jilk.ros.message.ros.rosbridge.implementation.ROSBridgeWebSocketClient;
import com.jilk.ros.message.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(ConnectionStatusListener listener) {
boolean result = false;
client = ROSBridgeWebSocketClient.create(uriString);
if (client != null) {
client.setListener(listener);
try {
result = client.connectBlocking();
}
catch (InterruptedException ex) {
}
finally {
}
}
return result;
}
@Override
public void disconnect() {
try {
client.closeBlocking();
}
catch (InterruptedException ex) {
}
finally {
}
}
@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 {
com.jilk.ros.message.ros.Service<Empty, Nodes> nodeService =
new com.jilk.ros.message.ros.Service<Empty, Nodes>("/rosapi/nodes", Empty.class, Nodes.class, this);
return nodeService.callBlocking(new Empty()).nodes;
}
@Override
public String[] getTopics() throws InterruptedException {
com.jilk.ros.message.ros.Service<Empty, Topics> topicsService =
new com.jilk.ros.message.ros.Service<Empty, Topics>("/rosapi/topics", Empty.class, Topics.class, this);
return topicsService.callBlocking(new Empty()).topics;
}
@Override
public String[] getServices() throws InterruptedException {
com.jilk.ros.message.ros.Service<Empty, Services> servicesService =
new com.jilk.ros.message.ros.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 {
com.jilk.ros.message.ros.Service<Type, MessageDetails> messageDetailsService =
new com.jilk.ros.message.ros.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 {
com.jilk.ros.message.ros.Service<Type, MessageDetails> messageDetailsService =
new com.jilk.ros.message.ros.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 {
com.jilk.ros.message.ros.Service<Topic, Type> topicTypeService =
new com.jilk.ros.message.ros.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 {
com.jilk.ros.message.ros.Service<Service, Type> serviceTypeService =
new com.jilk.ros.message.ros.Service<Service, Type>("/rosapi/service_type",
Service.class, Type.class, this);
return serviceTypeService.callBlocking(new 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;
}
}

@ -0,0 +1,575 @@
package com.jilk.ros.message.ros.rosbridge.implementation;
import java.util.Arrays;
/** A very fast and memory efficient class to encode and decode to and from BASE64 in full accordance
* with RFC 2045.<br><br>
* On Windows XP sp1 with 1.4.2_04 and later ;), this encoder and decoder is about 10 times faster
* on small arrays (10 - 1000 bytes) and 2-3 times as fast on larger arrays (10000 - 1000000 bytes)
* compared to <code>sun.misc.Encoder()/Decoder()</code>.<br><br>
*
* On byte arrays the encoder is about 20% faster than Jakarta Commons Base64 Codec for encode and
* about 50% faster for decoding large arrays. This implementation is about twice as fast on very small
* arrays (&lt 30 bytes). If source/destination is a <code>String</code> this
* version is about three times as fast due to the fact that the Commons Codec result has to be recoded
* to a <code>String</code> from <code>byte[]</code>, which is very expensive.<br><br>
*
* This encode/decode algorithm doesn't create any temporary arrays as many other codecs do, it only
* allocates the resulting array. This produces less garbage and it is possible to handle arrays twice
* as large as algorithms that create a temporary array. (E.g. Jakarta Commons Codec). It is unknown
* whether Sun's <code>sun.misc.Encoder()/Decoder()</code> produce temporary arrays but since performance
* is quite low it probably does.<br><br>
*
* The encoder produces the same output as the Sun one except that the Sun's encoder appends
* a trailing line separator if the last character isn't a pad. Unclear why but it only adds to the
* length and is probably a side effect. Both are in conformance with RFC 2045 though.<br>
* Commons codec seem to always att a trailing line separator.<br><br>
*
* <b>Note!</b>
* The encode/decode method pairs (types) come in three versions with the <b>exact</b> same algorithm and
* thus a lot of code redundancy. This is to not create any temporary arrays for transcoding to/from different
* format types. The methods not used can simply be commented out.<br><br>
*
* There is also a "fast" version of all decode methods that works the same way as the normal ones, but
* har a few demands on the decoded input. Normally though, these fast verions should be used if the source if
* the input is known and it hasn't bee tampered with.<br><br>
*
* If you find the code useful or you find a bug, please send me a note at base64 @ miginfocom . com.
*
* Licence (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (base64 @ miginfocom . com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 2.2
* @author Mikael Grev
* Date: 2004-aug-02
* Time: 11:31:11
*/
public class Base64
{
private static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static final int[] IA = new int[256];
static {
Arrays.fill(IA, -1);
for (int i = 0, iS = CA.length; i < iS; i++)
IA[CA[i]] = i;
IA['='] = 0;
}
// ****************************************************************************************
// * char[] version
// ****************************************************************************************
/** Encodes a raw byte array into a BASE64 <code>char[]</code> representation i accordance with RFC 2045.
* @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
* @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
* No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
* little faster.
* @return A BASE64 encoded array. Never <code>null</code>.
*/
public final static char[] encodeToChar(byte[] sArr, boolean lineSep)
{
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if (sLen == 0)
return new char[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
char[] dArr = new char[dLen];
// Encode even 24-bits
for (int s = 0, d = 0, cc = 0; s < eLen;) {
// Copy next three bytes into lower 24 bits of int, paying attension to sign.
int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
// Encode the int into four chars
dArr[d++] = CA[(i >>> 18) & 0x3f];
dArr[d++] = CA[(i >>> 12) & 0x3f];
dArr[d++] = CA[(i >>> 6) & 0x3f];
dArr[d++] = CA[i & 0x3f];
// Add optional line separator
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
}
}
// Pad and encode last bits if source isn't even 24 bits.
int left = sLen - eLen; // 0 - 2.
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
// Set last four chars
dArr[dLen - 4] = CA[i >> 12];
dArr[dLen - 3] = CA[(i >>> 6) & 0x3f];
dArr[dLen - 2] = left == 2 ? CA[i & 0x3f] : '=';
dArr[dLen - 1] = '=';
}
return dArr;
}
/** Decodes a BASE64 encoded char array. All illegal characters will be ignored and can handle both arrays with
* and without line separators.
* @param sArr The source array. <code>null</code> or length 0 will return an empty array.
* @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters
* (including '=') isn't divideable by 4. (I.e. definitely corrupted).
*/
public final static byte[] decode(char[] sArr)
{
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if (sLen == 0)
return new byte[0];
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[sArr[i]] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if ((sLen - sepCnt) % 4 != 0)
return null;
int pad = 0;
for (int i = sLen; i > 1 && IA[sArr[--i]] <= 0;)
if (sArr[i] == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for (int s = 0, d = 0; d < len;) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[sArr[s++]];
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if (d < len) {
dArr[d++]= (byte) (i >> 8);
if (d < len)
dArr[d++] = (byte) i;
}
}
return dArr;
}
/** Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(char[])}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
* @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
*/
public final static byte[] decodeFast(char[] sArr)
{
// Check special case
int sLen = sArr.length;
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while (sIx < eIx && IA[sArr[sIx]] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[sArr[eIx]] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
dArr[d++] = (byte) (i >> 8);
dArr[d++] = (byte) i;
// If line separator, jump over it.
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[sArr[sIx++]] << (18 - j * 6);
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
// ****************************************************************************************
// * byte[] version
// ****************************************************************************************
/** Encodes a raw byte array into a BASE64 <code>byte[]</code> representation i accordance with RFC 2045.
* @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
* @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
* No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
* little faster.
* @return A BASE64 encoded array. Never <code>null</code>.
*/
public final static byte[] encodeToByte(byte[] sArr, boolean lineSep)
{
// Check special case
int sLen = sArr != null ? sArr.length : 0;
if (sLen == 0)
return new byte[0];
int eLen = (sLen / 3) * 3; // Length of even 24-bits.
int cCnt = ((sLen - 1) / 3 + 1) << 2; // Returned character count
int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
byte[] dArr = new byte[dLen];
// Encode even 24-bits
for (int s = 0, d = 0, cc = 0; s < eLen;) {
// Copy next three bytes into lower 24 bits of int, paying attension to sign.
int i = (sArr[s++] & 0xff) << 16 | (sArr[s++] & 0xff) << 8 | (sArr[s++] & 0xff);
// Encode the int into four chars
dArr[d++] = (byte) CA[(i >>> 18) & 0x3f];
dArr[d++] = (byte) CA[(i >>> 12) & 0x3f];
dArr[d++] = (byte) CA[(i >>> 6) & 0x3f];
dArr[d++] = (byte) CA[i & 0x3f];
// Add optional line separator
if (lineSep && ++cc == 19 && d < dLen - 2) {
dArr[d++] = '\r';
dArr[d++] = '\n';
cc = 0;
}
}
// Pad and encode last bits if source isn't an even 24 bits.
int left = sLen - eLen; // 0 - 2.
if (left > 0) {
// Prepare the int
int i = ((sArr[eLen] & 0xff) << 10) | (left == 2 ? ((sArr[sLen - 1] & 0xff) << 2) : 0);
// Set last four chars
dArr[dLen - 4] = (byte) CA[i >> 12];
dArr[dLen - 3] = (byte) CA[(i >>> 6) & 0x3f];
dArr[dLen - 2] = left == 2 ? (byte) CA[i & 0x3f] : (byte) '=';
dArr[dLen - 1] = '=';
}
return dArr;
}
/** Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with
* and without line separators.
* @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters
* (including '=') isn't divideable by 4. (I.e. definitely corrupted).
*/
public final static byte[] decode(byte[] sArr)
{
// Check special case
int sLen = sArr.length;
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[sArr[i] & 0xff] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if ((sLen - sepCnt) % 4 != 0)
return null;
int pad = 0;
for (int i = sLen; i > 1 && IA[sArr[--i] & 0xff] <= 0;)
if (sArr[i] == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for (int s = 0, d = 0; d < len;) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[sArr[s++] & 0xff];
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if (d < len) {
dArr[d++]= (byte) (i >> 8);
if (d < len)
dArr[d++] = (byte) i;
}
}
return dArr;
}
/** Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(byte[])}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
* @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
*/
public final static byte[] decodeFast(byte[] sArr)
{
// Check special case
int sLen = sArr.length;
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while (sIx < eIx && IA[sArr[sIx] & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[sArr[eIx] & 0xff] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = sArr[eIx] == '=' ? (sArr[eIx - 1] == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (sArr[76] == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[sArr[sIx++]] << 18 | IA[sArr[sIx++]] << 12 | IA[sArr[sIx++]] << 6 | IA[sArr[sIx++]];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
dArr[d++] = (byte) (i >> 8);
dArr[d++] = (byte) i;
// If line separator, jump over it.
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[sArr[sIx++]] << (18 - j * 6);
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
// ****************************************************************************************
// * String version
// ****************************************************************************************
/** Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045.
* @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
* @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
* No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
* little faster.
* @return A BASE64 encoded array. Never <code>null</code>.
*/
public final static String encodeToString(byte[] sArr, boolean lineSep)
{
// Reuse char[] since we can't create a String incrementally anyway and StringBuffer/Builder would be slower.
return new String(encodeToChar(sArr, lineSep));
}
/** Decodes a BASE64 encoded <code>String</code>. All illegal characters will be ignored and can handle both strings with
* and without line separators.<br>
* <b>Note!</b> It can be up to about 2x the speed to call <code>decode(str.toCharArray())</code> instead. That
* will create a temporary array though. This version will use <code>str.charAt(i)</code> to iterate the string.
* @param str The source string. <code>null</code> or length 0 will return an empty array.
* @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters
* (including '=') isn't divideable by 4. (I.e. definitely corrupted).
*/
public final static byte[] decode(String str)
{
// Check special case
int sLen = str != null ? str.length() : 0;
if (sLen == 0)
return new byte[0];
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of separator characters. (Actually illegal characters, but that's a bonus...)
for (int i = 0; i < sLen; i++) // If input is "pure" (I.e. no line separators or illegal chars) base64 this loop can be commented out.
if (IA[str.charAt(i)] < 0)
sepCnt++;
// Check so that legal chars (including '=') are evenly divideable by 4 as specified in RFC 2045.
if ((sLen - sepCnt) % 4 != 0)
return null;
// Count '=' at end
int pad = 0;
for (int i = sLen; i > 1 && IA[str.charAt(--i)] <= 0;)
if (str.charAt(i) == '=')
pad++;
int len = ((sLen - sepCnt) * 6 >> 3) - pad;
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
for (int s = 0, d = 0; d < len;) {
// Assemble three bytes into an int from four "valid" characters.
int i = 0;
for (int j = 0; j < 4; j++) { // j only increased if a valid char was found.
int c = IA[str.charAt(s++)];
if (c >= 0)
i |= c << (18 - j * 6);
else
j--;
}
// Add the bytes
dArr[d++] = (byte) (i >> 16);
if (d < len) {
dArr[d++]= (byte) (i >> 8);
if (d < len)
dArr[d++] = (byte) i;
}
}
return dArr;
}
/** Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as
* fast as {@link #decode(String)}. The preconditions are:<br>
* + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
* + Line separator must be "\r\n", as specified in RFC 2045
* + The array must not contain illegal characters within the encoded string<br>
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br>
* @param s The source string. Length 0 will return an empty array. <code>null</code> will throw an exception.
* @return The decoded array of bytes. May be of length 0.
*/
public final static byte[] decodeFast(String s)
{
// Check special case
int sLen = s.length();
if (sLen == 0)
return new byte[0];
int sIx = 0, eIx = sLen - 1; // Start and end index after trimming.
// Trim illegal chars from start
while (sIx < eIx && IA[s.charAt(sIx) & 0xff] < 0)
sIx++;
// Trim illegal chars from end
while (eIx > 0 && IA[s.charAt(eIx) & 0xff] < 0)
eIx--;
// get the padding count (=) (0, 1 or 2)
int pad = s.charAt(eIx) == '=' ? (s.charAt(eIx - 1) == '=' ? 2 : 1) : 0; // Count '=' at end.
int cCnt = eIx - sIx + 1; // Content count including possible separators
int sepCnt = sLen > 76 ? (s.charAt(76) == '\r' ? cCnt / 78 : 0) << 1 : 0;
int len = ((cCnt - sepCnt) * 6 >> 3) - pad; // The number of decoded bytes
byte[] dArr = new byte[len]; // Preallocate byte[] of exact length
// Decode all but the last 0 - 2 bytes.
int d = 0;
for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
// Assemble three bytes into an int from four "valid" characters.
int i = IA[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 | IA[s.charAt(sIx++)];
// Add the bytes
dArr[d++] = (byte) (i >> 16);
dArr[d++] = (byte) (i >> 8);
dArr[d++] = (byte) i;
// If line separator, jump over it.
if (sepCnt > 0 && ++cc == 19) {
sIx += 2;
cc = 0;
}
}
if (d < len) {
// Decode last 1-3 bytes (incl '=') into 1-3 bytes
int i = 0;
for (int j = 0; sIx <= eIx - pad; j++)
i |= IA[s.charAt(sIx++)] << (18 - j * 6);
for (int r = 16; d < len; r -= 8)
dArr[d++] = (byte) (i >> r);
}
return dArr;
}
}

@ -0,0 +1,347 @@
/**
* 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.ros.rosbridge.implementation;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.rosbridge.indication.Indication;
import com.jilk.ros.message.ros.rosbridge.operation.Wrapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
// The slightly crazy abstractions here are designed to isolate knowledge of
// the JSON library and data types from the Operation details of rosbridge.
// Why is this important? A few reasons I can see. First, we might want
// to change JSON libraries and this encapsulates all use of JSON-simple.
// Second, as much as possible I would like the semantics of the rosbridge
// protocol to be encapsulated in the Operation and its subclasses rather
// than in a module that is essentially about serialization.
//
// Unfortunately the hierarchical Message abstraction is a bit broken
// at the top level. Beginning at the actual operation (e.g., Publish), the
// types of the fields are determined either by the fields themselves or by
// an indicator. However, the type of the operation itself is not determined
// this way, because the indicator is in the object itself, which means it
// would have to be created before its type is known. Rather than build in
// exceptions, I elected to create a "Wrapper" operation type that simply
// wraps the concrete operation and copies its "op" field.
//
public class JSON {
/**
* Translates a Message recursively into JSON. Normally the Message is also an
* Operation, but it does not have to be. The caller constructs a complete
* message using @Operation and @Message types. This includes situations
* where one or more fields are marked to be turned into arrays, using @AsArray.
* @param m the @Message object to be recursively translated.
* @return the complete JSON string.
*/
public static String toJSON(Message m) {
JSONObject jo = convertObjectToJSONObject(m); // Object to JSON-Simple
return jo.toJSONString(); // JSON-Simple to string
}
/**
* Translates JSON into a hierarchical Operation/Message structure.
* This includes handling fields that are @Indicated and @AsArray. If the
* @Class parameter is a @Wrapper, this is a special case whereby the
* object is wrapped to create a consistent hierarchy.
* @param json the source JSON string
* @param c the top level class of the JSON. Normally @Wrapper
* @param r the @Registry containing topic registrations
* @return the fully instantiated message hierarchy represented
* by the JSON string.
*/
public static Message toMessage(String json, Class c, Registry<Class> r) {
JSONObject joUnwrapped = convertStringToJSONObject(json); // String to JSON-Simple
JSONObject jo = joUnwrapped;
if (Wrapper.class.isAssignableFrom(c))
jo = wrap(joUnwrapped, c); // wrap: a hack to make the hierarchy homogeneous
return convertJSONObjectToMessage(jo, c, r); // JSON-Simple to Message
}
// *** Create JSON from Messages *** //
// Translate the object into a JSON-Simple object, field-by-field,
// recursively via convertElementToJSON.
// except for the case where AsArray is indicated
private static JSONObject convertObjectToJSONObject(Object o) {
JSONObject result = new JSONObject();
for (Field f : o.getClass().getFields()) {
Object fieldObject = getFieldObject(f, o);
if (fieldObject != null) {
Object resultObject;
if (Indication.isBase64Encoded(f))
resultObject = convertByteArrayToBase64JSONString(fieldObject);
else if (Indication.asArray(f))
resultObject = convertObjectToJSONArray(fieldObject);
else resultObject = convertElementToJSON(fieldObject);
result.put(f.getName(), resultObject);
}
}
return result;
}
// Convert an array type to a JSON-Simple array, element-by-element,
// recursively via convertElementToJSON.
private static JSONArray convertArrayToJSONArray(Object array) {
JSONArray result = new JSONArray();
for (int i = 0; i < Array.getLength(array); i++) {
Object elementObject = Array.get(array, i);
if (elementObject != null) {
Object resultObject = convertElementToJSON(elementObject);
result.add(resultObject);
}
}
return result;
}
// For AsArray objects, convert the object to a JSON-Simple array
// NOTE: This relies on later versions of the JDK providing
// the fields in order.
private static JSONArray convertObjectToJSONArray(Object o) {
JSONArray result = new JSONArray();
for (Field f : o.getClass().getFields()) {
Object fieldObject = getFieldObject(f, o);
if (fieldObject != null) {
Object resultObject = convertElementToJSON(fieldObject);
result.add(resultObject);
}
}
return result;
}
// Convert the individual field or array element items recursively
private static Object convertElementToJSON(Object elementObject) {
Class elementClass = elementObject.getClass();
Object resultObject;
if (Message.isPrimitive(elementClass))
resultObject = elementObject;
else if (elementClass.isArray())
resultObject = convertArrayToJSONArray(elementObject);
else
resultObject = convertObjectToJSONObject(elementObject);
return resultObject;
}
// Special case for Base 64-encoded fields
private static Object convertByteArrayToBase64JSONString(Object fieldObject) {
return Base64.encodeToString((byte[]) fieldObject, false);
}
// This is just to buffer the code from the exception. Better error
// handling needed here.
private static Object getFieldObject(Field f, Object o) {
Object fo = null;
try {
fo = f.get(o);
}
catch (IllegalAccessException ex) {
ex.printStackTrace();
}
finally {
}
return fo;
}
// *** Create Messages from JSON *** //
// Use the JSON-simple parser to create the JSON-Simple object
private static JSONObject convertStringToJSONObject(String json) {
JSONObject result = null;
StringReader r = new StringReader(json);
JSONParser jp = new JSONParser();
try {
result = (JSONObject) jp.parse(r);
}
catch (Throwable t) {
System.out.println(t.getMessage());
}
finally {
}
r.close();
return result;
}
// A bit of a hack to create a consistent hierarchy with jsonbridge operations
// At least it does not depend on any specific field names, it just copies the
// Indicator and Indicated fields.
private static JSONObject wrap(JSONObject jo, Class c) {
JSONObject result = new JSONObject();
String indicatorName = Indication.getIndicatorName(c);
String indicatedName = Indication.getIndicatedName(c);
result.put(indicatorName, jo.get(indicatorName));
result.put(indicatedName, jo);
return result;
}
// Convert the JSON-Simple object to the indicated message, field-by-field
// recursively via convertElementToField.
private static Message convertJSONObjectToMessage(JSONObject jo, Class c, Registry<Class> r) {
//System.out.println("JSON.convertJSONObjectToMessage: " + jo.toJSONString());
try {
Message result = (Message) c.newInstance();
for (Field f : c.getFields()) {
Class fc = getFieldClass(result, jo, f, r);
Object lookup = jo.get(f.getName());
if (lookup != null) {
Object value = convertElementToField(lookup, fc, f, r);
f.set(result, value);
}
}
return result;
}
catch (Exception ex) {
//ex.printStackTrace();
return null;
}
finally {
}
}
// Convert the JSON-Simple array to the indicated message, element-by-element
// recursively via convertElementToField.
private static Object convertJSONArrayToArray(JSONArray ja, Class c, Registry<Class> r) {
Object result = Array.newInstance(c, ja.size());
for (int i = 0; i < ja.size(); i++) {
Object lookup = ja.get(i);
Object value = null;
if (lookup != null) {
if (lookup.getClass().equals(JSONObject.class))
value = convertJSONObjectToMessage((JSONObject) lookup, c, r);
else if (lookup.getClass().equals(JSONArray.class)) // this is not actually allowed in ROS
value = convertJSONArrayToArray((JSONArray) lookup, c.getComponentType(), r);
else
value = convertJSONPrimitiveToPrimitive(lookup, c);
Array.set(result, i, value);
}
}
return result;
}
// Convert a JSON-Simple array to a Message, field-by-field of the Message,
// element-by-element of the array, recursively via convertElementToField.
// NOTE: This relies on later versions of the JDK providing
// the fields in order.
private static Message convertJSONArrayToMessage(JSONArray ja, Class c, Registry<Class> r) {
try {
Message result = (Message) c.newInstance();
int arrayIndex = 0;
for (Field f : c.getFields()) {
Class fc = getFieldClass(result, null, f, r);
Object lookup = ja.get(arrayIndex++); // yes we are assuming that the fields are delivered in order
if (lookup != null) {
Object value = convertElementToField(lookup, fc, f, r);
f.set(result, value);
}
}
return result;
}
catch (Exception ex) {
ex.printStackTrace();
return null;
}
finally {
}
}
// Convert an individual array or object element to a field in the Message,
// recursively, and applying AsArray if needed.
private static Object convertElementToField(Object element, Class fc, Field f, Registry<Class> r) {
//System.out.println("JSON.convertElementToField: " + f.getName() + " " + fc.getName());
Object value;
if (element.getClass().equals(JSONObject.class)) {
//System.out.println("JSON.convertElementToField: JSON Object " + ((JSONObject) element).toJSONString());
value = convertJSONObjectToMessage((JSONObject) element, fc, r);
}
else if (element.getClass().equals(JSONArray.class)) {
//System.out.println("JSON.convertElementToField: JSON Array " + ((JSONArray) element).toJSONString());
if (Indication.asArray(f))
value = convertJSONArrayToMessage((JSONArray) element, fc, r);
else value = convertJSONArrayToArray((JSONArray) element, fc, r);
}
else {
//System.out.println("JSON.convertElementToField: Primitive " + element);
if (Indication.isBase64Encoded(f))
value = convertBase64JSONStringToByteArray(element);
else value = convertJSONPrimitiveToPrimitive(element, fc);
}
return value;
}
// Note that this is not checking ranges
public static Object convertJSONPrimitiveToPrimitive(Object o, Class c) {
Object result = o;
if (c.isPrimitive() || Number.class.isAssignableFrom(c)) {
if (c.equals(double.class) || c.equals(Double.class))
result = new Double(((Number) o).doubleValue());
else if (c.equals(float.class) || c.equals(Float.class))
result = new Float(((Number) o).floatValue());
else if (c.equals(long.class) || c.equals(Long.class))
result = new Long(((Number) o).longValue());
else if (int.class.equals(c) || c.equals(Integer.class))
result = new Integer(((Number) o).intValue());
else if (c.equals(short.class) || c.equals(Short.class))
result = new Short(((Number) o).shortValue());
else if (c.equals(byte.class) || c.equals(Byte.class))
result = new Byte(((Number) o).byteValue());
}
return result;
}
public static byte[] convertBase64JSONStringToByteArray(Object element) {
return Base64.decode((String) element);
}
// Determine the target class of a field in the object or array, based
// directly on the field's type, or using the Indicator if applicable,
// The Indicator field only provides the topic/service, so we have to look
// up the Class in the registry.
public static Class getFieldClass(Message parent, JSONObject jo, Field f, Registry<Class> r) {
Class fc;
fc = f.getType();
if (fc.isArray())
fc = f.getType().getComponentType();
if (Indication.isIndicated(f) && (jo != null)) {
//fc = Indication.getIndication(parent,
// (String) jo.get(Indication.getIndicatorName(parent.getClass())));
fc = r.lookup(parent.getClass(),
(String) jo.get(Indication.getIndicatorName(parent.getClass())));
//System.out.println("JSON.getFieldClass: parent class " + parent.getClass().getName() +
// " Indicator: " + Indication.getIndicatorName(parent.getClass()) +
// " result: " + fc.getName());
}
return fc;
}
}

@ -0,0 +1,24 @@
package com.jilk.ros.message.ros.rosbridge.implementation;
import com.jilk.ros.message.ros.rosbridge.operation.Operation;
/**EventBus event entity,describe ros server response info
* Created by xxhong on 16-11-22.
*/
public class PublishEvent {
public String msg;
public String id;
public String name;
public String op;
public PublishEvent(Operation operation, String name, String content) {
if(operation != null) {
id = operation.id;
op = operation.op;
}
this.name = name;
msg = content;
}
}

@ -0,0 +1,209 @@
/**
* Copyright (c) 2014 Jilk Systems, Inc.
* <p>
* This file is part of the Java ROSBridge Client.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.ros.rosbridge.implementation;
import com.jilk.ros.message.ros.ROSClient;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.rosbridge.FullMessageHandler;
import com.jilk.ros.message.ros.rosbridge.operation.Operation;
import com.jilk.ros.message.ros.rosbridge.operation.Publish;
import com.jilk.ros.message.ros.rosbridge.operation.ServiceResponse;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.CloseFrame;
import org.java_websocket.handshake.ServerHandshake;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.lang.reflect.Field;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.SocketChannel;
import de.greenrobot.event.EventBus;
public class ROSBridgeWebSocketClient extends WebSocketClient {
private Registry<Class> classes;
private Registry<FullMessageHandler> handlers;
private boolean debug;
private ROSClient.ConnectionStatusListener listener;
ROSBridgeWebSocketClient(URI serverURI) {
super(serverURI);
classes = new Registry<Class>();
handlers = new Registry<FullMessageHandler>();
Operation.initialize(classes); // note, this ensures that the Message Map is initialized too
listener = null;
}
public static ROSBridgeWebSocketClient create(String URIString) {
ROSBridgeWebSocketClient client = null;
try {
URI uri = new URI(URIString);
client = new ROSBridgeWebSocketClient(uri);
} catch (URISyntaxException ex) {
ex.printStackTrace();
} finally {
}
return client;
}
public void setListener(ROSClient.ConnectionStatusListener listener) {
this.listener = listener;
}
@Override
public void onOpen(ServerHandshake handshakedata) {
if (listener != null)
listener.onConnect();
}
@Override
public void onMessage(String message) {
if (debug) System.out.println("<ROS " + message);
//System.out.println("ROSBridgeWebSocketClient.onMessage (message): " + message);
Operation operation = Operation.toOperation(message, classes);
//System.out.println("ROSBridgeWebSocketClient.onMessage (operation): ");
//operation.print();
FullMessageHandler handler = null;
Message msg = null;
if (operation instanceof Publish) {
Publish p = (Publish) operation;
handler = handlers.lookup(Publish.class, p.topic);
msg = p.msg;
} else if (operation instanceof ServiceResponse) {
ServiceResponse r = ((ServiceResponse) operation);
handler = handlers.lookup(ServiceResponse.class, r.service);
msg = r.values;
}
// later we will add clauses for Fragment, PNG, and Status. When rosbridge has it, we'll have one for service requests.
// need to handle "result: null" possibility for ROSBridge service responses
// this is probably some sort of call to the operation for "validation." Do it
// as part of error handling.
if (handler != null && message.contains("\"id\":"))
handler.onMessage(operation.id, msg);
else {
if (debug)
System.out.print("No handler: id# " + operation.id + ", op:" + operation.op);
if (operation instanceof Publish) {
Publish publish = ((Publish) operation);
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(message);
String content = jsonObject.get("msg").toString();
EventBus.getDefault().post(new PublishEvent(operation, publish.topic, content));
} catch (ParseException e) {
e.printStackTrace();
} finally {
}
System.out.println("Publish " + publish.topic);
} else if (operation instanceof ServiceResponse) {
ServiceResponse serviceResponse = ((ServiceResponse) operation);
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(message);
String content = jsonObject.get("values").toString();
EventBus.getDefault().post(new PublishEvent(operation, serviceResponse.service, content));
} catch (ParseException e) {
e.printStackTrace();
} finally {
}
System.out.println("Service Response " + serviceResponse.service);
}
}
}
@Override
public void onClose(int code, String reason, boolean remote) {
if (listener != null) {
boolean normal = (remote || (code == CloseFrame.NORMAL));
listener.onDisconnect(normal, reason, code);
}
}
@Override
public void onError(Exception ex) {
if (listener != null)
listener.onError(ex);
else ex.printStackTrace();
}
// There is a bug in V1.2 of java_websockets that seems to appear only in Android, specifically,
// it does not shut down the thread and starts using gobs of RAM (symptom is frequent garbage collection).
// This method goes into the WebSocketClient object and hard-closes the socket, which causes the thread
// to exit (note, just interrupting the thread does not work).
@Override
public void closeBlocking() throws InterruptedException {
super.closeBlocking();
try {
Field channelField = this.getClass().getSuperclass().getDeclaredField("channel");
channelField.setAccessible(true);
SocketChannel channel = (SocketChannel) channelField.get(this);
if (channel != null && channel.isOpen()) {
Socket socket = channel.socket();
if (socket != null)
socket.close();
}
} catch (Exception ex) {
System.out.println("Exception in Websocket close hack.");
ex.printStackTrace();
} finally {
}
}
public void send(Operation operation) {
String json = operation.toJSON();
if (debug) System.out.println("ROS> " + json);
send(json);
}
public void register(Class<? extends Operation> c,
String s,
Class<? extends Message> m,
FullMessageHandler h) {
Message.register(m, classes.get(Message.class));
classes.register(c, s, m);
if (h != null)
handlers.register(c, s, h);
}
public void unregister(Class<? extends Operation> c, String s) {
handlers.unregister(c, s);
// Note that there is no concept of unregistering a class - it can get replaced is all
}
public Class<? extends Message> getRegisteredMessage(String messageString) {
return classes.lookup(Message.class, messageString);
}
public void setDebug(boolean debug) {
this.debug = debug;
}
}

@ -0,0 +1,49 @@
/**
* 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.ros.rosbridge.implementation;
import java.util.HashMap;
import java.util.Map;
public class Registry<T> extends HashMap<Class, Map<String, T>> {
public void register(Class c, String s, T t) {
Map<String, T> table = get(c);
if (table == null) {
table = new HashMap<String, T>();
put(c, table);
}
table.put(s, t);
}
public void unregister(Class c, String s) {
Map<String, T> table = get(c);
if (table != null)
table.remove(s);
}
public T lookup(Class c, String s) {
T result = null;
Map<String, T> table = get(c);
if (table != null)
result = table.get(s);
return result;
}
}

@ -0,0 +1,30 @@
/**
* 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.ros.rosbridge.indication;
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.FIELD)
public @interface AsArray {
}

@ -0,0 +1,30 @@
/**
* 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.ros.rosbridge.indication;
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.FIELD)
public @interface Base64Encoded {
}

@ -0,0 +1,31 @@
/**
* 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.ros.rosbridge.indication;
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.METHOD)
public @interface Indicate {
// if later we want multiple indicated fields, use an int here
}

@ -0,0 +1,31 @@
/**
* 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.ros.rosbridge.indication;
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.FIELD)
public @interface Indicated {
// if later we want multiple indicated fields, use an int here
}

@ -0,0 +1,83 @@
/**
* 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.ros.rosbridge.indication;
import java.lang.reflect.Field;
public class Indication {
public static boolean isIndicated(Field f) {
return (f.getAnnotation(Indicated.class) != null);
}
public static boolean asArray(Field f) {
return (f.getAnnotation(AsArray.class) != null);
}
public static boolean isBase64Encoded(Field f) {
return ((f.getAnnotation(Base64Encoded.class) != null) &&
f.getType().isArray() &&
f.getType().getComponentType().equals(byte.class));
}
public static String getIndicatorName(Class c) {
return getName(c, Indicator.class);
}
public static String getIndicatedName(Class c) {
return getName(c, Indicated.class);
}
private static String getName(Class c, Class annotation) {
String result = null;
for (Field f : c.getFields()) {
if (f.getAnnotation(annotation) != null) {
result = f.getName();
break;
}
}
return result;
}
/*
public static Class getIndication(Object o, String s) {
Class c = o.getClass();
Class result = null;
try {
Method m = getIndicateMethod(c);
result = (Class) (m.invoke(o, s));
}
catch (ReflectiveOperationException ex) {
ex.printStackTrace();
}
return result;
}
private static Method getIndicateMethod(Class c) {
Method result = null;
for (Method m : c.getMethods()) {
if (m.getAnnotation(Indicate.class) != null) {
result = m;
break;
}
}
return result;
}
*/
}

@ -0,0 +1,31 @@
/**
* 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.ros.rosbridge.indication;
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.FIELD)
public @interface Indicator {
// if later we want multiple indicated fields, use an int here
}

@ -0,0 +1,35 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "advertise")
public class Advertise extends Operation {
public String topic;
public String type;
public Advertise() {}
public Advertise(String topic, String type) {
this.topic = topic;
this.type = type;
}
}

@ -0,0 +1,56 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "auth")
public class Authenticate extends Operation {
public String mac;
public String client;
public String dest;
public String rand;
public int t;
public String level;
public int end;
public Authenticate() {}
public Authenticate(
String mac,
String client,
String dest,
String rand,
int t,
String level,
int end)
{
this.mac = mac;
this.client = client;
this.dest = dest;
this.rand = rand;
this.t = t;
this.level = level;
this.end = end;
this.id = null; // even though id is on EVERY OTHER operation type
}
}

@ -0,0 +1,44 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.rosbridge.indication.AsArray;
import com.jilk.ros.message.ros.rosbridge.indication.Indicated;
import com.jilk.ros.message.ros.rosbridge.indication.Indicator;
@MessageType(string = "call_service")
public class CallService extends Operation {
@Indicator
public String service;
@Indicated
@AsArray
public Message args;
public Integer fragment_size; // use Integer for optional items
public String compression;
public CallService() {}
public CallService(String service, Message args) {
this.service = service;
this.args = args;
}
}

@ -0,0 +1,37 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "fragment")
public class Fragment extends Operation {
public String data;
public int num;
public int total;
public Fragment() {}
public Fragment(String data, int num, int total) {
this.data = data;
this.num = num;
this.total = total;
}
}

@ -0,0 +1,77 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.rosbridge.implementation.JSON;
import com.jilk.ros.message.ros.rosbridge.implementation.Registry;
@MessageType(string = "operation")
public class Operation extends Message {
private static Long uid = 0L;
public String op;
public String id;
public Operation() {
this.op = getMessageType(getClass());
this.id = nextId();
}
private static synchronized String nextId() {
String result = uid.toString();
uid++;
return result;
}
public String toJSON() {
return JSON.toJSON(this);
}
public static Operation toOperation(String json, Registry<Class> registry) {
return ((Wrapper) JSON.toMessage(json, Wrapper.class, registry)).msg;
}
public static void initialize(Registry<Class> registry) {
initClass(registry, Advertise.class);
initClass(registry, Authenticate.class);
initClass(registry, CallService.class);
initClass(registry, Fragment.class);
initClass(registry, Operation.class);
initClass(registry, PNG.class);
initClass(registry, Publish.class);
initClass(registry, ServiceResponse.class);
initClass(registry, SetStatusLevel.class);
initClass(registry, Status.class);
initClass(registry, Subscribe.class);
initClass(registry, Unadvertise.class);
initClass(registry, Unsubscribe.class);
initClass(registry, Wrapper.class);
registry.register(Wrapper.class, Message.getMessageType(Publish.class), Publish.class);
registry.register(Wrapper.class, Message.getMessageType(CallService.class), CallService.class);
registry.register(Wrapper.class, Message.getMessageType(ServiceResponse.class), ServiceResponse.class);
}
private static void initClass(Registry<Class> registry, Class<? extends Message> c) {
registry.register(Message.class, Message.getMessageType(c), c);
}
}

@ -0,0 +1,41 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "png")
public class PNG extends Operation {
public String data;
public Integer num; // use Integer for optional items
public Integer total; // use Integer for optional items
public PNG() {}
public PNG(String data) {
this.data = data;
}
public PNG(String data, int num, int total) {
this.data = data;
this.num = num;
this.total = total;
}
}

@ -0,0 +1,41 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.rosbridge.indication.Indicated;
import com.jilk.ros.message.ros.rosbridge.indication.Indicator;
@MessageType(string = "publish")
public class Publish extends Operation {
@Indicator
public String topic;
@Indicated
public Message msg;
public Publish() {}
public Publish(String topic, Message msg) {
this.topic = topic;
this.msg = msg;
}
}

@ -0,0 +1,40 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.Message;
import com.jilk.ros.message.ros.message.MessageType;
import com.jilk.ros.message.ros.rosbridge.indication.Indicated;
import com.jilk.ros.message.ros.rosbridge.indication.Indicator;
@MessageType(string = "service_response")
public class ServiceResponse extends Operation {
@Indicator
public String service;
public boolean result;
@Indicated
public Message values;
public ServiceResponse() {}
public ServiceResponse(String service) {
this.service = service;
}
}

@ -0,0 +1,38 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "set_level")
public class SetStatusLevel extends Operation {
public String level;
public SetStatusLevel() {}
public SetStatusLevel(String level) {
this.level = null;
if ("none".equals(level) ||
"warning".equals(level) ||
"error".equals(level) ||
"info".equals(level))
this.level = level;
}
}

@ -0,0 +1,35 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "status")
public class Status extends Operation {
String level;
String msg;
public Status() {}
public Status(String level, String msg) {
this.level = level;
this.msg = msg;
}
}

@ -0,0 +1,39 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "subscribe")
public class Subscribe extends Operation {
public String topic;
public String type;
public Integer throttle_rate; // use Integer for optional items
public Integer queue_length; // use Integer for optional items
public Integer fragment_size; // use Integer for optional items
public String compression;
public Subscribe() {}
public Subscribe(String topic, String type) {
this.topic = topic;
this.type = type;
}
}

@ -0,0 +1,33 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "unadvertise")
public class Unadvertise extends Operation {
public String topic;
public Unadvertise() {}
public Unadvertise(String topic) {
this.topic = topic;
}
}

@ -0,0 +1,33 @@
/**
* 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.ros.rosbridge.operation;
import com.jilk.ros.message.ros.message.MessageType;
@MessageType(string = "unsubscribe")
public class Unsubscribe extends Operation {
public String topic;
public Unsubscribe() {}
public Unsubscribe(String topic) {
this.topic = topic;
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save