OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_factory.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Implement comm_drv_factory: Communication driver factory.
5 * Author: David Register, Alec Leamas
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David Register, Alec Leamas *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
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
53void MakeCommDriver(const ConnectionParams* params) {
54 wxLogMessage("MakeCommDriver: %s", params->GetDSPort().c_str());
55
56 auto& msgbus = NavMsgBus::GetInstance();
57 auto& registry = CommDriverRegistry::GetInstance();
58 switch (params->Type) {
59 case SERIAL:
60 switch (params->Protocol) {
61 case PROTO_NMEA2000: {
62 auto driver = std::make_unique<CommDriverN2KSerial>(params, msgbus);
63 registry.Activate(std::move(driver));
64 break;
65 }
66 default: {
67 auto driver = std::make_unique<CommDriverN0183Serial>(params, msgbus);
68 registry.Activate(std::move(driver));
69 break;
70 }
71 }
72 break;
73 case NETWORK:
74 switch (params->NetProtocol) {
75 case SIGNALK: {
76 auto driver = std::make_unique<CommDriverSignalKNet>(params, msgbus);
77 registry.Activate(std::move(driver));
78 break;
79 }
80 default: {
81 switch (params->Protocol) {
82 case PROTO_NMEA0183: {
83 auto driver =
84 std::make_unique<CommDriverN0183Net>(params, msgbus);
85 registry.Activate(std::move(driver));
86 break;
87 }
88 case PROTO_NMEA2000: {
89 auto driver = std::make_unique<CommDriverN2KNet>(params, msgbus);
90 registry.Activate(std::move(driver));
91 break;
92 }
93 default:
94 break;
95 }
96 break;
97 }
98 }
99
100 break;
101#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
102 case SOCKETCAN: {
103 auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
104 registry.Activate(std::move(driver));
105 break;
106 }
107#endif
108
109#ifdef __ANDROID__
110 case INTERNAL_GPS: {
111 auto driver = std::make_unique<CommDriverN0183AndroidInt>(params, msgbus);
112 registry.Activate(std::move(driver));
113 break;
114 }
115
116 case INTERNAL_BT: {
117 auto driver = std::make_unique<CommDriverN0183AndroidBT>(params, msgbus);
118 registry.Activate(std::move(driver));
119 break;
120 }
121#endif
122
123 default:
124 break;
125 }
126};
127
128void initIXNetSystem() { CommDriverSignalKNet::initIXNetSystem(); };
129
130void uninitIXNetSystem() { CommDriverSignalKNet::uninitIXNetSystem(); };
NMEA0183 over IP driver.
NMEA0183 serial driver.
Driver registration container, a singleton.
Raw messages layer, supports sending and recieving navmsg messages.