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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
26// FIXME Why is this needed?
27#ifdef __MSVC__
28#include <winsock2.h>
29#include <wx/msw/winundef.h>
30#endif
31
32#include <wx/wxprec.h>
33
34#ifndef WX_PRECOMP
35#include <wx/wx.h>
36#endif // precompiled headers
37
38#include "model/comm_util.h"
39#include "model/comm_drv_n2k_net.h"
40#include "model/comm_drv_n2k_serial.h"
43#include "model/comm_drv_signalk_net.h"
44#include "model/comm_drv_n0183_android_int.h"
45#include "model/comm_drv_n0183_android_bt.h"
48
49#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
50#include "model/comm_drv_n2k_socketcan.h"
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
74void MakeCommDriver(const ConnectionParams* params) {
75 static N0183Listener listener;
76
77 wxLogMessage("MakeCommDriver: %s", params->GetDSPort().c_str());
78
79 auto& msgbus = NavMsgBus::GetInstance();
80 auto& registry = CommDriverRegistry::GetInstance();
81 switch (params->Type) {
82 case SERIAL:
83 switch (params->Protocol) {
84 case PROTO_NMEA2000: {
85 auto driver = std::make_unique<CommDriverN2KSerial>(params, msgbus);
86 registry.Activate(std::move(driver));
87 break;
88 }
89 default: {
90 auto driver =
91 std::make_unique<CommDriverN0183Serial>(params, listener);
92 registry.Activate(std::move(driver));
93 break;
94 }
95 }
96 break;
97 case NETWORK:
98 switch (params->NetProtocol) {
99 case SIGNALK: {
100 auto driver = std::make_unique<CommDriverSignalKNet>(params, msgbus);
101 registry.Activate(std::move(driver));
102 break;
103 }
104 default: {
105 switch (params->Protocol) {
106 case PROTO_NMEA0183: {
107 auto driver =
108 std::make_unique<CommDriverN0183Net>(params, listener);
109 registry.Activate(std::move(driver));
110 break;
111 }
112 case PROTO_NMEA2000: {
113 auto driver = std::make_unique<CommDriverN2KNet>(params, msgbus);
114 registry.Activate(std::move(driver));
115 break;
116 }
117 default:
118 break;
119 }
120 break;
121 }
122 }
123
124 break;
125#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
126 case SOCKETCAN: {
127 auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
128 registry.Activate(std::move(driver));
129 break;
130 }
131#endif
132
133#ifdef __ANDROID__
134 case INTERNAL_GPS: {
135 auto driver = std::make_unique<CommDriverN0183AndroidInt>(params, msgbus);
136 registry.Activate(std::move(driver));
137 break;
138 }
139
140 case INTERNAL_BT: {
141 auto driver = std::make_unique<CommDriverN0183AndroidBT>(params, msgbus);
142 registry.Activate(std::move(driver));
143 break;
144 }
145#endif
146
147 default:
148 break;
149 }
150};
151
152void initIXNetSystem() { CommDriverSignalKNet::initIXNetSystem(); };
153
154void uninitIXNetSystem() { CommDriverSignalKNet::uninitIXNetSystem(); };
Common interface for all drivers.
Definition comm_driver.h:67
EventVar evt_dropped_msg
Updated by drivers with a shared Navmsg pointer when receiving data otherwise dropped,...
Interface for handling incoming messages.
Definition comm_driver.h:52
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 MakeCommDriver(const ConnectionParams *params)
Create and register a driver for given connection.
NMEA0183 over IP driver.
NMEA0183 serial driver.
Driver registration container, a singleton.
Raw messages layer, supports sending and recieving navmsg messages.