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 CommBridge();
92
93 ~CommBridge() override;
94
95 bool Initialize();
96
116 bool HandleN0183_AIVDO(const N0183MsgPtr& n0183_msg);
117
118 bool EvalPriority(const NavMsgPtr& msg, PriorityContainer& active_priority,
119 PriorityMap& priority_map);
120
121 std::vector<std::string> GetPriorityMaps() const;
122
123 PriorityContainer& GetPriorityContainer(const std::string& category);
124
125 void UpdateAndApplyMaps(const std::vector<std::string>& new_maps);
126
127 bool LoadConfig();
128
129 bool SaveConfig() const;
130
131private:
132 PriorityContainer active_priority_position;
133 PriorityContainer active_priority_velocity;
134 PriorityContainer active_priority_heading;
135 PriorityContainer active_priority_variation;
136 PriorityContainer active_priority_satellites;
137 PriorityContainer active_priority_void;
138
139 PriorityMap priority_map_position;
140 PriorityMap priority_map_velocity;
141 PriorityMap priority_map_heading;
142 PriorityMap priority_map_variation;
143 PriorityMap priority_map_satellites;
144
145 // comm event listeners
146 ObsListener m_n2k_129029_lstnr;
147 ObsListener m_n2k_129025_lstnr;
148 ObsListener m_n2k_129026_lstnr;
149 ObsListener m_n2k_127250_lstnr;
150 ObsListener m_n2k_129540_lstnr;
151
152 ObsListener m_n0183_rmc_lstnr;
153 ObsListener m_n0183_ths_lstnr;
154 ObsListener m_n0183_hdt_lstnr;
155 ObsListener m_n0183_hdg_lstnr;
156 ObsListener m_n0183_hdm_lstnr;
157 ObsListener m_n0183_vtg_lstnr;
158 ObsListener m_n0183_gsv_lstnr;
159 ObsListener m_n0183_gga_lstnr;
160 ObsListener m_n0183_gll_lstnr;
161 ObsListener m_n0183_aivdo_lstnr;
162
163 ObsListener m_signal_k_lstnr;
164
165 ObsListener m_driver_change_lstnr;
166
167 CommDecoder m_decoder;
168
169 bool HandleN0183_GGA(const N0183MsgPtr& n0183_msg);
170 bool HandleN0183_GLL(const N0183MsgPtr& n0183_msg);
171
172 int m_n_log_watchdog_period;
173
174 BridgeLogCallbacks m_log_callbacks;
175 int m_last_position_priority;
176 std::string m_last_position_source;
177 Watchdogs m_watchdogs;
178 wxTimer m_watchdog_timer;
179
180 void InitCommListeners();
181
182 void PresetWatchdogs();
183 void MakeHDTFromHDM();
184
185 void ApplyPriorityMaps(const std::vector<std::string>& new_maps);
186 void ClearPriorityMaps();
187 void PresetPriorityContainers();
188 void OnDriverStateChange();
189
190 void OnWatchdogTimer();
191 ;
192
193 bool HandleN2K_129029(const N2000MsgPtr& n2k_msg);
194 bool HandleN2K_129025(const N2000MsgPtr& n2k_msg);
195 bool HandleN2K_129026(const N2000MsgPtr& n2k_msg);
196 bool HandleN2K_127250(const N2000MsgPtr& n2k_msg);
197 bool HandleN2K_129540(const N2000MsgPtr& n2k_msg);
198
199 bool HandleN0183_RMC(const N0183MsgPtr& n0183_msg);
200 bool HandleN0183_THS(const N0183MsgPtr& n0183_msg);
201 bool HandleN0183_HDT(const N0183MsgPtr& n0183_msg);
202 bool HandleN0183_HDG(const N0183MsgPtr& n0183_msg);
203 bool HandleN0183_HDM(const N0183MsgPtr& n0183_msg);
204 bool HandleN0183_VTG(const N0183MsgPtr& n0183_msg);
205 bool HandleN0183_GSV(const N0183MsgPtr& n0183_msg);
206
207 bool HandleSignalK(const SignalKMsgPtr& sK_msg);
208};
209
210#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