22 #include "goby/acomms/acomms_constants.h" 23 #include "goby/acomms/connect.h" 24 #include "goby/acomms/dccl.h" 25 #include "goby/acomms/queue.h" 26 #include "goby/common/logger.h" 27 #include "goby/util/binary.h" 31 using goby::acomms::operator<<;
33 int receive_count = 0;
34 GobyMessage msg_in_macrura, msg_in_broadcast, msg_in_unicorn;
36 const int MY_MODEM_ID = 1;
37 const int UNICORN_MODEM_ID = 3;
38 const int MACRURA_MODEM_ID = 4;
39 boost::posix_time::ptime current_time = boost::posix_time::second_clock::universal_time();
41 int goby_message_qsize = 0;
43 int handle_ack_count = 0;
51 int main(
int argc,
char* argv[])
59 dccl_cfg.set_crypto_passphrase(
"my_passphrase!");
60 codec->set_cfg(dccl_cfg);
63 cfg.set_modem_id(MY_MODEM_ID);
66 q_entry->set_protobuf_name(
"GobyMessage");
67 q_entry->set_newest_first(
true);
70 src_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::SOURCE_ID);
71 src_role->set_field(
"header.source_platform");
74 dest_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::DESTINATION_ID);
75 dest_role->set_field(
"header.dest_platform");
78 time_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::TIMESTAMP);
79 time_role->set_field(
"header.time");
87 msg_in_macrura.set_telegram(
"hello mac!");
88 msg_in_macrura.mutable_header()->set_time(goby::util::as<goby::uint64>(current_time));
89 msg_in_macrura.mutable_header()->set_source_platform(MY_MODEM_ID);
90 msg_in_macrura.mutable_header()->set_dest_platform(MACRURA_MODEM_ID);
91 msg_in_macrura.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
93 msg_in_broadcast.set_telegram(
"hello all!");
94 msg_in_broadcast.mutable_header()->set_time(goby::util::as<goby::uint64>(current_time));
96 msg_in_broadcast.mutable_header()->set_source_platform(MY_MODEM_ID);
97 msg_in_broadcast.mutable_header()->set_dest_type(Header::PUBLISH_ALL);
99 msg_in_unicorn.set_telegram(
"hello uni!");
100 msg_in_unicorn.mutable_header()->set_time(goby::util::as<goby::uint64>(current_time));
101 msg_in_unicorn.mutable_header()->set_source_platform(MY_MODEM_ID);
102 msg_in_unicorn.mutable_header()->set_dest_platform(UNICORN_MODEM_ID);
103 msg_in_unicorn.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
105 std::cout <<
"Pushed: " << msg_in_broadcast << std::endl;
107 assert(goby_message_qsize == 1);
109 std::cout <<
"Pushed: " << msg_in_macrura << std::endl;
111 assert(goby_message_qsize == 2);
116 transmit_msg.set_max_frame_bytes(256);
122 assert(goby_message_qsize == 1);
125 std::cout <<
"Pushed: " << msg_in_broadcast << std::endl;
127 assert(goby_message_qsize == 2);
130 std::cout <<
"Pushed: " << msg_in_unicorn << std::endl;
132 assert(goby_message_qsize == 3);
134 transmit_msg.Clear();
135 transmit_msg.set_max_frame_bytes(256);
141 assert(goby_message_qsize == 2);
143 std::cout <<
"requesting data, got: " << transmit_msg << std::endl;
144 std::cout <<
"\tdata as hex: " << goby::util::hex_encode(transmit_msg.frame(0)) << std::endl;
146 std::list<const google::protobuf::Message*> msgs;
147 msgs.push_back(&msg_in_unicorn);
148 msgs.push_back(&msg_in_broadcast);
151 assert(transmit_msg.src() == MY_MODEM_ID);
152 assert(transmit_msg.dest() == UNICORN_MODEM_ID);
153 assert(transmit_msg.ack_requested() ==
true);
157 assert(receive_count == 0);
161 ack.set_src(UNICORN_MODEM_ID);
162 ack.set_dest(MY_MODEM_ID);
163 ack.add_acked_frame(0);
164 ack.set_type(goby::acomms::protobuf::ModemTransmission::ACK);
167 assert(goby_message_qsize == 1);
168 assert(handle_ack_count == 1);
171 cfg.set_modem_id(UNICORN_MODEM_ID);
177 assert(receive_count == 2);
179 std::cout <<
"all tests passed" << std::endl;
184 std::cout <<
"Received: " << msg << std::endl;
187 typed_msg.CopyFrom(msg);
189 assert(typed_msg.header().time() == goby::util::as<goby::uint64>(current_time));
191 if (!typed_msg.header().has_dest_platform())
192 assert(typed_msg.SerializeAsString() == msg_in_broadcast.SerializeAsString());
193 else if (typed_msg.header().dest_platform() == 3)
194 assert(typed_msg.SerializeAsString() == msg_in_unicorn.SerializeAsString());
204 std::cout <<
"got an ack: " << ack_msg <<
"\n" 205 <<
"of original: " << orig_msg << std::endl;
206 assert(orig_msg.SerializeAsString() == msg_in_unicorn.SerializeAsString());
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.
static DCCLCodec * get()
DCCLCodec is a singleton class; use this to get a pointer to the class.
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)
const int QUERY_DESTINATION_ID
special modem id used internally to goby-acomms for indicating that the MAC layer (amac) is agnostic ...