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
55public:
56 N0183Listener() = default;
57
59 void Notify(const AbstractCommDriver& driver) override {}
60
61 void Notify(std::shared_ptr<const NavMsg> message) override {
62 switch (message->state) {
63 case NavMsg::State::kCannotParse:
64 case NavMsg::State::kFiltered:
65 case NavMsg::State::kBadChecksum:
66 CommDriverRegistry::GetInstance().evt_dropped_msg.Notify(message);
67 break;
68 default:
69 NavMsgBus::GetInstance().Notify(message);
70 break;
71 }
72 }
73};
74
76 auto driver = std::make_unique<LoopbackDriver>(NavMsgBus::GetInstance());
77 CommDriverRegistry::GetInstance().Activate(std::move(driver));
78}
79
81 auto driver = std::make_unique<CommDriverInternal>(NavMsgBus::GetInstance());
82 CommDriverRegistry::GetInstance().Activate(std::move(driver));
83}
84
85void MakeCommDriver(const ConnectionParams* params) {
86 static N0183Listener listener;
87
88 wxLogMessage("MakeCommDriver: %s", params->GetDSPort().c_str());
89
90 auto& msgbus = NavMsgBus::GetInstance();
91 auto& registry = CommDriverRegistry::GetInstance();
92 switch (params->Type) {
93 case SERIAL:
94 switch (params->Protocol) {
95 case PROTO_NMEA2000: {
96 auto driver = std::make_unique<CommDriverN2KSerial>(params, msgbus);
97 registry.Activate(std::move(driver));
98 break;
99 }
100 default: {
101 auto driver =
102 std::make_unique<CommDriverN0183Serial>(params, listener);
103 registry.Activate(std::move(driver));
104 break;
105 }
106 }
107 break;
108 case NETWORK:
109 switch (params->NetProtocol) {
110 case SIGNALK: {
111 auto driver = std::make_unique<CommDriverSignalKNet>(params, msgbus);
112 registry.Activate(std::move(driver));
113 break;
114 }
115 default: {
116 switch (params->Protocol) {
117 case PROTO_NMEA0183: {
118 auto driver =
119 std::make_unique<CommDriverN0183Net>(params, listener);
120 registry.Activate(std::move(driver));
121 break;
122 }
123 case PROTO_NMEA2000: {
124 auto driver = std::make_unique<CommDriverN2KNet>(params, msgbus);
125 registry.Activate(std::move(driver));
126 break;
127 }
128 default:
129 break;
130 }
131 break;
132 }
133 }
134
135 break;
136#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
137 case SOCKETCAN: {
138 auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
139 registry.Activate(std::move(driver));
140 break;
141 }
142#endif
143
144#ifdef __ANDROID__
145 case INTERNAL_GPS: {
146 auto driver = std::make_unique<CommDriverN0183AndroidInt>(params, msgbus);
147 registry.Activate(std::move(driver));
148 break;
149 }
150
151 case INTERNAL_BT: {
152 auto driver = std::make_unique<CommDriverN0183AndroidBT>(params, msgbus);
153 registry.Activate(std::move(driver));
154 break;
155 }
156#endif
157
158 default:
159 break;
160 }
161};
162
163void initIXNetSystem() { CommDriverSignalKNet::initIXNetSystem(); };
164
165void uninitIXNetSystem() { CommDriverSignalKNet::uninitIXNetSystem(); };
Common interface for all drivers.
Definition comm_driver.h:65
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
Interface for handling incoming messages.
Definition comm_driver.h:50
void Notify() override
Notify all listeners, no data supplied.
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 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.
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.