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 "model/comm_decoder.h"
39#include "model/comm_navmsg.h"
40
41typedef struct {
42 std::string pcclass;
43 int active_priority;
44 std::string active_source;
45 std::string active_identifier;
46 int active_source_address;
47 time_t recent_active_time;
49
50typedef struct {
51 int position_watchdog;
52 int variation_watchdog;
53 int heading_watchdog;
54 int velocity_watchdog;
55 int satellite_watchdog;
56
57} Watchdogs;
58
59class CommBridge : public wxEvtHandler {
60public:
61 CommBridge();
62
64
65 bool Initialize();
66 void InitCommListeners();
67
68 bool HandleN2K_129029(std::shared_ptr<const Nmea2000Msg> n2k_msg);
69 bool HandleN2K_129025(std::shared_ptr<const Nmea2000Msg> n2k_msg);
70 bool HandleN2K_129026(std::shared_ptr<const Nmea2000Msg> n2k_msg);
71 bool HandleN2K_127250(std::shared_ptr<const Nmea2000Msg> n2k_msg);
72 bool HandleN2K_129540(std::shared_ptr<const Nmea2000Msg> n2k_msg);
73
74 bool HandleN0183_RMC(std::shared_ptr<const Nmea0183Msg> n0183_msg);
75 bool HandleN0183_HDT(std::shared_ptr<const Nmea0183Msg> n0183_msg);
76 bool HandleN0183_HDG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
77 bool HandleN0183_HDM(std::shared_ptr<const Nmea0183Msg> n0183_msg);
78 bool HandleN0183_VTG(std::shared_ptr<const Nmea0183Msg> n0183_msg);
79 bool HandleN0183_GSV(std::shared_ptr<const Nmea0183Msg> n0183_msg);
80 bool HandleN0183_GGA(std::shared_ptr<const Nmea0183Msg> n0183_msg);
81 bool HandleN0183_GLL(std::shared_ptr<const Nmea0183Msg> n0183_msg);
82 bool HandleN0183_AIVDO(std::shared_ptr<const Nmea0183Msg> n0183_msg);
83
84 bool HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg);
85
86 void OnDriverStateChange();
87
88 void OnWatchdogTimer(wxTimerEvent &event);
89 bool EvalPriority(std::shared_ptr<const NavMsg> msg,
90 PriorityContainer &active_priority,
91 std::unordered_map<std::string, int> &priority_map);
92 std::string GetPriorityKey(std::shared_ptr<const NavMsg> msg);
93
94 std::vector<std::string> GetPriorityMaps();
95 PriorityContainer &GetPriorityContainer(const std::string category);
96
97 void UpdateAndApplyMaps(std::vector<std::string> new_maps);
98 bool LoadConfig(void);
99 bool SaveConfig(void);
100
101 Watchdogs m_watchdogs;
102 wxTimer m_watchdog_timer;
103
104 // comm event listeners
105 ObservableListener listener_N2K_129029;
106 ObservableListener listener_N2K_129025;
107 ObservableListener listener_N2K_129026;
108 ObservableListener listener_N2K_127250;
109 ObservableListener listener_N2K_129540;
110
111 ObservableListener listener_N0183_RMC;
112 ObservableListener listener_N0183_HDT;
113 ObservableListener listener_N0183_HDG;
114 ObservableListener listener_N0183_HDM;
115 ObservableListener listener_N0183_VTG;
116 ObservableListener listener_N0183_GSV;
117 ObservableListener listener_N0183_GGA;
118 ObservableListener listener_N0183_GLL;
119 ObservableListener listener_N0183_AIVDO;
120
121 ObservableListener listener_SignalK;
122
123 ObservableListener driver_change_listener;
124
125 CommDecoder m_decoder;
126
127private:
128 void PresetWatchdogs();
129 void MakeHDTFromHDM();
130 void InitializePriorityContainers();
131 void PresetPriorityContainers();
132
133 std::string GetPriorityMap(std::unordered_map<std::string, int> &map);
134 void ApplyPriorityMap(std::unordered_map<std::string, int> &priority_map,
135 wxString &new_prio, int category);
136 void ApplyPriorityMaps(std::vector<std::string> new_maps);
137
138 void ClearPriorityMaps();
139 void PresetPriorityContainer(
141 const std::unordered_map<std::string, int> &priority_map);
142 void SelectNextLowerPriority(const std::unordered_map<std::string, int> &map,
144
145 PriorityContainer active_priority_position;
146 PriorityContainer active_priority_velocity;
147 PriorityContainer active_priority_heading;
148 PriorityContainer active_priority_variation;
149 PriorityContainer active_priority_satellites;
150 PriorityContainer active_priority_void;
151
152 std::unordered_map<std::string, int> priority_map_position;
153 std::unordered_map<std::string, int> priority_map_velocity;
154 std::unordered_map<std::string, int> priority_map_heading;
155 std::unordered_map<std::string, int> priority_map_variation;
156 std::unordered_map<std::string, int> priority_map_satellites;
157
158 int n_LogWatchdogPeriod;
159
160 DECLARE_EVENT_TABLE()
161};
162
163#endif // _COMM_BRIDGE_H
Keeps listening over it's lifespan, removes itself on destruction.
Definition observable.h:131
Raw, undecoded messages definitions.