OpenCPN Partial API docs
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"
42 #include "model/comm_drv_n0183_net.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"
46 #include "model/comm_navmsg_bus.h"
47 #include "model/comm_drv_registry.h"
48 
49 #if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
50 #include "model/comm_drv_n2k_socketcan.h"
51 #endif
52 
53 std::shared_ptr<AbstractCommDriver> MakeCommDriver(
54  const ConnectionParams* params) {
55  wxLogMessage(
56  wxString::Format(_T("MakeCommDriver: %s"), params->GetDSPort().c_str()));
57 
58  auto& msgbus = NavMsgBus::GetInstance();
59  auto& registry = CommDriverRegistry::GetInstance();
60  switch (params->Type) {
61  case SERIAL:
62  switch (params->Protocol) {
63  case PROTO_NMEA2000: {
64  auto driver = std::make_shared<CommDriverN2KSerial>(params, msgbus);
65  registry.Activate(driver);
66  return driver;
67  break;
68  }
69  default: {
70  auto driver = std::make_shared<CommDriverN0183Serial>(params, msgbus);
71  registry.Activate(driver);
72  return driver;
73 
74  break;
75  }
76  }
77  case NETWORK:
78  switch (params->NetProtocol) {
79  case SIGNALK: {
80  auto driver = std::make_shared<CommDriverSignalKNet>(params, msgbus);
81  registry.Activate(driver);
82  return driver;
83  break;
84  }
85  default: {
86  switch (params->Protocol) {
87  case PROTO_NMEA0183: {
88  auto driver =
89  std::make_shared<CommDriverN0183Net>(params, msgbus);
90  registry.Activate(driver);
91  return driver;
92  break;
93  }
94  case PROTO_NMEA2000:{
95  auto driver =
96  std::make_shared<CommDriverN2KNet>(params, msgbus);
97  registry.Activate(driver);
98  return driver;
99 
100  break;
101  }
102  default:
103  break;
104  }
105  break;
106  }
107  }
108 
109 #if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
110  case SOCKETCAN:
111  {
112  auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
113  registry.Activate(driver);
114  return driver;
115  break;
116  }
117 #endif
118 
119 #ifdef __ANDROID__
120  case INTERNAL_GPS: {
121  auto driver = std::make_shared<CommDriverN0183AndroidInt>(params, msgbus);
122  registry.Activate(driver);
123  return driver;
124  break;
125  }
126 
127  case INTERNAL_BT: {
128  auto driver = std::make_shared<CommDriverN0183AndroidBT>(params, msgbus);
129  registry.Activate(driver);
130  return driver;
131  break;
132  }
133 #endif
134 
135  default:
136  break;
137  }
138  return NULL;
139 };
140 
141 
142 void initIXNetSystem() {
143  CommDriverSignalKNet::initIXNetSystem();
144 };
145 
146 void uninitIXNetSystem() {
147  CommDriverSignalKNet::uninitIXNetSystem();
148 };
NMEA0183 serial driver.