ROSSerialADKService.java
Go to the documentation of this file.
00001 package org.ros.rosserial;
00002 
00003 import android.app.NotificationManager;
00004 import android.app.Service;
00005 import android.content.Intent;
00006 import android.media.ExifInterface;
00007 import android.os.Binder;
00008 import android.os.IBinder;
00009 import android.util.Log;
00010 import android.widget.TextView;
00011 import android.widget.Toast;
00012 
00013 import org.ros.node.Node;
00014 import org.ros.RosUtils;
00015 import org.ros.message.rosserial_msgs.TopicInfo;
00016 import org.ros.rosserial.ROSSerialADK;
00017 
00018 import com.android.future.usb.UsbManager;
00019 
00020 public class ROSSerialADKService extends Service {
00021         static final String TAG = "ROSSerialSDKService";
00022         
00026         private String node_name;
00027         
00031         Node nh;
00032         
00036         ROSSerialADK adk = null;
00037         
00041     private  IBinder mBinder;
00042     
00050     public class LocalBinder extends Binder {
00051         ROSSerialADKService service;
00052         public LocalBinder(ROSSerialADKService s) {
00053                 service = s;
00054                 }
00055         ROSSerialADK getADK() {
00056             // Return this instance of LocalService so clients can call public methods
00057             return adk;
00058         }
00059         ROSSerialADKService getService(){
00060                 return service;}
00061     }
00062 
00063 
00064         @Override
00065         public IBinder onBind(Intent intent) {
00066                 return mBinder;
00067         }
00068         
00069 
00075         @Override
00076         public int onStartCommand(Intent intent, int flags, int startId) {
00077 
00078                 String master_uri = intent.getExtras().getString("ROS_MASTER_URI");
00079                 if (master_uri == null) master_uri = "http://localhost:11311";
00080                 
00081                 node_name = intent.getExtras().getString("name");
00082                 if (node_name ==null) node_name = "ROSSerialADK";
00083 
00084                 Log.v(TAG, "Starting ROSSerialADKService as node '" + node_name+"' with master '" + master_uri);
00085 
00086                 try{
00087                         nh = RosUtils.createExternalMaster(node_name, master_uri);
00088                         adk = new ROSSerialADK(this, nh);       
00089                 }
00090                 catch(Exception e){
00091                         // TODO Properly handle failure to connect to the ROS Master
00092 
00093                         e.printStackTrace();
00094                         System.exit(-1);
00095                 }
00096                 if (!adk.open()){
00097                         Log.v(TAG, "No ADK connected");
00098                 }
00099                 
00100                 mBinder = new LocalBinder(this);
00101                 
00102                 Toast t = Toast.makeText(this, node_name + " started.", Toast.LENGTH_SHORT);
00103                 t.show();
00104                 
00105                 return START_STICKY;
00106         }
00107 
00108         @Override
00109         public void onDestroy() {
00110                 if (adk!=null) this.adk.shutdown();
00111                 if (nh != null) this.nh.shutdown();
00112                 Toast t = Toast.makeText(this, node_name + " stopped.", Toast.LENGTH_SHORT);
00113                 t.show();
00114         
00115                 super.onDestroy();
00116         }
00117 
00118         public ROSSerialADKService(){
00119                 super();
00120         }
00121         
00122 }


rosserial_android
Author(s): Adam Stambler
autogenerated on Mon Dec 2 2013 12:02:05