]> rtime.felk.cvut.cz Git - orte.git/commitdiff
ROBOT_DEMO: use new constants and fix behavior of callback functions
authorMartin Vajnar <martin.vajnar@gmail.com>
Sun, 20 Oct 2013 16:07:55 +0000 (18:07 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 28 Oct 2013 15:47:35 +0000 (16:47 +0100)
Test the receive status to see whether the callback function was called
because of new new data reception or because of a deadline expiration.

orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java
orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedSubscribe.java
orte/Robot_Demo/src/org/ocera/orte/demo/PwrVoltageSubscribe.java

index 485c67289d1f42ffa580569a2a9bf2f3fe8f99be..900d9f21d0b5f3ecd97971ac12ebdd04b5460e40 100644 (file)
@@ -11,12 +11,10 @@ import org.ocera.orte.types.MessageData;
 import org.ocera.orte.types.NtpTime;
 import org.ocera.orte.types.RecvInfo;
 import org.ocera.orte.types.SubsProp;
+import org.ocera.orte.types.ORTEConstant;
 
 public class HokuyoScanSubscribe extends SubscriptionCallback{
 
-    public final static int IMMEDIATE    = 0x02;
-    public final static int BEST_EFFORTS = 0x01;
-    
        private Subscription sub;
        private HokuyoView view;
        private HokuyoScanType hokuyomsg;
@@ -41,8 +39,8 @@ public class HokuyoScanSubscribe extends SubscriptionCallback{
                                                        "hokuyo_scan",                                  
                                                        minSeparation,  
                                                        deadline,
-                                                       IMMEDIATE,
-                                                       BEST_EFFORTS,
+                                                       ORTEConstant.IMMEDIATE,
+                                                       ORTEConstant.BEST_EFFORTS,
                                                        0);
        }
        
@@ -76,6 +74,7 @@ public class HokuyoScanSubscribe extends SubscriptionCallback{
        }
        
     public void callback(RecvInfo info, MessageData msg) {
-       view.setData(((HokuyoScanType)msg).hokuyo);
-       }
-}
\ No newline at end of file
+      if (info.getRecvStatus() == ORTEConstant.NEW_DATA)
+        view.setData(((HokuyoScanType)msg).hokuyo);
+    }
+}
index 524e95482f33264802a4b6d406cf0faef93ea566..f9dc652e9199129f69ab3c2cb9d8a1ec18f3078b 100644 (file)
@@ -11,12 +11,10 @@ import org.ocera.orte.types.MessageData;
 import org.ocera.orte.types.NtpTime;
 import org.ocera.orte.types.RecvInfo;
 import org.ocera.orte.types.SubsProp;
+import org.ocera.orte.types.ORTEConstant;
 
 public class MotionSpeedSubscribe extends SubscriptionCallback{
 
-    public final static int IMMEDIATE    = 0x02;
-    public final static int BEST_EFFORTS = 0x01;
-    
        private Subscription sub;
        private HokuyoView view;
        private SpeedMotionType speedmsg;
@@ -41,8 +39,8 @@ public class MotionSpeedSubscribe extends SubscriptionCallback{
                                                        "motion_speed",                                 
                                                        minSeparation,  
                                                        deadline,
-                                                       IMMEDIATE,
-                                                       BEST_EFFORTS,
+                                                       ORTEConstant.IMMEDIATE,
+                                                       ORTEConstant.BEST_EFFORTS,
                                                        0);
        }
        
@@ -76,7 +74,7 @@ public class MotionSpeedSubscribe extends SubscriptionCallback{
        }
        
     public void callback(RecvInfo info, MessageData msg) {
-       view.setDataMotion(((SpeedMotionType)msg).speed);
-       //System.out.println(msg);
-       }
-}
\ No newline at end of file
+      if (info.getRecvStatus() == ORTEConstant.NEW_DATA)
+        view.setDataMotion(((SpeedMotionType)msg).speed);
+    }
+}
index 98529882c3bb71d7786df42b4aa8834afcb94bdd..70cf02558e3fca219655748ef698e967cbdd6d04 100644 (file)
@@ -11,6 +11,7 @@ import org.ocera.orte.types.MessageData;
 import org.ocera.orte.types.NtpTime;
 import org.ocera.orte.types.RecvInfo;
 import org.ocera.orte.types.SubsProp;
+import org.ocera.orte.types.ORTEConstant;
 
 import android.os.Bundle;
 import android.os.Handler;
@@ -18,9 +19,6 @@ import android.os.Message;
 
 public class PwrVoltageSubscribe extends SubscriptionCallback{
 
-    public final static int IMMEDIATE    = 0x02;
-    public final static int BEST_EFFORTS = 0x01;
-
     static Handler handler;
     
        private Subscription sub;
@@ -46,8 +44,8 @@ public class PwrVoltageSubscribe extends SubscriptionCallback{
                                                        "pwr_voltage",                                  
                                                        minSeparation,  
                                                        deadline,
-                                                       IMMEDIATE,
-                                                       BEST_EFFORTS,
+                                                       ORTEConstant.IMMEDIATE,
+                                                       ORTEConstant.BEST_EFFORTS,
                                                        0);
        }
        
@@ -81,11 +79,13 @@ public class PwrVoltageSubscribe extends SubscriptionCallback{
        }
        
     public void callback(RecvInfo info, MessageData msg) {
-       Message message = handler.obtainMessage();
-       Bundle bundle = new Bundle();
-       
-       bundle.putDoubleArray("voltages", ((PwrVoltageType)msg).voltage.clone());
-       message.setData(bundle);
-       handler.sendMessage(message);
+      if (info.getRecvStatus() == ORTEConstant.NEW_DATA) {
+        Message message = handler.obtainMessage();
+        Bundle bundle = new Bundle();
+
+        bundle.putDoubleArray("voltages", ((PwrVoltageType)msg).voltage.clone());
+        message.setData(bundle);
+        handler.sendMessage(message);
+      }
     }
-}
\ No newline at end of file
+}