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