Skip to content

Commit 12d4949

Browse files
committed
Refactor log interface #2
Since we now log complete NavMsg pointers there is no need for a separate "stream" parameter - this info is the NavMsg source address. Using this will probably expose occasional driver bugs in how it is configured. We will have to handle them.
1 parent 593a35e commit 12d4949

File tree

9 files changed

+53
-53
lines changed

9 files changed

+53
-53
lines changed

gui/src/data_monitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void DataLogger::Add(const Logline& ll) {
465465
} else {
466466
ws << kUtfCheckMark << " ";
467467
}
468-
ws << (ll.stream_name.empty() ? "-" : ll.stream_name) << " ";
468+
ws << (ll.navmsg ? "-" : ll.navmsg->source->iface) << " ";
469469
if (ll.state.status != NavmsgStatus::State::kOk) {
470470
ws << (ll.error_msg.size() > 0 ? ll.error_msg : "Unknown errror");
471471
} else {

gui/src/tty_scroll.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <sstream>
2222
#include <string>
2323

24+
#ifdef _WIN32
25+
#define NOMINMAX // Disable min/max compiler nacros.
26+
#endif
27+
2428
#include <wx/clipbrd.h>
2529
#include <wx/dcclient.h>
2630
#include <wx/string.h>
@@ -83,10 +87,9 @@ static void DrawLine(wxDC& dc, Logline ll, int data_pos, int y) {
8387
error_msg << " - "
8488
<< (ll.error_msg.size() > 0 ? ll.error_msg : "Unknown errror");
8589
}
86-
std::string stream(ll.stream_name);
87-
if (stream.empty() && ll.navmsg) stream = ll.navmsg->source->iface;
88-
if (stream.size() > 20) stream = stream.substr(0, 17) + "...";
89-
ws << stream;
90+
std::string iface(ll.navmsg ? ll.navmsg->source->iface : "");
91+
if (iface.size() > 20) iface = iface.substr(0, 17) + "...";
92+
ws << iface;
9093
dc.DrawText(ws, 0, y);
9194
ws = "";
9295

@@ -145,7 +148,7 @@ void TtyScroll::Copy(bool n0183) {
145148
for (auto& line : m_lines) {
146149
std::string s = line.navmsg->to_string();
147150
if (n0183) {
148-
size_t pos = 0;
151+
size_t pos;
149152
if ((pos = s.find("$")) != std::string::npos) {
150153
the_text.append(s.substr(pos) + "\n");
151154
} else if ((pos = s.find("!")) != std::string::npos) {

model/include/model/multiplexer.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ class Multiplexer : public wxEvtHandler {
5454
~Multiplexer();
5555

5656
void LogOutputMessage(const std::shared_ptr<const NavMsg>& msg,
57-
const std::string& stream_name, NavmsgStatus status);
57+
NavmsgStatus status);
5858

59-
void LogOutputMessageColor(const std::shared_ptr<const NavMsg>& msg,
60-
const std::string& stream_name,
61-
NavmsgStatus status);
59+
// void LogOutputMessageColor(const std::shared_ptr<const NavMsg>& msg,
60+
// NavmsgStatus status);
6261
/**
6362
* Logs an input message with context information.
6463
*
@@ -70,8 +69,8 @@ class Multiplexer : public wxEvtHandler {
7069
* @param error_msg The error message to be logged.
7170
*/
7271
void LogInputMessage(const std::shared_ptr<const NavMsg>& msg,
73-
const std::string& stream_name, bool is_filtered,
74-
bool is_error, const wxString error_msg = "");
72+
bool is_filtered, bool is_error,
73+
const wxString error_msg = "");
7574

7675
bool IsLogActive() { return m_log_callbacks.log_is_active(); }
7776

model/include/model/nmea_log.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
struct Logline {
1111
const std::shared_ptr<const NavMsg> navmsg;
1212
const NavmsgStatus state;
13-
const std::string stream_name;
1413
std::string error_msg;
1514
std::string prefix;
1615

1716
Logline() {}
18-
Logline(const std::shared_ptr<const NavMsg>& msg, NavmsgStatus sts,
19-
const std::string& stream)
20-
: navmsg(msg),
21-
state(sts),
22-
stream_name(stream),
23-
error_msg("Unknown error") {}
17+
Logline(const std::shared_ptr<const NavMsg>& msg, NavmsgStatus sts)
18+
: navmsg(msg), state(sts), error_msg("Unknown error") {}
2419
Logline(const std::shared_ptr<const NavMsg>& msg) : navmsg(msg), state() {}
2520
};
2621

model/src/ais_decoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,7 @@ void AisDecoder::HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg) {
10931093
if (g_pMUX && g_pMUX->IsLogActive()) {
10941094
wxString logmsg;
10951095
logmsg.Printf("AIS :MMSI: %ld", mmsi);
1096-
std::string source = sK_msg->source->to_string();
1097-
g_pMUX->LogInputMessage(sK_msg, source, false, false);
1096+
g_pMUX->LogInputMessage(sK_msg, false, false);
10981097
}
10991098

11001099
// Stop here if the target shall be ignored

model/src/comm_bridge.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,7 @@ bool CommBridge::HandleSignalK(std::shared_ptr<const SignalkMsg> sK_msg) {
10381038
if (content.empty()) content = "Not used by OCPN, maybe passed to plugins";
10391039

10401040
logmsg += content;
1041-
std::string source = sK_msg->source->to_string();
1042-
g_pMUX->LogInputMessage(sK_msg, source, false, false);
1041+
g_pMUX->LogInputMessage(sK_msg, false, false);
10431042
}
10441043

10451044
SendBasicNavdata(valid_flag);

model/src/comm_n0183_output.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@
5757
#endif
5858

5959
void LogBroadcastOutputMessageColor(const std::shared_ptr<const NavMsg>& msg,
60-
const std::string& stream_name,
61-
NavmsgStatus ns, NmeaLog& nmea_log) {
62-
if (nmea_log.IsActive()) {
63-
ns.direction = NavmsgStatus::Direction::kOutput;
64-
Logline ll(msg, ns, stream_name);
65-
nmea_log.Add(ll);
66-
}
60+
NavmsgStatus ns, NmeaLog& nmea_log) {
61+
if (nmea_log.IsActive()) {
62+
ns.direction = NavmsgStatus::Direction::kOutput;
63+
Logline ll(msg, ns);
64+
nmea_log.Add(ll);
65+
}
6766
}
6867

6968
void BroadcastNMEA0183Message(const wxString& msg, NmeaLog& nmea_log,
@@ -108,8 +107,7 @@ void BroadcastNMEA0183Message(const wxString& msg, NmeaLog& nmea_log,
108107
} else {
109108
ns.accepted = NavmsgStatus::Accepted::kFilteredDropped;
110109
}
111-
LogBroadcastOutputMessageColor(
112-
msg_out, params.GetDSPort().ToStdString(), ns, nmea_log);
110+
LogBroadcastOutputMessageColor(msg_out, ns, nmea_log);
113111
}
114112
}
115113
}
@@ -486,7 +484,8 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
486484
} else
487485

488486
{
489-
auto address = std::make_shared<NavAddr>();
487+
auto address =
488+
std::make_shared<NavAddr>(NavAddr::Bus::N0183, drv_n0183->iface);
490489
SENTENCE snt;
491490
NMEA0183 oNMEA0183(NmeaCtxFactory());
492491
oNMEA0183.TalkerID = _T ( "EC" );
@@ -572,7 +571,7 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
572571

573572
NavmsgStatus ns;
574573
ns.direction = NavmsgStatus::Direction::kOutput;
575-
multiplexer.LogOutputMessage(msg_out, com_name.ToStdString(), ns);
574+
multiplexer.LogOutputMessage(msg_out, ns);
576575
auto msg =
577576
wxString("-->GPS Port: ") + com_name + " Sentence: " + snt.Sentence;
578577
msg.Trim();
@@ -780,7 +779,7 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
780779

781780
NavmsgStatus ns;
782781
ns.direction = NavmsgStatus::Direction::kOutput;
783-
multiplexer.LogOutputMessage(msg_out, com_name.ToStdString(), ns);
782+
multiplexer.LogOutputMessage(msg_out, ns);
784783
wxYield();
785784

786785
// LogOutputMessage(sentence, dstr->GetPort(), false);
@@ -799,7 +798,7 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
799798

800799
NavmsgStatus ns;
801800
ns.direction = NavmsgStatus::Direction::kOutput;
802-
multiplexer.LogOutputMessage(msg_out, com_name.ToStdString(), ns);
801+
multiplexer.LogOutputMessage(msg_out, ns);
803802
wxYield();
804803

805804
auto msg =
@@ -823,7 +822,7 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
823822
drv_n0183->SendMessage(msg_out, address);
824823
NavmsgStatus ns;
825824
ns.direction = NavmsgStatus::Direction::kOutput;
826-
multiplexer.LogOutputMessage(msg_out, com_name.ToStdString(), ns);
825+
multiplexer.LogOutputMessage(msg_out, ns);
827826

828827
auto msg = wxString("-->GPS Port:") + com_name + " Sentence: " + rte;
829828
msg.Trim();
@@ -838,7 +837,7 @@ int SendRouteToGPS_N0183(Route* pr, const wxString& com_name,
838837

839838
ns = NavmsgStatus();
840839
ns.direction = NavmsgStatus::Direction::kOutput;
841-
multiplexer.LogOutputMessage(msg_outf, com_name.ToStdString(), ns);
840+
multiplexer.LogOutputMessage(msg_outf, ns);
842841

843842
msg = wxString("-->GPS Port:") + com_name + " Sentence: " + term;
844843
msg.Trim();
@@ -1039,7 +1038,7 @@ int SendWaypointToGPS_N0183(RoutePoint* prp, const wxString& com_name,
10391038

10401039
NavmsgStatus ns;
10411040
ns.direction = NavmsgStatus::Direction::kOutput;
1042-
multiplexer.LogOutputMessage(msg_out, com_name.ToStdString(), ns);
1041+
multiplexer.LogOutputMessage(msg_out, ns);
10431042
auto msg = wxString("-->GPS Port:") + com_name + " Sentence: ";
10441043
msg.Trim();
10451044
wxLogMessage(msg);

model/src/multiplexer.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,16 @@ Multiplexer::Multiplexer(MuxLogCallbacks cb, bool &filter_behaviour)
8080

8181
Multiplexer::~Multiplexer() {}
8282

83-
void Multiplexer::LogOutputMessage(const std::shared_ptr<const NavMsg>& msg,
84-
const std::string& stream_name,
85-
NavmsgStatus ns) {
83+
void Multiplexer::LogOutputMessage(const std::shared_ptr<const NavMsg> &msg,
84+
NavmsgStatus ns) {
8685
if (m_log_callbacks.log_is_active()) {
8786
ns.direction = NavmsgStatus::Direction::kOutput;
88-
Logline ll(msg, ns, stream_name);
87+
Logline ll(msg, ns);
8988
m_log_callbacks.log_message(ll);
9089
}
9190
}
9291

9392
void Multiplexer::LogInputMessage(const std::shared_ptr<const NavMsg> &msg,
94-
const std::string &stream_name,
9593
bool is_filtered, bool is_error,
9694
const wxString error_msg) {
9795
if (m_log_callbacks.log_is_active()) {
@@ -110,7 +108,7 @@ void Multiplexer::LogInputMessage(const std::shared_ptr<const NavMsg> &msg,
110108
ns.accepted = NavmsgStatus::Accepted::kOk;
111109
}
112110
}
113-
Logline ll(msg, ns, stream_name);
111+
Logline ll(msg, ns);
114112
ll.error_msg = error_msg;
115113
m_log_callbacks.log_message(ll);
116114
}
@@ -184,8 +182,7 @@ void Multiplexer::HandleN0183(std::shared_ptr<const Nmea0183Msg> n0183_msg) {
184182
//}
185183

186184
wxString port(n0183_msg->source->iface);
187-
LogInputMessage(n0183_msg, port.ToStdString(), !bpass_input_filter, b_error,
188-
error_msg);
185+
LogInputMessage(n0183_msg, !bpass_input_filter, b_error, error_msg);
189186
}
190187

191188
// Detect virtual driver, message comes from plugin API
@@ -251,7 +248,7 @@ void Multiplexer::HandleN0183(std::shared_ptr<const Nmea0183Msg> n0183_msg) {
251248
} else {
252249
if (!bxmit_ok) ns.status = NavmsgStatus::State::kTxError;
253250
}
254-
LogOutputMessage(n0183_msg, driver->iface, ns);
251+
LogOutputMessage(n0183_msg, ns);
255252
}
256253
}
257254
}
@@ -306,7 +303,7 @@ bool Multiplexer::HandleN2K_Log(std::shared_ptr<const Nmea2000Msg> n2k_msg) {
306303
log_msg.Printf("PGN: %d Source: %s ID: %s Desc: %s\n", pgn, source, ident,
307304
N2K_LogMessage_Detail(pgn).c_str());
308305

309-
LogInputMessage(n2k_msg, "N2000", false, false);
306+
LogInputMessage(n2k_msg, false, false);
310307

311308
last_pgn_logged = pgn;
312309
return true;

model/src/plugin_comm.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ static std::string MsgToString(PlugIn_Position_Fix fix) {
7171
return ss.str();
7272
}
7373

74+
static std::string JoinLines(const std::string lines) {
75+
std::istringstream is(lines);
76+
std::string line;
77+
std::string output;
78+
while (std::getline(is, line)) output += line + " ";
79+
return output.substr(0, output.size() - 1);
80+
}
81+
7482
static void LogMessage(const std::shared_ptr<const NavMsg>& message,
7583
const std::string prefix = "") {
7684
auto w = wxWindow::FindWindowByName(kDataMonitorWindowName);
7785
auto log = dynamic_cast<NmeaLog*>(w);
7886
if (log) {
7987
NavmsgStatus ns;
8088
ns.direction = NavmsgStatus::Direction::kInternal;
81-
Logline ll(message, ns, "Internal");
89+
Logline ll(message, ns);
8290
ll.prefix = prefix;
8391
log->Add(ll);
8492
}
@@ -95,7 +103,7 @@ void SendMessageToAllPlugins(const wxString& message_id,
95103
wxString body(message_body);
96104

97105
LogMessage(msg);
98-
//LogMessage(std::string("internal ALL ") + msg->to_string()); FIXME/leamas
106+
// LogMessage(std::string("internal ALL ") + msg->to_string()); FIXME/leamas
99107

100108
for (auto pic : *PluginLoader::getInstance()->GetPlugInArray()) {
101109
if (pic->m_enabled && pic->m_init_state) {
@@ -136,7 +144,7 @@ void SendMessageToAllPlugins(const wxString& message_id,
136144
}
137145

138146
void SendJSONMessageToAllPlugins(const wxString& message_id, wxJSONValue v) {
139-
wxJSONWriter w;
147+
wxJSONWriter w(wxJSONWRITER_NO_LINEFEEDS | wxJSONWRITER_STYLED);
140148
wxString out;
141149
w.Write(v, out);
142150
auto msg =
@@ -158,7 +166,8 @@ void SendAISSentenceToAllPlugIns(const wxString& sentence) {
158166
pic->m_pplugin->SetAISSentence(decouple_sentence);
159167
}
160168
}
161-
auto msg = std::make_shared<PluginMsg>("AIS", sentence.ToStdString());
169+
auto msg =
170+
std::make_shared<PluginMsg>("AIS", JoinLines(sentence.ToStdString()));
162171
LogMessage(msg, "AIS data ");
163172
}
164173

0 commit comments

Comments
 (0)