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 MMDriver WHOI Micro-Modem driver
23 
24 #include "../driver_tester/driver_tester.h"
25 #include "goby/acomms/modemdriver/mm_driver.h"
26 
27 boost::shared_ptr<goby::acomms::ModemDriverBase> driver1, driver2;
28 
29 int main(int argc, char* argv[])
30 {
31  if (argc < 3)
32  {
33  std::cout
34  << "usage: test_mmdriver1 /dev/ttyS0 /dev/ttyS1 [file to write] [mm version (1 or 2)]"
35  << std::endl;
36  exit(1);
37  }
38 
39  goby::glog.add_stream(goby::common::logger::DEBUG3, &std::clog);
40  std::ofstream fout;
41  if (argc >= 4)
42  {
43  fout.open(argv[3]);
44  goby::glog.add_stream(goby::common::logger::DEBUG3, &fout);
45  }
46  int mm_version = 1;
47  if (argc == 5)
48  {
49  mm_version = goby::util::as<int>(argv[4]);
50  }
51 
52  goby::glog.set_name(argv[0]);
53 
55 
56  cfg1.set_serial_port(argv[1]);
57  cfg1.set_modem_id(1);
58  // 0111
59  cfg1.MutableExtension(micromodem::protobuf::Config::remus_lbl)->set_enable_beacons(7);
60 
61  if (mm_version != 2)
62  cfg1.SetExtension(micromodem::protobuf::Config::reset_nvram, true);
63  cfg2.SetExtension(micromodem::protobuf::Config::reset_nvram, true);
64 
65  // so we can play with the emulator box BNC cables and expect bad CRC'S (otherwise crosstalk is enough to receive everything ok!)
66  cfg1.AddExtension(micromodem::protobuf::Config::nvram_cfg, "AGC,0");
67  cfg2.AddExtension(micromodem::protobuf::Config::nvram_cfg, "AGC,0");
68  cfg1.AddExtension(micromodem::protobuf::Config::nvram_cfg, "AGN,0");
69  cfg2.AddExtension(micromodem::protobuf::Config::nvram_cfg, "AGN,0");
70 
71  cfg2.set_serial_port(argv[2]);
72  cfg2.set_modem_id(2);
73 
74  std::vector<int> tests_to_run;
75  tests_to_run.push_back(0);
76  if (mm_version == 1)
77  {
78  // ranging, mini-data not yet supported by MM2?
79  tests_to_run.push_back(1);
80  tests_to_run.push_back(2);
81  tests_to_run.push_back(3);
82  }
83 
84  tests_to_run.push_back(4);
85  tests_to_run.push_back(5);
86 
87  // FDP only supported in MM2
88  if (mm_version == 2)
89  {
90  tests_to_run.push_back(6);
91  cfg1.AddExtension(micromodem::protobuf::Config::nvram_cfg, "psk.packet.mod_hdr_version,0");
92  cfg2.AddExtension(micromodem::protobuf::Config::nvram_cfg, "psk.packet.mod_hdr_version,0");
93  }
94 
95  driver1.reset(new goby::acomms::MMDriver);
96  driver2.reset(new goby::acomms::MMDriver);
97 
98  DriverTester tester(driver1, driver2, cfg1, cfg2, tests_to_run,
99  goby::acomms::protobuf::DRIVER_WHOI_MICROMODEM);
100  return tester.run();
101 }
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
Definition: flex_ostream.h:67
provides an API to the WHOI Micro-Modem driver
Definition: mm_driver.h:41
common::FlexOstream glog
Access the Goby logger through this object.
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