25 #include <wx/wxprec.h>
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)
51 static wxArrayOfConnPrm* the_connection_params = 0;
53 wxArrayOfConnPrm* TheConnectionParams() {
54 if (the_connection_params == 0)
55 the_connection_params =
new wxArrayOfConnPrm();
56 return the_connection_params;
59 ConnectionParams::ConnectionParams(
const wxString &configStr) {
60 m_optionsPanel = NULL;
61 Deserialize(configStr);
64 void ConnectionParams::Deserialize(
const wxString &configStr) {
66 wxArrayString prms = wxStringTokenize(configStr, _T(
";"));
67 if (prms.Count() < 18) {
72 Type = (ConnectionType)wxAtoi(prms[0]);
73 NetProtocol = (NetworkProtocol)wxAtoi(prms[1]);
74 NetworkAddress = prms[2];
75 NetworkPort = (ConnectionType)wxAtoi(prms[3]);
76 Protocol = (DataProtocol)wxAtoi(prms[4]);
78 Baudrate = wxAtoi(prms[6]);
79 ChecksumCheck = wxAtoi(prms[7]);
80 int iotval = wxAtoi(prms[8]);
81 IOSelect = ((iotval <= 2) ? static_cast<dsPortType>(iotval) : DS_TYPE_INPUT);
82 InputSentenceListType = (ListType)wxAtoi(prms[9]);
83 InputSentenceList = wxStringTokenize(prms[10], _T(
","));
84 OutputSentenceListType = (ListType)wxAtoi(prms[11]);
85 OutputSentenceList = wxStringTokenize(prms[12], _T(
","));
86 Priority = wxAtoi(prms[13]);
87 Garmin = !!wxAtoi(prms[14]);
88 GarminUpload = !!wxAtoi(prms[15]);
89 FurunoGP3X = !!wxAtoi(prms[16]);
94 if (prms.Count() >= 18) {
95 bEnabled = !!wxAtoi(prms[17]);
97 if (prms.Count() >= 19) {
98 UserComment = prms[18];
100 if (prms.Count() >= 20) {
101 AutoSKDiscover = !!wxAtoi(prms[19]);
103 if (prms.Count() >= 21) {
104 socketCAN_port = prms[20];
106 if (prms.Count() >= 22) {
107 NoDataReconnect = wxAtoi(prms[21]);
109 if (prms.Count() >= 23) {
110 DisableEcho = wxAtoi(prms[22]);
112 if (prms.Count() >= 24) {
113 AuthToken = prms[22];
117 wxString ConnectionParams::Serialize()
const {
119 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
120 if (i > 0) istcs.Append(_T(
","));
121 istcs.Append(InputSentenceList[i]);
124 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
125 if (i > 0) ostcs.Append(_T(
","));
126 ostcs.Append(OutputSentenceList[i]);
128 wxString ret = wxString::Format(
129 _T(
"%d;%d;%s;%d;%d;%s;%d;%d;%d;%d;%s;%d;%s;%d;%d;%d;%d;%d;%s;%d;%s;%d;%d;%s"), Type,
130 NetProtocol, NetworkAddress.c_str(), NetworkPort, Protocol, Port.c_str(),
131 Baudrate, ChecksumCheck, IOSelect, InputSentenceListType, istcs.c_str(),
132 OutputSentenceListType, ostcs.c_str(), Priority, Garmin, GarminUpload,
133 FurunoGP3X, bEnabled, UserComment.c_str(), AutoSKDiscover, socketCAN_port.c_str(),
134 NoDataReconnect, DisableEcho, AuthToken.c_str());
139 ConnectionParams::ConnectionParams() {
142 NetworkAddress = wxEmptyString;
144 Protocol = PROTO_NMEA0183;
145 Port = wxEmptyString;
147 ChecksumCheck =
true;
150 IOSelect = DS_TYPE_INPUT;
151 InputSentenceListType = WHITELIST;
152 OutputSentenceListType = WHITELIST;
157 m_optionsPanel = NULL;
158 AutoSKDiscover =
false;
159 NoDataReconnect =
false;
161 AuthToken = wxEmptyString;
164 ConnectionParams::~ConnectionParams() {
168 wxString ConnectionParams::GetSourceTypeStr()
const {
183 wxString ConnectionParams::GetAddressStr()
const {
185 return wxString::Format(_T(
"%s"), Port.c_str());
186 else if (Type == NETWORK)
187 return wxString::Format(_T(
"%s:%d"), NetworkAddress.c_str(), NetworkPort);
188 else if (Type == INTERNAL_GPS)
189 return _(
"Internal");
190 else if (Type == INTERNAL_BT)
191 return NetworkAddress;
197 static wxString NetworkProtocolToString(NetworkProtocol NetProtocol) {
198 switch (NetProtocol) {
206 return _(
"Signal K");
208 return _(
"Undefined");
212 wxString ConnectionParams::GetParametersStr()
const {
215 return wxString::Format(_T(
"%d"), Baudrate);
217 return NetworkProtocolToString(NetProtocol);
227 wxString ConnectionParams::GetIOTypeValueStr()
const {
228 if (IOSelect == DS_TYPE_INPUT)
230 else if (IOSelect == DS_TYPE_OUTPUT)
236 wxString ConnectionParams::FilterTypeToStr(ListType type,
237 FilterDirection dir)
const {
238 if (dir == FILTER_INPUT) {
239 if (type == BLACKLIST)
244 if (type == BLACKLIST)
251 wxString ConnectionParams::GetFiltersStr()
const {
253 for (
size_t i = 0; i < InputSentenceList.Count(); i++) {
254 if (i > 0) istcs.Append(_T(
","));
255 istcs.Append(InputSentenceList[i]);
258 for (
size_t i = 0; i < OutputSentenceList.Count(); i++) {
259 if (i > 0) ostcs.Append(_T(
","));
260 ostcs.Append(OutputSentenceList[i]);
262 wxString ret = wxEmptyString;
263 if (istcs.Len() > 0) {
265 ret.Append(wxString::Format(
267 FilterTypeToStr(InputSentenceListType, FILTER_INPUT).c_str(),
270 ret.Append(_(
"In: None"));
272 if (ostcs.Len() > 0) {
273 ret.Append(_T(
", "));
274 ret.Append(_(
"Out"));
275 ret.Append(wxString::Format(
277 FilterTypeToStr(OutputSentenceListType, FILTER_OUTPUT).c_str(),
280 ret.Append(_(
", Out: None"));
284 wxString ConnectionParams::GetDSPort()
const {
286 return wxString::Format(_T(
"Serial:%s"), Port.c_str());
287 else if (Type == NETWORK) {
288 wxString proto = NetworkProtocolToString(NetProtocol);
289 return wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
290 NetworkAddress.c_str(), NetworkPort);
291 }
else if (Type == INTERNAL_BT) {
297 std::string ConnectionParams::GetStrippedDSPort() {
299 wxString t = wxString::Format(_T(
"Serial:%s"), Port.c_str());
300 wxString comx = t.AfterFirst(
':').BeforeFirst(
' ');
301 return comx.ToStdString();
303 else if (Type == NETWORK) {
304 wxString proto = NetworkProtocolToString(NetProtocol);
305 wxString t = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
306 NetworkAddress.c_str(), NetworkPort);
307 return t.ToStdString();
309 }
else if (Type == SOCKETCAN) {
310 std::string rv =
"socketCAN-";
311 rv += socketCAN_port.ToStdString();
313 }
else if (Type == INTERNAL_BT) {
314 return Port.ToStdString();
319 std::string ConnectionParams::GetLastDSPort()
const {
321 wxString sp = wxString::Format(_T(
"Serial:%s"), Port.c_str());
322 return sp.ToStdString();
325 wxString proto = NetworkProtocolToString(LastNetProtocol);
326 wxString sp = wxString::Format(_T(
"%s:%s:%d"), proto.c_str(),
327 LastNetworkAddress.c_str(), LastNetworkPort);
328 return sp.ToStdString();
332 bool ConnectionParams::SentencePassesFilter(
const wxString& sentence, FilterDirection direction)
334 wxArrayString filter;
335 bool listype =
false;
337 if (direction == FILTER_INPUT)
339 filter = InputSentenceList;
340 if (InputSentenceListType == WHITELIST)
345 filter = OutputSentenceList;
346 if (OutputSentenceListType == WHITELIST)
349 if (filter.Count() == 0)
353 for (
size_t i = 0; i < filter.Count(); i++)
359 if (fs == sentence.Mid(1, 2))
363 if (fs == sentence.Mid(3, 3))
367 if (fs == sentence.Mid(1, 5))
375 if (re.Matches(sentence.Mid(0, 8)))
385 NavAddr::Bus ConnectionParams::GetCommProtocol(){
386 if (Type == NETWORK){
387 if (NetProtocol == SIGNALK)
388 return NavAddr::Bus::Signalk;
389 else if (NetProtocol == GPSD)
390 return NavAddr::Bus::N0183;
395 return NavAddr::Bus::N0183;
397 return NavAddr::Bus::N2000;
399 return NavAddr::Bus::Undef;
403 NavAddr::Bus ConnectionParams::GetLastCommProtocol(){
404 if (Type == NETWORK){
405 if (LastNetProtocol == SIGNALK)
406 return NavAddr::Bus::Signalk;
407 else if (LastNetProtocol == GPSD)
408 return NavAddr::Bus::N0183;
411 switch (LastDataProtocol){
413 return NavAddr::Bus::N0183;
415 return NavAddr::Bus::N2000;
417 return NavAddr::Bus::Undef;