Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OK..I've gotten alittle closer...Here's what I have so far...

public class WebViewActivity extends RosActivity implements NodeMain{

private WebView webView;
String url;
String selfIP;
String hostIP;

public WebViewActivity() {
    super("WebViewActivity", "view streams");
}

@Override
protected void init(NodeMainExecutor nodeMainExecutor) {
    //NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic( InetAddressFactory.newNonLoopback().getHostAddress()); //For everything else
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(selfIP); //For everything else
    nodeConfiguration.setMasterUri(URI.create("http://" + hostIP + ":11311"));
  }

@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.commit();
    selfIP = prefs.getString("selfIP", "192.168.0.100");
    hostIP = prefs.getString("simulationpc2", "192.168.0.51");

    ...

}
...

@Override
public void onError(Node arg0, Throwable arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdown(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdownComplete(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onStart(ConnectedNode connectednode) {

    try{
        ListView ParamListView = (ListView) findViewById(R.id.ParamListView);
        final String[] NodeName = url.split("=");
        //ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(Integer.MAX_VALUE);
        //NodeFactory nodeFactory = new DefaultNodeFactory(scheduledExecutorService);
        //Node node = nodeFactory.newNode(nodeConfiguration);
        //ConnectedNode connectednode = (ConnectedNode) node;
        final ParameterTree ParamList = connectednode.getParameterTree();
        //final ParameterTree ParamList = (ParameterTree) new ArrayList<String>();
        @SuppressWarnings("unchecked")
        List<String> ParamJavaList = (List<String>) ParamList.getList(NodeName[1]);
        final ArrayAdapter<String> ParamListAdapter = new ArrayAdapter<String>(this, android.R.id.text1, ParamJavaList);
        ParamListView.setAdapter(ParamListAdapter);
        ParamListView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                  double value = ParamList.getDouble(NodeName[1] + ParamListAdapter.getItem(position),0.5);
                  SeekBar ParamSeekBar = (SeekBar) findViewById(R.id.ParamSeekBar);
                  ParamSeekBar.setProgress((int)value);
              }
            }); 
    }catch(Exception e){
        toast("Unable to Obtain List of Parameters");
    }

}

@Override
public GraphName getDefaultNodeName() {
    return null;
}

}

But it still doesn't work. Is my form correct? is there a better way I should be implementing this?

click to hide/show revision 2
Sorry for ...'s, the code is proprietary to my company

OK..I've gotten alittle closer...Here's what I have so far...

public class WebViewActivity extends RosActivity implements NodeMain{

private WebView webView;
String url;
String selfIP;
String hostIP;

public WebViewActivity() {
    super("WebViewActivity", "view streams");
}

@Override
protected void init(NodeMainExecutor nodeMainExecutor) {
    //NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic( InetAddressFactory.newNonLoopback().getHostAddress()); //For everything else
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(selfIP); //For everything else
    nodeConfiguration.setMasterUri(URI.create("http://" + hostIP + ":11311"));
  }

@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.commit();
    selfIP = prefs.getString("selfIP", "192.168.0.100");
    hostIP = prefs.getString("simulationpc2", "192.168.0.51");

    ...

}
...

@Override
public void onError(Node arg0, Throwable arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdown(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdownComplete(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onStart(ConnectedNode connectednode) {

    try{
        ListView ParamListView = (ListView) findViewById(R.id.ParamListView);
        final String[] NodeName = url.split("=");
        //ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(Integer.MAX_VALUE);
        //NodeFactory nodeFactory = new DefaultNodeFactory(scheduledExecutorService);
        //Node node = nodeFactory.newNode(nodeConfiguration);
        //ConnectedNode connectednode = (ConnectedNode) node;
        final ParameterTree ParamList = connectednode.getParameterTree();
        //final ParameterTree ParamList = (ParameterTree) new ArrayList<String>();
        @SuppressWarnings("unchecked")
        List<String> ParamJavaList = (List<String>) ParamList.getList(NodeName[1]);
        final ArrayAdapter<String> ParamListAdapter = new ArrayAdapter<String>(this, android.R.id.text1, ParamJavaList);
        ParamListView.setAdapter(ParamListAdapter);
        ParamListView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                  double value = ParamList.getDouble(NodeName[1] + ParamListAdapter.getItem(position),0.5);
                  SeekBar ParamSeekBar = (SeekBar) findViewById(R.id.ParamSeekBar);
                  ParamSeekBar.setProgress((int)value);
              }
            }); 
    }catch(Exception e){
        toast("Unable to Obtain List of Parameters");
    }

}

