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" 30 using goby::acomms::operator<<;
32 int receive_count = 0;
37 int main(
int argc,
char* argv[])
44 const int MY_MODEM_ID = 1;
45 const int UNICORN_MODEM_ID = 3;
46 cfg.set_modem_id(MY_MODEM_ID);
48 q_entry->set_protobuf_name(
"GobyMessage");
49 q_entry->set_newest_first(
true);
52 dest_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::DESTINATION_ID);
53 dest_role->set_field(
"header.dest_platform");
56 time_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::TIMESTAMP);
57 time_role->set_field(
"header.time");
60 src_role->set_type(goby::acomms::protobuf::QueuedMessageEntry::SOURCE_ID);
62 src_role->set_field(
"hder.source_platform");
67 bool FAILED_CHECK_FIELDS =
false;
68 assert(FAILED_CHECK_FIELDS);
76 src_role->set_field(
"header.source_platform");
81 msg_in1.set_telegram(
"hello!");
82 msg_in1.mutable_header()->set_time(
83 goby::util::as<goby::uint64>(boost::posix_time::second_clock::universal_time()));
84 msg_in1.mutable_header()->set_source_platform(MY_MODEM_ID);
85 msg_in1.mutable_header()->set_dest_platform(UNICORN_MODEM_ID);
86 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
88 std::cout <<
"Pushed: " << msg_in1 << std::endl;
92 transmit_msg.set_max_frame_bytes(256);
93 transmit_msg.set_dest(UNICORN_MODEM_ID);
97 std::cout <<
"requesting data, got: " << transmit_msg << std::endl;
98 std::cout <<
"\tdata as hex: " << goby::util::hex_encode(transmit_msg.frame(0)) << std::endl;
103 assert(transmit_msg.frame(0) == encoded);
104 assert(transmit_msg.src() == MY_MODEM_ID);
105 assert(transmit_msg.dest() == UNICORN_MODEM_ID);
106 assert(transmit_msg.ack_requested() ==
true);
110 assert(receive_count == 0);
113 cfg.set_modem_id(UNICORN_MODEM_ID);
119 assert(receive_count == 1);
121 std::cout <<
"all tests passed" << std::endl;
126 std::cout <<
"Received: " << msg << std::endl;
128 assert(msg_in1.SerializeAsString() == msg.SerializeAsString());
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.
boost::signals2::signal< void(const google::protobuf::Message &msg)> signal_receive
Signals when a DCCL message is received.
Exception class for libdccl.
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...
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)