Goby v2
liaison_acomms.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef LIAISONACOMMS20140626H
24 #define LIAISONACOMMS20140626H
25 
26 #include <Wt/Chart/WCartesianChart>
27 #include <Wt/WCssDecorationStyle>
28 #include <Wt/WPanel>
29 #include <Wt/WProgressBar>
30 #include <Wt/WTimer>
31 
32 #include <dccl.h>
33 
34 #include "goby/common/liaison_container.h"
35 #include "goby/moos/moos_node.h"
36 #include "goby/moos/protobuf/liaison_config.pb.h"
37 #include "goby/moos/protobuf/pAcommsHandler_config.pb.h"
38 
39 namespace goby
40 {
41 namespace common
42 {
43 class QueueBar : public Wt::WProgressBar
44 {
45  public:
46  QueueBar(Wt::WContainerWidget* parent = 0) : Wt::WProgressBar(parent) {}
47  Wt::WString text() const;
48 };
49 
50 class MACBar : public Wt::WProgressBar
51 {
52  public:
53  MACBar(Wt::WContainerWidget* parent = 0) : Wt::WProgressBar(parent) {}
54  Wt::WString text() const;
55 };
56 
58 {
59  public:
60  LiaisonAcomms(ZeroMQService* zeromq_service, const protobuf::LiaisonConfig& cfg,
61  Wt::WContainerWidget* parent = 0);
62 
63  private:
64  void process_acomms_config();
65 
66  void loop();
67  void moos_inbox(CMOOSMsg& msg);
68 
69  void dccl_analyze(const Wt::WMouseEvent& event);
70  void dccl_select(Wt::WString msg);
71  void dccl_message(const Wt::WMouseEvent& event);
72 
73  void queue_info(const Wt::WMouseEvent& event, int id);
74  void queue_flush(const Wt::WMouseEvent& event, int id);
75 
76  void mac_info(const Wt::WMouseEvent& event, int id);
77 
78  class DriverStats;
79  void update_driver_stats(int now, DriverStats* driver_stats);
80  void handle_modem_message(DriverStats* driver_stats, bool good,
82 
83  void driver_info(const Wt::WMouseEvent& event, DriverStats* driver_stats);
84  void mm_check(int axis, int column, bool checked);
85  void mm_range(double range);
86 
87  void focus() { timer_.start(); }
88 
89  void unfocus() { timer_.stop(); }
90 
91  std::string format_seconds(int sec);
92 
93  private:
94  boost::mutex dccl_mutex_;
95  dccl::Codec dccl_;
96 
97  Wt::WPushButton* dccl_analyze_;
98  Wt::WPushButton* dccl_message_;
99  Wt::WText* dccl_analyze_text_;
100  Wt::WText* dccl_message_text_;
101  Wt::WComboBox* dccl_combo_;
102  Wt::WTable* queue_table_;
103 
104  Wt::WContainerWidget* amac_box_;
105 
106  std::map<dccl::int32, QueueBar*> queue_bars_;
107 
108  // maps dccl id onto QueuedMessageEntry index
109  std::map<dccl::int32, int> queue_cfg_;
110 
111  // maps index of MAC cycle to container
112  std::map<int, Wt::WContainerWidget*> mac_slots_;
113  std::map<int, MACBar*> mac_bars_;
114  MACBar* mac_cycle_bar_;
115  Wt::WCssDecorationStyle mac_slot_style_;
116 
117  struct QueueStats
118  {
119  QueueStats() : last_rx_time(-1) {}
120 
121  int last_rx_time;
122  Wt::WText* last_rx_time_text;
123  };
124  std::map<dccl::int32, QueueStats> queue_stats_;
125 
126  ZeroMQService* zeromq_service_;
127  const protobuf::AcommsConfig& cfg_;
128  pAcommsHandlerConfig acomms_config_;
129  bool have_acomms_config_;
130 
131  Wt::WPanel* driver_panel_;
132  WContainerWidget* driver_box_;
133 
134  enum Direction
135  {
136  RX,
137  TX
138  };
139 
140  struct DriverStats
141  {
142  DriverStats(Direction d) : direction(d), last_time(-1) {}
143 
144  Direction direction;
145  int last_time;
146  Wt::WText* last_time_text;
148  Wt::WGroupBox* box;
149  };
150 
151  DriverStats driver_rx_;
152  DriverStats driver_tx_;
153 
154  Wt::WGroupBox* mm_rx_stats_box_;
155  Wt::WStandardItemModel* mm_rx_stats_model_;
156  Wt::Chart::WCartesianChart* mm_rx_stats_graph_;
157 
158  enum
159  {
160  TIME_COLUMN = 0,
161  ELAPSED_COLUMN = 1,
162  MSE_COLUMN = 2,
163  SNR_IN_COLUMN = 3,
164  SNR_OUT_COLUMN = 4,
165  DOPPLER_COLUMN = 5,
166  PERCENT_BAD_FRAMES_COLUMN = 6,
167  MAX_COLUMN = 6
168  };
169 
170  int mm_rx_stats_range_;
171 
172  // column -> axis -> Checkbox
173  std::map<int, std::map<int, Wt::WCheckBox*> > mm_rx_chks_;
174 
175  Wt::WTimer timer_;
176 
178 };
179 
180 } // namespace common
181 } // namespace goby
182 
183 #endif
The global namespace for the Goby project.