@Override
public GraphName getDefaultNodeName() {
    return null;
}

}

But it still doesn't work. Is my form correct? is there a better way I should be implementing this?

OK..I've gotten alittle closer...Here's what I have so far...was able to solve it by going the route of ssh-ing into the host machine (using Jsch). This code did the bulk of the work from an AsyncTask.

public class WebViewActivity extends RosActivity implements NodeMain{

private WebView webView;
            JSch jsch=new JSch();  

            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");
            config.put("compression.s2c", "zlib,none");
            config.put("compression.c2s", "zlib,none");

            this.user = params[0];
            this.host = params[1];
            this.pwd = params[2];
            this.cmd = params[3];

            session=jsch.getSession(user, host, 22);   
            session.setConfig(config);
            session.setPassword(pwd);
            session.connect();

            StringBuffer result = new StringBuffer();

            channelexec = (ChannelExec) session.openChannel("exec");
            String url;
setPATH = "source /opt/ros/fuerte/setup.bash;export ROS_PACKAGE_PATH=/home/YOURCOMPNAME/ros_workspace:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks;";
            channelexec.setCommand(setPATH+cmd);//
            channelexec.setInputStream(null);
            //channel.setOutputStream(System.out);
            channelexec.setErrStream(System.err);

            InputStream stdout = channelexec.getInputStream();
            InputStream stderr = channelexec.getErrStream();
            //channelexec.setPty(true);
            channelexec.connect();

            msg = "Connected to Host";
            toastHandler.post(toastRunnable);

            String selfIP;
String hostIP;

public WebViewActivity() aux = "";
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stdout));
            while ((aux=bufferedReader.readLine()) != null) {
    super("WebViewActivity", "view streams");
}

@Override
protected void init(NodeMainExecutor nodeMainExecutor) {
    //NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic( InetAddressFactory.newNonLoopback().getHostAddress()); //For everything else
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(selfIP); //For everything else
    nodeConfiguration.setMasterUri(URI.create("http://" + hostIP + ":11311"));
  }

@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.commit();
    selfIP = prefs.getString("selfIP", "192.168.0.100");
    hostIP = prefs.getString("simulationpc2", "192.168.0.51");

    ...

}
...

@Override
public void onError(Node arg0, Throwable arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdown(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onShutdownComplete(Node arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onStart(ConnectedNode connectednode) {

    try{
        ListView ParamListView = (ListView) findViewById(R.id.ParamListView);
        final String[] NodeName = url.split("=");
        //ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(Integer.MAX_VALUE);
        //NodeFactory nodeFactory = new DefaultNodeFactory(scheduledExecutorService);
        //Node node = nodeFactory.newNode(nodeConfiguration);
        //ConnectedNode connectednode = (ConnectedNode) node;
        final ParameterTree ParamList = connectednode.getParameterTree();
        //final ParameterTree ParamList = (ParameterTree) new ArrayList<String>();
        @SuppressWarnings("unchecked")
        List<String> ParamJavaList = (List<String>) ParamList.getList(NodeName[1]);
        final ArrayAdapter<String> ParamListAdapter = new ArrayAdapter<String>(this, android.R.id.text1, ParamJavaList);
        ParamListView.setAdapter(ParamListAdapter);
        ParamListView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                  double value = ParamList.getDouble(NodeName[1] + ParamListAdapter.getItem(position),0.5);
                  SeekBar ParamSeekBar = (SeekBar) findViewById(R.id.ParamSeekBar);
                  ParamSeekBar.setProgress((int)value);
              }
            }); 
                aux.replaceAll(NodeName,"");
                builder.append(","+aux);
            }    

        }catch(Exception e){
        toast("Unable to Obtain List of Parameters");
    msg = "Cannot Retrieve Param List";
            toastHandler.post(toastRunnable);
            e.printStackTrace();
        }

}

@Override
public GraphName getDefaultNodeName() {
     return null;
}

}
builder.toString().substring(1);

But it still doesn't work. Is my form correct? is there a better way And the cmd I should be implementing this?called was:

String cmd = "rosparam list "+NodeName