OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_signalk_net.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2022 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24// Originally by balp on 2018-07-28.
25
26#ifndef _SIGNALK_NET_H
27#define _SIGNALK_NET_H
28
29#include <atomic>
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/socket.h>
40
41#include "rapidjson/fwd.h"
42#include "model/conn_params.h"
44#include "comm_drv_stats.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; // Forward in .cpp file
53class OCPN_WebSocketMessageHandler; // Indirectly unused
54class CommDriverSignalKNetEvent; // Forward in .cpp file
55
57 public wxEvtHandler,
58 public DriverStatsProvider {
59public:
61 virtual ~CommDriverSignalKNet();
62
63 void Open();
64 void Close();
65 static bool DiscoverSKServer(wxString &ip, int &port, int tSec);
66 static bool DiscoverSKServer(std::string serviceIdent, wxString &ip,
67 int &port, int tSec);
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
74 void handle_SK_sentence(CommDriverSignalKNetEvent &event);
75 void handleUpdate(const rapidjson::Value &update);
76 void updateItem(const rapidjson::Value &item, wxString &sfixtime);
77
78 void OpenWebSocket();
79 void CloseWebSocket();
80 bool IsThreadRunning() { return m_threadActive == 1; }
81
82 DriverStats GetDriverStats() const override;
83
84 std::string m_self;
85 std::string m_context;
86
87 std::atomic_int m_Thread_run_flag;
88 std::atomic_int m_threadActive;
89
90 ConnectionParams m_params;
91 DriverListener &m_listener;
92
93 static void initIXNetSystem();
94
95 static void uninitIXNetSystem();
96
97private:
98 wxIPV4address m_addr;
99 wxIPV4address GetAddr() const { return m_addr; }
100
101 int m_dog_value;
102
103 wxTimer m_socketread_watchdog_timer;
104 wxTimer *GetSocketThreadWatchdogTimer() {
105 return &m_socketread_watchdog_timer;
106 }
107
108 OCPN_WebSocketMessageHandler *m_eventHandler;
109 bool m_useWebSocket;
110
111 bool m_bGPSValid_SK;
112
113 bool SetOutputSocketOptions(wxSocketBase *sock);
114
115 std::string m_token;
116 WebSocketThread *m_wsThread;
117 StatsTimer m_stats_timer;
118 DriverStats m_driver_stats;
119};
120
121#endif // _SIGNALK_NET_H
DriverStats GetDriverStats() const override
Get the Driver Statistics.
Interface for handling incoming messages.
Definition comm_driver.h:50
Driver interface providing driver statistics.
Continuously report driver stats to CommDrvRegistry.evt_driver_stats.
SignalK driver.
Communication statistics infrastructure.
Connection parameters.
Driver statistics report.