OpenCPN Partial API docs
Loading...
Searching...
No Matches
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 "comm_decoder.h"
39#include "comm_navmsg.h"
40
41
43typedef struct{
44 std::string pcclass;
45 int active_priority;
46 std::string active_source;
47 std::string active_identifier;
48 int active_source_address;
50
52typedef struct {
53 int position_watchdog;
54 int variation_watchdog;
55 int heading_watchdog;
56 int velocity_watchdog;
57 int satellite_watchdog;
58
59} Watchdogs;
69class CommBridge : public wxEvtHandler {
70public:
71 CommBridge();
72
74
75 bool Initialize();
76 void InitCommListeners();
77
78 bool HandleN2K_129029(std::shared_ptr<const Nmea2000Msg> n2k_msg);
79 bool HandleN2K_129025(std::shared_ptr<const Nmea2000Msg> n2k_msg);
80 bool HandleN2K_129026(std::shared_ptr<const Nmea2000Msg> n2k_msg);
81 bool HandleN2K_127250(std::shared_ptr<const Nmea2000Msg> n2k_msg);
82 bool HandleN2K_129540(std::shared_ptr<const Nmea2000Msg> n2k_msg);
83
84 bool HandleN0183_RMC(std::shared_ptr<const Nmea0183Msg> n0183_msg);
85 bool HandleN0183_HDT(std::shared_ptr<const Nmea0183Msg> n0183_msg);
86 bool HandleN0183_HDG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
87 bool HandleN0183_HDM(std::shared_ptr<const Nmea0183Msg> n0183_msg);
88 bool HandleN0183_VTG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
89 bool HandleN0183_GSV(std::shared_ptr<const Nmea0183Msg> n0183_msg);
90 bool HandleN0183_GGA(std::shared_ptr<const Nmea0183Msg> n0183_msg);
91 bool HandleN0183_GLL(std::shared_ptr<const Nmea0183Msg> n0183_msg);
92 bool HandleN0183_AIVDO(std::shared_ptr<const Nmea0183Msg> n0183_msg);
93
94 bool HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
95
96 void OnDriverStateChange();
97
98 void OnWatchdogTimer(wxTimerEvent& event);
99 bool EvalPriority(std::shared_ptr <const NavMsg> msg,
100 PriorityContainer& active_priority,
101 std::unordered_map<std::string, int>& priority_map);
102 std::string GetPriorityKey(std::shared_ptr <const NavMsg> msg);
103
104 std::vector<std::string> GetPriorityMaps();
105 PriorityContainer& GetPriorityContainer(const std::string category);
106
107 void UpdateAndApplyMaps(std::vector<std::string> new_maps);
108 bool LoadConfig( void );
109 bool SaveConfig( void );
110
111 Watchdogs m_watchdogs;
112 wxTimer m_watchdog_timer;
113
114 // comm event listeners
115 ObservableListener listener_N2K_129029;
116 ObservableListener listener_N2K_129025;
117 ObservableListener listener_N2K_129026;
118 ObservableListener listener_N2K_127250;
119 ObservableListener listener_N2K_129540;
120
121 ObservableListener listener_N0183_RMC;
122 ObservableListener listener_N0183_HDT;
123 ObservableListener listener_N0183_HDG;
124 ObservableListener listener_N0183_HDM;
125 ObservableListener listener_N0183_VTG;
126 ObservableListener listener_N0183_GSV;
127 ObservableListener listener_N0183_GGA;
128 ObservableListener listener_N0183_GLL;
129 ObservableListener listener_N0183_AIVDO;
130
131 ObservableListener listener_SignalK;
132
133 ObservableListener driver_change_listener;
134
135 CommDecoder m_decoder;
136
137private:
138 void PresetWatchdogs();
139 void MakeHDTFromHDM();
140 void InitializePriorityContainers();
141 void PresetPriorityContainers();
142
143 std::string GetPriorityMap(std::unordered_map<std::string, int> &map);
144 void ApplyPriorityMap(std::unordered_map<std::string, int>& priority_map,
145 wxString &new_prio, int category);
146 void ApplyPriorityMaps(std::vector<std::string> new_maps);
147
148 void ClearPriorityMaps();
149 void PresetPriorityContainer(PriorityContainer &pc,
150 const std::unordered_map<std::string, int> &priority_map);
151 void SelectNextLowerPriority(const std::unordered_map<std::string, int> &map,
153
154 PriorityContainer active_priority_position;
155 PriorityContainer active_priority_velocity;
156 PriorityContainer active_priority_heading;
157 PriorityContainer active_priority_variation;
158 PriorityContainer active_priority_satellites;
159 PriorityContainer active_priority_void;
160
161 std::unordered_map<std::string, int> priority_map_position;
162 std::unordered_map<std::string, int> priority_map_velocity;
163 std::unordered_map<std::string, int> priority_map_heading;
164 std::unordered_map<std::string, int> priority_map_variation;
165 std::unordered_map<std::string, int> priority_map_satellites;
166
167 DECLARE_EVENT_TABLE()
168};
169
170#endif // _COMM_BRIDGE_H
Handle most incoming messages and make them available for other parties.
Definition: comm_bridge.h:69
Decode received NMEA messages and update global values from comm_vars.h and own_ship....
Definition: comm_decoder.h:58
Keeps listening over it's lifespan, removes itself on destruction.
Definition: observable.h:143
Data for selected source from multiple candidates.
Definition: comm_bridge.h:43
Kind of watchdog events.
Definition: comm_bridge.h:52