22 #include "driver_tester.h"    30 DriverTester::DriverTester(boost::shared_ptr<goby::acomms::ModemDriverBase> driver1,
    31                            boost::shared_ptr<goby::acomms::ModemDriverBase> driver2,
    34                            const std::vector<int>& tests_to_run,
    35                            goby::acomms::protobuf::DriverType driver_type)
    37     : driver1_(driver1), driver2_(driver2), check_count_(0), tests_to_run_(tests_to_run),
    38       tests_to_run_index_(0), test_number_(-1), driver_type_(driver_type)
    46                           &DriverTester::handle_transmit_result1);
    48                           &DriverTester::handle_modify_transmission1);
    50                           &DriverTester::handle_data_request1);
    53                           &DriverTester::handle_transmit_result2);
    55                           &DriverTester::handle_modify_transmission2);
    57                           &DriverTester::handle_data_request2);
    62     driver1_->startup(cfg1);
    63     driver2_->startup(cfg2);
    66     while (((i / 10) < 3))
    75     test_str0_.resize(32);
    76     for (std::string::size_type i = 0, n = test_str0_.size(); i < n; ++i) test_str0_[i] = i;
    78     test_str1_.resize(64);
    79     for (std::string::size_type i = 0, n = test_str1_.size(); i < n; ++i)
    80         test_str1_[i] = i + 64; 
    82     test_str2_.resize(64);
    83     for (std::string::size_type i = 0, n = test_str2_.size(); i < n; ++i)
    84         test_str2_[i] = i + 2 * 64;
    86     test_str3_.resize(64);
    87     for (std::string::size_type i = 0, n = test_str3_.size(); i < n; ++i)
    88         test_str3_[i] = i + 3 * 64;
    90     test_number_ = tests_to_run_[tests_to_run_index_];
    93 int DriverTester::run()
   101                 case 0: test0(); 
break;
   102                 case 1: test1(); 
break;
   103                 case 2: test2(); 
break;
   104                 case 3: test3(); 
break;
   105                 case 4: test4(); 
break;
   106                 case 5: test5(); 
break;
   107                 case 6: test6(); 
break;
   109                     goby::glog << group(
"test") << 
"all tests passed" << std::endl;
   110                     driver1_->shutdown();
   111                     driver2_->shutdown();
   116             goby::glog << 
"Test " << group(
"test") << test_number_ << 
" passed." << std::endl;
   117             ++tests_to_run_index_;
   119             if (tests_to_run_index_ < static_cast<int>(tests_to_run_.size()))
   120                 test_number_ = tests_to_run_[tests_to_run_index_];
   128     catch (std::exception& e)
   130         goby::glog << warn << 
"Exception: " << e.what() << std::endl;
   138     goby::glog << group(
"driver1") << 
"Data request: " << *msg << std::endl;
   140     switch (test_number_)
   144             msg->add_frame(test_str0_);
   145             static bool entered = 
false;
   156             static bool entered = 
false;
   157             msg->add_frame(test_str2_);
   158             msg->add_frame(test_str3_);
   168     goby::glog << group(
"driver1") << 
"Post data request: " << *msg << std::endl;
   173     goby::glog << group(
"driver1") << 
"Can modify: " << *msg << std::endl;
   178     goby::glog << group(
"driver1") << 
"Completed transmit: " << msg << std::endl;
   183     goby::glog << group(
"driver1") << 
"Received: " << msg << std::endl;
   185     switch (test_number_)
   189             if (driver_type_ == goby::acomms::protobuf::DRIVER_WHOI_MICROMODEM)
   191                 assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   192                        msg.GetExtension(micromodem::protobuf::type) ==
   193                            micromodem::protobuf::MICROMODEM_TWO_WAY_PING);
   196             else if (driver_type_ == goby::acomms::protobuf::DRIVER_BENTHOS_ATM900)
   198                 assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   199                        msg.GetExtension(benthos::protobuf::type) ==
   200                            benthos::protobuf::BENTHOS_TWO_WAY_PING);
   208             assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   209                    msg.GetExtension(micromodem::protobuf::type) ==
   210                        micromodem::protobuf::MICROMODEM_REMUS_LBL_RANGING);
   212             assert(msg.src() == 1);
   213             assert(!msg.has_dest());
   216             ptime reported = as<ptime>(msg.time());
   217             assert(reported < now && reported > now - seconds(2));
   224             assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   225                    msg.GetExtension(micromodem::protobuf::type) ==
   226                        micromodem::protobuf::MICROMODEM_NARROWBAND_LBL_RANGING);
   228             assert(msg.src() == 1);
   229             assert(!msg.has_dest());
   232             ptime reported = as<ptime>(msg.time());
   233             assert(reported < now && reported > now - seconds(2));
   240             assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   241                    msg.GetExtension(micromodem::protobuf::type) ==
   242                        micromodem::protobuf::MICROMODEM_MINI_DATA);
   244             assert(msg.src() == 2);
   245             assert(msg.dest() == 1);
   246             assert(msg.frame_size() == 1);
   247             assert(msg.frame(0) == goby::util::hex_decode(
"0123"));
   254             assert(msg.type() == protobuf::ModemTransmission::ACK);
   255             assert(msg.src() == 2);
   256             assert(msg.dest() == 1);
   257             assert(msg.acked_frame_size() == 1 && msg.acked_frame(0) == 0);
   264             assert(msg.type() == protobuf::ModemTransmission::ACK);
   265             assert(msg.src() == 2);
   266             assert(msg.dest() == 1);
   267             assert(msg.acked_frame_size() == 3 && msg.acked_frame(1) == msg.acked_frame(0) + 1 &&
   268                    msg.acked_frame(2) == msg.acked_frame(0) + 2);
   275             assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   276                    msg.GetExtension(micromodem::protobuf::type) ==
   277                        micromodem::protobuf::MICROMODEM_FLEXIBLE_DATA);
   279             assert(msg.src() == 2);
   280             assert(msg.dest() == 1);
   281             assert(msg.rate() == 1);
   282             assert(msg.frame_size() == 1);
   284             std::cout << 
