OpenCPN Partial API docs
comm_navmsg.cpp
Go to the documentation of this file.
1  /**************************************************************************
2  * Copyright (C) 2022 David Register *
3  * Copyright (C) 2022 - 2024 Alec Leamas *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  **************************************************************************/
20 
23 // For compilers that support precompilation, includes "wx.h".
24 #include <wx/wxprec.h>
25 
26 #ifndef WX_PRECOMP
27 #include <wx/wx.h>
28 #endif // precompiled headers
29 
30 #include <algorithm>
31 #include <string>
32 #include <iomanip>
33 
34 #include "model/comm_driver.h"
35 
36 std::string NavAddr::BusToString(NavAddr::Bus b) {
37  switch (b) {
38  case NavAddr::Bus::N0183:
39  return "nmea0183";
40  break;
41  case NavAddr::Bus::N2000:
42  return "nmea2000";
43  break;
44  case NavAddr::Bus::Signalk:
45  return "SignalK";
46  break;
47  case NavAddr::Bus::Onenet:
48  return "Onenet";
49  break;
50  case NavAddr::Bus::Plugin:
51  return "Plugin";
52  break;
53  case NavAddr::Bus::TestBus:
54  return "TestBus";
55  break;
56  case NavAddr::Bus::Undef:
57  return "??";
58  break;
59  }
60  return "????";
61 }
62 
63 NavAddr::Bus NavAddr::StringToBus(const std::string& s) {
64  if (s == "nmea0183") return NavAddr::Bus::N0183;
65  if (s == "nmea2000") return NavAddr::Bus::N2000;
66  if (s == "SignalK") return NavAddr::Bus::Signalk;
67  if (s == "Onenet") return NavAddr::Bus::Onenet;
68  if (s == "TestBus") return NavAddr::Bus::TestBus;
69  return NavAddr::Bus::Undef;
70 }
71 
72 static std::string CharToString(unsigned char c) {
73  using namespace std;
74  stringstream ss;
75  ss << setfill('0') << hex << setw(2) << (c & 0x00ff);
76  return ss.str();
77 }
78 
79 std::string Nmea2000Msg::to_string() const {
80  std::string s;
81  std::for_each(payload.begin(), payload.end(),
82  [&s](unsigned char c) { s.append(CharToString(c)); });
83 
84  return NavMsg::to_string() + " " + PGN.to_string() + " " + s;
85 }
std::string to_string() const
Print "bus key id payload".
Definition: comm_navmsg.cpp:79