DiagnosticArraySubscriber.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Chad Rockey
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Android Robot Monitor nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 package org.ros.android.robot_monitor;
00031 
00032 import org.ros.node.ConnectedNode;
00033 import org.ros.android.MessageCallable;
00034 import org.ros.message.MessageListener;
00035 import org.ros.namespace.GraphName;
00036 import org.ros.node.Node;
00037 import org.ros.node.NodeMain;
00038 import org.ros.node.topic.Subscriber;
00039 
00040 import diagnostic_msgs.DiagnosticArray;
00041 
00045 public class DiagnosticArraySubscriber implements NodeMain
00046 {
00047   MessageCallable<DiagnosticArray, DiagnosticArray> callable;
00048   
00049   DiagnosticArray last_message;
00050   
00051   public DiagnosticArraySubscriber()
00052   {
00053   }
00054   
00055   public void setMessageCallable(MessageCallable<DiagnosticArray, DiagnosticArray> callable){
00056           this.callable = callable;
00057   }
00058   
00059   public void clearCallable(){
00060           this.callable = null;
00061   }
00062 
00063   @Override
00064   public GraphName getDefaultNodeName() {
00065     return GraphName.of("android_gingerbread/ros_text_view");
00066   }
00067   
00068   public DiagnosticArray getLastMessage(){
00069           return this.last_message;
00070   }
00071 
00072   @Override
00073   public void onStart(ConnectedNode connectedNode) {
00074     Subscriber<DiagnosticArray> subscriber = connectedNode.newSubscriber("/diagnostics_agg", "diagnostic_msgs/DiagnosticArray");
00075     subscriber.addMessageListener(new MessageListener<DiagnosticArray>() {
00076       @Override
00077       public void onNewMessage(final DiagnosticArray message) {
00078         if(callable != null){
00079                 callable.call(message);
00080         }
00081         DiagnosticArraySubscriber.this.last_message = message;
00082       }
00083     });
00084   }
00085 
00086   @Override
00087   public void onShutdown(Node node) {
00088   }
00089 
00090   @Override
00091   public void onShutdownComplete(Node node) {
00092   }
00093 
00094   @Override
00095   public void onError(Node node, Throwable throwable) {
00096   }
00097 
00098 }


android_robot_monitor
Author(s): Chad Rockey
autogenerated on Sat Dec 28 2013 16:44:07