22 #include "goby/acomms/acomms_constants.h" 23 #include "goby/acomms/connect.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 int encode_on_demand_count = 0;
35 bool handle_ack_called =
false;
36 int goby_message_qsize = 0;
37 int last_decoded_count = 0;
38 std::deque<int> decode_order;
41 const int MY_MODEM_ID = 1;
42 bool provide_data =
true;
51 void request_test(
int request_bytes,
int expected_encode_requests,
int expected_messages_sent);
53 int main(
int argc,
char* argv[])
61 cfg.set_modem_id(MY_MODEM_ID);
63 entry->set_protobuf_name(
"GobyMessage");
64 entry->set_newest_first(
true);
65 entry->add_manipulator(goby::acomms::protobuf::ON_DEMAND);
66 cfg.set_on_demand_skew_seconds(0.1);
77 decode_order.push_back(0);
79 assert(decode_order.empty());
82 decode_order.push_back(1);
84 assert(decode_order.empty());
87 decode_order.push_back(2);
88 decode_order.push_back(3);
89 request_test(codec->size(
GobyMessage()) * 2 + 1, 3, 2);
90 assert(decode_order.empty());
95 decode_order.push_back(5);
97 assert(decode_order.empty());
100 provide_data =
false;
101 decode_order.push_back(4);
103 assert(decode_order.empty());
105 std::cout <<
"all tests passed" << std::endl;
108 void request_test(
int request_bytes,
int expected_encode_requests,
int expected_messages_sent)
110 int starting_qsize = goby_message_qsize;
111 int starting_encode_count = encode_on_demand_count;
114 transmit_msg.set_max_frame_bytes(request_bytes);
115 transmit_msg.set_max_num_frames(1);
118 std::cout <<
"requesting data, got: " << transmit_msg << std::endl;
121 assert(encode_on_demand_count - starting_encode_count == expected_encode_requests);
123 std::cout <<
"\tdata as hex: " << goby::util::hex_encode(transmit_msg.frame(0)) << std::endl;
125 assert(transmit_msg.src() == MY_MODEM_ID);
127 assert(transmit_msg.ack_requested() ==
false);
130 assert(goby_message_qsize ==
131 starting_qsize + expected_encode_requests - expected_messages_sent);
133 assert(goby_message_qsize == starting_qsize - expected_messages_sent);
144 msg.set_telegram(encode_on_demand_count);
146 std::cout <<
"encoded on demand: " << msg << std::endl;
149 data_msg->CopyFrom(msg);
150 ++encode_on_demand_count;
158 msg.CopyFrom(in_msg);
160 std::cout <<
"Received: " << msg << std::endl;
162 assert(decode_order.front() == msg.telegram());
163 decode_order.pop_front();
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 protobuf::ModemTransmission &request_msg, google::protobuf::Message *data_msg)> signal_data_on_demand
Forwards the data request to the application layer. This advanced feature is used when queue...
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.
const int BROADCAST_ID
special modem id for the broadcast destination - no one is assigned this address. Analogous to 192...
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...