OpenCPN Partial API docs
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 <memory>
30 #include <string>
31 
32 #include <wx/wxprec.h>
33 
34 #ifndef WX_PRECOMP
35 #include <wx/wx.h>
36 #endif // precompiled header
37 
38 #include <wx/datetime.h>
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_drv_n0183.h"
60 #include "model/conn_params.h"
61 #include "observable.h"
62 
63 class CommDriverN0183NetEvent; // Internal
64 class MrqContainer;
65 
66 class CommDriverN0183Net : public CommDriverN0183, public wxEvtHandler {
67 public:
69  CommDriverN0183Net(const ConnectionParams* params, DriverListener& listener);
70 
71  virtual ~CommDriverN0183Net();
72 
73  void Open();
74  void Close();
75  ConnectionParams GetParams() const { return m_params; }
76 
77  bool SetOutputSocketOptions(wxSocketBase* tsock);
78  bool SendSentenceNetwork(const wxString& payload);
79  void OnServerSocketEvent(wxSocketEvent& event); // The listener
80  void OnTimerSocket(wxTimerEvent& event) { OnTimerSocket(); }
81  void OnTimerSocket();
82  void OnSocketEvent(wxSocketEvent& event);
83  void OpenNetworkGPSD();
84  void OpenNetworkTCP(unsigned int addr);
85  void OpenNetworkUDP(unsigned int addr);
86  void OnSocketReadWatchdogTimer(wxTimerEvent& event);
87  void HandleResume();
88 
89  bool SendMessage(std::shared_ptr<const NavMsg> msg,
90  std::shared_ptr<const NavAddr> addr) override;
91  wxSocketBase* GetSock() const { return m_sock; }
92 
93 private:
94  ConnectionParams m_params;
95  DriverListener& m_listener;
96 
97  void handle_N0183_MSG(CommDriverN0183NetEvent& event);
98  wxString GetNetPort() const { return m_net_port; }
99  wxIPV4address GetAddr() const { return m_addr; }
100  wxTimer* GetSocketThreadWatchdogTimer() {
101  return &m_socketread_watchdog_timer;
102  }
103  wxTimer* GetSocketTimer() { return &m_socket_timer; }
104  void SetSock(wxSocketBase* sock) { m_sock = sock; }
105  void SetTSock(wxSocketBase* sock) { m_tsock = sock; }
106  wxSocketBase* GetTSock() const { return m_tsock; }
107  void SetSockServer(wxSocketServer* sock) { m_socket_server = sock; }
108  wxSocketServer* GetSockServer() const { return m_socket_server; }
109  void SetMulticast(bool multicast) { m_is_multicast = multicast; }
110  bool GetMulticast() const { return m_is_multicast; }
111 
112  NetworkProtocol GetProtocol() { return m_net_protocol; }
113  void SetBrxConnectEvent(bool event) { m_brx_connect_event = event; }
114  bool GetBrxConnectEvent() { return m_brx_connect_event; }
115 
116  void SetConnectTime(wxDateTime time) { m_connect_time = time; }
117  wxDateTime GetConnectTime() { return m_connect_time; }
118 
119  dsPortType GetPortType() const { return m_io_select; }
120  wxString GetPort() const { return m_portstring; }
121 
122  ConnectionType GetConnectionType() const { return m_connection_type; }
123 
124  bool ChecksumOK(const std::string& sentence);
125  void SetOk(bool ok) { m_bok = ok; };
126 
127  wxString m_net_port;
128  NetworkProtocol m_net_protocol;
129  wxIPV4address m_addr;
130  wxSocketBase* m_sock;
131  wxSocketBase* m_tsock;
132  wxSocketServer* m_socket_server;
133  bool m_is_multicast;
134  MrqContainer *m_mrq_container;
135 
136  int m_txenter;
137  int m_dog_value;
138  std::string m_sock_buffer;
139  wxString m_portstring;
140  dsPortType m_io_select;
141  wxDateTime m_connect_time;
142  bool m_brx_connect_event;
143  bool m_bchecksumCheck;
144  ConnectionType m_connection_type;
145 
146  wxTimer m_socket_timer;
147  wxTimer m_socketread_watchdog_timer;
148 
149  bool m_bok;
150 
151  ObsListener resume_listener;
152 
153  DECLARE_EVENT_TABLE()
154 };
155 
156 #endif // guard
void OnSocketEvent(wxSocketEvent &event)
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition: comm_driver.h:47
Define an action to be performed when a KeyProvider is notified.
Definition: observable.h:210