OpenCPN Partial API docs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
comm_bridge.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose:
5 *
6 * Author: David Register, Alec Leamas
7 *
8 ***************************************************************************
9 * Copyright (C) 2022 by David Register, Alec Leamas *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 **************************************************************************/
26
27#ifndef _COMM_BRIDGE_H
28#define _COMM_BRIDGE_H
29
30#include <memory>
31#include <string>
32#include <unordered_map>
33
34#include <wx/event.h>
35#include <wx/log.h>
36#include <wx/timer.h>
37
38#include "model/comm_decoder.h"
39#include "model/comm_navmsg.h"
40#include "model/nmea_log.h"
41
42typedef struct {
43 std::string pcclass;
44 int active_priority;
45 std::string active_source;
46 std::string active_identifier;
47 int active_source_address;
48 time_t recent_active_time;
50
51typedef struct {
52 int position_watchdog;
53 int variation_watchdog;
54 int heading_watchdog;
55 int velocity_watchdog;
56 int satellite_watchdog;
57
58} Watchdogs;
59
61 std::function<bool()> log_is_active;
62 std::function<void(Logline)> log_message;
64 : log_is_active([]() { return false; }), log_message([](Logline) {}) {}
65};
66
67class CommBridge : public wxEvtHandler {
68public:
69 CommBridge();
70
72
73 bool Initialize();
74 void InitCommListeners();
75
76 bool HandleN2K_129029(std::shared_ptr<const Nmea2000Msg> n2k_msg);
77 bool HandleN2K_129025(std::shared_ptr<const Nmea2000Msg> n2k_msg);
78 bool HandleN2K_129026(std::shared_ptr<const Nmea2000Msg> n2k_msg);
79 bool HandleN2K_127250(std::shared_ptr<const Nmea2000Msg> n2k_msg);
80 bool HandleN2K_129540(std::shared_ptr<const Nmea2000Msg> n2k_msg);
81
82 bool HandleN0183_RMC(std::shared_ptr<const Nmea0183Msg> n0183_msg);
83 bool HandleN0183_HDT(std::shared_ptr<const Nmea0183Msg> n0183_msg);
84 bool HandleN0183_HDG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
85 bool HandleN0183_HDM(std::shared_ptr<const Nmea0183Msg> n0183_msg);
86 bool HandleN0183_VTG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
87 bool HandleN0183_GSV(std::shared_ptr<const Nmea0183Msg> n0183_msg);
88 bool HandleN0183_GGA(std::shared_ptr<const Nmea0183Msg> n0183_msg);
89 bool HandleN0183_GLL(std::shared_ptr<const Nmea0183Msg> n0183_msg);
109 bool HandleN0183_AIVDO(std::shared_ptr<const Nmea0183Msg> n0183_msg);
110
111 bool HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
112
113 void OnDriverStateChange();
114
115 void OnWatchdogTimer(wxTimerEvent &event);
116 bool EvalPriority(std::shared_ptr<const NavMsg> msg,
117 PriorityContainer &active_priority,
118 std::unordered_map<std::string, int> &priority_map);
119 std::string GetPriorityKey(std::shared_ptr<const NavMsg> msg);
120
121 std::vector<std::string> GetPriorityMaps();
122 PriorityContainer &GetPriorityContainer(const std::string category);
123
124 void UpdateAndApplyMaps(std::vector<std::string> new_maps);
125 bool LoadConfig(void);
126 bool SaveConfig(void);
127
128 Watchdogs m_watchdogs;
129 wxTimer m_watchdog_timer;
130
131 // comm event listeners
132 ObservableListener listener_N2K_129029;
133 ObservableListener listener_N2K_129025;
134 ObservableListener listener_N2K_129026;
135 ObservableListener listener_N2K_127250;
136 ObservableListener listener_N2K_129540;
137
138 ObservableListener listener_N0183_RMC;
139 ObservableListener listener_N0183_HDT;
140 ObservableListener listener_N0183_HDG;
141 ObservableListener listener_N0183_HDM;
142 ObservableListener listener_N0183_VTG;
143 ObservableListener listener_N0183_GSV;
144 ObservableListener listener_N0183_GGA;
145 ObservableListener listener_N0183_GLL;
146 ObservableListener listener_N0183_AIVDO;
147
148 ObservableListener listener_SignalK;
149
150 ObservableListener driver_change_listener;
151
152 CommDecoder m_decoder;
153
154private:
155 void PresetWatchdogs();
156 void MakeHDTFromHDM();
157 void InitializePriorityContainers();
158 void PresetPriorityContainers();
159
160 std::string GetPriorityMap(std::unordered_map<std::string, int> &map);
161 void ApplyPriorityMap(std::unordered_map<std::string, int> &priority_map,
162 wxString &new_prio, int category);
163 void ApplyPriorityMaps(std::vector<std::string> new_maps);
164
165 void ClearPriorityMaps();
166 void PresetPriorityContainer(
168 const std::unordered_map<std::string, int> &priority_map);
169 void SelectNextLowerPriority(const std::unordered_map<std::string, int> &map,
171
172 PriorityContainer active_priority_position;
173 PriorityContainer active_priority_velocity;
174 PriorityContainer active_priority_heading;
175 PriorityContainer active_priority_variation;
176 PriorityContainer active_priority_satellites;
177 PriorityContainer active_priority_void;
178
179 std::unordered_map<std::string, int> priority_map_position;
180 std::unordered_map<std::string, int> priority_map_velocity;
181 std::unordered_map<std::string, int> priority_map_heading;
182 std::unordered_map<std::string, int> priority_map_variation;
183 std::unordered_map<std::string, int> priority_map_satellites;
184
185 int n_LogWatchdogPeriod;
186
187 BridgeLogCallbacks m_log_callbacks;
188
189 DECLARE_EVENT_TABLE()
190};
191
192#endif // _COMM_BRIDGE_H
bool HandleN0183_AIVDO(std::shared_ptr< const Nmea0183Msg > n0183_msg)
Processes NMEA 0183 AIVDO sentences containing own vessel's AIS data.
Keeps listening over it's lifespan, removes itself on destruction.
Definition observable.h:131
Raw, undecoded messages definitions.
Item in the log window.
Definition nmea_log.h:10