28#include <wx/jsonval.h>
29#include <wx/jsonreader.h>
30#include <wx/jsonwriter.h>
44static struct sigaction sa_all_PIM_previous;
45static sigjmp_buf env_PIM;
47static void catch_signals_PIM(
int signo) {
50 siglongjmp(env_PIM, 1);
60static std::string PosItem(
const std::string what,
double item) {
62 ss <<
" " << what <<
" " << std::setprecision(3) << item;
69 << PosItem(
"Sog", fix.
Sog) <<
" " << PosItem(
"Var", fix.
Var)
70 <<
" Nsats: " << fix.
nSats;
74static std::string JoinLines(
const std::string lines) {
75 std::istringstream is(lines);
78 while (std::getline(is, line)) output += line +
" ";
79 return output.substr(0, output.size() - 1);
82static void LogMessage(
const std::shared_ptr<const NavMsg>& message,
83 const std::string prefix =
"") {
84 auto w = wxWindow::FindWindowByName(kDataMonitorWindowName);
85 auto log =
dynamic_cast<NmeaLog*
>(w);
88 ns.direction = NavmsgStatus::Direction::kInternal;
95void SendMessageToAllPlugins(
const std::string& message_id,
96 const std::string& message_body) {
97 auto msg = std::make_shared<PluginMsg>(
PluginMsg(message_id, message_body));
98 NavMsgBus::GetInstance().
Notify(msg);
101 wxString id(message_id);
102 wxString body(message_body);
107 for (
auto pic : *
PluginLoader::GetInstance()->GetPlugInArray()) {
108 if (pic->m_enabled && pic->m_init_state) {
110 switch (pic->m_api_version) {
118 if (ppi) ppi->SetPluginMessage(
id, body);
136 if (ppi) ppi->SetPluginMessage(
id, body);
147void SendJsonMessageToAllPlugins(
const std::string& message_id,
148 const nlohmann::json& v) {
149 std::string out = v.dump();
150 auto msg = std::make_shared<PluginMsg>(message_id, out);
151 SendMessageToAllPlugins(message_id, out);
152 wxLogDebug(wxString(message_id) +
" " + out);
153 LogMessage(msg,
"Json message ");
156void SendAISSentenceToAllPlugIns(
const wxString& sentence) {
158 wxString decouple_sentence(sentence);
159 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
160 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
162 if (pic->m_enabled && pic->m_init_state) {
168 std::make_shared<PluginMsg>(
"AIS", JoinLines(sentence.ToStdString()));
169 LogMessage(msg,
"AIS data ");
183 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
184 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
186 if (pic->m_enabled && pic->m_init_state) {
204 auto msg = std::make_shared<PluginMsg>(
"position-fix", MsgToString(pfix));
205 LogMessage(msg,
"application ALL gnss-fix ");
207 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
209 if (pic->m_enabled && pic->m_init_state) {
211 switch (pic->m_api_version) {
238void SendActiveLegInfoToAllPlugIns(
const ActiveLegDat* leg_info) {
240 leg.
Btw = leg_info->Btw;
241 leg.
Dtw = leg_info->Dtw;
242 leg.
wp_name = leg_info->wp_name;
243 leg.
Xte = leg_info->Xte;
244 leg.
arrival = leg_info->arrival;
245 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
246 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
248 if (pic->m_enabled && pic->m_init_state) {
250 switch (pic->m_api_version) {
267 if (ppi) ppi->SetActiveLegInfo(leg);
278bool SendMouseEventToPlugins(wxMouseEvent& event) {
280 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
281 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
283 if (pic->m_enabled && pic->m_init_state) {
285 switch (pic->m_api_version) {
297 if (ppi && ppi->MouseEventHook(event)) bret =
true;
309bool SendKeyEventToPlugins(wxKeyEvent& event) {
311 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
312 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
314 if (pic->m_enabled && pic->m_init_state) {
317 switch (pic->m_api_version) {
328 if (ppi && ppi->KeyboardEventHook(event)) bret =
true;
342void SendPreShutdownHookToPlugins() {
343 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
344 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
346 if (pic->m_enabled && pic->m_init_state) {
348 switch (pic->m_api_version) {
364void SendCursorLatLonToAllPlugIns(
double lat,
double lon) {
365 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
366 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
368 if (pic->m_enabled && pic->m_init_state) {
373 auto msg = std::make_shared<PluginMsg>(
375 LogMessage(msg,
"application ALL cursor-pos ");
380 wxString decouple_sentence(sentence);
383 sigaction(SIGSEGV, NULL, &sa_all_PIM_previous);
385 struct sigaction temp;
386 sigaction(SIGSEGV, NULL, &temp);
388 temp.sa_handler = catch_signals_PIM;
389 sigemptyset(&temp.sa_mask);
394 sigaction(SIGSEGV, &temp, NULL);
396 auto msg = std::make_shared<PluginMsg>(
"NMEA-msg", sentence.ToStdString());
397 LogMessage(msg,
"internal ALL nmea-msg ");
398 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
399 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
401 if (pic->m_enabled && pic->m_init_state) {
404 if (sigsetjmp(env_PIM, 1)) {
408 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
423 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
427int GetJSONMessageTargetCount() {
429 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
430 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
432 if (pic->m_enabled && pic->m_init_state &&
439void SendVectorChartObjectInfo(
const wxString& chart,
const wxString& feature,
440 const wxString& objname,
double& lat,
441 double& lon,
double&
scale,
int& nativescale) {
442 wxString decouple_chart(chart);
443 wxString decouple_feature(feature);
444 wxString decouple_objname(objname);
445 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
446 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
448 if (pic->m_enabled && pic->m_init_state) {
450 switch (pic->m_api_version) {
464 decouple_objname, lat, lon,
scale,
void Notify(std::shared_ptr< const NavMsg > message)
Accept message received by driver, make it available for upper layers.
Representation of message status as determined by the multiplexer.
Data for a loaded plugin, including dl-loaded library.
int m_cap_flag
PlugIn Capabilities descriptor.
Extended position fix information.
int nSats
Number of satellites used in the fix.
double Var
Magnetic variation in degrees, typically from RMC message.
double Cog
Course over ground in degrees [0-360).
double Lat
Latitude in decimal degrees.
double Hdm
Heading magnetic in degrees [0-360).
time_t FixTime
UTC time of fix.
double Lon
Longitude in decimal degrees.
double Sog
Speed over ground in knots.
double Hdt
Heading true in degrees [0-360).
Basic position fix information.
double Cog
Course over ground in degrees [0-360).
double Sog
Speed over ground in knots.
time_t FixTime
UTC time of fix as time_t value.
double Lat
Latitude in decimal degrees.
int nSats
Number of satellites used in the fix.
double Var
Magnetic variation in degrees, typically from RMC message.
double Lon
Longitude in decimal degrees.
PluginLoader is a backend module without any direct GUI functionality.
const ArrayOfPlugIns * GetPlugInArray()
Return list of currently loaded plugins.
A plugin to plugin json message over the REST interface.
Information about the currently active route leg.
double Dtw
Distance to waypoint in nautical miles.
wxString wp_name
Name of destination waypoint for the active leg.
double Xte
Cross track error in nautical miles, negative values indicate left side of track.
double Btw
Bearing to waypoint in degrees true.
bool arrival
True when vessel is within the arrival circle of the destination waypoint.
std::string to_string() const
Return utf string like 65°25,11N 21°12,01E.
virtual void SendVectorChartObjectInfo(wxString &chart, wxString &feature, wxString &objname, double lat, double lon, double scale, int nativescale)
Receives vector chart object information.
virtual void PreShutdownHook()
Called just before OpenCPN exits.
virtual void SetPluginMessage(wxString &message_id, wxString &message_body)
Receives plugin-to-plugin messages.
virtual void SetPositionFixEx(PlugIn_Position_Fix_Ex &pfix)
Updates plugin with extended position fix data at regular intervals.
virtual void SetPositionFix(PlugIn_Position_Fix &pfix)
Updates plugin with current position fix data at regular intervals.
virtual void SetNMEASentence(wxString &sentence)
Receive all NMEA 0183 sentences from OpenCPN.
virtual void SetAISSentence(wxString &sentence)
Receive all AIS sentences from OpenCPN.
virtual void SetCursorLatLon(double lat, double lon)
Receives cursor lat/lon position updates.
Decoded messages definitions.
Raw messages layer, supports sending and recieving navmsg messages.
Hooks into gui available in model.
Basic DataMonitor logging interface: LogLine (reflects a line in the log) and NmeaLog,...
PlugIn Object Definition/API.
#define WANTS_NMEA_EVENTS
Receive decoded NMEA events with parsed data.
#define WANTS_VECTOR_CHART_OBJECT_INFO
Receive information about vector chart objects.
#define WANTS_AIS_SENTENCES
Receive AIS target information and updates.
#define WANTS_KEYBOARD_EVENTS
Receive keyboard events from main window.
#define WANTS_NMEA_SENTENCES
Receive raw NMEA 0183 sentences from all active ports.
#define WANTS_MOUSE_EVENTS
Receive mouse events (clicks, movement, etc).
#define WANTS_PRESHUTDOWN_HOOK
Receive notification just before OpenCPN shutdown.
#define WANTS_PLUGIN_MESSAGING
Enable message passing between plugins.
#define WANTS_CURSOR_LATLON
Receive updates when cursor moves over chart.
Miscellaneous utilities, many of which string related.
void SendNMEASentenceToAllPlugIns(const wxString &sentence)
Distribute a NMEA 0183 sentence to all plugins that have registered interest by setting the WANTS_NME...
Tools to send data to plugins.
Low level code to load plugins from disk, notably the PluginLoader class.
A generic position and navigation data structure.
double kCog
Course over ground in degrees.
double kHdt
True heading in degrees.
int nSats
Number of satellites used in the fix.
double kHdm
Magnetic heading in degrees.
time_t FixTime
UTC time of fix.
double kLat
Latitude in decimal degrees.
double kSog
Speed over ground in knots.
double kVar
Magnetic variation in degrees.
double kLon
Longitude in decimal degrees.