36#include <wx/checklst.h>
37#include <wx/combobox.h>
40#include <wx/statline.h>
41#include <wx/tokenzr.h>
43#include "model/conn_params.h"
47#if !wxUSE_XLOCALE && wxCHECK_VERSION(3, 0, 0)
48#define wxAtoi(arg) atoi(arg)
51static std::vector<ConnectionParams*> the_connection_params;
53std::vector<ConnectionParams*>& TheConnectionParams() {
54 return the_connection_params;
57ConnectionParams::ConnectionParams(
const wxString& configStr) {
58 m_optionsPanel = NULL;
59 Deserialize(configStr);
62void ConnectionParams::Deserialize(
const wxString& configStr) {
64 wxArrayString prms = wxStringTokenize(configStr, _T(
";"));
65 if (prms.Count() < 18) {
70 Type = (ConnectionType)wxAtoi(prms[0]);
71 NetProtocol = (NetworkProtocol)wxAtoi(prms[1]);
72 NetworkAddress = prms[2];
73 NetworkPort = (ConnectionType)wxAtoi(prms[3]);
74 Protocol = (DataProtocol)wxAtoi(prms[4]);
76 Baudrate = wxAtoi(prms[6]);
77 ChecksumCheck = wxAtoi(prms[7]);
78 int iotval = wxAtoi(prms[8]);
79 IOSelect = ((iotval <= 2) ? static_cast<dsPortType>(iotval) : DS_TYPE_INPUT);
80 InputSentenceListType = (ListType)wxAtoi(prms[9]);
81 InputSentenceList = wxStringTokenize(prms[10], _T(
","));
82 OutputSentenceListType = (ListType)wxAtoi(prms[11]);
83 OutputSentenceList = wxStringTokenize(prms[12], _T(
","));
84 Garmin = !!wxAtoi(prms[14]);
85 GarminUpload = !!wxAtoi(prms[15]);
86 FurunoGP3X = !!wxAtoi(prms[16]);
91 if (prms.Count() >= 18) {
92 bEnabled = !!wxAtoi(prms[17]);
94 if (prms.Count() >= 19) {
95 UserComment = prms[18];
97 if (prms.Count() >= 20) {
98 AutoSKDiscover = !!wxAtoi(prms[19]);
100 if (prms.Count() >= 21) {
101 socketCAN_port = prms[20];
103 if (prms.Count() >= 22) {
104 NoDataReconnect = wxAtoi(prms[21]);
106 if (prms.Count() >= 23) {
107 DisableEcho = wxAtoi(prms[22]);
109 if (prms.Count() >= 24) {
110 AuthToken = prms[23];
114wxString ConnectionParams::Serialize()
const {
116 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
117 if (i > 0) istcs.Append(_T(
","));
118 istcs.Append(InputSentenceList[i]);
121 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
122 if (i > 0) ostcs.Append(_T(
","));
123 ostcs.Append(OutputSentenceList[i]);
125 wxString ret = wxString::Format(
126 "%d;%d;%s;%d;%d;%s;%d;%d;%d;%d;%s;%d;%s;%d;%d;%d;%d;%d;%s;%d;%s;%d;%d;%s",
127 Type, NetProtocol, NetworkAddress.c_str(), NetworkPort, Protocol,
128 Port.c_str(), Baudrate, ChecksumCheck, IOSelect, InputSentenceListType,
129 istcs.c_str(), OutputSentenceListType, ostcs.c_str(), 0 ,
130 Garmin, GarminUpload, FurunoGP3X, bEnabled, UserComment.c_str(),
131 AutoSKDiscover, socketCAN_port.c_str(), NoDataReconnect, DisableEcho,
138 std::stringstream ss;
139 ss << Type << NetProtocol << NetworkAddress << NetworkPort << Protocol << Port
140 << Baudrate << ChecksumCheck << IOSelect << InputSentenceListType
141 << OutputSentenceListType << Garmin << GarminUpload << FurunoGP3X
142 << UserComment << AutoSKDiscover << socketCAN_port << NoDataReconnect
143 << DisableEcho << AuthToken;
144 for (
const auto& sentence : OutputSentenceList) ss << sentence;
145 for (
const auto& sentence : InputSentenceList) ss << sentence;
149ConnectionParams::ConnectionParams() {
152 NetworkAddress = wxEmptyString;
154 Protocol = PROTO_NMEA0183;
155 Port = wxEmptyString;
157 ChecksumCheck =
true;
160 IOSelect = DS_TYPE_INPUT;
161 InputSentenceListType = WHITELIST;
162 OutputSentenceListType = WHITELIST;
166 m_optionsPanel = NULL;
167 AutoSKDiscover =
false;
168 NoDataReconnect =
false;
170 AuthToken = wxEmptyString;
173ConnectionParams::~ConnectionParams() {
177wxString ConnectionParams::GetSourceTypeStr()
const {
192wxString ConnectionParams::GetAddressStr()
const {
194 return wxString::Format(_T(
"%s"), Port.c_str());
195 else if (Type == NETWORK)
196 return wxString::Format(_T(
"%s:%d"), NetworkAddress.c_str(), NetworkPort);
197 else if (Type == INTERNAL_GPS)
198 return _(
"Internal");
199 else if (Type == INTERNAL_BT)
200 return NetworkAddress;
206static wxString NetworkProtocolToString(NetworkProtocol NetProtocol) {
207 switch (NetProtocol) {
215 return _(
"Signal K");
217 return _(
"Undefined");
221wxString ConnectionParams::GetParametersStr()
const {
224 return wxString::Format(_T(
"%d"), Baudrate);
226 return NetworkProtocolToString(NetProtocol);
236wxString ConnectionParams::GetIOTypeValueStr()
const {
237 if (IOSelect == DS_TYPE_INPUT)
239 else if (IOSelect == DS_TYPE_OUTPUT)
245wxString ConnectionParams::FilterTypeToStr(ListType type,
246 FilterDirection dir)
const {
247 if (dir == FILTER_INPUT) {
248 if (type == BLACKLIST)
253 if (type == BLACKLIST)
260wxString ConnectionParams::GetFiltersStr()
const {
262 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
263 if (i > 0) istcs.Append(_T(
","));
264 istcs.Append(InputSentenceList[i]);
267 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
268 if (i > 0) ostcs.Append(_T(
","));
269 ostcs.Append(OutputSentenceList[i]);
271 wxString ret = wxEmptyString;
272 if (istcs.Len() > 0) {
274 ret.Append(wxString::Format(
276 FilterTypeToStr(InputSentenceListType, FILTER_INPUT).c_str(),
279 ret.Append(_(
"In: None"));
281 if (ostcs.Len() > 0) {
282 ret.Append(_T(
", "));
283 ret.Append(_(
"Out"));
284 ret.Append(wxString::Format(
286 FilterTypeToStr(OutputSentenceListType, FILTER_OUTPUT).c_str(),
289 ret.Append(_(
", Out: None"));
293wxString ConnectionParams::GetDSPort()
const {
295 return wxString::Format(_T(
"Serial:%s"), Port.c_str());
296 else if (Type == NETWORK) {
297 wxString proto = NetworkProtocolToString(NetProtocol);
298 return wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
299 NetworkAddress.c_str(), NetworkPort);
300 }
else if (Type == INTERNAL_BT) {
306bool ConnectionParams::GetValidPort()
const {
307 if (Type == SERIAL && Port ==
"")
309 else if (Type == NETWORK && (NetworkAddress ==
"" || !NetworkPort))
311 else if (Type == INTERNAL_BT && Port ==
"")
317std::string ConnectionParams::GetStrippedDSPort()
const {
318 if (Type == SERIAL) {
319 wxString t = wxString::Format(_T(
"Serial:%s"), Port.c_str());
320 wxString comx = t.AfterFirst(
':').BeforeFirst(
' ');
321 return comx.ToStdString();
322 }
else if (Type == NETWORK) {
323 wxString proto = NetworkProtocolToString(NetProtocol);
324 wxString t = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
325 NetworkAddress.c_str(), NetworkPort);
326 return t.ToStdString();
328 }
else if (Type == SOCKETCAN) {
329 std::string rv =
"socketCAN-";
330 rv += socketCAN_port.ToStdString();
332 }
else if (Type == INTERNAL_BT) {
333 return Port.ToStdString();
334 }
else if (Type == INTERNAL_GPS) {
335 return Port.ToStdString();
340std::string ConnectionParams::GetLastDSPort()
const {
341 if (Type == SERIAL) {
342 wxString sp = wxString::Format(_T(
"Serial:%s"), Port.c_str());
343 return sp.ToStdString();
345 wxString proto = NetworkProtocolToString(LastNetProtocol);
346 wxString sp = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
347 LastNetworkAddress.c_str(), LastNetworkPort);
348 return sp.ToStdString();
352bool ConnectionParams::SentencePassesFilter(
const wxString& sentence,
353 FilterDirection direction)
const {
354 wxArrayString filter;
355 bool listype =
false;
357 if (direction == FILTER_INPUT) {
358 filter = InputSentenceList;
359 if (InputSentenceListType == WHITELIST) listype =
true;
361 filter = OutputSentenceList;
362 if (OutputSentenceListType == WHITELIST) listype =
true;
364 if (filter.Count() == 0)
368 for (
size_t i = 0; i < filter.Count(); i++) {
370 switch (fs.Length()) {
372 if (fs == sentence.Mid(1, 2))
return listype;
375 if (fs == sentence.Mid(3, 3))
return listype;
378 if (fs == sentence.Mid(1, 5))
return listype;
385 if (re.Matches(sentence.Mid(0, 8))) {
394NavAddr::Bus ConnectionParams::GetCommProtocol()
const {
395 if (Type == NETWORK) {
396 if (NetProtocol == SIGNALK)
397 return NavAddr::Bus::Signalk;
398 else if (NetProtocol == GPSD)
399 return NavAddr::Bus::N0183;
404 return NavAddr::Bus::N0183;
406 return NavAddr::Bus::N2000;
408 return NavAddr::Bus::Undef;
412NavAddr::Bus ConnectionParams::GetLastCommProtocol() {
413 if (Type == NETWORK) {
414 if (LastNetProtocol == SIGNALK)
415 return NavAddr::Bus::Signalk;
416 else if (LastNetProtocol == GPSD)
417 return NavAddr::Bus::N0183;
420 switch (LastDataProtocol) {
422 return NavAddr::Bus::N0183;
424 return NavAddr::Bus::N2000;
426 return NavAddr::Bus::Undef;
std::string GetKey() const
Return string unique for each instance.
PlugIn Object Definition/API.