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 "comm_util.h"
39#include "comm_drv_n2k_serial.h"
40#include "comm_drv_n0183_serial.h"
41#include "comm_drv_n0183_net.h"
42#include "comm_drv_signalk_net.h"
43#include "comm_navmsg_bus.h"
44#include "comm_drv_registry.h"
45
46#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
47#include "comm_drv_n2k_socketcan.h"
48#endif
49
50std::shared_ptr<AbstractCommDriver> MakeCommDriver(
51 const ConnectionParams* params) {
52 wxLogMessage(
53 wxString::Format(_T("MakeCommDriver: %s"), params->GetDSPort().c_str()));
54
55 auto& msgbus = NavMsgBus::GetInstance();
56 auto& registry = CommDriverRegistry::GetInstance();
57 switch (params->Type) {
58 case SERIAL:
59 switch (params->Protocol) {
60 case PROTO_NMEA2000: {
61 auto driver = std::make_shared<CommDriverN2KSerial>(params, msgbus);
62 registry.Activate(driver);
63 return driver;
64 break;
65 }
66 default: {
67 auto driver = std::make_shared<CommDriverN0183Serial>(params, msgbus);
68 registry.Activate(driver);
69 return driver;
70
71 break;
72 }
73 }
74 case NETWORK:
75 switch (params->NetProtocol) {
76 case SIGNALK: {
77 auto driver = std::make_shared<CommDriverSignalKNet>(params, msgbus);
78 registry.Activate(driver);
79 return driver;
80 break;
81 }
82 default: {
83 auto driver = std::make_shared<CommDriverN0183Net>(params, msgbus);
84 registry.Activate(driver);
85 return driver;
86 break;
87 }
88 }
89
90#if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
91 case SOCKETCAN:
92 {
93 auto driver = CommDriverN2KSocketCAN::Create(params, msgbus);
94 registry.Activate(driver);
95 return driver;
96 break;
97 }
98#endif
99
100#if 0 // FIXME (dave)
101 case INTERNAL_GPS:
102 return new InternalGPSDataStream(input_consumer, params);
103 case INTERNAL_BT:
104 return new InternalBTDataStream(input_consumer, params);
105
106#endif
107 default:
108 break;
109 }
110 return NULL;
111};