commit a8987cda5e2c606b2aba534af5ee0edb027c69b3
Author: Tom Mullins <tmullins@andrew.cmu.edu>
Date:   Sun Oct 7 22:41:54 2012 -0400

    Fixes to WirelessReceiver and wl_test
    
    Changed receive callback to use std::function so we can use std::bind to
    pass non-static member functions. There is still a weird problem where
    WirelessReceiver::dummy gets called many times for each incoming packet
    in wl_test.

diff --git a/scout/libscout/CMakeLists.txt b/scout/libscout/CMakeLists.txt
index ace9a63..d2230e2 100644
--- a/scout/libscout/CMakeLists.txt
+++ b/scout/libscout/CMakeLists.txt
@@ -36,4 +36,5 @@ set(HELPER_FILES src/helper_classes/Order.cpp src/helper_classes/PQWrapper.cpp)
 set(CONTROL_CLASSES src/MotorControl.cpp src/SonarControl.cpp src/HeadlightControl.cpp src/ButtonControl.cpp src/WirelessSender.cpp src/WirelessReceiver.cpp src/EncodersControl.cpp src/LinesensorControl.cpp)
 
 rosbuild_add_executable(libscout ${MAIN_FILES} ${BEHAVIOR_FILES} ${TEST_BEHAVIOR_FILES} ${CONTROL_CLASSES} ${HELPER_FILES})
+rosbuild_add_compile_flags(libscout -std=c++0x)
 rosbuild_add_executable(test_encoders src/test_encoders.cpp)
diff --git a/scout/libscout/src/WirelessReceiver.cpp b/scout/libscout/src/WirelessReceiver.cpp
index cf25d69..9d0f7ec 100644
--- a/scout/libscout/src/WirelessReceiver.cpp
+++ b/scout/libscout/src/WirelessReceiver.cpp
@@ -45,7 +45,7 @@ using namespace std;
  * @param libscout_node Node handle of the ROS node used by libscout.
  **/
 WirelessReceiver::WirelessReceiver(const ros::NodeHandle& libscout_node)
-    : node(libscout_node)
+    : node(libscout_node), callback(bind(&WirelessReceiver::dummy, this, _1))
 {
     sub = node.subscribe("/wireless/receive", QUEUE_SIZE,
           &WirelessReceiver::receive, this);
@@ -70,12 +70,12 @@ void WirelessReceiver::register_callback(WirelessCallback new_callback)
  **/
 void WirelessReceiver::receive(const ::messages::WirelessPacketConstPtr& packet)
 {
-    if (callback == NULL)
-    {
-        ROS_WARN("Warning: Ignored wireless packet.");
-    }
-    else
-    {
-        (*callback)(packet->data);
-    }
+    callback(packet->data);
+}
+
+/**
+ * @brief The default callback function, to be overwritten by register_callback
+ */
+void WirelessReceiver::dummy(std::vector<uint8_t> data) {
+    ROS_WARN("Warning: Ignored wireless packet.");
 }
diff --git a/scout/libscout/src/WirelessReceiver.h b/scout/libscout/src/WirelessReceiver.h
index 7227871..8e01916 100644
--- a/scout/libscout/src/WirelessReceiver.h
+++ b/scout/libscout/src/WirelessReceiver.h
@@ -39,11 +39,12 @@
 #define _WIRELESS_RECEIVER_H_
 
 #include <vector>
+#include <functional>
 #include <ros/ros.h>
 #include "messages/WirelessPacket.h"
 #include "constants.h"
 
-typedef void (*WirelessCallback)(std::vector<uint8_t>);
+typedef std::function<void(std::vector<uint8_t>)> WirelessCallback;
 
 class WirelessReceiver
 {
@@ -59,6 +60,7 @@ class WirelessReceiver
         ros::NodeHandle node;
         WirelessCallback callback;
         void receive(const ::messages::WirelessPacketConstPtr&);
+        void dummy(std::vector<uint8_t> data);
 };
 
 #endif
diff --git a/scout/libscout/src/behaviors/wl_test.cpp b/scout/libscout/src/behaviors/wl_test.cpp
index bdf3997..ee751db 100644
--- a/scout/libscout/src/behaviors/wl_test.cpp
+++ b/scout/libscout/src/behaviors/wl_test.cpp
@@ -25,48 +25,34 @@
 
 #include "wl_test.h"
 
-#define DATA_SIZE 10
-
 using namespace std;
 
-bool is_receiving = false;
-uint8_t highest_received = 0;
-
-void data_callback(std::vector<uint8_t> data)
+void wl_test::data_callback(std::vector<uint8_t> data)
 {
-    cout << "Wireless callback triggered." << endl;;
-    for (int i = 0; i < data.size(); i++)
-    {
-        if (data[i] > highest_received)
-        {
-            highest_received = data[i];
-        }
-    }
+    // We got a response! Stop publishing data = [1]
+    if (no_response)
+        no_response = false;
+
+    ROS_INFO("Wireless callback triggered.");
+    data[0]++;
+    sleep(1);
+    wl_sender->send(data,1);
 }
 
 void wl_test::run()
 {
-    motors->set_sides(20, 50, MOTOR_ABSOLUTE);
-    wl_receiver->register_callback(data_callback);
-
+    wl_receiver->register_callback(std::bind(&wl_test::data_callback, this,
+        std::placeholders::_1));
     while(ok())
     {
-        if (!is_receiving)
+        // Publish 1 if we are scout1 until we get a response.
+        if (scout_name == "scout1" && no_response) 
         {
-            // Fill up a bogus data array
-            vector<uint8_t> data;
-            for (int i = 0; i < DATA_SIZE; i++)
-            {
-                data.push_back(highest_received + i);
-            }
-
-            wl_sender->send(data);
-            cout << "Sent wireless packet." << endl;
-            is_receiving = true;
+            uint8_t data[1];
+            data[0] = 1;
+            wl_sender->send(data,1);
         }
-
         spinOnce();
         loop_rate->sleep();
     }
 }
-
diff --git a/scout/libscout/src/behaviors/wl_test.h b/scout/libscout/src/behaviors/wl_test.h
index baab5bd..8df23ed 100644
--- a/scout/libscout/src/behaviors/wl_test.h
+++ b/scout/libscout/src/behaviors/wl_test.h
@@ -1,40 +1,44 @@
-/**
- * Copyright (c) 2011 Colony Project
- * 
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- * 
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _WL_TEST_H_
-#define _WL_TEST_H_
-
-#include "../Behavior.h"
-
-class wl_test : Behavior
-{
-    public:
-        wl_test(std::string scoutname) : Behavior(scoutname, "wl_test") {};
-
-        /** Actually executes the behavior. */
-        void run();
-};
-
-#endif
+/**
+ * Copyright (c) 2011 Colony Project
+ * 
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _WL_TEST_H_
+#define _WL_TEST_H_
+
+#include "../Behavior.h"
+
+class wl_test : Behavior
+{
+    public:
+        wl_test(std::string scoutname) : Behavior(scoutname, "wl_test"),
+            no_response(true), scout_name(scoutname) {};
+        /** Actually executes the behavior. */
+        void data_callback(std::vector<uint8_t> data);
+        void run();
+    private:
+        bool no_response;
+        std::string scout_name;
+};
+
+#endif
