Goby3  3.1.5a
2024.05.23
message.h
Go to the documentation of this file.
1 // Copyright 2009-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_MOOS_TRANSITIONAL_MESSAGE_H
26 #define GOBY_MOOS_TRANSITIONAL_MESSAGE_H
27 
28 #include <algorithm>
29 #include <bitset>
30 #include <iostream>
31 #include <map>
32 #include <set>
33 #include <sstream>
34 #include <vector>
35 
36 #include <memory>
37 
39 
40 #include "goby/util/as.h"
41 #include "message_var.h"
42 // #include "message_var_bool.h"
43 // #include "message_var_enum.h"
44 // #include "message_var_float.h"
45 // #include "message_var_head.h"
46 // #include "message_var_hex.h"
47 // #include "message_var_int.h"
48 // #include "message_var_static.h"
49 // #include "message_var_string.h"
50 
51 #include "dccl_constants.h"
52 #include "message_publish.h"
53 
54 namespace goby
55 {
56 namespace moos
57 {
58 namespace transitional
59 {
60 // the DCCLMessage itself
62 {
63  public:
64  // Added in Goby2 for transition to new Protobuf structure
65  void write_schema_to_dccl2(std::ofstream* proto_file);
66 
67  DCCLMessage();
68 
69  // set
70  void set_name(const std::string& name) { name_ = name; }
71 
72  void set_id(unsigned id) { id_ = id; }
73  template <typename T> void set_id(const T& t) { set_id(util::as<unsigned>(t)); }
74 
75  void set_trigger(const std::string& trigger_type) { trigger_type_ = trigger_type; }
76 
77  void set_trigger_var(const std::string& trigger_var) { trigger_var_ = trigger_var; }
78 
79  void set_trigger_time(double trigger_time) { trigger_time_ = trigger_time; }
80  template <typename T> void set_trigger_time(const T& t)
81  {
82  set_trigger_time(util::as<double>(t));
83  }
84 
85  void set_trigger_mandatory(const std::string& trigger_mandatory)
86  {
87  trigger_mandatory_ = trigger_mandatory;
88  }
89 
90  void set_in_var(const std::string& in_var) { in_var_ = in_var; }
91 
92  void set_out_var(const std::string& out_var) { out_var_ = out_var; }
93 
94  void set_size(unsigned size) { size_ = size; }
95 
96  template <typename T> void set_size(const T& t) { set_size(util::as<unsigned>(t)); }
97 
98  void set_repeat_enabled(unsigned repeat_enabled) { repeat_enabled_ = repeat_enabled; }
99  template <typename T> void set_repeat_enabled(const T& t)
100  {
101  set_repeat_enabled(util::as<unsigned>(t));
102  }
103 
104  void add_message_var(const std::string& type);
105  void add_publish();
106 
107  void set_descriptor(const google::protobuf::Descriptor* descriptor)
108  {
109  descriptor_ = descriptor;
110  }
111 
112  //get
113  std::string name() const { return name_; }
114  unsigned id() const { return id_; }
115  unsigned size() const { return size_; }
116  std::string trigger_var() const { return trigger_var_; }
117  std::string trigger_mandatory() const { return trigger_mandatory_; }
118  double trigger_time() const { return trigger_time_; }
119  unsigned trigger_number() const { return trigger_number_; }
120  std::string trigger_type() const { return trigger_type_; }
121  std::string in_var() const { return in_var_; }
122  std::string out_var() const { return out_var_; }
123  bool repeat_enabled() const { return repeat_enabled_; }
124  unsigned repeat() const { return repeat_; }
125 
126  DCCLMessageVar& last_message_var() { return *layout_.back(); }
128  DCCLPublish& last_publish() { return publishes_.back(); }
129 
130  std::vector<std::shared_ptr<DCCLMessageVar> >& layout() { return layout_; }
131  std::vector<std::shared_ptr<DCCLMessageVar> >& header() { return header_; }
132 
133  const std::vector<std::shared_ptr<DCCLMessageVar> >& layout_const() const { return layout_; }
134  const std::vector<std::shared_ptr<DCCLMessageVar> >& header_const() const { return header_; }
135 
136  std::vector<DCCLPublish>& publishes() { return publishes_; }
137  const std::vector<DCCLPublish>& publishes_const() const { return publishes_; }
138 
139  std::shared_ptr<DCCLMessageVar> name2message_var(const std::string& name) const;
140 
141  const google::protobuf::Descriptor* descriptor() { return descriptor_; }
142 
143  //other
144  /* std::string get_display() const; */
145  /* std::string get_short_display() const; */
146  std::map<std::string, std::string> message_var_names() const;
147  void preprocess();
149  unsigned calc_total_size();
150 
151  void set_head_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& in,
152  unsigned modem_id);
153 
154  // increment, means increase trigger number
155  // prefix ++DCCLMessage
157  {
158  ++trigger_number_;
159  return (*this);
160  }
161  // postfix DCCLMessage++
163  {
164  DCCLMessage tmp(*this);
165  ++(*this);
166  return tmp;
167  }
168 
169  private:
170  private:
171  // total request size of message, e.g. 32 bytes
172  unsigned size_;
173 
174  unsigned trigger_number_;
175  // actual used bits in body part of message (not including header bits)
176  // unsigned body_bits_;
177 
178  unsigned id_;
179  unsigned modem_id_;
180  double trigger_time_;
181 
182  bool repeat_enabled_;
183  unsigned repeat_;
184 
185  std::string name_;
186  std::string trigger_type_;
187  std::string trigger_var_;
188  std::string trigger_mandatory_;
189  std::string in_var_;
190  std::string out_var_;
191 
192  std::vector<std::shared_ptr<DCCLMessageVar> > layout_;
193  std::vector<std::shared_ptr<DCCLMessageVar> > header_;
194 
195  std::vector<DCCLPublish> publishes_;
196 
197  const google::protobuf::Descriptor* descriptor_;
198 };
199 
200 /* inline void bitset2string(const boost::dynamic_bitset<unsigned char>& body_bits, */
201 /* std::string& body) */
202 /* { */
203 /* body.resize(body_bits.num_blocks()); // resize the string to fit the bitset */
204 /* to_block_range(body_bits, body.rbegin()); */
205 /* } */
206 
207 /* inline void string2bitset(boost::dynamic_bitset<unsigned char>& body_bits, */
208 /* const std::string& body) */
209 /* { */
210 /* from_block_range(body.rbegin(), body.rend(), body_bits); */
211 /* } */
212 
213 // std::ostream& operator<< (std::ostream& out, const DCCLMessage& message);
214 } // namespace transitional
215 } // namespace moos
216 } // namespace goby
217 #endif
goby::moos::transitional::DCCLMessage::set_trigger_time
void set_trigger_time(double trigger_time)
Definition: message.h:79
message_publish.h
goby::moos::transitional::DCCLMessage::DCCLMessage
DCCLMessage()
goby::moos::transitional::DCCLMessage::name
std::string name() const
Definition: message.h:113
queue.pb.h
goby::moos::transitional::DCCLMessage::set_repeat_enabled
void set_repeat_enabled(unsigned repeat_enabled)
Definition: message.h:98
goby::moos::transitional::DCCLMessage::message_var_names
std::map< std::string, std::string > message_var_names() const
goby::moos::transitional::DCCLMessage::operator++
DCCLMessage & operator++()
Definition: message.h:156
goby::moos::transitional::DCCLMessage::size
unsigned size() const
Definition: message.h:115
goby::moos::transitional::DCCLMessage::set_trigger
void set_trigger(const std::string &trigger_type)
Definition: message.h:75
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
message_var.h
as.h
goby::moos::transitional::DCCLMessage::add_message_var
void add_message_var(const std::string &type)
goby::moos::transitional::DCCLMessage::id
unsigned id() const
Definition: message.h:114
goby::moos::transitional::DCCLMessage::repeat
unsigned repeat() const
Definition: message.h:124
goby::moos::transitional::DCCLMessage::set_name
void set_name(const std::string &name)
Definition: message.h:70
goby::moos::transitional::DCCLMessage::publishes
std::vector< DCCLPublish > & publishes()
Definition: message.h:136
goby::moos::transitional::DCCLMessage::operator++
const DCCLMessage operator++(int)
Definition: message.h:162
goby::moos::transitional::DCCLMessage::trigger_var
std::string trigger_var() const
Definition: message.h:116
dccl_constants.h
goby::moos::transitional::DCCLMessage::write_schema_to_dccl2
void write_schema_to_dccl2(std::ofstream *proto_file)
goby::moos::transitional::DCCLPublish
Definition: message_publish.h:52
goby::moos::transitional::DCCLMessage::trigger_mandatory
std::string trigger_mandatory() const
Definition: message.h:117
goby::moos::transitional::DCCLHeaderPart
DCCLHeaderPart
Definition: dccl_constants.h:133
goby::moos::transitional::DCCLMessage::calc_total_size
unsigned calc_total_size()
goby::moos::transitional::DCCLMessage::header_const
const std::vector< std::shared_ptr< DCCLMessageVar > > & header_const() const
Definition: message.h:134
goby::moos::transitional::DCCLMessage::trigger_type
std::string trigger_type() const
Definition: message.h:120
goby::moos::transitional::DCCLMessage::header_var
DCCLMessageVar & header_var(moos::transitional::DCCLHeaderPart p)
Definition: message.h:127
goby::moos::transitional::DCCLMessage::set_trigger_time
void set_trigger_time(const T &t)
Definition: message.h:80
goby::moos::transitional::DCCLMessage::set_head_defaults
void set_head_defaults(std::map< std::string, std::vector< DCCLMessageVal > > &in, unsigned modem_id)
goby::moos::transitional::DCCLMessage::set_trigger_mandatory
void set_trigger_mandatory(const std::string &trigger_mandatory)
Definition: message.h:85
goby::moos::transitional::DCCLMessage::out_var
std::string out_var() const
Definition: message.h:122
goby::moos::transitional::DCCLMessage::header
std::vector< std::shared_ptr< DCCLMessageVar > > & header()
Definition: message.h:131
goby::moos::transitional::DCCLMessage::last_publish
DCCLPublish & last_publish()
Definition: message.h:128
goby::moos::transitional::DCCLMessage::publishes_const
const std::vector< DCCLPublish > & publishes_const() const
Definition: message.h:137
goby::moos::transitional::DCCLMessage::set_out_var
void set_out_var(const std::string &out_var)
Definition: message.h:92
goby::moos::transitional::DCCLMessage::last_message_var
DCCLMessageVar & last_message_var()
Definition: message.h:126
goby::moos::transitional::DCCLMessage::set_id
void set_id(const T &t)
Definition: message.h:73
goby::moos::transitional::DCCLMessage::layout
std::vector< std::shared_ptr< DCCLMessageVar > > & layout()
Definition: message.h:130
jwt::json::type
type
Generic JSON types used in JWTs.
Definition: jwt.h:2071
goby::moos::transitional::DCCLMessage::in_var
std::string in_var() const
Definition: message.h:121
goby::moos::transitional::DCCLMessage::set_trigger_var
void set_trigger_var(const std::string &trigger_var)
Definition: message.h:77
goby::moos::transitional::DCCLMessage::layout_const
const std::vector< std::shared_ptr< DCCLMessageVar > > & layout_const() const
Definition: message.h:133
goby::moos::transitional::DCCLMessage::trigger_time
double trigger_time() const
Definition: message.h:118
goby::moos::transitional::DCCLMessageVar
Definition: message_var.h:55
goby::moos::transitional::DCCLMessage::trigger_number
unsigned trigger_number() const
Definition: message.h:119
goby::moos::transitional::DCCLMessage::set_size
void set_size(const T &t)
Definition: message.h:96
goby::moos::transitional::DCCLMessage::set_repeat_enabled
void set_repeat_enabled(const T &t)
Definition: message.h:99
goby::moos::transitional::DCCLMessage::add_publish
void add_publish()
goby::moos::transitional::DCCLMessage
Definition: message.h:61
goby::moos::transitional::DCCLMessage::set_in_var
void set_in_var(const std::string &in_var)
Definition: message.h:90
goby::moos::transitional::DCCLMessage::set_descriptor
void set_descriptor(const google::protobuf::Descriptor *descriptor)
Definition: message.h:107
goby::moos::transitional::DCCLMessage::preprocess
void preprocess()
goby::moos::transitional::DCCLMessage::set_size
void set_size(unsigned size)
Definition: message.h:94
goby::moos::transitional::DCCLMessage::set_id
void set_id(unsigned id)
Definition: message.h:72
goby::moos::transitional::DCCLMessage::descriptor
const google::protobuf::Descriptor * descriptor()
Definition: message.h:141
goby::moos::transitional::DCCLMessage::set_repeat_array_length
void set_repeat_array_length()
goby::moos::transitional::DCCLMessage::name2message_var
std::shared_ptr< DCCLMessageVar > name2message_var(const std::string &name) const
goby::moos::transitional::DCCLMessage::repeat_enabled
bool repeat_enabled() const
Definition: message.h:123