Goby v2
test.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 // tests functionality of the Goby PBDriver, using goby_store_server
23 
24 #include "../../acomms/driver_tester/driver_tester.h"
25 #include "goby/acomms/acomms_helpers.h"
26 #include "goby/acomms/connect.h"
27 #include "goby/common/logger.h"
28 #include "goby/pb/pb_modem_driver.h"
29 #include "goby/util/binary.h"
30 
31 using namespace goby::common::logger;
32 using namespace goby::acomms;
34 using goby::util::as;
35 using namespace boost::posix_time;
36 
37 int main(int argc, char* argv[])
38 {
39  boost::shared_ptr<goby::pb::PBDriver> driver1, driver2;
40  goby::glog.add_stream(goby::common::logger::DEBUG3, &std::clog);
41  std::ofstream fout;
42 
43  if (argc == 2)
44  {
45  fout.open(argv[1]);
46  goby::glog.add_stream(goby::common::logger::DEBUG3, &fout);
47  }
48 
49  goby::glog.set_name(argv[0]);
50 
51  goby::glog.add_group("test", goby::common::Colors::green);
52  goby::glog.add_group("driver1", goby::common::Colors::green);
53  goby::glog.add_group("driver2", goby::common::Colors::yellow);
54 
55  goby::common::ZeroMQService zeromq_service1, zeromq_service2;
56 
57  driver1.reset(new goby::pb::PBDriver(&zeromq_service1));
58  driver2.reset(new goby::pb::PBDriver(&zeromq_service2));
59 
61 
62  cfg1.set_modem_id(1);
63 
65  cfg1.MutableExtension(PBDriverConfig::request_socket);
66 
67  socket1->set_socket_type(goby::common::protobuf::ZeroMQServiceConfig::Socket::REQUEST);
68  socket1->set_transport(goby::common::protobuf::ZeroMQServiceConfig::Socket::TCP);
69  socket1->set_connect_or_bind(goby::common::protobuf::ZeroMQServiceConfig::Socket::CONNECT);
70  socket1->set_ethernet_address("127.0.0.1");
71  socket1->set_ethernet_port(54321);
72 
73  cfg1.SetExtension(PBDriverConfig::query_interval_seconds, 2);
74  cfg1.AddExtension(PBDriverConfig::rate_to_frames, 1);
75  cfg1.AddExtension(PBDriverConfig::rate_to_frames, 3);
76  cfg1.AddExtension(PBDriverConfig::rate_to_frames, 3);
77  cfg1.AddExtension(PBDriverConfig::rate_to_bytes, 32);
78  cfg1.AddExtension(PBDriverConfig::rate_to_bytes, 64);
79  cfg1.AddExtension(PBDriverConfig::rate_to_bytes, 64);
80 
81  cfg2.set_modem_id(2);
82  cfg2.MutableExtension(PBDriverConfig::request_socket)->CopyFrom(*socket1);
83 
84  std::vector<int> tests_to_run;
85  tests_to_run.push_back(4);
86  tests_to_run.push_back(5);
87 
88  DriverTester tester(driver1, driver2, cfg1, cfg2, tests_to_run,
89  goby::acomms::protobuf::DRIVER_PB_STORE_SERVER);
90  return tester.run();
91 }
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
Definition: flex_ostream.h:67
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime.
Definition: time.h:104
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...
common::FlexOstream glog
Access the Goby logger through this object.
Objects pertaining to acoustic communications (acomms)
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...
Definition: flex_ostream.h:96