24 #include "goby/acomms/connect.h" 25 #include "goby/acomms/modemdriver/mm_driver.h" 26 #include "goby/common/application_base.h" 27 #include "goby/common/logger.h" 28 #include "goby/util/binary.h" 29 #include "test_config.pb.h" 37 boost::mutex driver_mutex;
38 int last_transmission_index = 0;
57 summary(
const std::map<
int, std::vector<micromodem::protobuf::ReceiveStatistics> >& receive,
65 std::map<int, std::vector<micromodem::protobuf::ReceiveStatistics> > driver1_receive,
72 : ApplicationBase(cfg), cfg_(*cfg), modems_running_(
true)
79 void MMDriverTest2::iterate()
83 &MMDriverTest2::handle_transmit_result1);
86 &MMDriverTest2::handle_transmit_result2);
88 boost::thread modem_thread_A(
89 boost::bind(&MMDriverTest2::run,
this, boost::ref(driver1), cfg_.mm1_cfg()));
90 boost::thread modem_thread_B(
91 boost::bind(&MMDriverTest2::run,
this, boost::ref(driver2), cfg_.mm2_cfg()));
93 while (!driver1.is_started() || !driver2.is_started()) usleep(10000);
95 for (
int i = 0, n = cfg_.repeat(); i < n; ++i)
98 <<
" of " << n << std::endl;
100 int o = cfg_.transmission_size();
101 for (last_transmission_index = 0; last_transmission_index < o; ++last_transmission_index)
103 if (cfg_.transmission(last_transmission_index).src() == 1)
105 boost::mutex::scoped_lock lock(driver_mutex);
106 driver1.handle_initiate_transmission(cfg_.transmission(last_transmission_index));
108 else if (cfg_.transmission(last_transmission_index).src() == 2)
110 boost::mutex::scoped_lock lock(driver_mutex);
111 driver2.handle_initiate_transmission(cfg_.transmission(last_transmission_index));
113 sleep(cfg_.transmission(last_transmission_index).slot_seconds());
117 modems_running_ =
false;
118 modem_thread_A.join();
119 modem_thread_B.join();
121 summary(driver1_receive, cfg_.mm1_cfg());
122 summary(driver2_receive, cfg_.mm2_cfg());
133 while (modems_running_)
136 boost::mutex::scoped_lock lock(driver_mutex);
149 for (
int i = 0, n = msg.ExtensionSize(micromodem::protobuf::receive_stat); i < n; ++i)
150 driver1_receive[last_transmission_index].push_back(
151 msg.GetExtension(micromodem::protobuf::receive_stat, i));
158 for (
int i = 0, n = msg.ExtensionSize(micromodem::protobuf::receive_stat); i < n; ++i)
159 driver2_receive[last_transmission_index].push_back(
160 msg.GetExtension(micromodem::protobuf::receive_stat, i));
173 void MMDriverTest2::summary(
174 const std::map<
int, std::vector<micromodem::protobuf::ReceiveStatistics> >& receive,
178 <<
" receive summary" << std::endl;
180 for (std::map<
int, std::vector<micromodem::protobuf::ReceiveStatistics> >::const_iterator
181 it = receive.begin(),
186 "transmission before this reception occured): " 187 << cfg_.transmission(it->first).DebugString()
190 const std::vector<micromodem::protobuf::ReceiveStatistics>& current_receive_vector =
193 std::multiset<micromodem::protobuf::PacketType> type;
194 std::multiset<micromodem::protobuf::ReceiveMode> mode;
195 std::multiset<micromodem::protobuf::PSKErrorCode> code;
197 for (
int i = 0, n = current_receive_vector.size(); i < n; ++i)
200 << current_receive_vector[i].ShortDebugString()
203 type.insert(current_receive_vector[i].packet_type());
204 mode.insert(current_receive_vector[i].mode());
205 code.insert(current_receive_vector[i].psk_error_code());
209 for (
int j = micromodem::protobuf::PacketType_MIN;
210 j <= micromodem::protobuf::PacketType_MAX; ++j)
212 if (micromodem::protobuf::PacketType_IsValid(j))
214 micromodem::protobuf::PacketType jt =
215 static_cast<micromodem::protobuf::PacketType
>(j);
217 << micromodem::protobuf::PacketType_Name(jt)
218 <<
": " << type.count(jt) << std::endl;
223 for (
int j = micromodem::protobuf::ReceiveMode_MIN;
224 j <= micromodem::protobuf::ReceiveMode_MAX; ++j)
226 if (micromodem::protobuf::ReceiveMode_IsValid(j))
228 micromodem::protobuf::ReceiveMode jt =
229 static_cast<micromodem::protobuf::ReceiveMode
>(j);
231 << micromodem::protobuf::ReceiveMode_Name(jt)
232 <<
": " << mode.count(jt) << std::endl;
237 for (
int j = micromodem::protobuf::PSKErrorCode_MIN;
238 j <= micromodem::protobuf::PSKErrorCode_MAX; ++j)
240 if (micromodem::protobuf::PSKErrorCode_IsValid(j))
242 micromodem::protobuf::PSKErrorCode jt =
243 static_cast<micromodem::protobuf::PSKErrorCode
>(j);
245 << micromodem::protobuf::PSKErrorCode_Name(jt)
246 <<
": " << code.count(jt) << std::endl;
250 goby::glog.is(VERBOSE) &&
goby::glog <<
"*** End modem " << cfg.modem_id() <<
" receive summary" 254 int main(
int argc,
char* argv[])
257 goby::run<MMDriverTest2>(argc, argv, &cfg);
void shutdown()
Stops the driver.
provides an API to the WHOI Micro-Modem driver
int run(int argc, char *argv[], Config *cfg)
Run a Goby application derived from MinimalApplicationBase. blocks caller until MinimalApplicationBas...
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime.
void do_work()
See ModemDriverBase::do_work()
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)
void startup(const protobuf::DriverConfig &cfg)
Starts the driver.