OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_signalk_net.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: PlugIn Manager Object
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David S. Register *
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// Originally by balp on 2018-07-28.
26
27#ifndef _SIGNALK_NET_H
28#define _SIGNALK_NET_H
29
30#include <atomic>
31#include <string>
32
33#include <wx/wxprec.h>
34
35#ifndef WX_PRECOMP
36#include <wx/wx.h>
37#endif // precompiled header
38
39#include <wx/datetime.h>
40#include <wx/socket.h>
41
42#include "rapidjson/fwd.h"
43#include "model/conn_params.h"
44#include "model/comm_drv_signalk.h"
45
46#define SIGNALK_SOCKET_ID 5011
47#define N_DOG_TIMEOUT 5 // seconds
48#define N_DOG_TIMEOUT_RECONNECT 10 // seconds
49
50static const double ms_to_knot_factor = 1.9438444924406;
51
52class WebSocketThread;
53class OCPN_WebSocketMessageHandler;
55
56class CommDriverSignalKNet : public CommDriverSignalK, public wxEvtHandler {
57public:
59 virtual ~CommDriverSignalKNet();
60
61 void Open();
62 void Close();
63 static bool DiscoverSKServer(wxString &ip, int &port, int tSec);
64 static bool DiscoverSKServer(std::string serviceIdent, wxString &ip,
65 int &port, int tSec);
66
67 void SetThreadRunning(bool active) { m_threadActive = active; }
68 void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
69 void ResetWatchdog() { m_dog_value = N_DOG_TIMEOUT; }
70 void SetWatchdog(int n) { m_dog_value = n; }
71
72 void handle_SK_sentence(CommDriverSignalKNetEvent &event);
73 void handleUpdate(const rapidjson::Value &update);
74 void updateItem(const rapidjson::Value &item, wxString &sfixtime);
75
76 void OpenWebSocket();
77 void CloseWebSocket();
78 bool IsThreadRunning() { return m_threadActive == 1; }
79
80 std::string m_self;
81 std::string m_context;
82
83 std::atomic_int m_Thread_run_flag;
84 std::atomic_int m_threadActive;
85
86 ConnectionParams m_params;
87 DriverListener &m_listener;
88
89 static void initIXNetSystem();
90
91 static void uninitIXNetSystem();
92
93private:
94 wxIPV4address m_addr;
95 wxIPV4address GetAddr() const { return m_addr; }
96
97 int m_dog_value;
98
99 wxTimer m_socketread_watchdog_timer;
100 wxTimer *GetSocketThreadWatchdogTimer() {
101 return &m_socketread_watchdog_timer;
102 }
103
104 OCPN_WebSocketMessageHandler *m_eventHandler;
105 bool m_useWebSocket;
106
107 bool m_bGPSValid_SK;
108
109 bool SetOutputSocketOptions(wxSocketBase *sock);
110
111 std::string m_token;
112
113 WebSocketThread *m_wsThread;
114};
115
116#endif // _SIGNALK_NET_H
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition comm_driver.h:48