22 #include "goby/acomms/connect.h" 23 #include "goby/acomms/dccl.h" 24 #include "goby/acomms/queue.h" 25 #include "goby/common/logger.h" 26 #include "goby/util/binary.h" 31 using goby::acomms::operator<<;
33 int receive_count = 0;
34 bool handle_ack_called =
false;
35 int goby_message_qsize = 0;
45 int main(
int argc,
char* argv[])
52 const int MY_MODEM_ID = 1;
53 const int UNICORN_MODEM_ID = 3;
54 cfg.set_modem_id(MY_MODEM_ID);
57 q_entry->set_protobuf_name(
"GobyMessage");
58 q_entry->set_newest_first(
true);
61 src_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::SOURCE_ID);
62 src_role->set_field(
"header.source_platform");
65 dest_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::DESTINATION_ID);
66 dest_role->set_field(
"header.dest_platform");
69 time_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::TIMESTAMP);
70 time_role->set_field(
"header.time");
78 msg_in1.set_telegram(
"hello!");
79 msg_in1.mutable_header()->set_time(
80 goby::util::as<goby::uint64>(boost::posix_time::second_clock::universal_time()));
81 msg_in1.mutable_header()->set_source_platform(MY_MODEM_ID);
82 msg_in1.mutable_header()->set_dest_platform(UNICORN_MODEM_ID);
83 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
84 msg_in1.set_telegram(
"hello 1");
87 msg_in2.set_telegram(
"hello 2");
89 std::cout <<
"Pushed: " << msg_in2 << std::endl;
91 std::cout <<
"Pushed: " << msg_in1 << std::endl;
95 transmit_msg.set_max_frame_bytes(16);
96 transmit_msg.set_max_num_frames(2);
97 transmit_msg.set_dest(UNICORN_MODEM_ID);
100 std::cout <<
"requesting data, got: " << transmit_msg << std::endl;
101 std::cout <<
"\tdata frame 0 as hex: " << goby::util::hex_encode(transmit_msg.frame(0))
103 std::cout <<
"\tdata frame 1 as hex: " << goby::util::hex_encode(transmit_msg.frame(1))
108 ack.set_type(goby::acomms::protobuf::ModemTransmission::ACK);
109 ack.set_src(UNICORN_MODEM_ID);
110 ack.set_dest(MY_MODEM_ID);
111 ack.add_acked_frame(0);
112 ack.add_acked_frame(1);
115 assert(goby_message_qsize == 0);
116 assert(handle_ack_called ==
true);
118 std::cout <<
"all tests passed" << std::endl;
123 std::cout <<
"Received: " << msg << std::endl;
133 std::cout <<
"got an ack: " << ack_msg <<
"\n" 134 <<
"of original: " << orig_msg << std::endl;
135 handle_ack_called =
true;
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 handle_modem_receive(const protobuf::ModemTransmission &message)
Receive incoming data from the 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.
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 push_message(const google::protobuf::Message &new_message)
Push a message (and add the queue if it does not exist)