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 "observable/observable.h"
58
59#include "model/comm_buffers.h"
62#include "model/conn_params.h"
63#include "model/ocpn_utils.h"
64
65class MrqContainer; // forward in .cpp file
66
68 public wxEvtHandler,
69 public DriverStatsProvider {
70public:
71 CommDriverN0183Net(const ConnectionParams* params, DriverListener& listener);
72
73 ~CommDriverN0183Net() override;
74
75 const ConnectionParams& GetParams() const override { return m_params; }
76
77 const wxSocketBase* GetSock() const { return m_sock; }
78
79 bool SendMessage(std::shared_ptr<const NavMsg> msg,
80 std::shared_ptr<const NavAddr> addr) override;
81
82 DriverStats GetDriverStats() const override { return m_driver_stats; }
83
84private:
85 class SocketTimer : public wxTimer {
86 public:
87 SocketTimer(CommDriverN0183Net& owner) : wxTimer(), m_owner(owner) {}
88 void Notify() override { m_owner.OnTimerSocket(); }
89
90 private:
91 CommDriverN0183Net& m_owner;
92 };
93
94 class SocketReadWatchdogTimer : public wxTimer {
95 public:
96 SocketReadWatchdogTimer(CommDriverN0183Net& owner)
97 : wxTimer(), m_owner(owner) {}
98 void Notify() override { m_owner.OnSocketReadWatchdogTimer(); }
99
100 private:
101 CommDriverN0183Net& m_owner;
102 };
103
104 void Open();
105 void Close();
106 void HandleResume();
107 void OnServerSocketEvent(wxSocketEvent& event); // The listener
108 void OnTimerSocket();
109 void OnSocketEvent(wxSocketEvent& event);
110 void OnSocketReadWatchdogTimer();
111 void OpenNetworkGpsd();
112 void OpenNetworkTcp(unsigned int addr);
113 void OpenNetworkUdp(unsigned int addr);
114 void HandleN0183Msg(const std::string& sentence);
115 bool SendSentenceNetwork(const wxString& payload);
116
117 const ConnectionParams m_params;
118 DriverListener& m_listener;
119 N0183Buffer n0183_buffer;
120 wxIPV4address m_addr;
121 wxSocketBase* m_sock;
122 wxSocketBase* m_tsock;
123 wxSocketServer* m_socket_server;
124 bool m_is_multicast;
125 std::unique_ptr<MrqContainer> m_mrq_container;
126 StatsTimer m_stats_timer;
127 DriverStats m_driver_stats;
128
129 int m_txenter;
130 int m_dog_value;
131 std::chrono::time_point<std::chrono::steady_clock> m_connect_time;
132 bool m_rx_connect_event;
133
134 SocketTimer m_socket_timer;
135 SocketReadWatchdogTimer m_socketread_watchdog_timer;
136
137 bool m_ok;
138 bool m_is_conn_err_reported;
139
140 obs::Listener resume_listener;
141};
142
143#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.
Continuously report driver stats to CommDrvRegistry.evt_driver_stats.
Various input/output buffers.
NMEA0183 drivers common base.
Communication statistics infrastructure.
Connection parameters.
Miscellaneous utilities, many of which string related.
Driver statistics report.