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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
26#ifndef COMMDRIVERN0183NET_H_
27#define COMMDRIVERN0183NET_H_
28
29#include <chrono>
30#include <memory>
31#include <string>
32
33#include <wx/wxprec.h>
34
35#ifndef WX_PRECOMP
36#include <wx/wx.h>
37#endif
38
39#include <wx/string.h>
40#include <wx/timer.h>
41
42#ifdef __WXGTK__
43// newer versions of glib define its own GSocket, but we unfortunately use this
44// name in our own (semi-)public header and so can't change it -- rename glib
45// one instead
46// #include <gtk/gtk.h>
47#define GSocket GlibGSocket
48#include <wx/socket.h>
49#undef GSocket
50#else
51#include <wx/socket.h>
52#endif
53
54#ifndef __WXMSW__
55#include <sys/socket.h> // needed for (some) Mac builds
56#include <netinet/in.h>
57#endif
58
59#include "model/comm_buffers.h"
62#include "model/conn_params.h"
63#include "model/ocpn_utils.h"
64#include "observable.h"
65
66class MrqContainer;
67
69 public wxEvtHandler,
70 public DriverStatsProvider {
71public:
72 CommDriverN0183Net(const ConnectionParams* params, DriverListener& listener);
73
74 ~CommDriverN0183Net() override;
75
76 ConnectionParams GetParams() const { return m_params; }
77
78 const wxSocketBase* GetSock() const { return m_sock; }
79
80 bool SendMessage(std::shared_ptr<const NavMsg> msg,
81 std::shared_ptr<const NavAddr> addr) override;
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 DriverStats GetDriverStats() const override { return m_driver_stats; }
117
118 const ConnectionParams m_params;
119 DriverListener& m_listener;
120 N0183Buffer n0183_buffer;
121 wxIPV4address m_addr;
122 wxSocketBase* m_sock;
123 wxSocketBase* m_tsock;
124 wxSocketServer* m_socket_server;
125 bool m_is_multicast;
126 std::unique_ptr<MrqContainer> m_mrq_container;
127 StatsTimer m_stats_timer;
128 DriverStats m_driver_stats;
129
130 int m_txenter;
131 int m_dog_value;
132 std::chrono::time_point<std::chrono::steady_clock> m_connect_time;
133 bool m_rx_connect_event;
134
135 SocketTimer m_socket_timer;
136 SocketReadWatchdogTimer m_socketread_watchdog_timer;
137
138 bool m_ok;
139 bool m_is_conn_err_reported;
140
141 ObsListener resume_listener;
142};
143
144#endif // COMMDRIVERN0183NET_H_
NMEA0183 drivers common part.
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition comm_driver.h:48
Driver interface providing driver statistics.
Assemble characters to NMEA0183 sentences.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:228
Continuously report driver stats to CommDrvRegistry.evt_driver_stats.
Line-oriented input/output buffers.
NMEA0183 drivers common base.
Communication statistics infrastructure.
Driver statistics report.