OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_navmsg.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Implements comm_navmsg -- raw, undecoded messages.
5 * Author: David Register, Alec Leamas
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David Register, Alec Leamas *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26// For compilers that support precompilation, includes "wx.h".
27#include <wx/wxprec.h>
28
29#ifndef WX_PRECOMP
30#include <wx/wx.h>
31#endif // precompiled headers
32
33#include <algorithm>
34#include <string>
35#include <iomanip>
36
37#include "comm_driver.h"
38
39std::string NavAddr::BusToString(NavAddr::Bus b) {
40 switch (b) {
41 case NavAddr::Bus::N0183:
42 return "nmea0183";
43 break;
44 case NavAddr::Bus::N2000:
45 return "nmea2000";
46 break;
47 case NavAddr::Bus::Signalk:
48 return "SignalK";
49 break;
50 case NavAddr::Bus::Onenet:
51 return "Onenet";
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
63NavAddr::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
72static 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
79std::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