OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_factory.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 David Register *
3 * Copyright (C) 2022 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25// FIXME Why is this needed?
26#ifdef _WIN32
27#include <winsock2.h>
28#include <wx/msw/winundef.h>
29#endif
30
31#include <wx/wxprec.h>
32
33#ifndef WX_PRECOMP
34#include <wx/wx.h>
35#endif // precompiled headers
36
37#include "model/comm_util.h"
49
50#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
52#endif
53
54#ifdef _WIN32
56#endif
57
59public:
60 N0183Listener() = default;
61
63 void Notify(const AbstractCommDriver& driver) override {}
64
65 void Notify(std::shared_ptr<const NavMsg> message) override {
66 switch (message->state) {
67 case NavMsg::State::kCannotParse:
68 case NavMsg::State::kFiltered:
69 case NavMsg::State::kBadChecksum:
70 CommDriverRegistry::GetInstance().evt_dropped_msg.Notify(message);
71 break;
72 default:
73 NavMsgBus::GetInstance().Notify(message);
74 break;
75 }
76 }
77};
78
80 auto driver = std::make_unique<LoopbackDriver>(NavMsgBus::GetInstance());
81 CommDriverRegistry::GetInstance().Activate(std::move(driver));
82}
83
85 auto driver = std::make_unique<CommDriverInternal>(NavMsgBus::GetInstance());
86 CommDriverRegistry::GetInstance().Activate(std::move(driver));
87}
88
89void MakeCommDriver(const ConnectionParams* params) {
90 static N0183Listener listener;
91
92 wxLogMessage("MakeCommDriver: %s", params->GetDSPort().c_str());
93
94 auto& msgbus = NavMsgBus::GetInstance();
95 auto& registry = CommDriverRegistry::GetInstance();
96 switch (params->type) {
97 case CANABLE: {
98#ifdef _WIN32
99 auto driver = std::make_unique<CommDriverN2KCanable>(params, msgbus);
100 registry.Activate(std::move(driver));
101#else
102 wxLogMessage("CANable connections require Windows.");
103#endif
104 break;
105 }
106 case SERIAL:
107 switch (params->data_protocol) {
108 case PROTO_NMEA2000: {
109 auto driver = std::make_unique<CommDriverN2KSerial>(params, msgbus);
110 registry.Activate(std::move(driver));
111 break;
112 }
113 default: {
114 auto driver =
115 std::make_unique<CommDriverN0183Serial>(params, listener);
116 registry.Activate(std::move(driver));
117 break;
118 }
119 }
120 break;
121 case NETWORK:
122 switch (params->net_protocol) {
123 case SIGNALK: {
124 auto driver = std::make_unique<CommDriverSignalKNet>(params, msgbus);
125 registry.Activate(std::move(driver));
126 break;
127 }
128 default: {
129 switch (params->data_protocol) {
130 case PROTO_NMEA0183: {
131 auto driver =
132 std::make_unique<CommDriverN0183Net>(params, listener);
133 registry.Activate(std::move(driver));
134 break;
135 }
136 case PROTO_NMEA2000: {
137 auto driver = std::make_unique<CommDriverN2KNet>(params, msgbus);
138 registry.Activate(std::move(driver));
139 break;
140 }
141 default:
142 break;
143 }
144 break;
145 }
146 }
147
148 break;
149#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
150 case SOCKETCAN: {
151 auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
152 registry.Activate(std::move(driver));
153 break;
154 }
155#endif
156
157#ifdef __ANDROID__
158 case INTERNAL_GPS: {
159 auto driver = std::make_unique<CommDriverN0183AndroidInt>(params, msgbus);
160 registry.Activate(std::move(driver));
161 break;
162 }
163
164 case INTERNAL_BT: {
165 auto driver = std::make_unique<CommDriverN0183AndroidBT>(params, msgbus);
166 registry.Activate(std::move(driver));
167 break;
168 }
169#endif
170
171 default:
172 break;
173 }
174};
175
176void initIXNetSystem() { CommDriverSignalKNet::initIXNetSystem(); };
177
178void uninitIXNetSystem() { CommDriverSignalKNet::uninitIXNetSystem(); };
Common interface for all drivers.
Definition comm_driver.h:65
obs::EventVar evt_dropped_msg
Updated by drivers with a shared Navmsg pointer when receiving data otherwise dropped,...
void Activate(DriverPtr driver)
Add driver to list of active drivers.
static void uninitIXNetSystem()
ix::uninitIXNetSystem wrapper
static void initIXNetSystem()
ix::initIXNetSystem wrapper
Connection data container close to a POD struct.
Definition conn_params.h:76
wxString GetDSPort() const
Return port description including for example serial port or network address/port,...
Interface for handling incoming messages.
Definition comm_driver.h:50
void Notify(std::shared_ptr< const NavMsg > message) override
Handle a received message.
void Notify(const AbstractCommDriver &driver) override
Handle driver status change.
void Notify(std::shared_ptr< const NavMsg > message)
Accept message received by driver, make it available for upper layers.
void Notify() override
Notify all listeners, no data supplied.
Definition evtvar.h:83
void MakeLoopbackDriver()
Create and register the loopback driver.
void MakeInternalDriver()
Create and register the internal driver.
void MakeCommDriver(const ConnectionParams *params)
Create and register a driver for given connection.
Internal send-only driver sending to plugins.
Loopback driver, treat sent messages as received.
Android nmea0183 internal bluetooth driver.
Android internal nmea0183 driver.
NMEA0183 over IP driver.
NMEA0183 serial driver.
comm_drv_n2k_canable.h NMEA2000 driver for CANable "Contact" (and other SLCAN/LAWICEL-firmware) USB-C...
Nmea2000 IP network driver.
Nmea2000 serial driver.
Low-level driver for socketcan devices (linux only).
Driver registration container, a singleton.
SignalK IP network driver.
Raw messages layer, supports sending and recieving navmsg messages.
Misc driver utilities.