24 #include "goby/acomms/modemdriver/udp_driver.h" 26 #include "goby/acomms/acomms_helpers.h" 27 #include "goby/acomms/bind.h" 28 #include "goby/acomms/connect.h" 29 #include "goby/acomms/queue.h" 30 #include "goby/common/logger.h" 31 #include "goby/util/binary.h" 35 boost::asio::io_service io1, io2;
36 boost::shared_ptr<goby::acomms::ModemDriverBase> driver1, driver2;
39 bool received_ack =
false;
53 msg_in1.set_telegram(
"hello!");
54 msg_in1.mutable_header()->set_time(
55 goby::util::as<goby::uint64>(boost::posix_time::second_clock::universal_time()));
56 msg_in1.mutable_header()->set_source_platform(1);
57 msg_in1.mutable_header()->set_dest_platform(2);
58 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
59 msg_in1.set_telegram(
"hello 1");
62 msg_in2.set_telegram(
"hello 2");
64 std::cout <<
"Pushed: " << msg_in2 << std::endl;
66 std::cout <<
"Pushed: " << msg_in1 << std::endl;
71 transmit.set_type(protobuf::ModemTransmission::DATA);
75 transmit.set_ack_requested(
true);
76 transmit.set_max_frame_bytes(15);
79 transmit.set_frame_start(0);
81 assert(transmit.frame_size() == 1);
83 transmit.clear_frame();
85 transmit.set_frame_start(1);
86 driver1->handle_initiate_transmission(transmit);
89 while (((i / 10) < 60) && !received_ack)
99 transmit.clear_frame();
100 transmit.set_frame_start(2);
102 assert(transmit.frame_size() == 1);
105 int main(
int argc,
char* argv[])
123 cfg1.set_modem_id(1);
126 int port1 = rand() % 1000 + 50010;
127 int port2 = port1 + 1;
131 local_endpoint1->set_port(port1);
133 cfg2.set_modem_id(2);
137 local_endpoint2->set_port(port2);
141 remote_endpoint1->set_ip(
"localhost");
142 remote_endpoint1->set_port(port2);
146 remote_endpoint2->set_ip(
"127.0.0.1");
147 remote_endpoint2->set_port(port1);
149 cfg1.SetExtension(UDPDriverConfig::max_frame_size, 15);
150 cfg2.SetExtension(UDPDriverConfig::max_frame_size, 15);
153 qcfg1.set_modem_id(1);
154 qcfg1.set_minimum_ack_wait_seconds(.1);
157 q_entry->set_protobuf_name(
"GobyMessage");
158 q_entry->set_newest_first(
true);
161 src_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::SOURCE_ID);
162 src_role->set_field(
"header.source_platform");
165 dest_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::DESTINATION_ID);
166 dest_role->set_field(
"header.dest_platform");
169 time_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::TIMESTAMP);
170 time_role->set_field(
"header.time");
173 qcfg2.set_modem_id(2);
190 goby::glog << cfg1.DebugString() << std::endl;
191 goby::glog << cfg2.DebugString() << std::endl;
193 goby::glog << qcfg1.DebugString() << std::endl;
194 goby::glog << qcfg2.DebugString() << std::endl;
196 driver1->startup(cfg1);
197 driver2->startup(cfg2);
201 std::cout <<
"all tests passed." << std::endl;
207 std::cout <<
"Received: " << msg << std::endl;
212 std::cout <<
"Queue size: " << size.size() << std::endl;
218 std::cout <<
"got an ack: " << ack_msg <<
"\n" 219 <<
"of original: " << orig_msg << std::endl;
220 assert(orig_msg.SerializeAsString() == msg_in2.SerializeAsString());
225 if (msg.type() == protobuf::ModemTransmission::ACK)
provides an API to the goby-acomms Queuing Library.
boost::signals2::signal< void(const protobuf::ModemTransmission &ack_msg, const google::protobuf::Message &orig_msg)> signal_ack
Signals when acknowledgment of proper message receipt has been received. This is only sent for queues...
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
boost::signals2::signal< void(const google::protobuf::Message &msg)> signal_receive
Signals when a DCCL message is received.
void handle_modem_data_request(protobuf::ModemTransmission *msg)
Finds data to send to the modem.
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...
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...
boost::signals2::signal< void(protobuf::QueueSize size)> signal_queue_size_change
Signals when any queue changes size (message is popped or pushed)
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
void push_message(const google::protobuf::Message &new_message)
Push a message (and add the queue if it does not exist)