23 #include <boost/foreach.hpp> 25 #include "goby/acomms/dccl/dccl.h" 26 #include "goby/common/logger.h" 27 #include "goby/util/as.h" 33 goby::transitional::DCCLMessage::DCCLMessage()
34 : size_(0), trigger_number_(1), id_(0), trigger_time_(0.0), repeat_enabled_(false), repeat_(1)
36 header_.resize(DCCL_NUM_HEADER_PARTS);
37 header_[HEAD_CCL_ID] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarCCLID());
38 header_[HEAD_DCCL_ID] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarDCCLID());
39 header_[HEAD_TIME] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarTime());
40 header_[HEAD_SRC_ID] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarSrc());
41 header_[HEAD_DEST_ID] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarDest());
42 header_[HEAD_MULTIMESSAGE_FLAG] =
43 boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarMultiMessageFlag());
44 header_[HEAD_BROADCAST_FLAG] =
45 boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarBroadcastFlag());
46 header_[HEAD_UNUSED] = boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarUnused());
50 void goby::transitional::DCCLMessage::add_message_var(
const std::string& type)
53 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarStatic()));
54 else if (type ==
"int")
55 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarInt()));
56 else if (type ==
"string")
57 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarString()));
58 else if (type ==
"float")
59 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarFloat()));
60 else if (type ==
"enum")
61 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarEnum()));
62 else if (type ==
"bool")
63 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarBool()));
64 else if (type ==
"hex")
65 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(
new DCCLMessageVarHex()));
70 void goby::transitional::DCCLMessage::add_publish()
73 publishes_.push_back(p);
78 void goby::transitional::DCCLMessage::preprocess()
83 glog.is(goby::common::logger::WARN) &&
84 glog <<
"<repeat> is deprecated and ignored in this version of Goby. Simply post a " 85 "message several times." 92 BOOST_FOREACH (boost::shared_ptr<DCCLMessageVar> mv, header_)
93 mv->initialize(*this);
94 BOOST_FOREACH (
boost::shared_ptr<DCCLMessageVar> mv, layout_)
95 mv->initialize(*this);
98 BOOST_FOREACH (DCCLPublish& p, publishes_)
103 in_var_ = "IN_" +
boost::to_upper_copy(name_) + "_HEX_" + as<
std::
string>(size_) + "
B";
105 out_var_ = "OUT_" +
boost::to_upper_copy(name_) + "_HEX_" + as<
std::
string>(size_) + "B";
108 void goby::transitional::DCCLMessage::set_repeat_array_length()
111 BOOST_FOREACH (boost::shared_ptr<DCCLMessageVar> mv, layout_)
112 mv->set_array_length(repeat_);
115 unsigned goby::transitional::DCCLMessage::calc_total_size()
117 boost::shared_ptr<acomms::DCCLFieldCodecBase> codec = acomms::DCCLFieldCodecManager::find(
118 descriptor_, descriptor_->options().GetExtension(dccl::msg).codec());
120 codec->base_max_size(&u, descriptor_, acomms::MessageHandler::BODY);
124 std::map<std::string, std::string> goby::transitional::DCCLMessage::message_var_names()
const 126 std::map<std::string, std::string> s;
127 BOOST_FOREACH (
const boost::shared_ptr<DCCLMessageVar> mv, layout_)
128 s.insert(
std::pair<
std::
string,
std::
string>(mv->name(), type_to_string(mv->type())));
132 void goby::transitional::DCCLMessage::set_head_defaults(
133 std::map<
std::
string,
std::vector<DCCLMessageVal> >& in,
unsigned modem_id)
135 for (std::vector<boost::shared_ptr<DCCLMessageVar> >::iterator it = header_.begin(),
138 { (*it)->set_defaults(in, modem_id, id_); } }
140 boost::shared_ptr<goby::transitional::DCCLMessageVar>
141 goby::transitional::DCCLMessage::name2message_var(
const std::string& name)
const 143 BOOST_FOREACH (boost::shared_ptr<DCCLMessageVar> mv, layout_)
145 if (mv->name() == name)
148 BOOST_FOREACH (boost::shared_ptr<DCCLMessageVar> mv, header_)
150 if (mv->name() == name)
154 throw goby::acomms::DCCLException(
155 std::string(
"DCCL: no such name \"" + name +
"\" found in <layout> or <header>"));
157 return boost::shared_ptr<DCCLMessageVar>();
161 void goby::transitional::DCCLMessage::write_schema_to_dccl2(std::ofstream* proto_file)
163 *proto_file <<
"message " << name_ <<
" { " << std::endl;
165 <<
"option (dccl.msg).id = " << id_ <<
";" << std::endl;
167 <<
"option (dccl.msg).max_bytes = " << size_ <<
";" << std::endl;
169 int sequence_number = 0;
171 header_[HEAD_TIME]->write_schema_to_dccl2(proto_file, ++sequence_number);
172 header_[HEAD_SRC_ID]->write_schema_to_dccl2(proto_file, ++sequence_number);
173 header_[HEAD_DEST_ID]->write_schema_to_dccl2(proto_file, ++sequence_number);
175 BOOST_FOREACH (boost::shared_ptr<DCCLMessageVar> mv, layout_)
176 mv->write_schema_to_dccl2(proto_file, ++sequence_number);
178 *proto_file << "} " <<
std::endl;
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.