34 #include "goby/acomms/acomms_helpers.h" 35 #include "goby/acomms/amac/mac_manager.h" 36 #include "goby/acomms/bind.h" 37 #include "goby/acomms/connect.h" 38 #include "goby/acomms/modemdriver/udp_driver.h" 39 #include "goby/acomms/route/route.h" 40 #include "goby/common/logger.h" 41 #include "goby/common/time.h" 42 #include "goby/util/as.h" 43 #include "goby/util/binary.h" 54 const int ID_1_1 = (1 << 8) + 1;
55 const int ID_2_1 = (2 << 8) + 1;
56 const int ID_3_1 = (3 << 8) + 1;
64 boost::asio::io_service io2, io3;
65 boost::shared_ptr<goby::acomms::UDPDriver> driver2, driver3;
67 bool received_message =
false;
71 int main(
int argc,
char* argv[])
80 q_entry->set_protobuf_name(
"RouteMessage");
81 q_entry->set_newest_first(
true);
84 src_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::SOURCE_ID);
85 src_role->set_field(
"src");
88 dest_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::DESTINATION_ID);
89 dest_role->set_field(
"dest");
92 time_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::TIMESTAMP);
93 time_role->set_field(
"time");
95 q_cfg2.add_message_entry()->CopyFrom(*q_entry);
96 q_cfg3.add_message_entry()->CopyFrom(*q_entry);
98 q_cfg1.set_skip_decoding(
true);
99 q_cfg2.set_skip_decoding(
true);
100 q_cfg3.set_skip_decoding(
false);
102 q_cfg1.set_modem_id(ID_1_1);
105 q_cfg2.set_modem_id(ID_2_1);
108 q_cfg3.set_modem_id(ID_3_1);
119 r_cfg.mutable_route()->add_hop(ID_0_1);
120 r_cfg.mutable_route()->add_hop(ID_1_1);
121 r_cfg.mutable_route()->add_hop(ID_2_1);
122 r_cfg.mutable_route()->add_hop(ID_3_1);
123 r_cfg.set_subnet_mask(0xFFFFFF00);
124 r_manager.set_cfg(r_cfg);
131 d_cfg2.set_modem_id(ID_2_1);
132 d_cfg3.set_modem_id(ID_3_1);
135 int port1 = rand() % 1000 + 50020;
136 int port2 = port1 + 1;
138 d_cfg2.MutableExtension(UDPDriverConfig::local)->set_port(port1);
139 d_cfg3.MutableExtension(UDPDriverConfig::local)->set_port(port2);
140 d_cfg2.MutableExtension(UDPDriverConfig::remote)
141 ->CopyFrom(d_cfg3.GetExtension(UDPDriverConfig::local));
142 d_cfg3.MutableExtension(UDPDriverConfig::remote)
143 ->CopyFrom(d_cfg2.GetExtension(UDPDriverConfig::local));
145 driver2->startup(d_cfg2);
146 driver3->startup(d_cfg3);
151 m_cfg2.set_modem_id(ID_2_1);
152 m_cfg3.set_modem_id(ID_3_1);
153 m_cfg2.set_type(goby::acomms::protobuf::MAC_FIXED_DECENTRALIZED);
154 m_cfg3.set_type(goby::acomms::protobuf::MAC_FIXED_DECENTRALIZED);
157 slot2.set_src(ID_2_1);
158 slot2.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
159 slot2.set_slot_seconds(0.1);
160 m_cfg2.add_slot()->CopyFrom(slot2);
161 m_cfg3.add_slot()->CopyFrom(slot2);
164 slot3.set_src(ID_3_1);
165 slot3.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
166 slot3.set_slot_seconds(0.1);
167 m_cfg2.add_slot()->CopyFrom(slot3);
168 m_cfg3.add_slot()->CopyFrom(slot3);
184 in_msg.set_src(ID_0_1);
185 in_msg.set_dest(ID_3_1);
186 in_msg.set_time(goby_time<goby::uint64>() / 1000000 *
188 in_msg.set_telegram(
"0-->3");
192 initial_transmit.set_src(ID_0_1);
193 initial_transmit.set_dest(ID_1_1);
194 initial_transmit.set_time(goby_time<goby::uint64>());
195 initial_transmit.set_type(goby::acomms::protobuf::ModemTransmission::DATA);
200 dccl_cfg.set_crypto_passphrase(
"my_passphrase2!");
201 dccl->set_cfg(dccl_cfg);
204 dccl->encode(initial_transmit.add_frame(), in_msg);
207 dccl_cfg.clear_crypto_passphrase();
208 dccl->set_cfg(dccl_cfg);
211 std::cout <<
"Modem receive on q1: " << initial_transmit.DebugString() << std::endl;
216 while (((i / 10) < 10))
230 if (received_message)
236 if (received_message)
238 std::cout <<
"all tests passed" << std::endl;
243 std::cout <<
"never received message" << std::endl;
254 std::cout <<
"Received at 3.1: " << msg.DebugString() << std::endl;
255 std::cout <<
"Original: " << in_msg.DebugString() << std::endl;
256 received_message =
true;
257 assert(in_msg.SerializeAsString() == msg.SerializeAsString());
264 dccl_cfg.set_crypto_passphrase(
"my_passphrase2!");
265 dccl->set_cfg(dccl_cfg);
provides an API to the goby-acomms Queuing Library.
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
static DCCLCodec * get()
DCCLCodec is a singleton class; use this to get a pointer to the class.
void startup(const protobuf::MACConfig &cfg)
Starts the MAC with given configuration.
boost::signals2::signal< void(const google::protobuf::Message &msg)> signal_receive
Signals when a DCCL message is received.
void do_work()
Allows the MAC timer to do its work. Does not block. If you prefer more control you can directly cont...
void handle_modem_receive(const protobuf::ModemTransmission &message)
Receive incoming data from the modem.
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 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 set_cfg(const protobuf::QueueManagerConfig &cfg)
Set (and overwrite completely if present) the current configuration. (protobuf::QueueManagerConfig de...
void do_work()
Calculates which messages have expired and emits the goby::acomms::QueueManager::signal_expire as nec...
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...
void bind(ModemDriverBase &driver, QueueManager &queue_manager)
binds the driver link-layer callbacks to the QueueManager