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[22];
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) {
306std::string ConnectionParams::GetStrippedDSPort()
const {
307 if (Type == SERIAL) {
308 wxString t = wxString::Format(_T(
"Serial:%s"), Port.c_str());
309 wxString comx = t.AfterFirst(
':').BeforeFirst(
' ');
310 return comx.ToStdString();
311 }
else if (Type == NETWORK) {
312 wxString proto = NetworkProtocolToString(NetProtocol);
313 wxString t = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
314 NetworkAddress.c_str(), NetworkPort);
315 return t.ToStdString();
317 }
else if (Type == SOCKETCAN) {
318 std::string rv =
"socketCAN-";
319 rv += socketCAN_port.ToStdString();
321 }
else if (Type == INTERNAL_BT) {
322 return Port.ToStdString();
327std::string ConnectionParams::GetLastDSPort()
const {
328 if (Type == SERIAL) {
329 wxString sp = wxString::Format(_T(
"Serial:%s"), Port.c_str());
330 return sp.ToStdString();
332 wxString proto = NetworkProtocolToString(LastNetProtocol);
333 wxString sp = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
334 LastNetworkAddress.c_str(), LastNetworkPort);
335 return sp.ToStdString();
339bool ConnectionParams::SentencePassesFilter(
const wxString& sentence,
340 FilterDirection direction)
const {
341 wxArrayString filter;
342 bool listype =
false;
344 if (direction == FILTER_INPUT) {
345 filter = InputSentenceList;
346 if (InputSentenceListType == WHITELIST) listype =
true;
348 filter = OutputSentenceList;
349 if (OutputSentenceListType == WHITELIST) listype =
true;
351 if (filter.Count() == 0)
355 for (
size_t i = 0; i < filter.Count(); i++) {
357 switch (fs.Length()) {
359 if (fs == sentence.Mid(1, 2))
return listype;
362 if (fs == sentence.Mid(3, 3))
return listype;
365 if (fs == sentence.Mid(1, 5))
return listype;
372 if (re.Matches(sentence.Mid(0, 8))) {
381NavAddr::Bus ConnectionParams::GetCommProtocol()
const {
382 if (Type == NETWORK) {
383 if (NetProtocol == SIGNALK)
384 return NavAddr::Bus::Signalk;
385 else if (NetProtocol == GPSD)
386 return NavAddr::Bus::N0183;
391 return NavAddr::Bus::N0183;
393 return NavAddr::Bus::N2000;
395 return NavAddr::Bus::Undef;
399NavAddr::Bus ConnectionParams::GetLastCommProtocol() {
400 if (Type == NETWORK) {
401 if (LastNetProtocol == SIGNALK)
402 return NavAddr::Bus::Signalk;
403 else if (LastNetProtocol == GPSD)
404 return NavAddr::Bus::N0183;
407 switch (LastDataProtocol) {
409 return NavAddr::Bus::N0183;
411 return NavAddr::Bus::N2000;
413 return NavAddr::Bus::Undef;
std::string GetKey() const
Return string unique for each instance.
PlugIn Object Definition/API.