29#include <wx/jsonval.h>
30#include <wx/jsonreader.h>
31#include <wx/jsonwriter.h>
33#include "model/comm_appmsg.h"
45static struct sigaction sa_all_PIM_previous;
46static sigjmp_buf env_PIM;
48static void catch_signals_PIM(
int signo) {
51 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 wxString& message_id,
96 const wxString& message_body) {
97 auto msg = std::make_shared<PluginMsg>(
98 PluginMsg(message_id.ToStdString(), message_body.ToStdString()));
99 NavMsgBus::GetInstance().
Notify(msg);
102 wxString id(message_id);
103 wxString body(message_body);
108 for (
auto pic : *
PluginLoader::GetInstance()->GetPlugInArray()) {
109 if (pic->m_enabled && pic->m_init_state) {
111 switch (pic->m_api_version) {
119 if (ppi) ppi->SetPluginMessage(
id, body);
137 if (ppi) ppi->SetPluginMessage(
id, body);
148void SendJSONMessageToAllPlugins(
const wxString& message_id,
wxJSONValue v) {
149 wxJSONWriter w(wxJSONWRITER_NO_LINEFEEDS | wxJSONWRITER_STYLED);
153 std::make_shared<PluginMsg>(message_id.ToStdString(), out.ToStdString());
154 SendMessageToAllPlugins(message_id, out);
155 wxLogDebug(message_id);
157 LogMessage(msg,
"Json message ");
160void SendAISSentenceToAllPlugIns(
const wxString& sentence) {
162 wxString decouple_sentence(sentence);
163 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
164 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
166 if (pic->m_enabled && pic->m_init_state) {
172 std::make_shared<PluginMsg>(
"AIS", JoinLines(sentence.ToStdString()));
173 LogMessage(msg,
"AIS data ");
187 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
188 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
190 if (pic->m_enabled && pic->m_init_state) {
208 auto msg = std::make_shared<PluginMsg>(
"position-fix", MsgToString(pfix));
209 LogMessage(msg,
"application ALL gnss-fix ");
211 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
213 if (pic->m_enabled && pic->m_init_state) {
215 switch (pic->m_api_version) {
242void SendActiveLegInfoToAllPlugIns(
const ActiveLegDat* leg_info) {
244 leg.
Btw = leg_info->Btw;
245 leg.
Dtw = leg_info->Dtw;
246 leg.
wp_name = leg_info->wp_name;
247 leg.
Xte = leg_info->Xte;
248 leg.
arrival = leg_info->arrival;
249 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
250 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
252 if (pic->m_enabled && pic->m_init_state) {
254 switch (pic->m_api_version) {
271 if (ppi) ppi->SetActiveLegInfo(leg);
282bool SendMouseEventToPlugins(wxMouseEvent& event) {
284 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
285 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
287 if (pic->m_enabled && pic->m_init_state) {
289 switch (pic->m_api_version) {
301 if (ppi && ppi->MouseEventHook(event)) bret =
true;
313bool SendKeyEventToPlugins(wxKeyEvent& event) {
315 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
316 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
318 if (pic->m_enabled && pic->m_init_state) {
321 switch (pic->m_api_version) {
332 if (ppi && ppi->KeyboardEventHook(event)) bret =
true;
346void SendPreShutdownHookToPlugins() {
347 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
348 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
350 if (pic->m_enabled && pic->m_init_state) {
352 switch (pic->m_api_version) {
368void SendCursorLatLonToAllPlugIns(
double lat,
double lon) {
369 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
370 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
372 if (pic->m_enabled && pic->m_init_state) {
377 auto msg = std::make_shared<PluginMsg>(
379 LogMessage(msg,
"application ALL cursor-pos ");
384 wxString decouple_sentence(sentence);
387 sigaction(SIGSEGV, NULL, &sa_all_PIM_previous);
389 struct sigaction temp;
390 sigaction(SIGSEGV, NULL, &temp);
392 temp.sa_handler = catch_signals_PIM;
393 sigemptyset(&temp.sa_mask);
398 sigaction(SIGSEGV, &temp, NULL);
400 auto msg = std::make_shared<PluginMsg>(
"NMEA-msg", sentence.ToStdString());
401 LogMessage(msg,
"internal ALL nmea-msg ");
402 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
403 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
405 if (pic->m_enabled && pic->m_init_state) {
408 if (sigsetjmp(env_PIM, 1)) {
412 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
427 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
431int GetJSONMessageTargetCount() {
433 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
434 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
436 if (pic->m_enabled && pic->m_init_state &&
443void SendVectorChartObjectInfo(
const wxString& chart,
const wxString& feature,
444 const wxString& objname,
double& lat,
445 double& lon,
double&
scale,
int& nativescale) {
446 wxString decouple_chart(chart);
447 wxString decouple_feature(feature);
448 wxString decouple_objname(objname);
449 auto plugin_array = PluginLoader::GetInstance()->
GetPlugInArray();
450 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
452 if (pic->m_enabled && pic->m_init_state) {
454 switch (pic->m_api_version) {
468 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.
The JSON value class implementation.
The JSON document writer.
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.