40std::string NavAddr::BusToString(NavAddr::Bus b) {
42 case NavAddr::Bus::N0183:
45 case NavAddr::Bus::N2000:
48 case NavAddr::Bus::Signalk:
51 case NavAddr::Bus::Onenet:
54 case NavAddr::Bus::Plugin:
57 case NavAddr::Bus::TestBus:
60 case NavAddr::Bus::AppMsg:
63 case NavAddr::Bus::Undef:
70NavAddr::Bus NavAddr::StringToBus(
const std::string& s) {
71 if (s ==
"nmea0183")
return NavAddr::Bus::N0183;
72 if (s ==
"nmea2000")
return NavAddr::Bus::N2000;
73 if (s ==
"SignalK")
return NavAddr::Bus::Signalk;
74 if (s ==
"Onenet")
return NavAddr::Bus::Onenet;
75 if (s ==
"Plugin")
return NavAddr::Bus::Plugin;
76 if (s ==
"TestBus")
return NavAddr::Bus::TestBus;
77 if (s ==
"AppMsg")
return NavAddr::Bus::AppMsg;
78 return NavAddr::Bus::Undef;
81static std::string CharToString(
unsigned char c) {
84 ss << setfill(
'0') << hex << setw(2) << (c & 0x00ff);
88static std::string CharToString(
char c) {
89 return CharToString(
static_cast<unsigned char>(c));
97 unsigned char* c = (
unsigned char*)&pgn;
100 *c++ = payload.at(5);
103 size_t data_start = 12;
104 if (payload.at(0) == 0x94) data_start = 7;
106 while (i < payload.size() - 1) {
107 if (i > data_start) {
108 for (
int j = 0; j < 8; j++) {
109 st.append(CharToString(payload[i]));
112 if (i >= payload.size() - 1) {
121 std::stringstream ss1;
122 std::string spgn =
" ";
123 if (PGN.pgn == 1) spgn =
"ALL ";
124 ss1 <<
"n2000-" << spgn <<
"PGN: " << pgn <<
" [ " << st <<
" ]";
130 for (
auto c : payload) s.append(CharToString(c) +
" ");
135 std::stringstream ss;
144 if (name ==
"position-fix")
return name +
":" +
ocpn::rtrim(message);
146 std::stringstream ss;
148 if (c >=
' ' && c <=
'~')
151 ss << CharToString(c);
153 return name +
": " + ss.str();
const std::string type
For example 'GGA'.
std::string key() const override
Return unique key used by observable to notify/listen.
const std::string talker
For example 'GP'.
const std::string payload
Complete NMEA0183 sentence, also prefix.
std::string to_vdr() const override
Return message in unquoted format used by VDR plugin, see https://opencpn-manuals....
std::string to_string() const override
Return printable string for logging etc without trailing nl.
std::string to_string() const override
Print "bus key id payload".
std::string to_vdr() const override
Return message in unquoted format used by VDR plugin, see https://opencpn-manuals....
std::string to_string() const
Return printable string for logging etc without trailing nl.
Communication driver layer.
std::string printable(const std::string &str)
Return copy of str with non-printable chars replaced by hex like "<0D>".
std::string rtrim(const std::string &arg)
Strip possibly trailing space characters in s.
Miscellaneous utilities, many of which string related.