OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_bridge.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2022 by David Register *
3 * Copyright (C) 2022 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef COMM_BRIDGE_H
26#define COMM_BRIDGE_H
27
28#include <memory>
29#include <string>
30#include <unordered_map>
31
32#include <wx/event.h>
33#include <wx/timer.h>
34
35#include "model/comm_decoder.h"
36#include "model/comm_navmsg.h"
37#include "model/nmea_log.h"
38
39using N0183MsgPtr = std::shared_ptr<const Nmea0183Msg>;
40using N2000MsgPtr = std::shared_ptr<const Nmea2000Msg>;
41using SignalKMsgPtr = std::shared_ptr<const SignalkMsg>;
42using NavMsgPtr = std::shared_ptr<const NavMsg>;
43
44using PriorityMap = std::unordered_map<std::string, int>;
45
47 std::string prio_class;
48 int active_priority;
49 std::string active_source;
50 std::string active_identifier;
51 int active_source_address;
52 time_t recent_active_time;
53 PriorityContainer(const std::string& cls, int prio = 0)
54 : prio_class(cls),
55 active_priority(prio),
56 active_source_address(-1),
57 recent_active_time(0) {}
58};
59
60struct Watchdogs {
61 int position_watchdog;
62 int variation_watchdog;
63 int heading_watchdog;
64 int velocity_watchdog;
65 int satellite_watchdog;
66 Watchdogs()
67 : position_watchdog(0),
68 variation_watchdog(0),
69 heading_watchdog(0),
70 velocity_watchdog(0),
71 satellite_watchdog(0) {}
72};
73
75 std::function<bool()> log_is_active;
76 std::function<void(const Logline&)> log_message;
78 : log_is_active([]() { return false; }),
79 log_message([](const Logline&) {}) {}
80};
81
89class CommBridge : public wxEvtHandler {
90public:
91 static CommBridge& GetInstance();
92
93 CommBridge(const CommBridge&) = delete;
94 CommBridge& operator=(const CommBridge&) = delete;
95
96 ~CommBridge() override;
97
98 bool Initialize();
99
119 bool HandleN0183_AIVDO(const N0183MsgPtr& n0183_msg);
120
121 bool EvalPriority(const NavMsgPtr& msg, PriorityContainer& active_priority,
122 PriorityMap& priority_map);
123
124 std::vector<std::string> GetPriorityMaps() const;
125
126 PriorityContainer& GetPriorityContainer(const std::string& category);
127
128 void UpdateAndApplyMaps(const std::vector<std::string>& new_maps);
129
130 bool LoadConfig();
131
132 bool SaveConfig() const;
133
134private:
135 CommBridge();
136
137 PriorityContainer active_priority_position;
138 PriorityContainer active_priority_velocity;
139 PriorityContainer active_priority_heading;
140 PriorityContainer active_priority_variation;
141 PriorityContainer active_priority_satellites;
142 PriorityContainer active_priority_void;
143
144 PriorityMap priority_map_position;
145 PriorityMap priority_map_velocity;
146 PriorityMap priority_map_heading;
147 PriorityMap priority_map_variation;
148 PriorityMap priority_map_satellites;
149
150 // comm event listeners
151 ObsListener m_n2k_129029_lstnr;
152 ObsListener m_n2k_129025_lstnr;
153 ObsListener m_n2k_129026_lstnr;
154 ObsListener m_n2k_127250_lstnr;
155 ObsListener m_n2k_127258_lstnr;
156 ObsListener m_n2k_129540_lstnr;
157
158 ObsListener m_n0183_rmc_lstnr;
159 ObsListener m_n0183_ths_lstnr;
160 ObsListener m_n0183_hdt_lstnr;
161 ObsListener m_n0183_hdg_lstnr;
162 ObsListener m_n0183_hdm_lstnr;
163 ObsListener m_n0183_hvd_lstnr;
164 ObsListener m_n0183_vtg_lstnr;
165 ObsListener m_n0183_gsv_lstnr;
166 ObsListener m_n0183_gga_lstnr;
167 ObsListener m_n0183_gll_lstnr;
168 ObsListener m_n0183_aivdo_lstnr;
169
170 ObsListener m_signal_k_lstnr;
171
172 ObsListener m_driver_change_lstnr;
173
174 CommDecoder m_decoder;
175
176 bool HandleN0183_GGA(const N0183MsgPtr& n0183_msg);
177 bool HandleN0183_GLL(const N0183MsgPtr& n0183_msg);
178
179 int m_n_log_watchdog_period;
180
181 BridgeLogCallbacks m_log_callbacks;
182 int m_last_position_priority;
183 std::string m_last_position_source;
184 Watchdogs m_watchdogs;
185 wxTimer m_watchdog_timer;
186
187 void InitCommListeners();
188
189 void PresetWatchdogs();
190 void MakeHDTFromHDM();
191
192 void ApplyPriorityMaps(const std::vector<std::string>& new_maps);
193 void ClearPriorityMaps();
194 void PresetPriorityContainers();
195 void OnDriverStateChange();
196
197 void OnWatchdogTimer();
198 ;
199
200 bool HandleN2K_129029(const N2000MsgPtr& n2k_msg);
201 bool HandleN2K_129025(const N2000MsgPtr& n2k_msg);
202 bool HandleN2K_129026(const N2000MsgPtr& n2k_msg);
203 bool HandleN2K_127250(const N2000MsgPtr& n2k_msg);
204 bool HandleN2K_127258(const N2000MsgPtr& n2k_msg);
205 bool HandleN2K_129540(const N2000MsgPtr& n2k_msg);
206
207 bool HandleN0183_RMC(const N0183MsgPtr& n0183_msg);
208 bool HandleN0183_THS(const N0183MsgPtr& n0183_msg);
209 bool HandleN0183_HDT(const N0183MsgPtr& n0183_msg);
210 bool HandleN0183_HDG(const N0183MsgPtr& n0183_msg);
211 bool HandleN0183_HDM(const N0183MsgPtr& n0183_msg);
212 bool HandleN0183_HVD(const N0183MsgPtr& n0183_msg);
213 bool HandleN0183_VTG(const N0183MsgPtr& n0183_msg);
214 bool HandleN0183_GSV(const N0183MsgPtr& n0183_msg);
215
216 bool HandleSignalK(const SignalKMsgPtr& sK_msg);
217};
218
219#endif // COMM_BRIDGE_H
Process incoming messages.
Definition comm_bridge.h:89
bool HandleN0183_AIVDO(const N0183MsgPtr &n0183_msg)
Processes NMEA 0183 AIVDO sentences containing own vessel's AIS data.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Incoming messages decoding support.
Raw, undecoded messages definitions.
Basic DataMonitor logging interface: LogLine (reflects a line in the log) and NmeaLog,...
Item in the log window.
Definition nmea_log.h:32