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, Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
26#ifndef COMM_BRIDGE_H
27#define COMM_BRIDGE_H
28
29#include <memory>
30#include <string>
31#include <unordered_map>
32
33#include <wx/event.h>
34#include <wx/timer.h>
35
36#include "model/comm_decoder.h"
37#include "model/comm_navmsg.h"
38#include "model/nmea_log.h"
39
40using N0183MsgPtr = std::shared_ptr<const Nmea0183Msg>;
41using N2000MsgPtr = std::shared_ptr<const Nmea2000Msg>;
42using SignalKMsgPtr = std::shared_ptr<const SignalkMsg>;
43using NavMsgPtr = std::shared_ptr<const NavMsg>;
44
45using PriorityMap = std::unordered_map<std::string, int>;
46
48 std::string prio_class;
49 int active_priority;
50 std::string active_source;
51 std::string active_identifier;
52 int active_source_address;
53 time_t recent_active_time;
54 PriorityContainer(const std::string& cls, int prio = 0)
55 : prio_class(cls),
56 active_priority(prio),
57 active_source_address(-1),
58 recent_active_time(0) {}
59};
60
61struct Watchdogs {
62 int position_watchdog;
63 int variation_watchdog;
64 int heading_watchdog;
65 int velocity_watchdog;
66 int satellite_watchdog;
67 Watchdogs()
68 : position_watchdog(0),
69 variation_watchdog(0),
70 heading_watchdog(0),
71 velocity_watchdog(0),
72 satellite_watchdog(0) {}
73};
74
76 std::function<bool()> log_is_active;
77 std::function<void(const Logline&)> log_message;
79 : log_is_active([]() { return false; }),
80 log_message([](const Logline&) {}) {}
81};
82
90class CommBridge : public wxEvtHandler {
91public:
92 CommBridge();
93
94 ~CommBridge() override;
95
96 bool Initialize();
97
117 bool HandleN0183_AIVDO(const N0183MsgPtr& n0183_msg);
118
119 bool EvalPriority(const NavMsgPtr& msg, PriorityContainer& active_priority,
120 PriorityMap& priority_map);
121
122 std::vector<std::string> GetPriorityMaps() const;
123
124 PriorityContainer& GetPriorityContainer(const std::string& category);
125
126 void UpdateAndApplyMaps(const std::vector<std::string>& new_maps);
127
128 bool LoadConfig();
129
130 bool SaveConfig() const;
131
132private:
133 PriorityContainer active_priority_position;
134 PriorityContainer active_priority_velocity;
135 PriorityContainer active_priority_heading;
136 PriorityContainer active_priority_variation;
137 PriorityContainer active_priority_satellites;
138 PriorityContainer active_priority_void;
139
140 PriorityMap priority_map_position;
141 PriorityMap priority_map_velocity;
142 PriorityMap priority_map_heading;
143 PriorityMap priority_map_variation;
144 PriorityMap priority_map_satellites;
145
146 // comm event listeners
147 ObsListener m_n2k_129029_lstnr;
148 ObsListener m_n2k_129025_lstnr;
149 ObsListener m_n2k_129026_lstnr;
150 ObsListener m_n2k_127250_lstnr;
151 ObsListener m_n2k_129540_lstnr;
152
153 ObsListener m_n0183_rmc_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_HDT(const N0183MsgPtr& n0183_msg);
201 bool HandleN0183_HDG(const N0183MsgPtr& n0183_msg);
202 bool HandleN0183_HDM(const N0183MsgPtr& n0183_msg);
203 bool HandleN0183_VTG(const N0183MsgPtr& n0183_msg);
204 bool HandleN0183_GSV(const N0183MsgPtr& n0183_msg);
205
206 bool HandleSignalK(const SignalKMsgPtr& sK_msg);
207};
208
209#endif // COMM_BRIDGE_H
Process incoming messages.
Definition comm_bridge.h:90
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
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:34