OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_n0183_net.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose:
5 * Author: David Register, Alec Leamas
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David Register, Alec Leamas *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#ifndef _COMMDRIVERN0183NET_H
27#define _COMMDRIVERN0183NET_H
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/wx.h>
33#endif // precompiled header
34
35#include "comm_drv_n0183.h"
36
37#include <wx/datetime.h>
38
39#ifdef __WXGTK__
40// newer versions of glib define its own GSocket but we unfortunately use this
41// name in our own (semi-)public header and so can't change it -- rename glib
42// one instead
43//#include <gtk/gtk.h>
44#define GSocket GlibGSocket
45#include <wx/socket.h>
46#undef GSocket
47#else
48#include <wx/socket.h>
49#endif
50
51#ifndef __WXMSW__
52#include <sys/socket.h> // needed for (some) Mac builds
53#include <netinet/in.h>
54#endif
55
57
58class MrqContainer;
59
61class CommDriverN0183Net : public CommDriverN0183, public wxEvtHandler {
62public:
64 CommDriverN0183Net(const ConnectionParams* params, DriverListener& listener);
65
66 virtual ~CommDriverN0183Net();
67
68 void Open();
69 void Close();
70 ConnectionParams GetParams() const { return m_params; }
71
72 bool SetOutputSocketOptions(wxSocketBase* tsock);
73 bool SendSentenceNetwork(const wxString& payload);
74 void OnServerSocketEvent(wxSocketEvent& event); // The listener
75 void OnTimerSocket(wxTimerEvent& event);
76 void OnSocketEvent(wxSocketEvent& event);
77 void OpenNetworkGPSD();
78 void OpenNetworkTCP(unsigned int addr);
79 void OpenNetworkUDP(unsigned int addr);
80 void OnSocketReadWatchdogTimer(wxTimerEvent& event);
81
82 bool SendMessage(std::shared_ptr<const NavMsg> msg,
83 std::shared_ptr<const NavAddr> addr) override;
84 wxSocketBase* GetSock() const { return m_sock; }
85
86private:
87 ConnectionParams m_params;
88 DriverListener& m_listener;
89
90 void handle_N0183_MSG(CommDriverN0183NetEvent& event);
91 wxString GetNetPort() const { return m_net_port; }
92 wxIPV4address GetAddr() const { return m_addr; }
93 wxTimer* GetSocketThreadWatchdogTimer() {
94 return &m_socketread_watchdog_timer;
95 }
96 wxTimer* GetSocketTimer() { return &m_socket_timer; }
97 void SetSock(wxSocketBase* sock) { m_sock = sock; }
98 void SetTSock(wxSocketBase* sock) { m_tsock = sock; }
99 wxSocketBase* GetTSock() const { return m_tsock; }
100 void SetSockServer(wxSocketServer* sock) { m_socket_server = sock; }
101 wxSocketServer* GetSockServer() const { return m_socket_server; }
102 void SetMulticast(bool multicast) { m_is_multicast = multicast; }
103 bool GetMulticast() const { return m_is_multicast; }
104
105 NetworkProtocol GetProtocol() { return m_net_protocol; }
106 void SetBrxConnectEvent(bool event) { m_brx_connect_event = event; }
107 bool GetBrxConnectEvent() { return m_brx_connect_event; }
108
109 void SetConnectTime(wxDateTime time) { m_connect_time = time; }
110 wxDateTime GetConnectTime() { return m_connect_time; }
111
112 dsPortType GetPortType() const { return m_io_select; }
113 wxString GetPort() const { return m_portstring; }
114
115 ConnectionType GetConnectionType() const { return m_connection_type; }
116
117 bool ChecksumOK(const std::string& sentence);
118 void SetOk(bool ok) { m_bok = ok; };
119
120 wxString m_net_port;
121 NetworkProtocol m_net_protocol;
122 wxIPV4address m_addr;
123 wxSocketBase* m_sock;
124 wxSocketBase* m_tsock;
125 wxSocketServer* m_socket_server;
126 bool m_is_multicast;
127 MrqContainer *m_mrq_container;
128
129 int m_txenter;
130 int m_dog_value;
131 std::string m_sock_buffer;
132 wxString m_portstring;
133 dsPortType m_io_select;
134 wxDateTime m_connect_time;
135 bool m_brx_connect_event;
136 bool m_bchecksumCheck;
137 ConnectionType m_connection_type;
138
139 wxTimer m_socket_timer;
140 wxTimer m_socketread_watchdog_timer;
141
142 bool m_bok;
143
144 DECLARE_EVENT_TABLE()
145};
146
147#endif // guard
Internal wxEvent worker thread – main driver.
Driver for NMEA0183 over TCP/IP.
Abstract NMEA0183 drivers common parts.
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition: comm_driver.h:47
Internal helper class.