OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_n0183_net.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 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 COMMDRIVERN0183NET_H_
26#define COMMDRIVERN0183NET_H_
27
28#include <chrono>
29#include <memory>
30#include <string>
31
32#ifndef __WXMSW__
33#include <sys/socket.h> // needed for (some) Mac builds
34#include <netinet/in.h>
35#endif
36
37#include <wx/wxprec.h>
38
39#ifndef WX_PRECOMP
40#include <wx/wx.h>
41#endif
42
43#include <wx/string.h>
44#include <wx/timer.h>
45
46#ifdef __WXGTK__
47// newer versions of glib define its own GSocket, but we unfortunately use this
48// name in our own (semi-)public header and so can't change it -- rename glib
49// one instead
50#define GSocket GlibGSocket
51#include <wx/socket.h>
52#undef GSocket
53#else
54#include <wx/socket.h>
55#endif
56
57#include "model/comm_buffers.h"
60#include "model/conn_params.h"
61#include "model/ocpn_utils.h"
62#include "observable.h"
63
64class MrqContainer; // forward in .cpp file
65
67 public wxEvtHandler,
68 public DriverStatsProvider {
69public:
70 CommDriverN0183Net(const ConnectionParams* params, DriverListener& listener);
71
72 ~CommDriverN0183Net() override;
73
74 const ConnectionParams& GetParams() const override { return m_params; }
75
76 const wxSocketBase* GetSock() const { return m_sock; }
77
78 bool SendMessage(std::shared_ptr<const NavMsg> msg,
79 std::shared_ptr<const NavAddr> addr) override;
80
81 DriverStats GetDriverStats() const override { return m_driver_stats; }
82
83private:
84 class SocketTimer : public wxTimer {
85 public:
86 SocketTimer(CommDriverN0183Net& owner) : wxTimer(), m_owner(owner) {}
87 void Notify() override { m_owner.OnTimerSocket(); }
88
89 private:
90 CommDriverN0183Net& m_owner;
91 };
92
93 class SocketReadWatchdogTimer : public wxTimer {
94 public:
95 SocketReadWatchdogTimer(CommDriverN0183Net& owner)
96 : wxTimer(), m_owner(owner) {}
97 void Notify() override { m_owner.OnSocketReadWatchdogTimer(); }
98
99 private:
100 CommDriverN0183Net& m_owner;
101 };
102
103 void Open();
104 void Close();
105 void HandleResume();
106 void OnServerSocketEvent(wxSocketEvent& event); // The listener
107 void OnTimerSocket();
108 void OnSocketEvent(wxSocketEvent& event);
109 void OnSocketReadWatchdogTimer();
110 void OpenNetworkGpsd();
111 void OpenNetworkTcp(unsigned int addr);
112 void OpenNetworkUdp(unsigned int addr);
113 void HandleN0183Msg(const std::string& sentence);
114 bool SendSentenceNetwork(const wxString& payload);
115
116 const ConnectionParams m_params;
117 DriverListener& m_listener;
118 N0183Buffer n0183_buffer;
119 wxIPV4address m_addr;
120 wxSocketBase* m_sock;
121 wxSocketBase* m_tsock;
122 wxSocketServer* m_socket_server;
123 bool m_is_multicast;
124 std::unique_ptr<MrqContainer> m_mrq_container;
125 StatsTimer m_stats_timer;
126 DriverStats m_driver_stats;
127
128 int m_txenter;
129 int m_dog_value;
130 std::chrono::time_point<std::chrono::steady_clock> m_connect_time;
131 bool m_rx_connect_event;
132
133 SocketTimer m_socket_timer;
134 SocketReadWatchdogTimer m_socketread_watchdog_timer;
135
136 bool m_ok;
137 bool m_is_conn_err_reported;
138
139 ObsListener resume_listener;
140};
141
142#endif // COMMDRIVERN0183NET_H_
DriverStats GetDriverStats() const override
Get the Driver Statistics.
NMEA0183 basic parsing common parts:
Interface for handling incoming messages.
Definition comm_driver.h:50
Driver interface providing driver statistics.
Assemble characters to NMEA0183 sentences.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Continuously report driver stats to CommDrvRegistry.evt_driver_stats.
Line-oriented input/output buffers.
NMEA0183 drivers common base.
Communication statistics infrastructure.
Connection parameters.
General observable implementation with several specializations.
Miscellaneous utilities, many of which string related.
Driver statistics report.