"[" << goby::util::hex_encode(msg.frame(0)) << 
"]" << std::endl;
   285             assert(msg.frame(0) ==
   286                    goby::util::hex_decode(
"00112233445566778899001122334455667788990011"));
   297     goby::glog << group(
"driver2") << 
"Data request: " << *msg << std::endl;
   299     switch (test_number_)
   301         default: assert(
false); 
break;
   305             static bool entered = 
false;
   312             msg->add_frame(goby::util::hex_decode(
"0123"));
   320             static bool entered = 
false;
   327             msg->add_frame(goby::util::hex_decode(
"00112233445566778899001122334455667788990011"));
   332     goby::glog << group(
"driver2") << 
"Post data request: " << *msg << std::endl;
   337     goby::glog << group(
"driver2") << 
"Can modify: " << *msg << std::endl;
   342     goby::glog << group(
"driver2") << 
"Completed transmit: " << msg << std::endl;
   347     goby::glog << group(
"driver2") << 
"Received: " << msg << std::endl;
   349     switch (test_number_)
   354             if (driver_type_ == goby::acomms::protobuf::DRIVER_WHOI_MICROMODEM)
   356                 assert(msg.type() == protobuf::ModemTransmission::DRIVER_SPECIFIC &&
   357                        msg.GetExtension(micromodem::protobuf::type) ==
   358                            micromodem::protobuf::MICROMODEM_TWO_WAY_PING);
   365             if (msg.type() == protobuf::ModemTransmission::DATA)
   367                 assert(msg.src() == 1);
   368                 assert(msg.dest() == 2);
   369                 assert(msg.frame_size() == 1);
   370                 assert(msg.frame(0) == test_str0_);
   378             if (msg.type() == protobuf::ModemTransmission::DATA)
   380                 assert(msg.src() == 1);
   381                 assert(msg.dest() == 2);
   382                 assert(msg.frame_size() == 3);
   383                 assert(msg.frame(0) == test_str1_);
   384                 assert(msg.frame(1) == test_str2_);
   385                 assert(msg.frame(2) == test_str3_);
   392 void DriverTester::test0()
   395     goby::glog << group(
"test") << 
"Ping test" << std::endl;
   399     transmit.set_type(protobuf::ModemTransmission::DRIVER_SPECIFIC);
   401     if (driver_type_ == goby::acomms::protobuf::DRIVER_WHOI_MICROMODEM)
   402         transmit.SetExtension(micromodem::protobuf::type,
   403                               micromodem::protobuf::MICROMODEM_TWO_WAY_PING);
   404     else if (driver_type_ == goby::acomms::protobuf::DRIVER_BENTHOS_ATM900)
   405         transmit.SetExtension(benthos::protobuf::type, benthos::protobuf::BENTHOS_TWO_WAY_PING);
   408     transmit.set_dest(2);
   410     driver1_->handle_initiate_transmission(transmit);
   413     while (((i / 10) < 10) && check_count_ < 2)
   422     if (driver_type_ == goby::acomms::protobuf::DRIVER_WHOI_MICROMODEM)
   423         assert(check_count_ == 2);
   424     else if (driver_type_ == goby::acomms::protobuf::DRIVER_BENTHOS_ATM900)
   425         assert(check_count_ == 1); 
   428 void DriverTester::test1()
   430     goby::glog << group(
"test") << 
"Remus LBL test" << std::endl;
   434     transmit.set_type(protobuf::ModemTransmission::DRIVER_SPECIFIC);
   435     transmit.SetExtension(micromodem::protobuf::type,
   436                           micromodem::protobuf::MICROMODEM_REMUS_LBL_RANGING);
   439     transmit.MutableExtension(micromodem::protobuf::remus_lbl)->set_lbl_max_range(1000);
   441     driver1_->handle_initiate_transmission(transmit);
   444     while (((i / 10) < 10) && check_count_ < 1)
   452     assert(check_count_ == 1);
   455 void DriverTester::test2()
   457     goby::glog << group(
"test") << 
"Narrowband LBL test" << std::endl;
   461     transmit.set_type(protobuf::ModemTransmission::DRIVER_SPECIFIC);
   462     transmit.SetExtension(micromodem::protobuf::type,
   463                           micromodem::protobuf::MICROMODEM_NARROWBAND_LBL_RANGING);
   467         transmit.MutableExtension(micromodem::protobuf::narrowband_lbl);
   468     params->set_lbl_max_range(1000);
   469     params->set_turnaround_ms(20);
   470     params->set_transmit_freq(26000);
   471     params->set_transmit_ping_ms(5);
   472     params->set_receive_ping_ms(5);
   473     params->add_receive_freq(25000);
   474     params->set_transmit_flag(
true);
   476     driver1_->handle_initiate_transmission(transmit);
   479     while (((i / 10) < 10) && check_count_ < 1)
   487     assert(check_count_ == 1);
   490 void DriverTester::test3()
   492     goby::glog << group(
"test") << 
"Mini data test" << std::endl;
   496     transmit.set_type(protobuf::ModemTransmission::DRIVER_SPECIFIC);
   497     transmit.SetExtension(micromodem::protobuf::type, micromodem::protobuf::MICROMODEM_MINI_DATA);
   500     transmit.set_dest(1);
   502     driver2_->handle_initiate_transmission(transmit);
   505     while (((i / 10) < 10) && check_count_ < 2)
   513     assert(check_count_ == 2);
   516 void DriverTester::test4()
   518     goby::glog << group(
"test") << 
"Rate 0 test" << std::endl;
   522     transmit.set_type(protobuf::ModemTransmission::DATA);
   524     transmit.set_dest(2);
   525     transmit.set_rate(0);
   526     transmit.set_ack_requested(
true);
   528     driver1_->handle_initiate_transmission(transmit);
   531     while (((i / 10) < 60) && check_count_ < 3)
   539     assert(check_count_ == 3);
   542 void DriverTester::test5()
   544     goby::glog << group(
"test") << 
"Rate 2 test" << std::endl;
   548     transmit.set_type(protobuf::ModemTransmission::DATA);
   550     transmit.set_dest(2);
   551     transmit.set_rate(2);
   553     transmit.add_frame(test_str1_);
   554     transmit.set_ack_requested(
true);
   556     driver1_->handle_initiate_transmission(transmit);
   559     while (((i / 10) < 60) && check_count_ < 3)
   567     assert(check_count_ == 3);
   570 void DriverTester::test6()
   572     goby::glog << group(
"test") << 
"FDP data test" << std::endl;
   576     transmit.set_type(protobuf::ModemTransmission::DRIVER_SPECIFIC);
   577     transmit.SetExtension(micromodem::protobuf::type,
   578                           micromodem::protobuf::MICROMODEM_FLEXIBLE_DATA);
   581         ->write_single_cfg(
"psk.packet.mod_hdr_version,1");
   583         ->write_single_cfg(
"psk.packet.mod_hdr_version,1");
   586     transmit.set_dest(1);
   587     transmit.set_rate(1);
   589     driver2_->handle_initiate_transmission(transmit);
   592     while (((i / 10) < 10) && check_count_ < 2)
   600     assert(check_count_ == 2);
 
provides an API to the WHOI Micro-Modem driver 
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime. 
void add_group(const std::string &name, Colors::Color color=Colors::nocolor, const std::string &description="")
Add another group to the logger. A group provides related manipulator for categorizing log messages...
void connect(Signal *signal, Slot slot)
connect a signal to a slot (e.g. function pointer) 
common::FlexOstream glog
Access the Goby logger through this object. 
Objects pertaining to acoustic communications (acomms)