24 #include "goby/acomms/amac.h" 25 #include "goby/acomms/connect.h" 26 #include "goby/common/logger.h" 27 #include "goby/util/sci.h" 30 const int num_cycles_check = 3;
32 int current_cycle = -1;
35 using goby::acomms::operator<<;
39 std::cout <<
"We were told to start transmission of " << msg << std::endl;
40 assert(msg.src() == me);
41 double cycles_since_day =
45 std::cout << std::setprecision(15) << cycles_since_day << std::endl;
46 std::cout << std::setprecision(15) << goby::util::unbiased_round(cycles_since_day, 0)
49 current_cycle = cycles_since_day;
50 if (first_cycle == -1)
51 first_cycle = current_cycle;
53 assert(mac.cycle_count() == 3);
55 assert(goby::util::unbiased_round(
56 cycles_since_day - goby::util::unbiased_round(cycles_since_day, 0), 1) == 0);
59 int main(
int argc,
char* argv[])
67 cfg.set_type(goby::acomms::protobuf::MAC_FIXED_DECENTRALIZED);
70 downlink_slot.set_src(1);
71 downlink_slot.set_rate(0);
72 downlink_slot.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
73 downlink_slot.set_slot_seconds(0.1);
74 cfg.add_slot()->CopyFrom(downlink_slot);
77 uplink3_slot.set_src(3);
78 uplink3_slot.set_rate(0);
79 uplink3_slot.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
80 uplink3_slot.set_slot_seconds(0.1);
81 cfg.add_slot()->CopyFrom(uplink3_slot);
84 uplink4_slot.set_src(4);
85 uplink4_slot.set_rate(0);
86 uplink4_slot.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
87 uplink4_slot.set_slot_seconds(0.1);
88 cfg.add_slot()->CopyFrom(uplink4_slot);
94 while (first_cycle == -1 || (current_cycle < first_cycle + num_cycles_check))
108 cfg.set_modem_id(me);
109 cfg.set_type(goby::acomms::protobuf::MAC_FIXED_DECENTRALIZED);
114 mac.push_back(downlink_slot);
115 mac.push_back(uplink3_slot);
118 mac.push_back(uplink4_slot);
119 mac.remove(downlink_slot);
120 mac.push_back(downlink_slot);
123 while (first_cycle == -1 || (current_cycle < first_cycle + num_cycles_check))
124 mac.get_io_service().run_one();
126 std::cout <<
"all tests passed" << std::endl;
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
void startup(const protobuf::MACConfig &cfg)
Starts the MAC with given configuration.
void do_work()
Allows the MAC timer to do its work. Does not block. If you prefer more control you can directly cont...
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime.
provides an API to the goby-acomms MAC library. MACManager is essentially a std::list<protobuf::Modem...
void shutdown()
Shutdown the MAC.
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.
void update()
You must call this after any change to the underlying list that would invalidate iterators or change ...
boost::signals2::signal< void(const protobuf::ModemTransmission &m)> signal_initiate_transmission
Signals when it is time for this platform to begin transmission of an acoustic message at the start o...
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...