38std::string NavAddr::BusToString(NavAddr::Bus b) {
40 case NavAddr::Bus::N0183:
43 case NavAddr::Bus::N2000:
46 case NavAddr::Bus::Signalk:
49 case NavAddr::Bus::Onenet:
52 case NavAddr::Bus::Plugin:
55 case NavAddr::Bus::TestBus:
58 case NavAddr::Bus::AppMsg:
61 case NavAddr::Bus::Undef:
68NavAddr::Bus NavAddr::StringToBus(
const std::string& s) {
69 if (s ==
"nmea0183")
return NavAddr::Bus::N0183;
70 if (s ==
"nmea2000")
return NavAddr::Bus::N2000;
71 if (s ==
"SignalK")
return NavAddr::Bus::Signalk;
72 if (s ==
"Onenet")
return NavAddr::Bus::Onenet;
73 if (s ==
"Plugin")
return NavAddr::Bus::Plugin;
74 if (s ==
"TestBus")
return NavAddr::Bus::TestBus;
75 if (s ==
"AppMsg")
return NavAddr::Bus::AppMsg;
76 return NavAddr::Bus::Undef;
79static std::string CharToString(
unsigned char c) {
82 ss << setfill(
'0') << hex << setw(2) << (c & 0x00ff);
86static std::string CharToString(
char c) {
87 return CharToString(
static_cast<unsigned char>(c));
95 unsigned char* c = (
unsigned char*)&pgn;
101 size_t data_start = 12;
102 if (payload.at(0) == 0x94) data_start = 7;
104 while (i < payload.size() - 1) {
105 if (i > data_start) {
106 for (
int j = 0; j < 8; j++) {
107 st.append(CharToString(payload[i]));
110 if (i >= payload.size() - 1) {
119 std::stringstream ss1;
120 std::string spgn =
" ";
121 if (PGN.pgn == 1) spgn =
"ALL ";
122 ss1 <<
"n2000-" << spgn <<
"PGN: " << pgn <<
" [ " << st <<
" ]";
128 for (
auto c : payload) s.append(CharToString(c) +
" ");
133 std::stringstream ss;
142 if (name ==
"position-fix")
return name +
":" +
ocpn::rtrim(message);
144 std::stringstream ss;
146 if (c >=
' ' && c <=
'~')
149 ss << CharToString(c);
151 return name +
": " + ss.str();
155 if (
key.find(
"::") == std::string::npos)
return NavAddr::Bus::Undef;
157 return NavAddr::StringToBus(key_parts[0]);
virtual std::string key() const =0
Return unique key used by observable to notify/listen.
static NavAddr::Bus GetBusByKey(const std::string &key)
Return bus corresponding to given key.
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::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
std::string rtrim(const std::string &arg)
Strip possibly trailing space characters in s.
Miscellaneous utilities, many of which string related.