35#include <wx/checklst.h>
36#include <wx/combobox.h>
39#include <wx/statline.h>
40#include <wx/tokenzr.h>
46#if !wxUSE_XLOCALE && wxCHECK_VERSION(3, 0, 0)
47#define wxAtoi(arg) atoi(arg)
50static std::vector<ConnectionParams*> the_connection_params;
52std::vector<ConnectionParams*>& TheConnectionParams() {
53 return the_connection_params;
56ConnectionParams::ConnectionParams(
const wxString& configStr) {
57 m_optionsPanel = NULL;
58 Deserialize(configStr);
61void ConnectionParams::Deserialize(
const wxString& configStr) {
63 wxArrayString prms = wxStringTokenize(configStr,
";");
64 if (prms.Count() < 18) {
69 Type = (ConnectionType)wxAtoi(prms[0]);
70 NetProtocol = (NetworkProtocol)wxAtoi(prms[1]);
71 NetworkAddress = prms[2];
72 NetworkPort = (ConnectionType)wxAtoi(prms[3]);
73 Protocol = (DataProtocol)wxAtoi(prms[4]);
75 Baudrate = wxAtoi(prms[6]);
76 ChecksumCheck = wxAtoi(prms[7]);
77 int iotval = wxAtoi(prms[8]);
78 IOSelect = ((iotval <= 2) ? static_cast<dsPortType>(iotval) : DS_TYPE_INPUT);
79 InputSentenceListType = (ListType)wxAtoi(prms[9]);
80 InputSentenceList = wxStringTokenize(prms[10],
",");
81 OutputSentenceListType = (ListType)wxAtoi(prms[11]);
82 OutputSentenceList = wxStringTokenize(prms[12],
",");
83 Garmin = !!wxAtoi(prms[14]);
84 GarminUpload = !!wxAtoi(prms[15]);
85 FurunoGP3X = !!wxAtoi(prms[16]);
90 if (prms.Count() >= 18) {
91 bEnabled = !!wxAtoi(prms[17]);
93 if (prms.Count() >= 19) {
94 UserComment = prms[18];
96 if (prms.Count() >= 20) {
97 AutoSKDiscover = !!wxAtoi(prms[19]);
99 if (prms.Count() >= 21) {
100 socketCAN_port = prms[20];
102 if (prms.Count() >= 22) {
103 NoDataReconnect = wxAtoi(prms[21]);
105 if (prms.Count() >= 23) {
106 DisableEcho = wxAtoi(prms[22]);
108 if (prms.Count() >= 24) {
109 AuthToken = prms[23];
113wxString ConnectionParams::Serialize()
const {
115 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
116 if (i > 0) istcs.Append(
",");
117 istcs.Append(InputSentenceList[i]);
120 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
121 if (i > 0) ostcs.Append(
",");
122 ostcs.Append(OutputSentenceList[i]);
124 wxString ret = wxString::Format(
125 "%d;%d;%s;%d;%d;%s;%d;%d;%d;%d;%s;%d;%s;%d;%d;%d;%d;%d;%s;%d;%s;%d;%d;%s",
126 Type, NetProtocol, NetworkAddress.c_str(), NetworkPort, Protocol,
127 Port.c_str(), Baudrate, ChecksumCheck, IOSelect, InputSentenceListType,
128 istcs.c_str(), OutputSentenceListType, ostcs.c_str(), 0 ,
129 Garmin, GarminUpload, FurunoGP3X, bEnabled, UserComment.c_str(),
130 AutoSKDiscover, socketCAN_port.c_str(), NoDataReconnect, DisableEcho,
137 std::stringstream ss;
138 ss << Type << NetProtocol << NetworkAddress << NetworkPort << Protocol << Port
139 << Baudrate << ChecksumCheck << IOSelect << InputSentenceListType
140 << OutputSentenceListType << Garmin << GarminUpload << FurunoGP3X
141 << UserComment << AutoSKDiscover << socketCAN_port << NoDataReconnect
142 << DisableEcho << AuthToken;
143 for (
const auto& sentence : OutputSentenceList) ss << sentence;
144 for (
const auto& sentence : InputSentenceList) ss << sentence;
148ConnectionParams::ConnectionParams() {
153 Protocol = PROTO_NMEA0183;
156 ChecksumCheck =
true;
159 IOSelect = DS_TYPE_INPUT;
160 InputSentenceListType = WHITELIST;
161 OutputSentenceListType = WHITELIST;
165 m_optionsPanel = NULL;
166 AutoSKDiscover =
false;
167 NoDataReconnect =
false;
172ConnectionParams::~ConnectionParams() {
176wxString ConnectionParams::GetSourceTypeStr()
const {
191wxString ConnectionParams::GetAddressStr()
const {
193 return wxString::Format(
"%s", Port.c_str());
194 else if (Type == NETWORK)
195 return wxString::Format(
"%s:%d", NetworkAddress.c_str(), NetworkPort);
196 else if (Type == INTERNAL_GPS)
197 return _(
"Internal");
198 else if (Type == INTERNAL_BT)
199 return NetworkAddress;
205static wxString NetworkProtocolToString(NetworkProtocol NetProtocol) {
206 switch (NetProtocol) {
214 return _(
"Signal K");
216 return _(
"Undefined");
220wxString ConnectionParams::GetParametersStr()
const {
223 return wxString::Format(
"%d", Baudrate);
225 return NetworkProtocolToString(NetProtocol);
235wxString ConnectionParams::GetIOTypeValueStr()
const {
236 if (IOSelect == DS_TYPE_INPUT)
238 else if (IOSelect == DS_TYPE_OUTPUT)
244wxString ConnectionParams::FilterTypeToStr(ListType type,
245 FilterDirection dir)
const {
246 if (dir == FILTER_INPUT) {
247 if (type == BLACKLIST)
252 if (type == BLACKLIST)
259wxString ConnectionParams::GetFiltersStr()
const {
261 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
262 if (i > 0) istcs.Append(
",");
263 istcs.Append(InputSentenceList[i]);
266 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
267 if (i > 0) ostcs.Append(
",");
268 ostcs.Append(OutputSentenceList[i]);
271 if (istcs.Len() > 0) {
273 ret.Append(wxString::Format(
274 ": %s %s", FilterTypeToStr(InputSentenceListType, FILTER_INPUT).c_str(),
277 ret.Append(_(
"In: None"));
279 if (ostcs.Len() > 0) {
281 ret.Append(_(
"Out"));
282 ret.Append(wxString::Format(
284 FilterTypeToStr(OutputSentenceListType, FILTER_OUTPUT).c_str(),
287 ret.Append(_(
", Out: None"));
291wxString ConnectionParams::GetDSPort()
const {
293 return wxString::Format(
"Serial:%s", Port.c_str());
294 else if (Type == NETWORK) {
295 wxString proto = NetworkProtocolToString(NetProtocol);
296 return wxString::Format(
"%s:%s:%d", proto.c_str(), NetworkAddress.c_str(),
298 }
else if (Type == INTERNAL_BT) {
304bool ConnectionParams::GetValidPort()
const {
305 if (Type == SERIAL && Port ==
"")
307 else if (Type == NETWORK && (NetworkAddress ==
"" || !NetworkPort))
309 else if (Type == INTERNAL_BT && Port ==
"")
315std::string ConnectionParams::GetStrippedDSPort()
const {
316 if (Type == SERIAL) {
317 wxString t = wxString::Format(
"Serial:%s", Port.c_str());
318 wxString comx = t.AfterFirst(
':').BeforeFirst(
' ');
319 return comx.ToStdString();
320 }
else if (Type == NETWORK) {
321 wxString proto = NetworkProtocolToString(NetProtocol);
322 wxString t = wxString::Format(
"%s:%s:%d", proto.c_str(),
323 NetworkAddress.c_str(), NetworkPort);
324 return t.ToStdString();
326 }
else if (Type == SOCKETCAN) {
327 std::string rv =
"socketCAN-";
328 rv += socketCAN_port.ToStdString();
330 }
else if (Type == INTERNAL_BT) {
331 return Port.ToStdString();
332 }
else if (Type == INTERNAL_GPS) {
333 return Port.ToStdString();
338std::string ConnectionParams::GetLastDSPort()
const {
339 if (Type == SERIAL) {
340 wxString sp = wxString::Format(
"Serial:%s", Port.c_str());
341 return sp.ToStdString();
343 wxString proto = NetworkProtocolToString(LastNetProtocol);
344 wxString sp = wxString::Format(
"%s:%s:%d", proto.c_str(),
345 LastNetworkAddress.c_str(), LastNetworkPort);
346 return sp.ToStdString();
350bool ConnectionParams::SentencePassesFilter(
const wxString& sentence,
351 FilterDirection direction)
const {
352 wxArrayString filter;
353 bool listype =
false;
355 if (direction == FILTER_INPUT) {
356 filter = InputSentenceList;
357 if (InputSentenceListType == WHITELIST) listype =
true;
359 filter = OutputSentenceList;
360 if (OutputSentenceListType == WHITELIST) listype =
true;
362 if (filter.Count() == 0)
366 for (
size_t i = 0; i < filter.Count(); i++) {
368 switch (fs.Length()) {
370 if (fs == sentence.Mid(1, 2))
return listype;
373 if (fs == sentence.Mid(3, 3))
return listype;
376 if (fs == sentence.Mid(1, 5))
return listype;
383 if (re.Matches(sentence.Mid(0, 8))) {
392NavAddr::Bus ConnectionParams::GetCommProtocol()
const {
393 if (Type == NETWORK) {
394 if (NetProtocol == SIGNALK)
395 return NavAddr::Bus::Signalk;
396 else if (NetProtocol == GPSD)
397 return NavAddr::Bus::N0183;
402 return NavAddr::Bus::N0183;
404 return NavAddr::Bus::N2000;
406 return NavAddr::Bus::Undef;
410NavAddr::Bus ConnectionParams::GetLastCommProtocol() {
411 if (Type == NETWORK) {
412 if (LastNetProtocol == SIGNALK)
413 return NavAddr::Bus::Signalk;
414 else if (LastNetProtocol == GPSD)
415 return NavAddr::Bus::N0183;
418 switch (LastDataProtocol) {
420 return NavAddr::Bus::N0183;
422 return NavAddr::Bus::N2000;
424 return NavAddr::Bus::Undef;
std::string GetKey() const
Return string unique for each instance.
PlugIn Object Definition/API.