test_full.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * C++ unit test for dataspeed_lm/version.h
00003  *********************************************************************/
00004 
00005 #include <gtest/gtest.h>
00006 
00007 #include <ros/ros.h>
00008 #include <ros/package.h>
00009 #include <can_msgs/Frame.h>
00010 #include <std_msgs/Bool.h>
00011 #include <std_msgs/Int8.h>
00012 #include <std_msgs/Int16.h>
00013 #include <std_msgs/Int32.h>
00014 #include <std_msgs/Int64.h>
00015 #include <std_msgs/UInt8.h>
00016 #include <std_msgs/UInt16.h>
00017 #include <std_msgs/UInt32.h>
00018 #include <std_msgs/UInt64.h>
00019 
00020 // String stream
00021 #include <iostream>
00022 #include <fstream>
00023 #include <string>
00024 
00025 // File under test
00026 #include "../src/DbcIterator.hpp"
00027 
00028 // Duration constants for waits
00029 const ros::WallDuration DUR_A = ros::WallDuration(3.0); // Expecting success
00030 const ros::WallDuration DUR_B = ros::WallDuration(0.1); // Expecting timeout
00031 
00033 // https://github.com/ros/ros_comm/blob/ebd9e491e71947889eb81089306698775ab5d2a2/test/test_roscpp/test/src/subscribe_star.cpp#L123
00034 
00035 template <typename MsgT>
00036 class MsgHelper {
00037 public:
00038   MsgHelper(std::string tag) : count_(0) {
00039     tag_ = tag;
00040   }
00041 
00042   void set(const MsgT& msg) { latest_ = msg; stamp_ = ros::Time::now(); }
00043   
00044   void cb(const boost::shared_ptr<MsgT const>& msg) {
00045     set(*msg);
00046     ++count_;
00047   }
00048 
00049   bool waitForMessage(ros::WallDuration timeout) const {
00050     const ros::WallTime start = ros::WallTime::now();
00051     while (true) {
00052       if (count_ > 0) {
00053         ROS_DEBUG("Received message (%s)", tag_.c_str());
00054         return true;
00055       }
00056       if ((ros::WallTime::now() - start) > timeout) {
00057         ROS_DEBUG("Message TIMED OUT (%s)", tag_.c_str());
00058         break;
00059       }
00060       ros::WallDuration(0.001).sleep();
00061     }
00062     return false;
00063   }
00064 
00065   void clear() {
00066     stamp_ = ros::Time();
00067     count_ = 0;
00068     latest_ = MsgT();
00069     // tag_ is an identifier for the MsgHelper; it stays the same.
00070   }
00071 
00072   MsgT getLatest() const {return latest_;}
00073   uint32_t getCount() const {return count_;}
00074   ros::Time getStamp() const {return stamp_;}
00075 private:
00076   MsgT latest_;
00077   std::string tag_;
00078   uint32_t count_;
00079   ros::Time stamp_;
00080 };
00081 
00082 
00083 bool waitPublisher(const ros::Publisher &pub, ros::WallDuration timeout) {
00084   const ros::WallTime start = ros::WallTime::now();
00085   while (true) {
00086     if ((pub.getNumSubscribers() > 0)) {
00087       return true;
00088     }
00089     if ((ros::WallTime::now() - start) > timeout) {
00090       break;
00091     }
00092     ros::WallDuration(0.001).sleep();
00093   }
00094   return false;
00095 }
00096 
00097 bool waitSubscriber(const ros::Subscriber &sub, ros::WallDuration timeout) {
00098   const ros::WallTime start = ros::WallTime::now();
00099   while (true) {
00100     if ((sub.getNumPublishers() > 0)) {
00101       return true;
00102     }
00103     if ((ros::WallTime::now() - start) > timeout) {
00104       break;
00105     }
00106     ros::WallDuration(0.001).sleep();
00107   }
00108   return false;
00109 }
00110 
00111 // Check the values output by parsing valid signals
00112 TEST(FULL, Basic)
00113 {
00114   // Message receive helpers
00115   typedef std_msgs::Int8 Msg1;
00116   typedef std_msgs::Int8 Msg2;
00117   typedef std_msgs::Int8 Msg3;
00118   typedef std_msgs::Bool Msg4;
00119   MsgHelper<can_msgs::Frame> rx0("basictest");
00120   MsgHelper<Msg1> rx1("basictest/basicsignal1");
00121   MsgHelper<Msg2> rx2("basictest/basicsignal2");
00122   MsgHelper<Msg3> rx3("basictest/basicsignal3");
00123   MsgHelper<Msg4> rx4("basictest/basicsignal4");
00124 
00125   // Create ROS topics and wait for publisher connection
00126   ros::NodeHandle nh("can_bus_test");
00127   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00128   ros::Subscriber sub0 = nh.subscribe("BasicTest", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00129   ros::Subscriber sub1 = nh.subscribe("BasicTest/BasicSignal1", 10, &MsgHelper<Msg1>::cb, &rx1);
00130   ros::Subscriber sub2 = nh.subscribe("BasicTest/BasicSignal2", 10, &MsgHelper<Msg2>::cb, &rx2);
00131   ros::Subscriber sub3 = nh.subscribe("BasicTest/BasicSignal3", 10, &MsgHelper<Msg3>::cb, &rx3);
00132   ros::Subscriber sub4 = nh.subscribe("BasicTest/BasicSignal4", 10, &MsgHelper<Msg4>::cb, &rx4);
00133   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00134 
00135   // Create a message to publish
00136   // Message ID 161 0xA1
00137   // Signal 1: 23
00138   // Signal 2: 43 (Only 7 bits to accommodate +8 offset)
00139   // Signal 3: 53 (Only 7 bits to accommodate +18 offset)
00140   // Signal 4: 1
00141   can_msgs::Frame msg;
00142   msg.header.stamp = ros::Time::now();
00143   msg.is_rtr = false;
00144   msg.is_error = false;
00145   msg.is_extended = false;
00146   msg.id = 161;
00147   msg.data = {23, 43, 53, 1, 0, 0, 0, 0};
00148 
00149   // Publish the message and verify topic creation (but we might not get the data)
00150   pub.publish(msg);
00151   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00152   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00153   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00154   ASSERT_TRUE(waitSubscriber(sub3, DUR_A));
00155   ASSERT_TRUE(waitSubscriber(sub4, DUR_A));
00156   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear();
00157 
00158   // Publish the message again and wait for the response (now that the topics are connected)
00159   pub.publish(msg);
00160   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00161   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00162   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00163   ASSERT_TRUE(rx3.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx3.getCount());
00164   ASSERT_TRUE(rx4.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx4.getCount());
00165 
00166   // Compare the response with the expected values
00167   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00168   EXPECT_EQ(rx0.getLatest().data, msg.data);
00169   EXPECT_EQ(rx1.getLatest().data, 23);
00170   EXPECT_EQ(rx2.getLatest().data, 43 + 8);
00171   EXPECT_EQ(rx3.getLatest().data, 53 + 18);
00172   EXPECT_EQ(rx4.getLatest().data, true);
00173 }
00174 
00175 // Check the values output by parsing valid signals
00176 TEST(FULL, IntelA)
00177 {
00178   // Message receive helpers
00179   typedef std_msgs::Int8   Msg1;
00180   typedef std_msgs::UInt8  Msg2;
00181   typedef std_msgs::Int16  Msg3;
00182   typedef std_msgs::UInt16 Msg4;
00183   MsgHelper<can_msgs::Frame> rx0("inteltesta");
00184   MsgHelper<Msg1> rx1("inteltesta/intelsignal8");
00185   MsgHelper<Msg2> rx2("inteltesta/intelsignalU8");
00186   MsgHelper<Msg3> rx3("inteltesta/intelsignal16");
00187   MsgHelper<Msg4> rx4("inteltesta/intelsignalU16");
00188 
00189   // Create ROS topics and wait for publisher connection
00190   ros::NodeHandle nh("can_bus_test");
00191   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00192   ros::Subscriber sub0 = nh.subscribe("IntelTestA", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00193   ros::Subscriber sub1 = nh.subscribe("IntelTestA/IntelSignal8", 10, &MsgHelper<Msg1>::cb, &rx1);
00194   ros::Subscriber sub2 = nh.subscribe("IntelTestA/IntelSignalU8", 10, &MsgHelper<Msg2>::cb, &rx2);
00195   ros::Subscriber sub3 = nh.subscribe("IntelTestA/IntelSignal16", 10, &MsgHelper<Msg3>::cb, &rx3);
00196   ros::Subscriber sub4 = nh.subscribe("IntelTestA/IntelSignalU16", 10, &MsgHelper<Msg4>::cb, &rx4);
00197   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00198 
00199   // Create a message to publish
00200   // Message ID 177 0xB1
00201   // Signal 1: 11 8 bit
00202   // Signal 2: 22 unsigned 8 bit
00203   // Signal 3: 0xCDEF 16 bit
00204   // Signal 4: 0x89AB unsigned 16 bit
00205   can_msgs::Frame msg;
00206   msg.header.stamp = ros::Time::now();
00207   msg.is_rtr = false;
00208   msg.is_error = false;
00209   msg.is_extended = false;
00210   msg.id = 177;
00211   msg.data = {11, 22, 0xEF, 0xCD, 0xAB, 0x89, 0, 0};
00212 
00213   // Publish the message and verify topic creation (but we might not get the data)
00214   pub.publish(msg);
00215   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00216   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00217   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00218   ASSERT_TRUE(waitSubscriber(sub3, DUR_A));
00219   ASSERT_TRUE(waitSubscriber(sub4, DUR_A));
00220   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear();
00221 
00222   // Publish the message again and wait for the response (now that the topics are connected)
00223   pub.publish(msg);
00224   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00225   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00226   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00227   ASSERT_TRUE(rx3.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx3.getCount());
00228   ASSERT_TRUE(rx4.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx4.getCount());
00229 
00230   // Compare the response with the expected values
00231   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00232   EXPECT_EQ(rx0.getLatest().data, msg.data);
00233   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)11);
00234   EXPECT_EQ(rx2.getLatest().data, (Msg2::_data_type)22);
00235   EXPECT_EQ(rx3.getLatest().data, (Msg3::_data_type)0xCDEF);
00236   EXPECT_EQ(rx4.getLatest().data, (Msg4::_data_type)0x89AB);
00237 }
00238 
00239 // Check the values output by parsing valid signals
00240 TEST(FULL, IntelB)
00241 {
00242   // Message receive helpers
00243   typedef std_msgs::Int32  Msg1;
00244   typedef std_msgs::UInt32 Msg2;
00245   MsgHelper<can_msgs::Frame> rx0("inteltestb");
00246   MsgHelper<Msg1> rx1("inteltestb/intelsignal32");
00247   MsgHelper<Msg2> rx2("inteltestb/intelsignalU32");
00248 
00249   // Create ROS topics and wait for publisher connection
00250   ros::NodeHandle nh("can_bus_test");
00251   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00252   ros::Subscriber sub0 = nh.subscribe("IntelTestB", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00253   ros::Subscriber sub1 = nh.subscribe("IntelTestB/IntelSignal32", 10, &MsgHelper<Msg1>::cb, &rx1);
00254   ros::Subscriber sub2 = nh.subscribe("IntelTestB/IntelSignalU32", 10, &MsgHelper<Msg2>::cb, &rx2);
00255   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00256 
00257   // Create a message to publish
00258   // Message ID 178 0xB2
00259   // Signal 1: 0x89ABCDEF 32 bit
00260   // Signal 2: 0x01234567 unsigned 32 bit
00261   can_msgs::Frame msg;
00262   msg.header.stamp = ros::Time::now();
00263   msg.is_rtr = false;
00264   msg.is_error = false;
00265   msg.is_extended = false;
00266   msg.id = 178;
00267   msg.data = {0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01};
00268 
00269   // Publish the message and verify topic creation (but we might not get the data)
00270   pub.publish(msg);
00271   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00272   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00273   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00274   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear();
00275 
00276   // Publish the message again and wait for the response (now that the topics are connected)
00277   pub.publish(msg);
00278   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00279   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00280   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00281 
00282   // Compare the response with the expected values
00283   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00284   EXPECT_EQ(rx0.getLatest().data, msg.data);
00285   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x89ABCDEF);
00286   EXPECT_EQ(rx2.getLatest().data, (Msg2::_data_type)0x01234567);
00287 }
00288 
00289 // Check the values output by parsing valid signals
00290 TEST(FULL, IntelC)
00291 {
00292   // Message receive helpers
00293   typedef std_msgs::Int64 Msg1;
00294   MsgHelper<can_msgs::Frame> rx0("inteltestc");
00295   MsgHelper<Msg1> rx1("inteltestc/intelsignal64");
00296 
00297   // Create ROS topics and wait for publisher connection
00298   ros::NodeHandle nh("can_bus_test");
00299   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00300   ros::Subscriber sub0 = nh.subscribe("IntelTestC", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00301   ros::Subscriber sub1 = nh.subscribe("IntelTestC/IntelSignal64", 10, &MsgHelper<Msg1>::cb, &rx1);
00302   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00303 
00304   // Create a message to publish
00305   // Message ID 177 0xB3
00306   // Signal 1: 0x0123456789ABCDEF 64 bit
00307   can_msgs::Frame msg;
00308   msg.header.stamp = ros::Time::now();
00309   msg.is_rtr = false;
00310   msg.is_error = false;
00311   msg.is_extended = false;
00312   msg.id = 179;
00313   msg.data = {0xE0, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01};
00314 
00315   // Publish the message and verify topic creation (but we might not get the data)
00316   pub.publish(msg);
00317   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00318   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00319   DUR_B.sleep(); rx0.clear(); rx1.clear();
00320 
00321   // Publish the message again and wait for the response (now that the topics are connected)
00322   pub.publish(msg);
00323   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00324   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00325 
00326   // Compare the response with the expected values
00327   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00328   EXPECT_EQ(rx0.getLatest().data, msg.data);
00329   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x0123456789ABCDE0);
00331 }
00332 
00333 // Check the values output by parsing valid signals
00334 TEST(FULL, IntelD)
00335 {
00336   // Message receive helpers
00337   typedef std_msgs::UInt64 Msg1;
00338   MsgHelper<can_msgs::Frame> rx0("inteltestd");
00339   MsgHelper<Msg1> rx1("inteltestd/intelsignalU64");
00340 
00341   // Create ROS topics and wait for publisher connection
00342   ros::NodeHandle nh("can_bus_test");
00343   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00344   ros::Subscriber sub0 = nh.subscribe("IntelTestD", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00345   ros::Subscriber sub1 = nh.subscribe("IntelTestD/IntelSignalU64", 10, &MsgHelper<Msg1>::cb, &rx1);
00346   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00347 
00348   // Create a message to publish
00349   // Message ID 180 0xB4
00350   // Signal 1: 0x0123456789ABCDEF unsigned 64 bit
00351   can_msgs::Frame msg;
00352   msg.header.stamp = ros::Time::now();
00353   msg.is_rtr = false;
00354   msg.is_error = false;
00355   msg.is_extended = false;
00356   msg.id = 180;
00357   msg.data = {0xE0, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01};
00358 
00359   // Publish the message and verify topic creation (but we might not get the data)
00360   pub.publish(msg);
00361   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00362   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00363   DUR_B.sleep(); rx0.clear(); rx1.clear();
00364 
00365   // Publish the message again and wait for the response (now that the topics are connected)
00366   pub.publish(msg);
00367   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00368   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00369 
00370   // Compare the response with the expected values
00371   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00372   EXPECT_EQ(rx0.getLatest().data, msg.data);
00373   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x0123456789ABCDE0);
00375 }
00376 
00377 // Check the values output by parsing valid signals
00378 TEST(FULL, AdvancedA)
00379 {
00380   // Message receive helpers
00381   typedef std_msgs::Int32 Msg1;
00382   typedef std_msgs::Int32 Msg2;
00383   MsgHelper<can_msgs::Frame> rx0("advancedtesta");
00384   MsgHelper<Msg1> rx1("advancedtesta/advancedsignal1");
00385   MsgHelper<Msg2> rx2("advancedtesta/advancedsignal2");
00386 
00387   // Create ROS topics and wait for publisher connection
00388   ros::NodeHandle nh("can_bus_test");
00389   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00390   ros::Subscriber sub0 = nh.subscribe("AdvancedTestA", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00391   ros::Subscriber sub1 = nh.subscribe("AdvancedTestA/AdvancedSignal1", 10, &MsgHelper<Msg1>::cb, &rx1);
00392   ros::Subscriber sub2 = nh.subscribe("AdvancedTestA/AdvancedSignal2", 10, &MsgHelper<Msg2>::cb, &rx2);
00393   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00394 
00395   // Create a message to publish
00396   // Message ID 162 0xA2
00397   // Signal 1: 210 little endian (smallest first)
00398   // Signal 2: 153 big endian (largest first)
00399   can_msgs::Frame msg;
00400   msg.header.stamp = ros::Time::now();
00401   msg.is_rtr = false;
00402   msg.is_error = false;
00403   msg.is_extended = false;
00404   msg.id = 162;
00405   msg.data = {210, 0, 0, 0, 0, 0, 0, 153}; //little
00406 
00407   // Publish the message and verify topic creation (but we might not get the data)
00408   pub.publish(msg);
00409   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00410   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00411   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00412   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear();
00413 
00414   // Publish the message again and wait for the response (now that the topics are connected)
00415   pub.publish(msg);
00416   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00417   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00418   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00419 
00420   // Compare the response with the expected values
00421   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00422   EXPECT_EQ(rx0.getLatest().data, msg.data);
00423   EXPECT_EQ(rx1.getLatest().data, 210);
00424   EXPECT_EQ(rx2.getLatest().data, 153);
00426 }
00427 
00428 // Check the values output by parsing valid signals
00429 TEST(FULL, AdvancedB)
00430 {
00431   // Message receive helpers
00432   typedef std_msgs::Int64 Msg1;
00433   MsgHelper<can_msgs::Frame> rx0("advancedtestb");
00434   MsgHelper<Msg1> rx1("advancedtestb/advancedsignal3");
00435 
00436   // Create ROS topics and wait for publisher connection
00437   ros::NodeHandle nh("can_bus_test");
00438   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00439   ros::Subscriber sub0 = nh.subscribe("AdvancedTestB", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00440   ros::Subscriber sub1 = nh.subscribe("AdvancedTestB/AdvancedSignal3", 10, &MsgHelper<Msg1>::cb, &rx1);
00441   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00442 
00443   // Create a message to publish
00444   // Message ID 163 0xA3
00445   // Signal 1: 210 64 bit little endian (smallest first)
00446   can_msgs::Frame msg;
00447   msg.header.stamp = ros::Time::now();
00448   msg.is_rtr = false;
00449   msg.is_error = false;
00450   msg.is_extended = false;
00451   msg.id = 163;
00452   msg.data = {210, 0, 0, 0, 0, 0, 0, 0}; //little
00453 
00454   // Publish the message and verify topic creation (but we might not get the data)
00455   pub.publish(msg);
00456   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00457   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00458   DUR_B.sleep(); rx0.clear(); rx1.clear();
00459 
00460   // Publish the message again and wait for the response (now that the topics are connected)
00461   pub.publish(msg);
00462   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00463   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00464 
00465   // Compare the response with the expected values
00466   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00467   EXPECT_EQ(rx0.getLatest().data, msg.data);
00468   EXPECT_EQ(rx1.getLatest().data, 210);
00470 }
00471 
00472 // Check the values output by parsing valid signals
00473 TEST(FULL, AdvancedC)
00474 {
00475   // Message receive helpers
00476   typedef std_msgs::Int64 Msg1;
00477   MsgHelper<can_msgs::Frame> rx0("advancedtestc");
00478   MsgHelper<Msg1> rx1("advancedtestc/advancedsignal4");
00479 
00480   // Create ROS topics and wait for publisher connection
00481   ros::NodeHandle nh("can_bus_test");
00482   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00483   ros::Subscriber sub0 = nh.subscribe("AdvancedTestC", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00484   ros::Subscriber sub1 = nh.subscribe("AdvancedTestC/AdvancedSignal4", 10, &MsgHelper<Msg1>::cb, &rx1);
00485   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00486 
00487   // Create a message to publish
00488   // Message ID 164 0xA4
00489   // Signal 1: 210 64 bit big endian (largest first)
00490   can_msgs::Frame msg;
00491   msg.header.stamp = ros::Time::now();
00492   msg.is_rtr = false;
00493   msg.is_error = false;
00494   msg.is_extended = false;
00495   msg.id = 164;
00496   msg.data = {0, 0, 0, 0, 0, 0, 0, 210}; //little
00497 
00498   // Publish the message and verify topic creation (but we might not get the data)
00499   pub.publish(msg);
00500   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00501   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00502   DUR_B.sleep(); rx0.clear(); rx1.clear();
00503 
00504   // Publish the message again and wait for the response (now that the topics are connected)
00505   pub.publish(msg);
00506   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00507   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00508 
00509   // Compare the response with the expected values
00510   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00511   EXPECT_EQ(rx0.getLatest().data, msg.data);
00512   EXPECT_EQ(rx1.getLatest().data, 210);
00514 }
00515 
00516 // Check the values output by parsing valid signals
00517 TEST(FULL, AdvancedD)
00518 {
00519   // Message receive helpers
00520   typedef std_msgs::Int16  Msg1;
00521   typedef std_msgs::UInt16 Msg2;
00522   typedef std_msgs::Int16  Msg3;
00523   typedef std_msgs::Int16  Msg4; // Factor is negative.
00524   MsgHelper<can_msgs::Frame> rx0("advancedtestd");
00525   MsgHelper<Msg1> rx1("advancedtestd/advancedsignal5");
00526   MsgHelper<Msg2> rx2("advancedtestd/advancedsignal6");
00527   MsgHelper<Msg3> rx3("advancedtestd/advancedsignal7");
00528   MsgHelper<Msg4> rx4("advancedtestd/advancedsignal8");
00529 
00530   // Create ROS topics and wait for publisher connection
00531   ros::NodeHandle nh("can_bus_test");
00532   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00533   ros::Subscriber sub0 = nh.subscribe("AdvancedTestD", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00534   ros::Subscriber sub1 = nh.subscribe("AdvancedTestD/AdvancedSignal5", 10, &MsgHelper<Msg1>::cb, &rx1);
00535   ros::Subscriber sub2 = nh.subscribe("AdvancedTestD/AdvancedSignal6", 10, &MsgHelper<Msg2>::cb, &rx2);
00536   ros::Subscriber sub3 = nh.subscribe("AdvancedTestD/AdvancedSignal7", 10, &MsgHelper<Msg3>::cb, &rx3);
00537   ros::Subscriber sub4 = nh.subscribe("AdvancedTestD/AdvancedSignal8", 10, &MsgHelper<Msg4>::cb, &rx4);
00538   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00539 
00540   // Create a message to publish
00541   // Message ID 165 0xA5
00542   // Signal 1: 320 x10 factor signed
00543   // Signal 1: 640 x10 factor unsigned
00544   // Signal 1: -120 x-10 factor signed
00545   // Signal 1: -240 x-10 factor unsigned changed to signed
00546   can_msgs::Frame msg;
00547   msg.header.stamp = ros::Time::now();
00548   msg.is_rtr = false;
00549   msg.is_error = false;
00550   msg.is_extended = false;
00551   msg.id = 165;
00552   msg.data = {32, 64, 12, 24}; //little
00553 
00554   // Publish the message and verify topic creation (but we might not get the data)
00555   pub.publish(msg);
00556   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00557   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00558   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00559   ASSERT_TRUE(waitSubscriber(sub3, DUR_A));
00560   ASSERT_TRUE(waitSubscriber(sub4, DUR_A));
00561   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear();
00562 
00563   // Publish the message again and wait for the response (now that the topics are connected)
00564   pub.publish(msg);
00565   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00566   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00567   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00568   ASSERT_TRUE(rx3.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx3.getCount());
00569   ASSERT_TRUE(rx4.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx4.getCount());
00570 
00571   // Compare the response with the expected values
00572   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00573   EXPECT_EQ(rx0.getLatest().data, msg.data);
00574   EXPECT_EQ(rx1.getLatest().data, 320);
00575   EXPECT_EQ(rx2.getLatest().data, 640);
00576   EXPECT_EQ(rx3.getLatest().data, -120);
00577   EXPECT_EQ(rx4.getLatest().data, -240);
00578 }
00579 
00580 // Check the values output by parsing valid signals
00581 TEST(FULL, MotorolaA)
00582 {
00583   // Message receive helpers
00584   typedef std_msgs::Int8   Msg1;
00585   typedef std_msgs::UInt8  Msg2;
00586   typedef std_msgs::Int16  Msg3;
00587   typedef std_msgs::UInt16 Msg4;
00588   MsgHelper<can_msgs::Frame> rx0("motorolatesta");
00589   MsgHelper<Msg1> rx1("motorolatesta/motorolasignal8");
00590   MsgHelper<Msg2> rx2("motorolatesta/motorolasignalU8");
00591   MsgHelper<Msg3> rx3("motorolatesta/motorolasignal16");
00592   MsgHelper<Msg4> rx4("motorolatesta/motorolasignalU16");
00593 
00594   // Create ROS topics and wait for publisher connection
00595   ros::NodeHandle nh("can_bus_test");
00596   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00597   ros::Subscriber sub0 = nh.subscribe("MotorolaTestA", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00598   ros::Subscriber sub1 = nh.subscribe("MotorolaTestA/MotorolaSignal8", 10, &MsgHelper<Msg1>::cb, &rx1);
00599   ros::Subscriber sub2 = nh.subscribe("MotorolaTestA/MotorolaSignalU8", 10, &MsgHelper<Msg2>::cb, &rx2);
00600   ros::Subscriber sub3 = nh.subscribe("MotorolaTestA/MotorolaSignal16", 10, &MsgHelper<Msg3>::cb, &rx3);
00601   ros::Subscriber sub4 = nh.subscribe("MotorolaTestA/MotorolaSignalU16", 10, &MsgHelper<Msg4>::cb, &rx4);
00602   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00603 
00604   // Create a message to publish
00605   // Message ID 193 0xC1
00606   // Signal 1: 11 8 bit
00607   // Signal 2: 22 unsigned 8 bit
00608   // Signal 3: 0x89AB 16 bit
00609   // Signal 4: 0xCDEF unsigned 16 bit
00610   can_msgs::Frame msg;
00611   msg.header.stamp = ros::Time::now();
00612   msg.is_rtr = false;
00613   msg.is_error = false;
00614   msg.is_extended = false;
00615   msg.id = 193;
00616   msg.data = {11, 22, 0, 33, 0, 44, 0, 0};
00617   msg.data = {11, 22, 0x89, 0xAB, 0xCD, 0xEF, 0, 0};
00618 
00619   // Publish the message and verify topic creation (but we might not get the data)
00620   pub.publish(msg);
00621   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00622   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00623   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00624   ASSERT_TRUE(waitSubscriber(sub3, DUR_A));
00625   ASSERT_TRUE(waitSubscriber(sub4, DUR_A));
00626   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear();
00627 
00628   // Publish the message again and wait for the response (now that the topics are connected)
00629   pub.publish(msg);
00630   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00631   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00632   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00633   ASSERT_TRUE(rx3.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx3.getCount());
00634   ASSERT_TRUE(rx4.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx4.getCount());
00635 
00636   // Compare the response with the expected values
00637   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00638   EXPECT_EQ(rx0.getLatest().data, msg.data);
00639   EXPECT_EQ(rx1.getLatest().data, 11);
00640   EXPECT_EQ(rx2.getLatest().data, 22);
00641   EXPECT_EQ(rx3.getLatest().data, (Msg3::_data_type)0x89AB);
00642   EXPECT_EQ(rx4.getLatest().data, (Msg4::_data_type)0xCDEF);
00643 }
00644 
00645 // Check the values output by parsing valid signals
00646 TEST(FULL, MotorolaB)
00647 {
00648   // Message receive helpers
00649   typedef std_msgs::Int32  Msg1;
00650   typedef std_msgs::UInt32 Msg2;
00651   MsgHelper<can_msgs::Frame> rx0("motorolatestb");
00652   MsgHelper<Msg1> rx1("motorolatestb/motorolasignal32");
00653   MsgHelper<Msg2> rx2("motorolatestb/motorolasignalU32");
00654 
00655   // Create ROS topics and wait for publisher connection
00656   ros::NodeHandle nh("can_bus_test");
00657   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00658   ros::Subscriber sub0 = nh.subscribe("MotorolaTestB", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00659   ros::Subscriber sub1 = nh.subscribe("MotorolaTestB/MotorolaSignal32", 10, &MsgHelper<Msg1>::cb, &rx1);
00660   ros::Subscriber sub2 = nh.subscribe("MotorolaTestB/MotorolaSignalU32", 10, &MsgHelper<Msg2>::cb, &rx2);
00661   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00662 
00663   // Create a message to publish
00664   // Message ID 194 0xC2
00665   // Signal 1: 0x01234567 32 bit
00666   // Signal 2: 0x89ABCDEF unsigned 32 bit
00667   can_msgs::Frame msg;
00668   msg.header.stamp = ros::Time::now();
00669   msg.is_rtr = false;
00670   msg.is_error = false;
00671   msg.is_extended = false;
00672   msg.id = 194;
00673   msg.data = {0, 0, 0, 55, 0, 0, 0, 66};
00674   msg.data = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
00675 
00676   // Publish the message and verify topic creation (but we might not get the data)
00677   pub.publish(msg);
00678   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00679   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00680   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00681   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear();
00682 
00683   // Publish the message again and wait for the response (now that the topics are connected)
00684   pub.publish(msg);
00685   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00686   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00687   ASSERT_TRUE(rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00688 
00689   // Compare the response with the expected values
00690   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00691   EXPECT_EQ(rx0.getLatest().data, msg.data);
00692   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x01234567);
00693   EXPECT_EQ(rx2.getLatest().data, (Msg2::_data_type)0x89ABCDEF);
00694 }
00695 
00696 // Check the values output by parsing valid signals
00697 TEST(FULL, MotorolaC)
00698 {
00699   // Message receive helpers
00700   typedef std_msgs::Int64 Msg1;
00701   MsgHelper<can_msgs::Frame> rx0("motorolatestc");
00702   MsgHelper<Msg1> rx1("motorolatestc/motorolasignal64");
00703 
00704   // Create ROS topics and wait for publisher connection
00705   ros::NodeHandle nh("can_bus_test");
00706   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00707   ros::Subscriber sub0 = nh.subscribe("MotorolaTestC", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00708   ros::Subscriber sub1 = nh.subscribe("MotorolaTestC/MotorolaSignal64", 10, &MsgHelper<Msg1>::cb, &rx1);
00709   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00710 
00711   // Create a message to publish
00712   //Message ID 195 0xC3
00713   //Signal 1: 0x0123456789ABCDEF 64 bit
00714   can_msgs::Frame msg;
00715   msg.header.stamp = ros::Time::now();
00716   msg.is_rtr = false;
00717   msg.is_error = false;
00718   msg.is_extended = false;
00719   msg.id = 195;
00720   msg.data = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE0};
00721 
00722   // Publish the message and verify topic creation (but we might not get the data)
00723   pub.publish(msg);
00724   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00725   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00726   DUR_B.sleep(); rx0.clear(); rx1.clear();
00727 
00728   // Publish the message again and wait for the response (now that the topics are connected)
00729   pub.publish(msg);
00730   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00731   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00732 
00733   // Compare the response with the expected values
00734   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00735   EXPECT_EQ(rx0.getLatest().data, msg.data);
00736   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x0123456789ABCDE0);
00738 }
00739 
00740 // Check the values output by parsing valid signals
00741 TEST(FULL, MotorolaD)
00742 {
00743   // Message receive helpers
00744   typedef std_msgs::UInt64 Msg1;
00745   MsgHelper<can_msgs::Frame> rx0("motorolatestd");
00746   MsgHelper<Msg1> rx1("motorolatestd/motorolasignalU64");
00747 
00748   // Create ROS topics and wait for publisher connection
00749   ros::NodeHandle nh("can_bus_test");
00750   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00751   ros::Subscriber sub0 = nh.subscribe("MotorolaTestD", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00752   ros::Subscriber sub1 = nh.subscribe("MotorolaTestD/MotorolaSignalU64", 10, &MsgHelper<Msg1>::cb, &rx1);
00753   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00754 
00755   // Create a message to publish
00756   // Message ID 196 0xC4
00757   // Signal 1: 0x0123456789ABCDEF unsigned 64 bit
00758   can_msgs::Frame msg;
00759   msg.header.stamp = ros::Time::now();
00760   msg.is_rtr = false;
00761   msg.is_error = false;
00762   msg.is_extended = false;
00763   msg.id = 196;
00764   msg.data = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE0};
00765 
00766   // Publish the message and verify topic creation (but we might not get the data)
00767   pub.publish(msg);
00768   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00769   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00770   DUR_B.sleep(); rx0.clear(); rx1.clear();
00771 
00772   // Publish the message again and wait for the response (now that the topics are connected)
00773   pub.publish(msg);
00774   ASSERT_TRUE(rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00775   ASSERT_TRUE(rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00776 
00777   // Compare the response with the expected values
00778   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00779   EXPECT_EQ(rx0.getLatest().data, msg.data);
00780   EXPECT_EQ(rx1.getLatest().data, (Msg1::_data_type)0x0123456789ABCDE0);
00782 }
00783 
00784 // Check the values output by parsing valid signals
00785 TEST(FULL, Multiplex)
00786 {
00787   // Message receive helpers
00788   typedef std_msgs::UInt8  Msg1;
00789   typedef std_msgs::Int8   Msg2;
00790   typedef std_msgs::Int8   Msg3;
00791   typedef std_msgs::UInt16 Msg4;
00792   typedef std_msgs::Int32  Msg5;
00793   MsgHelper<can_msgs::Frame> rx0("multiplextest");
00794   MsgHelper<Msg1> rx1("multiplextest/multiplexor");
00795   MsgHelper<Msg2> rx2("multiplextest/multiplexeda");
00796   MsgHelper<Msg3> rx3("multiplextest/multiplexedb");
00797   MsgHelper<Msg4> rx4("multiplextest/multiplexedc");
00798   MsgHelper<Msg5> rx5("multiplextest/multiplexedd");
00799 
00800   // Create ROS topics and wait for publisher connection
00801   ros::NodeHandle nh("can_bus_test");
00802   ros::Publisher pub = nh.advertise<can_msgs::Frame>("can_rx", 10);
00803   ros::Subscriber sub0 = nh.subscribe("MultiplexTest", 10, &MsgHelper<can_msgs::Frame>::cb, &rx0);
00804   ros::Subscriber sub1 = nh.subscribe("MultiplexTest/Multiplexor", 10, &MsgHelper<Msg1>::cb, &rx1);
00805   ros::Subscriber sub2 = nh.subscribe("MultiplexTest/MultiplexedA", 10, &MsgHelper<Msg2>::cb, &rx2);
00806   ros::Subscriber sub3 = nh.subscribe("MultiplexTest/MultiplexedB", 10, &MsgHelper<Msg3>::cb, &rx3);
00807   ros::Subscriber sub4 = nh.subscribe("MultiplexTest/MultiplexedC", 10, &MsgHelper<Msg4>::cb, &rx4);
00808   ros::Subscriber sub5 = nh.subscribe("MultiplexTest/MultiplexedD", 10, &MsgHelper<Msg5>::cb, &rx5);
00809   ASSERT_TRUE(waitPublisher(pub, DUR_A)); DUR_B.sleep();
00810 
00811   // Create a message to publish
00812   // Signal 1: 0 multiplexor
00813   can_msgs::Frame msg;
00814   msg.header.stamp = ros::Time::now();
00815   msg.is_rtr = false;
00816   msg.is_error = false;
00817   msg.is_extended = false;
00818   msg.id = 166;
00819   msg.data = {0, 0, 0, 0, 0, 0, 0, 0};
00820 
00821   // Publish the message and verify topic creation (but we might not get the data)
00822   pub.publish(msg);
00823   ASSERT_TRUE(waitSubscriber(sub0, DUR_A));
00824   ASSERT_TRUE(waitSubscriber(sub1, DUR_A));
00825   ASSERT_TRUE(waitSubscriber(sub2, DUR_A));
00826   ASSERT_TRUE(waitSubscriber(sub3, DUR_A));
00827   ASSERT_TRUE(waitSubscriber(sub4, DUR_A));
00828   ASSERT_TRUE(waitSubscriber(sub5, DUR_A));
00829   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear(); rx5.clear();
00830 
00831   // Change multiplexor and data
00832   // Signal 1: 0x99 multiplexor
00833   msg.data = {0x99, 0, 0, 0, 0, 0, 0, 0};
00834 
00835   // Publish the new message and wait for the response
00836   pub.publish(msg);
00837   EXPECT_TRUE (rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00838   EXPECT_TRUE (rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00839   EXPECT_FALSE(rx2.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx2.getCount());
00840   EXPECT_FALSE(rx3.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx3.getCount());
00841   EXPECT_FALSE(rx4.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx4.getCount());
00842   EXPECT_FALSE(rx5.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx5.getCount());
00843 
00844   // Compare the response with the expected values
00845   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00846   EXPECT_EQ(rx0.getLatest().data, msg.data);
00847   EXPECT_EQ(rx1.getLatest().data, 0x99);
00848   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear(); rx5.clear();
00849 
00850   // Change multiplexor and data
00851   // Signal 1: 0x11 multiplexor
00852   // Signal 2: 52 multiplexed a
00853   msg.data = {0x11, 52, 0, 0, 0, 0, 0, 0};
00854 
00855   // Publish the new message and wait for the response
00856   pub.publish(msg);
00857   EXPECT_TRUE (rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00858   EXPECT_TRUE (rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00859   EXPECT_TRUE (rx2.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx2.getCount());
00860   EXPECT_FALSE(rx3.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx3.getCount());
00861   EXPECT_FALSE(rx4.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx4.getCount());
00862   EXPECT_FALSE(rx5.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx5.getCount());
00863 
00864   // Compare the response with the expected values
00865   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00866   EXPECT_EQ(rx0.getLatest().data, msg.data);
00867   EXPECT_EQ(rx1.getLatest().data, 0x11);
00868   EXPECT_EQ(rx2.getLatest().data, 52);
00869   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear(); rx5.clear();
00870 
00871   // Change multiplexor and data
00872   // Signal 1: 0x22 multiplexor
00873   // Signal 2: 102 multiplexed b 8 bit
00874   // Signal 3: 103 multiplexed c 16 bit unsigned
00875   msg.data = {0x22, 102, 103, 0, 0, 0, 0, 0};
00876 
00877   // Publish the new message and wait for the response
00878   pub.publish(msg);
00879   EXPECT_TRUE (rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00880   EXPECT_TRUE (rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00881   EXPECT_FALSE(rx2.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx2.getCount());
00882   EXPECT_TRUE (rx3.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx3.getCount());
00883   EXPECT_TRUE (rx4.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx4.getCount());
00884   EXPECT_FALSE(rx5.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx5.getCount());
00885 
00886   // Compare the response with the expected values
00887   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00888   EXPECT_EQ(rx0.getLatest().data, msg.data);
00889   EXPECT_EQ(rx1.getLatest().data, 0x22);
00890   EXPECT_EQ(rx3.getLatest().data, 102);
00891   EXPECT_EQ(rx4.getLatest().data, 103);
00892   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear(); rx5.clear();
00893 
00894   // Change multiplexor and data
00895   // Signal 1: 0x33 multiplexor
00896   // Signal 2: 0x12345678 multiplexed 32 bit
00897   msg.id = 166;
00898   msg.data = {0x33, 0x78, 0x56, 0x34, 0x12, 0, 0, 0};
00899 
00900   // Publish the new message and wait for the response
00901   pub.publish(msg);
00902   EXPECT_TRUE (rx0.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx0.getCount());
00903   EXPECT_TRUE (rx1.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx1.getCount());
00904   EXPECT_FALSE(rx2.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx2.getCount());
00905   EXPECT_FALSE(rx3.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx3.getCount());
00906   EXPECT_FALSE(rx4.waitForMessage(DUR_B)); EXPECT_EQ(0u, rx4.getCount());
00907   EXPECT_TRUE (rx5.waitForMessage(DUR_A)); EXPECT_EQ(1u, rx5.getCount());
00908 
00909   // Compare the response with the expected values
00910   EXPECT_EQ(rx0.getLatest().header.stamp, msg.header.stamp);
00911   EXPECT_EQ(rx0.getLatest().data, msg.data);
00912   EXPECT_EQ(rx1.getLatest().data, 0x33);
00913   EXPECT_EQ(rx5.getLatest().data, 0x12345678);
00914   DUR_B.sleep(); rx0.clear(); rx1.clear(); rx2.clear(); rx3.clear(); rx4.clear(); rx5.clear();
00915 }
00916 
00917 int main(int argc, char **argv)
00918 {
00919   ros::init(argc, argv, "test_full");
00920 
00921   ros::AsyncSpinner spinner(4); // Use 4 threads
00922   spinner.start();
00923  
00924   testing::InitGoogleTest(&argc, argv);
00925   return RUN_ALL_TESTS();
00926 }


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Thu Jun 6 2019 21:16:41