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 <wx/wxprec.h>
31
32#ifndef WX_PRECOMP
33#include <wx/wx.h>
34#endif // precompiled header
35
36#include <wx/datetime.h>
37#include <wx/socket.h>
38
39#include <string>
40#include "rapidjson/fwd.h"
41#include "conn_params.h"
42#include "comm_drv_signalk.h"
43
44#define SIGNALK_SOCKET_ID 5011
45#define N_DOG_TIMEOUT 5 // seconds
46#define N_DOG_TIMEOUT_RECONNECT 10 // seconds
47
48#define TIMER_SOCKET 9006
49
50static const double ms_to_knot_factor = 1.9438444924406;
51
52class WebSocketThread;
53class OCPN_WebSocketMessageHandler;
55
57class CommDriverSignalKNet : public CommDriverSignalK, public wxEvtHandler {
58public:
60 virtual ~CommDriverSignalKNet();
61
62 void Open();
63 void Close();
64 static bool DiscoverSKServer(wxString &ip, int &port, int tSec);
65 static bool DiscoverSKServer(std::string serviceIdent, wxString &ip,
66 int &port, int tSec);
67
68
69 void SetThreadRunning(bool active) { m_threadActive = active; }
70 void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
71 void ResetWatchdog() { m_dog_value = N_DOG_TIMEOUT; }
72 void SetWatchdog(int n) { m_dog_value = n; }
73
75 void Activate() override;
76
77 void handle_SK_sentence(CommDriverSignalKNetEvent& event);
78 void handleUpdate(const rapidjson::Value &update);
79 void updateItem(const rapidjson::Value &item, wxString &sfixtime);
80
81 void OpenWebSocket();
82 void CloseWebSocket();
83 bool IsThreadRunning() { return m_threadActive; }
84
85 std::string m_self;
86 std::string m_context;
87
88 bool m_bsec_thread_active;
89
90 int m_Thread_run_flag;
91 ConnectionParams m_params;
92 DriverListener& m_listener;
93
94private:
95 wxIPV4address m_addr;
96 wxIPV4address GetAddr() const { return m_addr; }
97
98 int m_dog_value;
99
100 wxTimer m_socketread_watchdog_timer;
101 wxTimer *GetSocketThreadWatchdogTimer() {
102 return &m_socketread_watchdog_timer;
103 }
104
105 OCPN_WebSocketMessageHandler *m_eventHandler;
106 bool m_useWebSocket;
107 bool m_threadActive;
108
109 bool m_bGPSValid_SK;
110
111 bool SetOutputSocketOptions(wxSocketBase *sock);
112
113 WebSocketThread *m_wsThread;
114
115};
116
117#endif // _SIGNALK_NET_H
Internal event worker thread -> main driver.
Driver for SignalK messages over TCP/IP.
void Activate() override
Register driver and possibly do other post-ctor steps.
Abstract SignalK driver interface.
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition: comm_driver.h:47
Internal worker thread.