31 #include <wx/wxprec.h>
39 #include <wx/tokenzr.h>
42 #if defined(__linux__) && !defined(__ANDROID__)
43 #include <linux/can.h>
44 #include <linux/can/raw.h>
46 #include <serial/serial.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
53 #include "androidUTIL.h"
57 #include "model/comm_drv_factory.h"
58 #include "model/config_vars.h"
59 #include "model/ocpn_utils.h"
60 #include "model/ser_ports.h"
61 #include "model/sys_events.h"
63 #include "connection_edit.h"
64 #include "conn_params_panel.h"
67 #include "NMEALogWindow.h"
68 #include "OCPNPlatform.h"
71 #include "priority_gui.h"
74 extern bool g_bfilter_cogsog;
75 extern int g_COGFilterSec;
76 extern int g_SOGFilterSec;
80 static wxString StringArrayToString(
const wxArrayString& arr) {
81 wxString ret = wxEmptyString;
82 for (
size_t i = 0; i < arr.Count(); i++) {
83 if (i > 0) ret.Append(
",");
91 #if defined(__linux__) && !defined(__ANDROID__)
93 std::vector<std::string> can_if_candidates;
94 static int print_intf(
const struct intf_entry* entry,
void* arg) {
95 std::string iface = entry->intf_name;
96 if (entry->intf_type == 1 && iface.find(
"can") != std::string::npos) {
97 can_if_candidates.push_back(entry->intf_name);
103 static wxArrayString GetAvailableSocketCANInterfaces() {
106 #if defined(__linux__) && !defined(__ANDROID__)
107 struct intf_entry* entry;
109 can_if_candidates.clear();
111 if ((intf = intf_open()) == NULL) {
112 wxLogWarning(
"Error opening interface list");
115 if (intf_loop(intf, print_intf, NULL) < 0) {
116 wxLogWarning(
"Error looping over interface list");
120 for (
const auto& iface : can_if_candidates) {
121 int sock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
127 struct ifreq if_request;
128 strcpy(if_request.ifr_name, iface.c_str());
129 if (ioctl(sock, SIOCGIFINDEX, &if_request) < 0) {
134 struct sockaddr_can can_address;
135 can_address.can_family = AF_CAN;
136 can_address.can_ifindex = if_request.ifr_ifindex;
137 if (ioctl(sock, SIOCGIFFLAGS, &if_request) < 0) {
140 if (if_request.ifr_flags & IFF_UP) {
150 static void LoadSerialPorts(wxComboBox* box) {
154 std::string GetKey(
const std::string& s)
const {
155 if (s.find(
"->") == std::string::npos)
return s;
156 return ocpn::trim(ocpn::split(s,
"->")[1]) +
" link";
160 bool operator()(
const std::string& lhs,
const std::string& rhs)
const {
161 return GetKey(lhs) < GetKey(rhs);
165 std::set<std::string, PortSorter> sorted_ports(port_sorter);
166 std::unique_ptr<wxArrayString> ports(EnumerateSerialPorts());
167 for (
size_t i = 0; i < ports->GetCount(); i++)
168 sorted_ports.insert((*ports)[i].ToStdString());
171 for (
auto& p : sorted_ports) box->Append(p);
183 ConnectionEditDialog::ConnectionEditDialog() {}
185 ConnectionEditDialog::ConnectionEditDialog(
options* parent,
187 : wxDialog(parent, wxID_ANY, _(
"Connection Edit"), wxDefaultPosition,
194 ConnectionEditDialog::~ConnectionEditDialog() {}
196 void ConnectionEditDialog::SetInitialSettings(
void) {
197 LoadSerialPorts(m_comboPort);
200 void ConnectionEditDialog::Init() {
201 MORE =
"<span foreground=\'blue\'>";
203 MORE +=
"...</span>";
204 LESS =
"<span foreground=\'blue\'>";
206 LESS +=
"...</span>";
214 m_choiceBTDataSources = 0;
216 m_BTScanTimer.SetOwner(
this, ID_BT_SCANTIMER);
221 wxBoxSizer* mainSizer =
new wxBoxSizer(wxVERTICAL);
223 wxBoxSizer* boxSizer02 =
new wxBoxSizer(wxVERTICAL);
224 mainSizer->Add(boxSizer02, 1, wxEXPAND | wxALL, 2);
227 new wxScrolledWindow(
this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1),
228 wxTAB_TRAVERSAL | wxVSCROLL);
229 m_scrolledwin->SetScrollRate(0, 5);
230 boxSizer02->Add(m_scrolledwin, 1, wxALL | wxEXPAND, 3);
232 auto boxSizerSWin =
new wxBoxSizer(wxVERTICAL);
233 m_scrolledwin->SetSizer(boxSizerSWin);
235 wxStdDialogButtonSizer* btnSizer =
new wxStdDialogButtonSizer();
236 wxButton* btnOK =
new wxButton(
this, wxID_OK);
237 wxButton* btnCancel =
new wxButton(
this, wxID_CANCEL, _(
"Cancel"));
238 btnSizer->AddButton(btnOK);
239 btnSizer->AddButton(btnCancel);
241 mainSizer->Add(btnSizer, 0, wxALL | wxEXPAND, 5);
245 int group_item_spacing = 2;
247 wxFont* dFont = GetOCPNScaledFont_PlugIn(_(
"Dialog"));
248 double font_size = dFont->GetPointSize() * 17 / 16;
249 wxFont* bFont = wxTheFontList->FindOrCreateFont(
250 font_size, dFont->GetFamily(), dFont->GetStyle(), wxFONTWEIGHT_BOLD);
259 new wxStaticBox(m_scrolledwin, wxID_ANY, _(
"Edit Selected Connection"));
260 m_sbConnEdit->SetFont(*bFont);
262 sbSizerConnectionProps =
new wxStaticBoxSizer(m_sbConnEdit, wxVERTICAL);
263 m_scrolledwin->GetSizer()->Add(sbSizerConnectionProps, 1, wxALL | wxEXPAND,
266 wxBoxSizer* bSizer15;
267 bSizer15 =
new wxBoxSizer(wxHORIZONTAL);
269 sbSizerConnectionProps->Add(bSizer15, 0, wxTOP | wxEXPAND, 5);
273 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Serial"), wxDefaultPosition,
274 wxDefaultSize, wxRB_GROUP);
275 m_rbTypeSerial->SetValue(TRUE);
276 bSizer15->Add(m_rbTypeSerial, 0, wxALL, 5);
278 m_rbTypeNet =
new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Network"),
279 wxDefaultPosition, wxDefaultSize, 0);
280 bSizer15->Add(m_rbTypeNet, 0, wxALL, 5);
282 m_rbTypeCAN =
new wxRadioButton(m_scrolledwin, wxID_ANY,
"socketCAN",
283 wxDefaultPosition, wxDefaultSize, 0);
284 #if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
285 bSizer15->Add(m_rbTypeCAN, 0, wxALL, 5);
290 if (OCPNPlatform::hasInternalGPS()) {
291 m_rbTypeInternalGPS =
292 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Built-in GPS"),
293 wxDefaultPosition, wxDefaultSize, 0);
294 bSizer15->Add(m_rbTypeInternalGPS, 0, wxALL, 5);
296 m_rbTypeInternalGPS = NULL;
299 if (OCPNPlatform::hasInternalBT()) {
301 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Built-in Bluetooth SPP"),
302 wxDefaultPosition, wxDefaultSize, 0);
303 bSizer15->Add(m_rbTypeInternalBT, 0, wxALL, 5);
305 m_buttonScanBT =
new wxButton(m_scrolledwin, wxID_ANY, _(
"BT Scan"),
306 wxDefaultPosition, wxDefaultSize);
307 m_buttonScanBT->Hide();
312 sbSizerConnectionProps->Add(m_buttonScanBT, 0, wxALL, 5);
315 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Bluetooth Data Sources"),
316 wxDefaultPosition, wxDefaultSize, 0);
317 m_stBTPairs->Wrap(-1);
319 sbSizerConnectionProps->Add(m_stBTPairs, 0, wxALL, 5);
324 int ref_size = m_scrolledwin->GetCharWidth();
325 m_choiceBTDataSources =
326 new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition,
327 wxSize(40 * ref_size, 2 * ref_size), mt);
330 m_choiceBTDataSources->SetSelection(0);
331 m_choiceBTDataSources->Hide();
332 sbSizerConnectionProps->Add(m_choiceBTDataSources, 1, wxEXPAND | wxTOP, 5);
335 m_rbTypeInternalBT = NULL;
337 gSizerNetProps =
new wxFlexGridSizer(0, 4, 0, 0);
339 sbSizerConnectionProps->Add(gSizerNetProps, 0, wxEXPAND, 5);
342 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Network Protocol"),
343 wxDefaultPosition, wxDefaultSize, 0);
344 m_stNetProto->Wrap(-1);
345 gSizerNetProps->Add(m_stNetProto, 0, wxALL, 5);
347 wxBoxSizer* bSizer16;
348 bSizer16 =
new wxBoxSizer(wxHORIZONTAL);
351 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"TCP"), wxDefaultPosition,
352 wxDefaultSize, wxRB_GROUP);
353 m_rbNetProtoTCP->Enable(TRUE);
354 m_rbNetProtoTCP->SetValue(TRUE);
356 bSizer16->Add(m_rbNetProtoTCP, 0, wxALL, 5);
358 m_rbNetProtoUDP =
new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"UDP"),
359 wxDefaultPosition, wxDefaultSize, 0);
360 m_rbNetProtoUDP->Enable(TRUE);
362 bSizer16->Add(m_rbNetProtoUDP, 0, wxALL, 5);
364 m_rbNetProtoGPSD =
new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"GPSD"),
365 wxDefaultPosition, wxDefaultSize, 0);
366 m_rbNetProtoGPSD->Enable(TRUE);
367 bSizer16->Add(m_rbNetProtoGPSD, 0, wxALL, 5);
369 m_rbNetProtoSignalK =
370 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Signal K"),
371 wxDefaultPosition, wxDefaultSize, 0);
372 m_rbNetProtoSignalK->Enable(TRUE);
373 bSizer16->Add(m_rbNetProtoSignalK, 0, wxALL, 5);
375 gSizerNetProps->Add(bSizer16, 1, wxEXPAND, 5);
376 gSizerNetProps->AddSpacer(1);
377 gSizerNetProps->AddSpacer(1);
379 m_stNetDataProtocol =
380 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Data Protocol"),
381 wxDefaultPosition, wxDefaultSize, 0);
382 m_stNetDataProtocol->Wrap(-1);
384 gSizerNetProps->Add(m_stNetDataProtocol, 0, wxALL, 5);
386 wxString m_choiceNetProtocolChoices[] = {_(
"NMEA 0183"), _(
"NMEA 2000")};
387 int m_choiceNetProtocolNChoices =
388 sizeof(m_choiceNetProtocolChoices) /
sizeof(wxString);
389 m_choiceNetDataProtocol =
390 new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition, wxDefaultSize,
391 m_choiceNetProtocolNChoices, m_choiceNetProtocolChoices, 0);
394 m_choiceNetDataProtocol->SetSelection(0);
395 m_choiceNetDataProtocol->Enable(TRUE);
397 gSizerNetProps->Add(m_choiceNetDataProtocol, 1, wxEXPAND | wxTOP, 5);
398 gSizerNetProps->AddSpacer(1);
399 gSizerNetProps->AddSpacer(1);
401 m_stNetAddr =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Address"),
402 wxDefaultPosition, wxDefaultSize, 0);
403 m_stNetAddr->Wrap(-1);
404 int column1width = 16 * m_stNetProto->GetCharWidth();
405 m_stNetAddr->SetMinSize(wxSize(column1width, -1));
406 gSizerNetProps->Add(m_stNetAddr, 0, wxALL, 5);
408 m_tNetAddress =
new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString,
409 wxDefaultPosition, wxDefaultSize, 0);
410 int column2width = 40 * m_scrolledwin->GetCharWidth();
411 m_tNetAddress->SetMaxSize(wxSize(column2width, -1));
412 m_tNetAddress->SetMinSize(wxSize(column2width, -1));
414 gSizerNetProps->Add(m_tNetAddress, 0, wxEXPAND | wxTOP, 5);
415 gSizerNetProps->AddSpacer(1);
416 gSizerNetProps->AddSpacer(1);
418 m_stNetPort =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"DataPort"),
419 wxDefaultPosition, wxDefaultSize, 0);
420 m_stNetPort->Wrap(-1);
421 gSizerNetProps->Add(m_stNetPort, 0, wxALL, 5);
423 m_tNetPort =
new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString,
424 wxDefaultPosition, wxDefaultSize, 0);
425 gSizerNetProps->Add(m_tNetPort, 1, wxEXPAND | wxTOP, 5);
426 gSizerNetProps->AddSpacer(1);
427 gSizerNetProps->AddSpacer(1);
429 gSizerCanProps =
new wxGridSizer(0, 1, 0, 0);
431 wxFlexGridSizer* fgSizer1C;
432 fgSizer1C =
new wxFlexGridSizer(0, 2, 0, 0);
437 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"socketCAN Source"),
438 wxDefaultPosition, wxDefaultSize, 0);
439 m_stCANSource->Wrap(-1);
440 m_stCANSource->SetMinSize(wxSize(column1width, -1));
441 fgSizer1C->Add(m_stCANSource, 0, wxALL, 5);
443 wxArrayString choices = GetAvailableSocketCANInterfaces();
444 m_choiceCANSource =
new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition,
445 wxDefaultSize, choices);
447 m_choiceCANSource->SetSelection(0);
448 m_choiceCANSource->Enable(TRUE);
449 m_choiceCANSource->SetMaxSize(wxSize(column2width, -1));
450 m_choiceCANSource->SetMinSize(wxSize(column2width, -1));
451 fgSizer1C->Add(m_choiceCANSource, 1, wxEXPAND | wxTOP, 5);
453 gSizerCanProps->Add(fgSizer1C, 0, wxEXPAND, 5);
455 sbSizerConnectionProps->Add(gSizerCanProps, 0, wxEXPAND, 5);
457 gSizerSerProps =
new wxGridSizer(0, 1, 0, 0);
458 sbSizerConnectionProps->Add(gSizerSerProps, 0, wxEXPAND, 5);
460 wxFlexGridSizer* fgSizer1;
461 fgSizer1 =
new wxFlexGridSizer(0, 4, 0, 0);
462 fgSizer1->SetFlexibleDirection(wxBOTH);
463 fgSizer1->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
466 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Data port"),
467 wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
468 m_stSerPort->SetMinSize(wxSize(column1width, -1));
469 m_stSerPort->Wrap(-1);
471 fgSizer1->Add(m_stSerPort, 0, wxALL, 5);
473 m_comboPort =
new wxComboBox(m_scrolledwin, wxID_ANY, wxEmptyString,
474 wxDefaultPosition, wxDefaultSize, 0, NULL, 0);
476 m_comboPort->SetMaxSize(wxSize(column2width, -1));
477 m_comboPort->SetMinSize(wxSize(column2width, -1));
479 fgSizer1->Add(m_comboPort, 0, wxEXPAND | wxTOP, 5);
481 m_stSerBaudrate =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Baudrate"),
482 wxDefaultPosition, wxDefaultSize, 0);
483 m_stSerBaudrate->Wrap(-1);
484 fgSizer1->AddSpacer(1);
485 fgSizer1->AddSpacer(1);
486 fgSizer1->Add(m_stSerBaudrate, 0, wxALL, 5);
488 wxString m_choiceBaudRateChoices[] = {
489 _(
"150"), _(
"300"), _(
"600"), _(
"1200"), _(
"2400"),
490 _(
"4800"), _(
"9600"), _(
"19200"), _(
"38400"), _(
"57600"),
491 _(
"115200"), _(
"230400"), _(
"460800"), _(
"921600")};
492 int m_choiceBaudRateNChoices =
493 sizeof(m_choiceBaudRateChoices) /
sizeof(wxString);
495 new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition, wxDefaultSize,
496 m_choiceBaudRateNChoices, m_choiceBaudRateChoices, 0);
500 m_choiceBaudRate->SetSelection(0);
502 fgSizer1->Add(m_choiceBaudRate, 1, wxEXPAND | wxTOP, 5);
503 fgSizer1->AddSpacer(1);
504 fgSizer1->AddSpacer(1);
506 m_stSerProtocol =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Protocol"),
507 wxDefaultPosition, wxDefaultSize, 0);
508 m_stSerProtocol->Wrap(-1);
509 fgSizer1->Add(m_stSerProtocol, 0, wxALL, 5);
511 wxString m_choiceSerialProtocolChoices[] = {_(
"NMEA 0183"), _(
"NMEA 2000")};
512 int m_choiceSerialProtocolNChoices =
513 sizeof(m_choiceSerialProtocolChoices) /
sizeof(wxString);
514 m_choiceSerialProtocol =
new wxChoice(
515 m_scrolledwin, wxID_ANY, wxDefaultPosition, wxDefaultSize,
516 m_choiceSerialProtocolNChoices, m_choiceSerialProtocolChoices, 0);
520 m_choiceSerialProtocol->SetSelection(0);
521 m_choiceSerialProtocol->Enable(TRUE);
522 fgSizer1->Add(m_choiceSerialProtocol, 1, wxEXPAND | wxTOP, 5);
524 gSizerSerProps->Add(fgSizer1, 0, wxEXPAND, 5);
528 wxFlexGridSizer* commentSizer =
new wxFlexGridSizer(0, 2, 0, 0);
532 m_stNetComment =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"User Comment"),
533 wxDefaultPosition, wxDefaultSize, 0);
534 m_stNetComment->Wrap(-1);
535 m_stNetComment->SetMinSize(wxSize(column1width, -1));
536 commentSizer->Add(m_stNetComment, 0, wxALL, 5);
538 m_tNetComment =
new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString,
539 wxDefaultPosition, wxDefaultSize, 0);
540 m_tNetComment->SetMaxSize(wxSize(column2width, -1));
541 m_tNetComment->SetMinSize(wxSize(column2width, -1));
543 commentSizer->Add(m_tNetComment, 1, wxEXPAND | wxTOP, 5);
547 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"User Comment"),
548 wxDefaultPosition, wxDefaultSize, 0);
549 m_stSerialComment->Wrap(-1);
550 m_stSerialComment->SetMinSize(wxSize(column1width, -1));
551 commentSizer->Add(m_stSerialComment, 0, wxALL, 5);
553 m_tSerialComment =
new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString,
554 wxDefaultPosition, wxDefaultSize, 0);
555 m_tSerialComment->SetMaxSize(wxSize(column2width, -1));
556 m_tSerialComment->SetMinSize(wxSize(column2width, -1));
558 commentSizer->Add(m_tSerialComment, 1, wxTOP, 5);
560 m_stPriority =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"List position"),
561 wxDefaultPosition, wxDefaultSize, 0);
562 m_stPriority->Wrap(-1);
563 commentSizer->Add(m_stPriority, 0, wxALL, 5);
565 wxString m_choicePriorityChoices[] = {_(
"0"), _(
"1"), _(
"2"), _(
"3"), _(
"4"),
566 _(
"5"), _(
"6"), _(
"7"), _(
"8"), _(
"9")};
567 int m_choicePriorityNChoices =
568 sizeof(m_choicePriorityChoices) /
sizeof(wxString);
570 new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition,
571 wxSize(8 * m_parent->GetCharWidth(), -1),
572 m_choicePriorityNChoices, m_choicePriorityChoices, 0);
576 m_choicePriority->SetSelection(9);
577 commentSizer->Add(m_choicePriority, 0, wxEXPAND | wxTOP, 5);
579 sbSizerConnectionProps->Add(commentSizer, 0, wxEXPAND, 5);
581 wxFlexGridSizer* fgSizer5;
582 fgSizer5 =
new wxFlexGridSizer(0, 2, 0, 0);
583 fgSizer5->SetFlexibleDirection(wxBOTH);
584 fgSizer5->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
585 sbSizerConnectionProps->Add(fgSizer5, 0, wxEXPAND, 5);
588 new wxCheckBox(m_scrolledwin, wxID_ANY, _(
"Receive Input on this Port"),
589 wxDefaultPosition, wxDefaultSize, 0);
590 fgSizer5->Add(m_cbInput, 0, wxALL, 2);
591 fgSizer5->AddSpacer(1);
594 new wxCheckBox(m_scrolledwin, wxID_ANY,
595 wxString::Format(
"%s (%s)", _(
"Output on this port"),
596 _(
"as autopilot or NMEA repeater")),
597 wxDefaultPosition, wxDefaultSize, 0);
598 fgSizer5->Add(m_cbOutput, 0, wxALL, 2);
599 fgSizer5->AddSpacer(1);
603 m_stAuthToken =
new wxStaticText(m_scrolledwin, wxID_ANY, _(
"Auth Token"),
604 wxDefaultPosition, wxDefaultSize, 0);
605 m_stAuthToken->SetMinSize(wxSize(column1width, -1));
606 m_stAuthToken->Wrap(-1);
607 fgSizer5->Add(m_stAuthToken, 0, wxALL, 5);
608 m_stAuthToken->Hide();
610 m_tAuthToken =
new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString,
611 wxDefaultPosition, wxDefaultSize, 0);
612 m_tAuthToken->SetMinSize(wxSize(column2width, -1));
613 fgSizer5->Add(m_tAuthToken, 1, wxEXPAND | wxTOP, 5);
615 m_tAuthToken->Hide();
617 m_cbCheckCRC =
new wxCheckBox(m_scrolledwin, wxID_ANY, _(
"Control checksum"),
618 wxDefaultPosition, wxDefaultSize, 0);
619 m_cbCheckCRC->SetValue(TRUE);
620 m_cbCheckCRC->SetToolTip(
621 _(
"If checked, only the sentences with a valid checksum are passed "
623 fgSizer5->Add(m_cbCheckCRC, 0, wxALL, 2);
624 fgSizer5->AddSpacer(1);
626 m_cbGarminHost =
new wxCheckBox(m_scrolledwin, wxID_ANY,
627 _(
"Use Garmin (GRMN) mode for input"),
628 wxDefaultPosition, wxDefaultSize, 0);
629 m_cbGarminHost->SetValue(FALSE);
630 fgSizer5->Add(m_cbGarminHost, 0, wxALL, 2);
631 fgSizer5->AddSpacer(1);
633 #ifndef USE_GARMINHOST
634 m_cbGarminHost->Hide();
637 m_cbMultiCast =
new wxCheckBox(m_scrolledwin, wxID_ANY, _(
" UDP Multicast"),
638 wxDefaultPosition, wxDefaultSize, 0);
639 m_cbMultiCast->SetValue(FALSE);
642 fgSizer5->Add(m_cbMultiCast, 0, wxALL, 2);
643 fgSizer5->AddSpacer(1);
646 new wxStaticText(m_scrolledwin, wxID_ANY, _(
"APB bearing precision"),
647 wxDefaultPosition, wxDefaultSize, 0);
649 m_stPrecision->Wrap(-1);
650 fgSizer5->Add(m_stPrecision, 0, wxALL, 2);
652 wxString m_choicePrecisionChoices[] = {_(
"x"), _(
"x.x"), _(
"x.xx"),
653 _(
"x.xxx"), _(
"x.xxxx")};
654 int m_choicePrecisionNChoices =
655 sizeof(m_choicePrecisionChoices) /
sizeof(wxString);
657 new wxChoice(m_scrolledwin, wxID_ANY, wxDefaultPosition, wxDefaultSize,
658 m_choicePrecisionNChoices, m_choicePrecisionChoices, 0);
662 m_choicePrecision->SetSelection(g_NMEAAPBPrecision);
663 fgSizer5->Add(m_choicePrecision, 0, wxALL, 2);
666 m_cbCheckSKDiscover =
667 new wxCheckBox(m_scrolledwin, wxID_ANY, _(
"Automatic server discovery"),
668 wxDefaultPosition, wxDefaultSize, 0);
669 m_cbCheckSKDiscover->SetValue(TRUE);
670 m_cbCheckSKDiscover->SetToolTip(
671 _(
"If checked, signal K server will be discovered automatically"));
673 fgSizer5->Add(m_cbCheckSKDiscover, 0, wxALL, 2);
677 new wxButton(m_scrolledwin, wxID_ANY, _(
"Discover now..."),
678 wxDefaultPosition, wxDefaultSize, 0);
679 m_ButtonSKDiscover->Hide();
680 fgSizer5->Add(m_ButtonSKDiscover, 0, wxALL, 2);
683 m_StaticTextSKServerStatus =
new wxStaticText(
684 m_scrolledwin, wxID_ANY,
"", wxDefaultPosition, wxDefaultSize, 0);
685 fgSizer5->Add(m_StaticTextSKServerStatus, 0, wxALL, 2);
687 sbSizerInFilter =
new wxStaticBoxSizer(
688 new wxStaticBox(m_scrolledwin, wxID_ANY, _(
"Input filtering")),
690 sbSizerConnectionProps->Add(sbSizerInFilter,
691 wxSizerFlags().Expand().Border());
694 bSizer9 =
new wxBoxSizer(wxHORIZONTAL);
697 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Accept only sentences"),
698 wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
699 bSizer9->Add(m_rbIAccept, 0, wxALL, 5);
702 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Ignore sentences"),
703 wxDefaultPosition, wxDefaultSize, 0);
704 bSizer9->Add(m_rbIIgnore, 0, wxALL, 5);
706 sbSizerInFilter->Add(bSizer9, 0, wxEXPAND, 5);
708 wxBoxSizer* bSizer11;
709 bSizer11 =
new wxBoxSizer(wxHORIZONTAL);
710 sbSizerInFilter->Add(bSizer11, 0, wxEXPAND, 5);
713 new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString, wxDefaultPosition,
714 wxDefaultSize, wxTE_READONLY);
715 bSizer11->Add(m_tcInputStc, 1, wxALL | wxEXPAND, 5);
718 new wxButton(m_scrolledwin, wxID_ANY,
"...", wxDefaultPosition,
719 wxDefaultSize, wxBU_EXACTFIT);
720 bSizer11->Add(m_btnInputStcList, 0, wxALL, 5);
722 bSizer11->AddSpacer(GetCharWidth() * 5);
724 sbSizerOutFilter =
new wxStaticBoxSizer(
725 new wxStaticBox(m_scrolledwin, wxID_ANY, _(
"Output filtering")),
727 sbSizerConnectionProps->Add(sbSizerOutFilter, 0, wxEXPAND, 5);
729 wxBoxSizer* bSizer10;
730 bSizer10 =
new wxBoxSizer(wxHORIZONTAL);
733 new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Transmit sentences"),
734 wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
735 bSizer10->Add(m_rbOAccept, 0, wxALL, 5);
737 m_rbOIgnore =
new wxRadioButton(m_scrolledwin, wxID_ANY, _(
"Drop sentences"),
738 wxDefaultPosition, wxDefaultSize, 0);
739 bSizer10->Add(m_rbOIgnore, 0, wxALL, 5);
741 sbSizerOutFilter->Add(bSizer10, 0, wxEXPAND, 5);
743 wxBoxSizer* bSizer12;
744 bSizer12 =
new wxBoxSizer(wxHORIZONTAL);
745 sbSizerOutFilter->Add(bSizer12, 0, wxEXPAND, 5);
748 new wxTextCtrl(m_scrolledwin, wxID_ANY, wxEmptyString, wxDefaultPosition,
749 wxDefaultSize, wxTE_READONLY);
750 bSizer12->Add(m_tcOutputStc, 1, wxALL | wxEXPAND, 5);
753 new wxButton(m_scrolledwin, wxID_ANY,
"...", wxDefaultPosition,
754 wxDefaultSize, wxBU_EXACTFIT);
755 bSizer12->Add(m_btnOutputStcList, 0, wxALL, 5);
757 bSizer12->AddSpacer(GetCharWidth() * 5);
759 sbSizerConnectionProps->AddSpacer(20);
761 m_more =
new wxStaticText(m_scrolledwin, wxID_ANY,
"4 chars",
762 wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
763 m_more->SetLabelMarkup(MORE);
764 sbSizerConnectionProps->Add(m_more, wxSizerFlags().Border());
768 SetInitialSettings();
772 ShowNMEACommon(
true);
773 ShowNMEASerial(
true);
776 connectionsaved = TRUE;
778 GetSizer()->Fit(m_scrolledwin);
780 new_device_listener.
Init(SystemEvents::GetInstance().evt_dev_change,
781 [&](
ObservedEvt&) { LoadSerialPorts(m_comboPort); });
788 void ConnectionEditDialog::SetSelectedConnectionPanel(
793 if (mSelectedConnection && mSelectedConnection->m_optionsPanel)
794 mSelectedConnection->m_optionsPanel->SetSelected(
false);
797 mSelectedConnection = panel->m_pConnectionParams;
798 panel->SetSelected(
true);
799 SetConnectionParams(mSelectedConnection);
800 m_buttonRemove->Enable();
801 m_buttonRemove->Show();
802 m_buttonAdd->Disable();
803 m_sbConnEdit->SetLabel(_(
"Edit Selected Connection"));
806 mSelectedConnection = NULL;
807 m_buttonRemove->Disable();
808 m_buttonAdd->Enable();
810 m_sbConnEdit->SetLabel(
"");
820 void ConnectionEditDialog::SetPropsLabel(wxString label) {
821 m_sbConnEdit->SetLabel(label);
827 conn->bEnabled = value;
828 conn->b_IsSetup = FALSE;
829 m_connection_enabled = conn->bEnabled;
834 void ConnectionEditDialog::OnValChange(wxCommandEvent& event) {
event.Skip(); }
836 void ConnectionEditDialog::OnScanBTClick(wxCommandEvent& event) {
840 m_btNoChangeCounter = 0;
841 m_btlastResultCount = 0;
843 m_BTScanTimer.Start(1000, wxTIMER_CONTINUOUS);
844 g_Platform->startBluetoothScan();
846 if (m_buttonScanBT) {
847 m_buttonScanBT->SetLabel(_(
"Stop Scan"));
852 void ConnectionEditDialog::onBTScanTimer(wxTimerEvent& event) {
856 m_BTscan_results = g_Platform->getBluetoothScanResults();
858 m_choiceBTDataSources->Clear();
859 m_choiceBTDataSources->Append(m_BTscan_results[0]);
862 while ((i + 1) < m_BTscan_results.GetCount()) {
863 wxString item1 = m_BTscan_results[i] +
";";
864 wxString item2 = m_BTscan_results.Item(i + 1);
865 m_choiceBTDataSources->Append(item1 + item2);
870 if (m_BTscan_results.GetCount() > 1) {
871 m_choiceBTDataSources->SetSelection(1);
875 if (m_btNoChangeCounter > 5) StopBTScan();
877 if ((
int)m_BTscan_results.GetCount() == m_btlastResultCount)
878 m_btNoChangeCounter++;
880 m_btNoChangeCounter = 0;
882 m_btlastResultCount = m_BTscan_results.GetCount();
885 if (m_BTscanning >= 15) {
893 void ConnectionEditDialog::StopBTScan(
void) {
894 m_BTScanTimer.Stop();
896 g_Platform->stopBluetoothScan();
900 if (m_buttonScanBT) {
901 m_buttonScanBT->SetLabel(_(
"BT Scan"));
902 m_buttonScanBT->Enable();
906 void ConnectionEditDialog::OnConnValChange(wxCommandEvent& event) {
907 connectionsaved = FALSE;
911 void ConnectionEditDialog::OnTypeSerialSelected(wxCommandEvent& event) {
912 OnConnValChange(event);
913 SetNMEAFormToSerial();
916 void ConnectionEditDialog::OnTypeNetSelected(wxCommandEvent& event) {
917 OnConnValChange(event);
921 void ConnectionEditDialog::OnTypeCANSelected(wxCommandEvent& event) {
922 OnConnValChange(event);
926 void ConnectionEditDialog::OnTypeGPSSelected(wxCommandEvent& event) {
927 OnConnValChange(event);
931 void ConnectionEditDialog::OnTypeBTSelected(wxCommandEvent& event) {
932 OnConnValChange(event);
936 void ConnectionEditDialog::OnUploadFormatChange(wxCommandEvent& event) {
937 if (event.GetEventObject() == m_cbGarminUploadHost && event.IsChecked())
938 m_cbFurunoGP3X->SetValue(FALSE);
939 else if (event.GetEventObject() == m_cbFurunoGP3X && event.IsChecked())
940 m_cbGarminUploadHost->SetValue(FALSE);
942 OnConnValChange(event);
947 void ConnectionEditDialog::ShowTypeCommon(
bool visible) {
948 m_rbTypeSerial->Show(visible);
949 m_rbTypeNet->Show(visible);
950 #if defined(__linux__) && !defined(__ANDROID__) && !defined(__WXOSX__)
951 m_rbTypeCAN->Show(visible);
953 if (m_rbTypeInternalGPS) m_rbTypeInternalGPS->Show(visible);
954 if (m_rbTypeInternalBT) m_rbTypeInternalBT->Show(visible);
957 void ConnectionEditDialog::ShowNMEACommon(
bool visible) {
958 bool advanced = m_advanced;
959 m_cbInput->Show(visible);
960 m_cbOutput->Show(visible);
961 m_stPrecision->Show(visible && advanced);
962 m_choicePrecision->Show(visible && advanced);
963 m_stPrecision->Show(visible && advanced);
964 m_cbCheckCRC->Show(visible && advanced);
965 m_stAuthToken->Show(visible && advanced);
966 m_tAuthToken->Show(visible && advanced);
968 const bool bout_enable = (m_cbOutput->IsChecked() && advanced);
969 m_stPrecision->Enable(bout_enable);
970 m_choicePrecision->Enable(bout_enable);
972 sbSizerOutFilter->SetDimension(0, 0, 0, 0);
973 sbSizerInFilter->SetDimension(0, 0, 0, 0);
974 sbSizerConnectionProps->SetDimension(0, 0, 0, 0);
975 m_sbConnEdit->SetLabel(
"");
978 m_cbCheckSKDiscover->Hide();
979 m_ButtonSKDiscover->Hide();
981 const bool bin_enable = (m_cbInput->IsChecked() && advanced);
982 ShowInFilter(visible && bin_enable);
983 const bool bout_enable = (m_cbOutput->IsChecked() && advanced);
984 ShowOutFilter(visible && bout_enable);
986 m_bNMEAParams_shown = visible;
989 void ConnectionEditDialog::ShowNMEANet(
bool visible) {
990 bool advanced = m_advanced;
991 m_stNetAddr->Show(visible);
992 m_tNetAddress->Show(visible);
993 m_stNetDataProtocol->Show(visible);
994 m_stNetPort->Show(visible);
995 m_choiceNetDataProtocol->Show(visible);
996 m_tNetPort->Show(visible);
997 m_stNetProto->Show(visible);
998 m_rbNetProtoSignalK->Show(visible);
999 m_rbNetProtoGPSD->Show(visible);
1000 m_rbNetProtoTCP->Show(visible);
1001 m_rbNetProtoUDP->Show(visible);
1002 m_stNetComment->Show(visible);
1003 m_tNetComment->Show(visible);
1004 m_stAuthToken->Show(visible);
1005 m_tAuthToken->Show(visible);
1006 m_cbGarminHost->Hide();
1009 void ConnectionEditDialog::ShowNMEASerial(
bool visible) {
1010 bool advanced = m_advanced;
1011 m_stSerBaudrate->Show(visible);
1012 m_choiceBaudRate->Show(visible);
1013 m_stSerPort->Show(visible);
1014 m_comboPort->Show(visible);
1015 m_stSerProtocol->Show(visible);
1016 m_choiceSerialProtocol->Show(visible);
1017 m_cbGarminHost->Show(visible && advanced);
1018 m_stSerialComment->Show(visible);
1019 m_tSerialComment->Show(visible);
1022 void ConnectionEditDialog::ShowNMEAGPS(
bool visible) {
1023 m_cbCheckSKDiscover->Hide();
1024 m_ButtonSKDiscover->Hide();
1025 m_stAuthToken->Hide();
1026 m_tAuthToken->Hide();
1030 void ConnectionEditDialog::ShowNMEACAN(
bool visible) {
1031 m_stCANSource->Show(visible);
1032 m_choiceCANSource->Show(visible);
1035 void ConnectionEditDialog::ShowNMEABT(
bool visible) {
1037 if (m_buttonScanBT) m_buttonScanBT->Show();
1038 if (m_stBTPairs) m_stBTPairs->Show();
1039 if (m_choiceBTDataSources) {
1040 if (m_choiceBTDataSources->GetCount() > 1)
1041 m_choiceBTDataSources->SetSelection(1);
1042 m_choiceBTDataSources->Show();
1045 if (m_buttonScanBT) m_buttonScanBT->Hide();
1046 if (m_stBTPairs) m_stBTPairs->Hide();
1047 if (m_choiceBTDataSources) m_choiceBTDataSources->Hide();
1049 m_cbCheckSKDiscover->Hide();
1050 m_stAuthToken->Hide();
1051 m_tAuthToken->Hide();
1052 m_cbCheckSKDiscover->Hide();
1053 m_ButtonSKDiscover->Hide();
1054 m_tcOutputStc->Show(visible);
1055 m_btnOutputStcList->Show(visible);
1056 m_cbOutput->Show(visible);
1059 void ConnectionEditDialog::SetNMEAFormToSerial(
void) {
1060 bool advanced = m_advanced;
1061 ShowNMEACommon(TRUE);
1065 ShowNMEASerial(TRUE);
1067 SetDSFormRWStates();
1071 void ConnectionEditDialog::SetNMEAFormToNet(
void) {
1072 bool advanced = m_advanced;
1073 ShowNMEACommon(TRUE);
1077 ShowNMEASerial(FALSE);
1079 SetUDPNetAddressVisiblity();
1080 SetDSFormRWStates();
1085 void ConnectionEditDialog::SetNMEAFormToCAN(
void) {
1086 bool advanced = m_advanced;
1087 ShowNMEACommon(FALSE);
1091 ShowNMEASerial(FALSE);
1093 sbSizerInFilter->Show(
false);
1094 sbSizerOutFilter->Show(
false);
1095 SetDSFormRWStates();
1100 void ConnectionEditDialog::SetNMEAFormToGPS(
void) {
1101 ShowNMEACommon(TRUE);
1105 ShowNMEASerial(FALSE);
1110 SetDSFormRWStates();
1114 void ConnectionEditDialog::SetNMEAFormToBT(
void) {
1115 m_rbNetProtoUDP->SetValue(
true);
1116 ShowNMEACommon(TRUE);
1120 ShowNMEASerial(FALSE);
1125 SetDSFormRWStates();
1129 void ConnectionEditDialog::ClearNMEAForm(
void) {
1130 ShowNMEACommon(FALSE);
1134 ShowNMEASerial(FALSE);
1141 void ConnectionEditDialog::SetDSFormOptionVizStates(
void) {
1142 bool advanced = m_advanced;
1146 m_cbCheckCRC->Show(advanced);
1147 m_stPrecision->Show(
true);
1148 m_choicePrecision->Show(
true);
1150 ShowInFilter(advanced);
1151 ShowOutFilter(advanced);
1154 m_stAuthToken->Show(advanced);
1155 m_tAuthToken->Show(advanced);
1157 m_StaticTextSKServerStatus->Show(advanced);
1159 if (m_rbTypeSerial->GetValue()) {
1160 m_cbMultiCast->Hide();
1161 m_cbCheckSKDiscover->Hide();
1162 m_stAuthToken->Hide();
1163 m_tAuthToken->Hide();
1164 m_ButtonSKDiscover->Hide();
1165 m_StaticTextSKServerStatus->Hide();
1166 bool n0183ctlenabled =
1167 (DataProtocol)m_choiceSerialProtocol->GetSelection() ==
1168 DataProtocol::PROTO_NMEA0183;
1169 if (!n0183ctlenabled) {
1172 ShowOutFilter(
false);
1173 ShowInFilter(
false);
1174 m_stPrecision->Hide();
1175 m_choicePrecision->Hide();
1176 m_cbCheckCRC->Hide();
1177 m_stNetDataProtocol->Hide();
1178 m_choiceNetDataProtocol->Hide();
1181 m_cbInput->Enable();
1183 ShowInFilter(m_cbInput->IsChecked() && advanced);
1184 ShowOutFilter(m_cbOutput->IsChecked() && advanced);
1186 m_stPrecision->Show(m_cbOutput->IsChecked() && advanced);
1187 m_choicePrecision->Show(m_cbOutput->IsChecked() && advanced);
1189 m_cbGarminHost->Show(m_cbInput->IsChecked() && advanced);
1193 if (m_rbTypeInternalGPS && m_rbTypeInternalGPS->GetValue()) {
1194 m_cbMultiCast->Hide();
1195 m_cbCheckSKDiscover->Hide();
1196 m_stAuthToken->Hide();
1197 m_tAuthToken->Hide();
1198 m_ButtonSKDiscover->Hide();
1199 m_StaticTextSKServerStatus->Hide();
1202 ShowOutFilter(
false);
1203 ShowInFilter(
false);
1204 m_stPrecision->Hide();
1205 m_choicePrecision->Hide();
1206 m_cbCheckCRC->Hide();
1207 m_cbGarminHost->Hide();
1211 if (m_rbTypeInternalBT && m_rbTypeInternalBT->GetValue()) {
1212 m_cbMultiCast->Hide();
1213 m_cbCheckSKDiscover->Hide();
1214 m_stAuthToken->Hide();
1215 m_tAuthToken->Hide();
1216 m_ButtonSKDiscover->Hide();
1217 m_StaticTextSKServerStatus->Hide();
1219 ShowInFilter(m_cbInput->IsChecked() && advanced);
1220 ShowOutFilter(m_cbOutput->IsChecked() && advanced);
1222 m_stPrecision->Show(m_cbOutput->IsChecked() && advanced);
1223 m_choicePrecision->Show(m_cbOutput->IsChecked() && advanced);
1226 if (m_rbTypeCAN->GetValue()) {
1227 m_cbMultiCast->Hide();
1228 m_cbCheckSKDiscover->Hide();
1229 m_stAuthToken->Hide();
1230 m_tAuthToken->Hide();
1231 m_ButtonSKDiscover->Hide();
1232 m_StaticTextSKServerStatus->Hide();
1233 m_cbGarminHost->Hide();
1237 ShowInFilter(
false);
1238 ShowOutFilter(
false);
1240 m_stPrecision->Hide();
1241 m_choicePrecision->Hide();
1242 m_cbCheckCRC->Hide();
1244 m_stNetDataProtocol->Hide();
1245 m_choiceNetDataProtocol->Hide();
1249 if (m_rbTypeNet->GetValue()) {
1250 if (m_rbNetProtoGPSD->GetValue()) {
1251 m_cbMultiCast->Hide();
1252 m_cbCheckSKDiscover->Hide();
1255 ShowInFilter(
false);
1256 ShowOutFilter(
false);
1257 m_cbCheckCRC->Hide();
1258 m_stPrecision->Hide();
1259 m_choicePrecision->Hide();
1260 m_ButtonSKDiscover->Hide();
1261 m_StaticTextSKServerStatus->Hide();
1262 m_stAuthToken->Hide();
1263 m_tAuthToken->Hide();
1264 m_stNetDataProtocol->Hide();
1265 m_choiceNetDataProtocol->Hide();
1266 m_cbGarminHost->Hide();
1269 }
else if (m_rbNetProtoSignalK->GetValue()) {
1270 m_cbMultiCast->Hide();
1273 ShowInFilter(
false);
1274 ShowOutFilter(
false);
1275 m_cbCheckCRC->Hide();
1276 m_stPrecision->Hide();
1277 m_choicePrecision->Hide();
1278 m_stNetDataProtocol->Hide();
1279 m_choiceNetDataProtocol->Hide();
1280 m_cbGarminHost->Hide();
1283 m_stAuthToken->Hide();
1284 m_tAuthToken->Hide();
1285 m_cbCheckSKDiscover->Hide();
1286 m_ButtonSKDiscover->Hide();
1287 m_StaticTextSKServerStatus->Hide();
1288 m_stNetDataProtocol->Show();
1289 m_choiceNetDataProtocol->Show();
1290 m_cbGarminHost->Hide();
1294 if ((DataProtocol)m_choiceNetDataProtocol->GetSelection() ==
1295 DataProtocol::PROTO_NMEA2000) {
1296 m_cbCheckCRC->Hide();
1297 m_stPrecision->Hide();
1298 m_choicePrecision->Hide();
1300 ShowInFilter(
false);
1301 ShowOutFilter(
false);
1302 if (m_rbNetProtoTCP->GetValue()) m_more->Hide();
1304 if ((DataProtocol)m_choiceNetDataProtocol->GetSelection() ==
1305 DataProtocol::PROTO_NMEA0183) {
1306 m_stPrecision->Show(advanced);
1307 m_choicePrecision->Show(advanced);
1308 m_stPrecision->Enable(m_cbOutput->IsChecked() && advanced);
1309 m_choicePrecision->Enable(m_cbOutput->IsChecked() && advanced);
1311 ShowInFilter(m_cbInput->IsChecked() && advanced);
1312 ShowOutFilter(m_cbOutput->IsChecked() && advanced);
1318 void ConnectionEditDialog::SetDSFormRWStates(
void) {
1319 if (m_rbTypeSerial->GetValue()) {
1320 m_cbInput->Enable(FALSE);
1321 m_cbOutput->Enable(TRUE);
1323 ShowOutFilter(m_cbOutput->IsChecked());
1324 }
else if (m_rbNetProtoGPSD->GetValue()) {
1325 if (m_tNetPort->GetValue() == wxEmptyString)
1326 m_tNetPort->SetValue(DEFAULT_GPSD_PORT);
1327 m_cbInput->SetValue(TRUE);
1328 m_cbInput->Enable(FALSE);
1330 m_cbOutput->Enable(FALSE);
1331 m_rbOAccept->Enable(FALSE);
1332 m_rbOIgnore->Enable(FALSE);
1333 m_btnOutputStcList->Enable(FALSE);
1334 }
else if (m_rbNetProtoSignalK->GetValue()) {
1335 if (m_tNetPort->GetValue() == wxEmptyString)
1336 m_tNetPort->SetValue(DEFAULT_SIGNALK_PORT);
1337 m_cbInput->SetValue(TRUE);
1338 m_cbInput->Enable(FALSE);
1340 m_cbOutput->Enable(FALSE);
1341 m_rbOAccept->Enable(FALSE);
1342 m_rbOIgnore->Enable(FALSE);
1343 UpdateDiscoverStatus(wxEmptyString);
1345 if (m_tNetPort->GetValue() == wxEmptyString) {
1346 if (m_rbNetProtoTCP->GetValue()) {
1347 m_tNetPort->SetValue(DEFAULT_TCP_PORT);
1349 m_tNetPort->SetValue(DEFAULT_UDP_PORT);
1352 m_cbInput->Enable(TRUE);
1353 m_cbOutput->Enable(TRUE);
1354 m_rbOAccept->Enable(TRUE);
1355 m_rbOIgnore->Enable(TRUE);
1356 m_btnOutputStcList->Enable(TRUE);
1359 SetDSFormOptionVizStates();
1363 void ConnectionEditDialog::ShowInFilter(
bool bshow) {
1364 sbSizerInFilter->GetStaticBox()->Show(bshow);
1365 m_rbIAccept->Show(bshow);
1366 m_rbIIgnore->Show(bshow);
1367 m_tcInputStc->Show(bshow);
1368 m_btnInputStcList->Show(bshow);
1371 void ConnectionEditDialog::ShowOutFilter(
bool bshow) {
1372 sbSizerOutFilter->GetStaticBox()->Show(bshow);
1373 m_rbOAccept->Show(bshow);
1374 m_rbOIgnore->Show(bshow);
1375 m_tcOutputStc->Show(bshow);
1376 m_btnOutputStcList->Show(bshow);
1380 SetConnectionParams(cp);
1384 if (wxNOT_FOUND == m_comboPort->FindString(cp->Port))
1385 m_comboPort->Append(cp->Port);
1387 m_comboPort->Select(m_comboPort->FindString(cp->Port));
1389 m_cbCheckCRC->SetValue(cp->ChecksumCheck);
1390 m_cbGarminHost->SetValue(cp->Garmin);
1391 m_cbInput->SetValue(cp->IOSelect != DS_TYPE_OUTPUT);
1392 m_cbOutput->SetValue(cp->IOSelect != DS_TYPE_INPUT);
1393 m_cbCheckSKDiscover->SetValue(cp->AutoSKDiscover);
1395 if (cp->InputSentenceListType == WHITELIST)
1396 m_rbIAccept->SetValue(TRUE);
1398 m_rbIIgnore->SetValue(TRUE);
1399 if (cp->OutputSentenceListType == WHITELIST)
1400 m_rbOAccept->SetValue(TRUE);
1402 m_rbOIgnore->SetValue(TRUE);
1403 m_tcInputStc->SetValue(StringArrayToString(cp->InputSentenceList));
1404 m_tcOutputStc->SetValue(StringArrayToString(cp->OutputSentenceList));
1405 m_choiceBaudRate->Select(
1406 m_choiceBaudRate->FindString(wxString::Format(
"%d", cp->Baudrate)));
1407 m_choiceSerialProtocol->Select(cp->Protocol);
1408 m_choicePriority->Select(
1409 m_choicePriority->FindString(wxString::Format(
"%d", cp->Priority)));
1410 m_tNetAddress->SetValue(cp->NetworkAddress);
1412 m_choiceNetDataProtocol->Select(cp->Protocol);
1414 m_cbMultiCast->SetValue(IsAddressMultiCast(m_tNetAddress->GetValue()));
1416 if (cp->NetworkPort == 0)
1417 m_tNetPort->SetValue(wxEmptyString);
1419 m_tNetPort->SetValue(wxString::Format(wxT(
"%i"), cp->NetworkPort));
1421 if (cp->NetProtocol == TCP)
1422 m_rbNetProtoTCP->SetValue(TRUE);
1423 else if (cp->NetProtocol == UDP)
1424 m_rbNetProtoUDP->SetValue(TRUE);
1425 else if (cp->NetProtocol == GPSD)
1426 m_rbNetProtoGPSD->SetValue(TRUE);
1427 else if (cp->NetProtocol == SIGNALK)
1428 m_rbNetProtoSignalK->SetValue(TRUE);
1430 m_rbNetProtoGPSD->SetValue(TRUE);
1432 if (cp->Type == SERIAL) {
1433 m_rbTypeSerial->SetValue(TRUE);
1434 SetNMEAFormToSerial();
1435 SetNMEAFormForSerialProtocol();
1436 }
else if (cp->Type == NETWORK) {
1437 m_rbTypeNet->SetValue(TRUE);
1439 }
else if (cp->Type == SOCKETCAN) {
1440 m_rbTypeCAN->SetValue(TRUE);
1443 }
else if (cp->Type == INTERNAL_GPS) {
1444 if (m_rbTypeInternalGPS) m_rbTypeInternalGPS->SetValue(TRUE);
1446 }
else if (cp->Type == INTERNAL_BT) {
1447 if (m_rbTypeInternalBT) m_rbTypeInternalBT->SetValue(TRUE);
1451 wxString bts = cp->NetworkAddress +
";" + cp->GetPortStr();
1452 m_choiceBTDataSources->Clear();
1453 m_choiceBTDataSources->Append(bts);
1454 m_choiceBTDataSources->SetSelection(0);
1458 if (cp->Type == SERIAL)
1459 m_tSerialComment->SetValue(cp->UserComment);
1460 else if (cp->Type == NETWORK)
1461 m_tNetComment->SetValue(cp->UserComment);
1463 m_tAuthToken->SetValue(cp->AuthToken);
1465 m_connection_enabled = cp->bEnabled;
1468 connectionsaved =
true;
1471 void ConnectionEditDialog::SetUDPNetAddressVisiblity(
void) {
1472 if (m_rbNetProtoUDP->GetValue() && !m_cbMultiCast->IsChecked() &&
1473 !m_cbOutput->IsChecked()) {
1476 m_tNetAddress->Enable(TRUE);
1478 m_stNetAddr->Show(TRUE);
1479 m_tNetAddress->Show(TRUE);
1480 m_tNetAddress->Enable(TRUE);
1482 if (!m_rbNetProtoUDP->GetValue()) {
1483 m_stNetAddr->Show(TRUE);
1484 m_tNetAddress->Show(TRUE);
1485 m_tNetAddress->Enable(TRUE);
1487 if (m_rbNetProtoUDP->GetValue() && m_advanced) {
1490 m_cbMultiCast->Hide();
1493 void ConnectionEditDialog::SetDefaultConnectionParams(
void) {
1494 if (m_comboPort && !m_comboPort->IsListEmpty()) {
1495 m_comboPort->Select(0);
1496 m_comboPort->SetValue(wxEmptyString);
1498 m_cbCheckCRC->SetValue(TRUE);
1499 m_cbGarminHost->SetValue(FALSE);
1500 m_cbInput->SetValue(TRUE);
1501 m_cbOutput->SetValue(FALSE);
1502 m_rbIAccept->SetValue(TRUE);
1503 m_rbOAccept->SetValue(TRUE);
1504 m_tcInputStc->SetValue(wxEmptyString);
1505 m_tcOutputStc->SetValue(wxEmptyString);
1506 m_choiceBaudRate->Select(m_choiceBaudRate->FindString(
"4800"));
1508 m_choicePriority->Select(m_choicePriority->FindString(
"1"));
1510 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1512 m_tNetComment->SetValue(wxEmptyString);
1513 m_tSerialComment->SetValue(wxEmptyString);
1514 m_tAuthToken->SetValue(wxEmptyString);
1516 bool bserial = TRUE;
1526 if (m_rbTypeInternalGPS) {
1527 m_rbTypeInternalGPS->SetValue(
true);
1530 m_rbTypeNet->SetValue(
true);
1535 m_rbTypeSerial->SetValue(bserial);
1536 m_rbTypeNet->SetValue(!bserial);
1537 bserial ? SetNMEAFormToSerial() : SetNMEAFormToNet();
1538 m_rbTypeCAN->SetValue(FALSE);
1541 m_connection_enabled = TRUE;
1544 connectionsaved =
false;
1547 bool ConnectionEditDialog::SortSourceList(
void) {
1548 if (TheConnectionParams()->Count() < 2)
return false;
1550 std::vector<int> ivec;
1551 for (
size_t i = 0; i < TheConnectionParams()->Count(); i++) ivec.push_back(i);
1553 bool did_sort =
false;
1554 bool did_swap =
true;
1557 for (
size_t j = 1; j < ivec.size(); j++) {
1561 if (c1->Priority > c2->Priority) {
1562 int t = ivec[j - 1];
1563 ivec[j - 1] = ivec[j];
1573 boxSizerConnections =
new wxBoxSizer(wxVERTICAL);
1574 m_scrollWinConnections->SetSizer(boxSizerConnections);
1576 for (
size_t i = 0; i < ivec.size(); i++) {
1578 TheConnectionParams()->Item(ivec[i])->m_optionsPanel;
1579 boxSizerConnections->Add(pPanel, 0, wxEXPAND | wxALL, 0);
1586 void ConnectionEditDialog::LayoutDialog() {
1587 gSizerNetProps->Layout();
1588 gSizerSerProps->Layout();
1589 m_scrolledwin->Layout();
1590 m_scrolledwin->Fit();
1591 GetSizer()->Layout();
1594 void ConnectionEditDialog::UpdateSourceList(
bool bResort) {
1595 for (
size_t i = 0; i < TheConnectionParams()->Count(); i++) {
1598 if (panel) panel->Update(TheConnectionParams()->Item(i));
1605 m_scrollWinConnections->Layout();
1608 void ConnectionEditDialog::OnSelectDatasource(wxListEvent& event) {
1609 SetConnectionParams(TheConnectionParams()->Item(event.GetData()));
1610 m_buttonRemove->Enable();
1611 m_buttonRemove->Show();
1615 void ConnectionEditDialog::OnDiscoverButton(wxCommandEvent& event) {
1619 std::string serviceIdent =
1620 std::string(
"_signalk-ws._tcp.local.");
1622 g_Platform->ShowBusySpinner();
1624 if (SignalKDataStream::DiscoverSKServer(serviceIdent, ip, port,
1627 m_tNetAddress->SetValue(ip);
1628 m_tNetPort->SetValue(wxString::Format(wxT(
"%i"), port));
1629 UpdateDiscoverStatus(_(
"Signal K server available."));
1631 UpdateDiscoverStatus(_(
"Signal K server not found."));
1633 g_Platform->HideBusySpinner();
1638 void ConnectionEditDialog::UpdateDiscoverStatus(wxString stat) {
1639 m_StaticTextSKServerStatus->SetLabel(stat);
1642 void ConnectionEditDialog::OnBtnIStcs(wxCommandEvent& event) {
1643 const ListType type = m_rbIAccept->GetValue() ? WHITELIST : BLACKLIST;
1644 const wxArrayString list = wxStringTokenize(m_tcInputStc->GetValue(),
",");
1647 if (dlg.ShowModal() == wxID_OK) m_tcInputStc->SetValue(dlg.GetSentences());
1650 void ConnectionEditDialog::OnBtnOStcs(wxCommandEvent& event) {
1651 const ListType type = m_rbOAccept->GetValue() ? WHITELIST : BLACKLIST;
1652 const wxArrayString list = wxStringTokenize(m_tcOutputStc->GetValue(),
",");
1655 if (dlg.ShowModal() == wxID_OK) m_tcOutputStc->SetValue(dlg.GetSentences());
1658 void ConnectionEditDialog::OnNetProtocolSelected(wxCommandEvent& event) {
1659 if (m_rbNetProtoGPSD->GetValue()) {
1660 if (IsDefaultPort(m_tNetPort->GetValue())) {
1661 m_tNetPort->SetValue(DEFAULT_GPSD_PORT);
1663 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1664 }
else if (m_rbNetProtoUDP->GetValue()) {
1665 if (IsDefaultPort(m_tNetPort->GetValue())) {
1666 m_tNetPort->SetValue(DEFAULT_UDP_PORT);
1668 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1669 if (m_cbInput->GetValue() && !m_cbMultiCast->GetValue() &&
1670 m_rbNetProtoUDP->GetValue())
1671 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1672 else if (m_cbOutput->GetValue() && !m_cbMultiCast->GetValue())
1673 m_tNetPort->SetValue(DEFAULT_UDP_OUT_ADDRESS);
1675 if (m_cbInput->GetValue() && m_cbOutput->GetValue())
1676 m_cbOutput->SetValue(
false);
1678 }
else if (m_rbNetProtoSignalK->GetValue()) {
1679 if (IsDefaultPort(m_tNetPort->GetValue())) {
1680 m_tNetPort->SetValue(DEFAULT_SIGNALK_PORT);
1682 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1683 }
else if (m_rbNetProtoTCP->GetValue()) {
1684 if (IsDefaultPort(m_tNetPort->GetValue())) {
1685 m_tNetPort->SetValue(DEFAULT_TCP_PORT);
1687 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1690 SetUDPNetAddressVisiblity();
1691 SetDSFormRWStates();
1693 OnConnValChange(event);
1696 void ConnectionEditDialog::OnRbAcceptInput(wxCommandEvent& event) {
1697 OnConnValChange(event);
1699 void ConnectionEditDialog::OnRbIgnoreInput(wxCommandEvent& event) {
1700 OnConnValChange(event);
1703 void ConnectionEditDialog::OnRbOutput(wxCommandEvent& event) {
1704 OnConnValChange(event);
1707 void ConnectionEditDialog::OnCbInput(wxCommandEvent& event) {
1708 const bool checked = m_cbInput->IsChecked();
1709 ShowInFilter(checked);
1710 if (checked && m_rbNetProtoUDP->GetValue() && m_rbTypeNet->GetValue()) {
1711 m_cbOutput->SetValue(FALSE);
1713 if (!m_cbMultiCast->GetValue()) m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1715 SetDSFormRWStates();
1717 if (m_rbTypeNet->GetValue()) SetUDPNetAddressVisiblity();
1718 OnConnValChange(event);
1721 void ConnectionEditDialog::OnCbOutput(wxCommandEvent& event) {
1722 OnConnValChange(event);
1723 const bool checked = m_cbOutput->IsChecked();
1724 m_stPrecision->Enable(checked);
1725 m_choicePrecision->Enable(checked);
1726 ShowOutFilter(checked);
1728 if (!m_cbMultiCast->IsChecked() && m_rbNetProtoUDP->GetValue()) {
1730 m_tNetAddress->SetValue(
1731 DEFAULT_UDP_OUT_ADDRESS);
1733 NetworkProtocol proto = UDP;
1734 for (
size_t i = 0; i < TheConnectionParams()->Count(); i++) {
1736 if (cp->NetProtocol == proto &&
1737 cp->NetworkPort == wxAtoi(m_tNetPort->GetValue()) &&
1738 cp->IOSelect == DS_TYPE_INPUT) {
1741 m_more->SetLabelMarkup(m_advanced ? LESS : MORE);
1742 SetNMEAFormForNetProtocol();
1748 mes = _(
"There is an enabled UDP input connection that uses the "
1751 << _(
"Please apply a filter on both connections to avoid a "
1756 mes = _(
"There is a disabled UDP Input connection that uses the "
1760 << _(
"If you enable that input please apply a filter on both "
1761 "connections to avoid a feedback loop.");
1764 << _(
"Or consider using a different data port for one of them");
1766 OCPNMessageBox(
this, mes, _(
"OpenCPN Warning"),
1767 wxOK | wxICON_EXCLAMATION, 60);
1769 OCPNMessageBox(
this, mes, _(
"OpenCPN info"),
1770 wxOK | wxICON_INFORMATION, 60);
1775 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1779 if (checked && m_rbNetProtoUDP->GetValue()) {
1780 m_cbInput->SetValue(FALSE);
1783 if (m_rbTypeNet->GetValue()) SetUDPNetAddressVisiblity();
1784 SetDSFormRWStates();
1788 void ConnectionEditDialog::OnCbMultiCast(wxCommandEvent& event) {
1789 const bool checked = m_cbMultiCast->IsChecked();
1791 if (!IsAddressMultiCast(m_tNetAddress->GetValue())) {
1792 m_tNetAddress->SetValue(
"224.0.2.21");
1794 }
else if (m_cbOutput->IsChecked()) {
1795 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1797 m_tNetAddress->SetValue(DEFAULT_IP_ADDRESS);
1800 SetUDPNetAddressVisiblity();
1804 void ConnectionEditDialog::OnClickMore(wxMouseEvent& event) {
1806 m_advanced = !m_advanced;
1807 m_more->SetLabelMarkup(m_advanced ? LESS : MORE);
1808 if (m_rbTypeNet->GetValue())
1809 SetNMEAFormForNetProtocol();
1811 SetNMEAFormForSerialProtocol();
1815 void ConnectionEditDialog::OnCbAdvanced(wxCommandEvent& event) {
1816 if (m_rbTypeNet->GetValue())
1817 SetNMEAFormForNetProtocol();
1819 SetNMEAFormForSerialProtocol();
1823 void ConnectionEditDialog::OnShowGpsWindowCheckboxClick(wxCommandEvent& event) {
1824 if (!m_cbNMEADebug->GetValue()) {
1825 NMEALogWindow::GetInstance().DestroyWindow();
1827 NMEALogWindow::GetInstance().Create((wxWindow*)(m_parent->pParent), 35);
1830 wxRect logRect(NMEALogWindow::GetInstance().GetPosX(),
1831 NMEALogWindow::GetInstance().GetPosY(),
1832 NMEALogWindow::GetInstance().GetSizeW(),
1833 NMEALogWindow::GetInstance().GetSizeH());
1836 if (m_container->GetRect().Contains(logRect)) {
1837 NMEALogWindow::Get().SetPos(
1838 m_container->GetRect().x / 2,
1839 (m_container->GetRect().y +
1840 (m_container->GetRect().height - logRect.height) / 2));
1841 NMEALogWindow::Get().Move();
1847 void ConnectionEditDialog::SetNMEAFormForSerialProtocol() {
1848 bool n0183ctlenabled = (DataProtocol)m_choiceSerialProtocol->GetSelection() ==
1849 DataProtocol::PROTO_NMEA0183;
1850 bool advanced = m_advanced;
1851 ShowNMEACommon(n0183ctlenabled && advanced);
1852 m_cbGarminHost->Show(n0183ctlenabled && advanced);
1853 m_stPriority->Show(
true);
1854 m_choicePriority->Show(
true);
1856 SetDSFormRWStates();
1860 void ConnectionEditDialog::SetNMEAFormForNetProtocol() {
1861 bool n0183ctlenabled =
1862 (DataProtocol)m_choiceNetDataProtocol->GetSelection() ==
1863 DataProtocol::PROTO_NMEA0183;
1864 bool advanced = m_advanced;
1865 ShowNMEACommon(n0183ctlenabled && advanced);
1866 m_cbGarminHost->Show(n0183ctlenabled && advanced);
1867 m_stPriority->Show(
true);
1868 m_choicePriority->Show(
true);
1870 SetDSFormRWStates();
1875 void ConnectionEditDialog::OnProtocolChoice(wxCommandEvent& event) {
1876 if (m_rbTypeNet->GetValue())
1877 SetNMEAFormForNetProtocol();
1879 SetNMEAFormForSerialProtocol();
1881 OnConnValChange(event);
1884 void ConnectionEditDialog::ApplySettings() {
1886 g_bfilter_cogsog = m_cbFilterSogCog->GetValue();
1888 long filter_val = 1;
1889 m_tFilterSec->GetValue().ToLong(&filter_val);
1891 wxMin(
static_cast<int>(filter_val),
1893 g_COGFilterSec = wxMax(g_COGFilterSec, 1);
1894 g_SOGFilterSec = g_COGFilterSec;
1896 g_bMagneticAPB = m_cbAPBMagnetic->GetValue();
1897 g_NMEAAPBPrecision = m_choicePrecision->GetCurrentSelection();
1904 NetworkProtocol lastNetProtocol = PROTO_UNDEFINED;
1905 DataProtocol lastDataProtocol = PROTO_NMEA0183;
1907 if (mSelectedConnection) {
1909 lastAddr = cpo->NetworkAddress;
1910 lastPort = cpo->NetworkPort;
1911 lastNetProtocol = cpo->NetProtocol;
1912 lastDataProtocol = cpo->Protocol;
1915 if (!connectionsaved) {
1916 size_t nCurrentPanelCount = TheConnectionParams()->GetCount();
1918 int old_priority = -1;
1920 if (mSelectedConnection) {
1921 cp = mSelectedConnection;
1922 old_priority = cp->Priority;
1923 UpdateConnectionParamsFromControls(cp);
1924 cp->b_IsSetup =
false;
1936 cp = CreateConnectionParamsFromSelectedItem();
1937 if (cp) TheConnectionParams()->Add(cp);
1942 cp->LastNetProtocol = lastNetProtocol;
1943 cp->LastNetworkAddress = lastAddr;
1944 cp->LastNetworkPort = lastPort;
1945 cp->LastDataProtocol = lastDataProtocol;
1948 if (TheConnectionParams()->GetCount() != nCurrentPanelCount)
1950 else if (old_priority >= 0) {
1951 if (old_priority != cp->Priority)
1952 UpdateSourceList(
true);
1954 UpdateSourceList(
false);
1957 connectionsaved = TRUE;
1964 SetSelectedConnectionPanel(
nullptr);
1968 for (
size_t i = 0; i < TheConnectionParams()->Count(); i++) {
1971 if (cp->b_IsSetup)
continue;
1976 StopAndRemoveCommDriver(cp->GetStrippedDSPort(), cp->GetCommProtocol());
1979 StopAndRemoveCommDriver(cp->GetLastDSPort(), cp->GetLastCommProtocol());
1983 if (cp->Type == INTERNAL_BT) wxSleep(1);
1986 if (!cp->bEnabled)
continue;
1990 cp->b_IsSetup = TRUE;
1993 g_bGarminHostUpload = m_cbGarminUploadHost->GetValue();
1995 m_cbFurunoGP3X->GetValue() ?
"FurunoGP3X" :
"Generic";
2000 ConnectionEditDialog::CreateConnectionParamsFromSelectedItem() {
2006 if (m_rbTypeSerial->GetValue() && m_comboPort->GetValue() ==
"Deleted")
2013 if (!(m_cbInput->GetValue() || m_cbOutput->GetValue())) {
2014 m_cbInput->SetValue(
true);
2017 if (m_rbTypeSerial->GetValue() && m_comboPort->GetValue() == wxEmptyString) {
2018 m_comboPort->Select(0);
2022 else if (m_rbTypeNet->GetValue()) {
2023 if (wxAtoi(m_tNetPort->GetValue()) == 0) {
2024 m_tNetPort->SetValue(
"10110");
2026 if (m_tNetAddress->GetValue() == wxEmptyString) {
2027 m_tNetAddress->SetValue(
"0.0.0.0");
2029 }
else if (m_rbTypeCAN->GetValue()) {
2034 UpdateConnectionParamsFromSelectedItem(pConnectionParams);
2037 m_scrollWinConnections, wxID_ANY, wxDefaultPosition, wxDefaultSize,
2038 pConnectionParams,
this);
2039 pPanel->SetSelected(
false);
2040 boxSizerConnections->Add(pPanel, 0, wxEXPAND | wxALL, 0);
2041 pConnectionParams->m_optionsPanel = pPanel;
2043 return pConnectionParams;
2050 UpdateConnectionParamsFromControls(pConnectionParams);
2051 return pConnectionParams;
2054 ConnectionParams* ConnectionEditDialog::UpdateConnectionParamsFromControls(
2056 pConnectionParams->Valid = TRUE;
2057 if (m_rbTypeSerial->GetValue())
2058 pConnectionParams->Type = SERIAL;
2059 else if (m_rbTypeNet->GetValue())
2060 pConnectionParams->Type = NETWORK;
2061 else if (m_rbTypeInternalGPS && m_rbTypeInternalGPS->GetValue())
2062 pConnectionParams->Type = INTERNAL_GPS;
2063 else if (m_rbTypeInternalBT && m_rbTypeInternalBT->GetValue())
2064 pConnectionParams->Type = INTERNAL_BT;
2065 else if (m_rbTypeCAN && m_rbTypeCAN->GetValue())
2066 pConnectionParams->Type = SOCKETCAN;
2068 if (m_rbTypeNet->GetValue()) {
2070 pConnectionParams->LastNetworkAddress = pConnectionParams->NetworkAddress;
2071 pConnectionParams->LastNetworkPort = pConnectionParams->NetworkPort;
2072 pConnectionParams->LastNetProtocol = pConnectionParams->NetProtocol;
2073 pConnectionParams->LastDataProtocol = pConnectionParams->Protocol;
2075 pConnectionParams->NetworkAddress =
2076 m_tNetAddress->GetValue().Trim(
false).Trim(
true);
2077 pConnectionParams->NetworkPort =
2078 wxAtoi(m_tNetPort->GetValue().Trim(
false).Trim(
true));
2079 if (m_rbNetProtoTCP->GetValue()) {
2080 pConnectionParams->NetProtocol = TCP;
2081 pConnectionParams->Protocol =
2082 (DataProtocol)m_choiceNetDataProtocol->GetSelection();
2083 }
else if (m_rbNetProtoUDP->GetValue()) {
2084 pConnectionParams->NetProtocol = UDP;
2085 pConnectionParams->Protocol =
2086 (DataProtocol)m_choiceNetDataProtocol->GetSelection();
2087 }
else if (m_rbNetProtoGPSD->GetValue())
2088 pConnectionParams->NetProtocol = GPSD;
2089 else if (m_rbNetProtoSignalK->GetValue())
2090 pConnectionParams->NetProtocol = SIGNALK;
2092 pConnectionParams->NetProtocol = PROTO_UNDEFINED;
2095 if (m_rbTypeSerial->GetValue())
2096 pConnectionParams->Protocol =
2097 (DataProtocol)m_choiceSerialProtocol->GetSelection();
2098 else if (m_rbTypeNet->GetValue())
2099 pConnectionParams->Protocol =
2100 (DataProtocol)m_choiceNetDataProtocol->GetSelection();
2102 pConnectionParams->Baudrate = wxAtoi(m_choiceBaudRate->GetStringSelection());
2103 pConnectionParams->Priority = wxAtoi(m_choicePriority->GetStringSelection());
2104 pConnectionParams->ChecksumCheck = m_cbCheckCRC->GetValue();
2105 pConnectionParams->AutoSKDiscover = m_cbCheckSKDiscover->GetValue();
2106 pConnectionParams->Garmin = m_cbGarminHost->GetValue();
2107 pConnectionParams->InputSentenceList =
2108 wxStringTokenize(m_tcInputStc->GetValue(),
",");
2109 if (m_rbIAccept->GetValue())
2110 pConnectionParams->InputSentenceListType = WHITELIST;
2112 pConnectionParams->InputSentenceListType = BLACKLIST;
2113 if (m_cbInput->GetValue()) {
2114 if (m_cbOutput->GetValue()) {
2115 pConnectionParams->IOSelect = DS_TYPE_INPUT_OUTPUT;
2117 pConnectionParams->IOSelect = DS_TYPE_INPUT;
2120 pConnectionParams->IOSelect = DS_TYPE_OUTPUT;
2122 pConnectionParams->OutputSentenceList =
2123 wxStringTokenize(m_tcOutputStc->GetValue(),
",");
2124 if (m_rbOAccept->GetValue())
2125 pConnectionParams->OutputSentenceListType = WHITELIST;
2127 pConnectionParams->OutputSentenceListType = BLACKLIST;
2128 pConnectionParams->Port = m_comboPort->GetValue().BeforeFirst(
' ');
2129 #if defined(__linux__) && !defined(__ANDROID__)
2130 if (pConnectionParams->Type == SERIAL)
2134 if (m_rbTypeCAN && m_rbTypeCAN->GetValue())
2135 pConnectionParams->Protocol = PROTO_NMEA2000;
2137 pConnectionParams->bEnabled = m_connection_enabled;
2138 pConnectionParams->b_IsSetup = FALSE;
2140 if (pConnectionParams->Type == INTERNAL_GPS) {
2141 pConnectionParams->NetworkAddress =
"";
2142 pConnectionParams->NetworkPort = 0;
2143 pConnectionParams->NetProtocol = PROTO_UNDEFINED;
2144 pConnectionParams->Baudrate = 0;
2147 if (pConnectionParams->Type == INTERNAL_BT) {
2148 wxString parms = m_choiceBTDataSources->GetStringSelection();
2149 wxStringTokenizer tkz(parms,
";");
2150 wxString name = tkz.GetNextToken();
2151 wxString mac = tkz.GetNextToken();
2153 pConnectionParams->NetworkAddress = name;
2154 pConnectionParams->Port = mac;
2155 pConnectionParams->NetworkPort = 0;
2156 pConnectionParams->NetProtocol = PROTO_UNDEFINED;
2157 pConnectionParams->Baudrate = 0;
2161 if (pConnectionParams->Type == SOCKETCAN) {
2162 pConnectionParams->NetworkAddress =
"";
2163 pConnectionParams->NetworkPort = 0;
2164 pConnectionParams->NetProtocol = PROTO_UNDEFINED;
2165 pConnectionParams->Baudrate = 0;
2166 pConnectionParams->socketCAN_port =
2167 m_choiceCANSource->GetString(m_choiceCANSource->GetSelection());
2170 if (pConnectionParams->Type == SERIAL) {
2171 pConnectionParams->UserComment = m_tSerialComment->GetValue();
2172 }
else if (pConnectionParams->Type == NETWORK) {
2173 pConnectionParams->UserComment = m_tNetComment->GetValue();
2175 pConnectionParams->AuthToken = m_tAuthToken->GetValue();
2177 return pConnectionParams;
2180 void ConnectionEditDialog::OnPriorityDialog(wxCommandEvent& event) {
2185 void ConnectionEditDialog::ConnectControls() {
2187 m_rbTypeSerial->Connect(
2188 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2189 wxCommandEventHandler(ConnectionEditDialog::OnTypeSerialSelected), NULL,
2191 m_rbTypeNet->Connect(
2192 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2193 wxCommandEventHandler(ConnectionEditDialog::OnTypeNetSelected), NULL,
2196 m_rbTypeCAN->Connect(
2197 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2198 wxCommandEventHandler(ConnectionEditDialog::OnTypeCANSelected), NULL,
2201 if (m_rbTypeInternalGPS)
2202 m_rbTypeInternalGPS->Connect(
2203 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2204 wxCommandEventHandler(ConnectionEditDialog::OnTypeGPSSelected), NULL,
2206 if (m_rbTypeInternalBT)
2207 m_rbTypeInternalBT->Connect(
2208 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2209 wxCommandEventHandler(ConnectionEditDialog::OnTypeBTSelected), NULL,
2213 m_rbNetProtoTCP->Connect(
2214 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2215 wxCommandEventHandler(ConnectionEditDialog::OnNetProtocolSelected), NULL,
2217 m_rbNetProtoUDP->Connect(
2218 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2219 wxCommandEventHandler(ConnectionEditDialog::OnNetProtocolSelected), NULL,
2221 m_rbNetProtoGPSD->Connect(
2222 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2223 wxCommandEventHandler(ConnectionEditDialog::OnNetProtocolSelected), NULL,
2225 m_rbNetProtoSignalK->Connect(
2226 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2227 wxCommandEventHandler(ConnectionEditDialog::OnNetProtocolSelected), NULL,
2229 m_choiceNetDataProtocol->Connect(
2230 wxEVT_COMMAND_CHOICE_SELECTED,
2231 wxCommandEventHandler(ConnectionEditDialog::OnProtocolChoice), NULL,
2233 m_choiceSerialProtocol->Connect(
2234 wxEVT_COMMAND_CHOICE_SELECTED,
2235 wxCommandEventHandler(ConnectionEditDialog::OnProtocolChoice), NULL,
2237 m_cbMultiCast->Connect(
2238 wxEVT_COMMAND_CHECKBOX_CLICKED,
2239 wxCommandEventHandler(ConnectionEditDialog::OnCbMultiCast), NULL,
this);
2243 m_more->Bind(wxEVT_LEFT_DOWN, &ConnectionEditDialog::OnClickMore,
this);
2246 m_cbInput->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
2247 wxCommandEventHandler(ConnectionEditDialog::OnCbInput),
2249 m_cbOutput->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
2250 wxCommandEventHandler(ConnectionEditDialog::OnCbOutput),
2266 m_btnInputStcList->Connect(
2267 wxEVT_COMMAND_BUTTON_CLICKED,
2268 wxCommandEventHandler(ConnectionEditDialog::OnBtnIStcs), NULL,
this);
2271 m_btnOutputStcList->Connect(
2272 wxEVT_COMMAND_BUTTON_CLICKED,
2273 wxCommandEventHandler(ConnectionEditDialog::OnBtnOStcs), NULL,
this);
2276 m_tNetAddress->Connect(
2277 wxEVT_COMMAND_TEXT_UPDATED,
2278 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2279 m_tNetPort->Connect(wxEVT_COMMAND_TEXT_UPDATED,
2280 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange),
2282 m_comboPort->Connect(
2283 wxEVT_COMMAND_COMBOBOX_SELECTED,
2284 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2285 m_comboPort->Connect(
2286 wxEVT_COMMAND_TEXT_UPDATED,
2287 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2288 m_choiceBaudRate->Connect(
2289 wxEVT_COMMAND_CHOICE_SELECTED,
2290 wxCommandEventHandler(ConnectionEditDialog::OnBaudrateChoice), NULL,
this);
2291 m_choicePriority->Connect(
2292 wxEVT_COMMAND_CHOICE_SELECTED,
2293 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2294 m_choiceCANSource->Connect(
2295 wxEVT_COMMAND_CHOICE_SELECTED,
2296 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2297 m_cbCheckCRC->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
2298 wxCommandEventHandler(ConnectionEditDialog::OnCrcCheck),
2300 m_cbGarminHost->Connect(
2301 wxEVT_COMMAND_CHECKBOX_CLICKED,
2302 wxCommandEventHandler(ConnectionEditDialog::OnUploadFormatChange), NULL,
2304 m_cbGarminUploadHost->Connect(
2305 wxEVT_COMMAND_CHECKBOX_CLICKED,
2306 wxCommandEventHandler(ConnectionEditDialog::OnUploadFormatChange), NULL,
2308 m_cbFurunoGP3X->Connect(
2309 wxEVT_COMMAND_CHECKBOX_CLICKED,
2310 wxCommandEventHandler(ConnectionEditDialog::OnUploadFormatChange), NULL,
2312 m_cbCheckSKDiscover->Connect(
2313 wxEVT_COMMAND_CHECKBOX_CLICKED,
2314 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2315 m_ButtonSKDiscover->Connect(
2316 wxEVT_COMMAND_BUTTON_CLICKED,
2317 wxCommandEventHandler(ConnectionEditDialog::OnDiscoverButton), NULL,
this);
2319 m_rbOAccept->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2320 wxCommandEventHandler(ConnectionEditDialog::OnRbOutput),
2322 m_rbOIgnore->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED,
2323 wxCommandEventHandler(ConnectionEditDialog::OnRbOutput),
2325 m_tcOutputStc->Connect(
2326 wxEVT_COMMAND_TEXT_UPDATED,
2327 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2328 m_cbCheckCRC->Connect(
2329 wxEVT_COMMAND_CHECKBOX_CLICKED,
2330 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2332 m_cbNMEADebug->Connect(
2333 wxEVT_COMMAND_CHECKBOX_CLICKED,
2334 wxCommandEventHandler(ConnectionEditDialog::OnShowGpsWindowCheckboxClick),
2336 m_cbFilterSogCog->Connect(
2337 wxEVT_COMMAND_CHECKBOX_CLICKED,
2338 wxCommandEventHandler(ConnectionEditDialog::OnValChange), NULL,
this);
2339 m_tFilterSec->Connect(wxEVT_COMMAND_TEXT_UPDATED,
2340 wxCommandEventHandler(ConnectionEditDialog::OnValChange),
2342 m_cbAPBMagnetic->Connect(
2343 wxEVT_COMMAND_CHECKBOX_CLICKED,
2344 wxCommandEventHandler(ConnectionEditDialog::OnValChange), NULL,
this);
2346 m_ButtonPriorityDialog->Connect(
2347 wxEVT_COMMAND_BUTTON_CLICKED,
2348 wxCommandEventHandler(ConnectionEditDialog::OnPriorityDialog), NULL,
this);
2350 m_tNetComment->Connect(
2351 wxEVT_COMMAND_TEXT_UPDATED,
2352 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2353 m_tSerialComment->Connect(
2354 wxEVT_COMMAND_TEXT_UPDATED,
2355 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2356 m_tAuthToken->Connect(
2357 wxEVT_COMMAND_TEXT_UPDATED,
2358 wxCommandEventHandler(ConnectionEditDialog::OnConnValChange), NULL,
this);
2361 m_buttonScanBT->Connect(
2362 wxEVT_COMMAND_BUTTON_CLICKED,
2363 wxCommandEventHandler(ConnectionEditDialog::OnScanBTClick), NULL,
this);
2367 bool ConnectionEditDialog::IsAddressMultiCast(wxString ip) {
2368 wxArrayString bytes = wxSplit(ip,
'.');
2369 if (bytes.size() != 4) {
2372 unsigned long ipNum = (wxAtoi(bytes[0]) << 24) + (wxAtoi(bytes[1]) << 16) +
2373 (wxAtoi(bytes[2]) << 8) + wxAtoi(bytes[3]);
2374 unsigned long multicastStart = (224 << 24);
2375 unsigned long multicastEnd = (239 << 24) + (255 << 16) + (255 << 8) + 255;
2376 return ipNum >= multicastStart && ipNum <= multicastEnd;
2379 bool ConnectionEditDialog::IsDefaultPort(wxString address) {
2380 return (address == DEFAULT_TCP_PORT) || (address == DEFAULT_UDP_PORT) ||
2381 (address == DEFAULT_SIGNALK_PORT) || (address == DEFAULT_GPSD_PORT);
2384 bool ConnectionEditDialog::IsAddressBroadcast(wxString ip) {
2385 wxArrayString bytes = wxSplit(ip,
'.');
2386 if (bytes.size() != 4) {
2387 std::cerr <<
"Invalid IP format." << std::endl;
2390 return wxAtoi(bytes[3]) == 255;
2393 SentenceListDlg::SentenceListDlg(wxWindow* parent, FilterDirection dir,
2394 ListType type,
const wxArrayString& list)
2395 : wxDialog(parent, wxID_ANY, _(
"Sentence Filter"), wxDefaultPosition,
2399 m_sentences(NMEA0183().GetRecognizedArray()) {
2401 wxBoxSizer* mainSizer =
new wxBoxSizer(wxVERTICAL);
2402 wxBoxSizer* secondSizer =
new wxBoxSizer(wxHORIZONTAL);
2403 wxStaticBox* pclbBox =
new wxStaticBox(
this, wxID_ANY, GetBoxLabel());
2404 wxStaticBoxSizer* stcSizer =
new wxStaticBoxSizer(pclbBox, wxVERTICAL);
2405 m_clbSentences =
new wxCheckListBox(
this, wxID_ANY, wxDefaultPosition,
2406 wxDefaultSize, m_sentences);
2407 wxBoxSizer* btnEntrySizer =
new wxBoxSizer(wxVERTICAL);
2408 wxButton* btnCheckAll =
new wxButton(
this, wxID_ANY, _(
"Select All"));
2409 wxButton* btnClearAll =
new wxButton(
this, wxID_ANY, _(
"Clear All"));
2410 wxButton* btnAdd =
new wxButton(
this, wxID_ANY, _(
"Add"));
2411 m_btnDel =
new wxButton(
this, wxID_ANY, _(
"Delete"));
2412 m_btnDel->Disable();
2413 wxStdDialogButtonSizer* btnSizer =
new wxStdDialogButtonSizer();
2414 wxButton* btnOK =
new wxButton(
this, wxID_OK);
2415 wxButton* btnCancel =
new wxButton(
this, wxID_CANCEL, _(
"Cancel"));
2417 secondSizer->Add(stcSizer, 1, wxALL | wxEXPAND, 5);
2418 stcSizer->Add(m_clbSentences, 1, wxALL | wxEXPAND, 5);
2419 btnEntrySizer->Add(btnCheckAll, 0, wxALL, 5);
2420 btnEntrySizer->Add(btnClearAll, 0, wxALL, 5);
2421 btnEntrySizer->AddSpacer(1);
2422 btnEntrySizer->Add(btnAdd, 0, wxALL, 5);
2423 btnEntrySizer->Add(m_btnDel, 0, wxALL, 5);
2424 secondSizer->Add(btnEntrySizer, 0, wxALL | wxEXPAND, 5);
2425 mainSizer->Add(secondSizer, 1, wxEXPAND, 5);
2426 btnSizer->AddButton(btnOK);
2427 btnSizer->AddButton(btnCancel);
2428 btnSizer->Realize();
2429 mainSizer->Add(btnSizer, 0, wxALL | wxEXPAND, 5);
2431 SetSizer(mainSizer);
2432 mainSizer->SetSizeHints(
this);
2436 btnAdd->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2437 wxCommandEventHandler(SentenceListDlg::OnAddClick), NULL,
2439 m_btnDel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2440 wxCommandEventHandler(SentenceListDlg::OnDeleteClick), NULL,
2442 m_clbSentences->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
2443 wxCommandEventHandler(SentenceListDlg::OnCLBSelect),
2445 btnCheckAll->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2446 wxCommandEventHandler(SentenceListDlg::OnCheckAllClick),
2448 btnClearAll->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2449 wxCommandEventHandler(SentenceListDlg::OnClearAllClick),
2455 wxString SentenceListDlg::GetBoxLabel(
void)
const {
2456 if (m_dir == FILTER_OUTPUT)
2457 return m_type == WHITELIST ? _(
"Transmit sentences") : _(
"Drop sentences");
2459 return m_type == WHITELIST ? _(
"Accept only sentences")
2460 : _(
"Ignore sentences");
2463 void SentenceListDlg::Populate(
const wxArrayString& list) {
2464 if (m_dir == FILTER_OUTPUT) {
2466 m_sentences.Add(g_TalkerIdText + wxString(
"RMB"));
2467 m_sentences.Add(g_TalkerIdText + wxString(
"RMC"));
2468 m_sentences.Add(g_TalkerIdText + wxString(
"APB"));
2469 m_sentences.Add(g_TalkerIdText + wxString(
"XTE"));
2471 m_sentences.Add(
"AIVDM");
2472 m_sentences.Add(
"AIVDO");
2473 m_sentences.Add(
"FRPOS");
2474 m_sentences.Add(g_TalkerIdText);
2475 m_sentences.Add(
"CD");
2477 m_clbSentences->Clear();
2478 m_clbSentences->InsertItems(m_sentences, 0);
2480 wxArrayString new_strings;
2482 if (list.Count() == 0) {
2483 for (
size_t i = 0; i < m_clbSentences->GetCount(); ++i)
2484 m_clbSentences->Check(i, m_type == WHITELIST);
2486 for (
size_t i = 0; i < list.Count(); ++i) {
2487 int item = m_clbSentences->FindString(list[i]);
2488 if (item != wxNOT_FOUND)
2489 m_clbSentences->Check(item);
2491 new_strings.Add(list[i]);
2493 if (new_strings.GetCount()) {
2494 m_clbSentences->InsertItems(new_strings, m_clbSentences->GetCount());
2495 for (
size_t i = 0; i < new_strings.GetCount(); ++i) {
2496 int item = m_clbSentences->FindString(new_strings[i]);
2497 if (item != wxNOT_FOUND) m_clbSentences->Check(item);
2503 wxString SentenceListDlg::GetSentences(
void) {
2504 wxArrayString retString;
2505 for (
size_t i = 0; i < m_clbSentences->GetCount(); i++) {
2506 if (m_clbSentences->IsChecked(i))
2507 retString.Add(m_clbSentences->GetString(i));
2509 return StringArrayToString(retString);
2512 void SentenceListDlg::OnCLBSelect(wxCommandEvent& e) {
2515 m_btnDel->Enable(m_sentences.Index(e.GetString()) == wxNOT_FOUND);
2518 void SentenceListDlg::OnAddClick(wxCommandEvent& event) {
2520 androidDisableRotation();
2523 wxTextEntryDialog textdlg(
2525 _(
"Enter the NMEA sentence (2, 3 or 5 characters)\n or a valid REGEX "
2526 "expression (6 characters or longer)"),
2527 _(
"Enter the NMEA sentence"));
2529 textdlg.SetTextValidator(wxFILTER_ASCII);
2530 int result = textdlg.ShowModal();
2533 androidEnableRotation();
2536 if (result == wxID_CANCEL)
return;
2537 wxString stc = textdlg.GetValue();
2539 if (stc.Length() == 2 || stc.Length() == 3 || stc.Length() == 5) {
2540 m_clbSentences->Append(stc);
2541 m_clbSentences->Check(m_clbSentences->FindString(stc));
2543 }
else if (stc.Length() < 2) {
2546 _(
"An NMEA sentence is generally 3 characters long (like RMC, GGA etc.)\n \
2547 It can also have a two letter prefix identifying the source, or TALKER, of the message.\n \
2548 The whole sentences then looks like GPGGA or AITXT.\n \
2549 You may filter out all the sentences with certain TALKER prefix (like GP, AI etc.).\n \
2550 The filter also accepts Regular Expressions (REGEX) with 6 or more characters. \n\n"),
2559 m_clbSentences->Append(stc);
2560 m_clbSentences->Check(m_clbSentences->FindString(stc));
2563 OCPNMessageBox(
this, _(
"REGEX syntax error: \n") + stc,
2570 void SentenceListDlg::OnDeleteClick(wxCommandEvent& event) {
2571 m_clbSentences->Delete(m_clbSentences->GetSelection());
2574 void SentenceListDlg::OnClearAllClick(wxCommandEvent& event) {
2575 for (
size_t i = 0; i < m_clbSentences->GetCount(); i++)
2576 m_clbSentences->Check(i, FALSE);
2579 void SentenceListDlg::OnCheckAllClick(wxCommandEvent& event) {
2580 for (
size_t i = 0; i < m_clbSentences->GetCount(); i++)
2581 m_clbSentences->Check(i, TRUE);
void Init(const KeyProvider &kp, std::function< void(ObservedEvt &ev)> action)
Initiate an object yet not listening.
Adds a std::shared<void> element to wxCommandEvent.
General purpose GUI support.
bool CheckSerialAccess(wxWindow *parent, const std::string device)
Run checks and possible dialogs to ensure device is accessible.
Access checks for comm devices and dongle.