29#include <wx/jsonval.h>
30#include <wx/jsonreader.h>
31#include <wx/jsonwriter.h>
33#include "model/comm_appmsg.h"
35#include "model/plugin_loader.h"
43static struct sigaction sa_all_PIM_previous;
44static sigjmp_buf env_PIM;
46static void catch_signals_PIM(
int signo) {
49 siglongjmp(env_PIM, 1);
59void SendMessageToAllPlugins(
const wxString& message_id,
60 const wxString& message_body) {
61 auto msg = std::make_shared<PluginMsg>(
62 PluginMsg(message_id.ToStdString(), message_body.ToStdString()));
63 NavMsgBus::GetInstance().
Notify(msg);
66 wxString decouple_message_id(message_id);
67 wxString decouple_message_body(message_body);
69 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
70 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
72 if (pic->m_enabled && pic->m_init_state) {
74 switch (pic->m_api_version) {
84 ppi->SetPluginMessage(decouple_message_id, decouple_message_body);
101 ppi->SetPluginMessage(decouple_message_id, decouple_message_body);
112void SendJSONMessageToAllPlugins(
const wxString& message_id,
wxJSONValue v) {
116 SendMessageToAllPlugins(message_id, out);
117 wxLogDebug(message_id);
121void SendAISSentenceToAllPlugIns(
const wxString& sentence) {
123 wxString decouple_sentence(sentence);
124 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
125 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
127 if (pic->m_enabled && pic->m_init_state) {
145 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
146 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
148 if (pic->m_enabled && pic->m_init_state) {
166 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
168 if (pic->m_enabled && pic->m_init_state) {
170 switch (pic->m_api_version) {
195void SendActiveLegInfoToAllPlugIns(
const ActiveLegDat* leg_info) {
197 leg.
Btw = leg_info->Btw;
198 leg.
Dtw = leg_info->Dtw;
199 leg.
wp_name = leg_info->wp_name;
200 leg.
Xte = leg_info->Xte;
201 leg.
arrival = leg_info->arrival;
202 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
203 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
205 if (pic->m_enabled && pic->m_init_state) {
207 switch (pic->m_api_version) {
222 if (ppi) ppi->SetActiveLegInfo(leg);
233bool SendMouseEventToPlugins(wxMouseEvent& event) {
235 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
236 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
238 if (pic->m_enabled && pic->m_init_state) {
240 switch (pic->m_api_version) {
250 if (ppi && ppi->MouseEventHook(event)) bret =
true;
262bool SendKeyEventToPlugins(wxKeyEvent& event) {
264 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
265 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
267 if (pic->m_enabled && pic->m_init_state) {
270 switch (pic->m_api_version) {
279 if (ppi && ppi->KeyboardEventHook(event)) bret =
true;
293void SendPreShutdownHookToPlugins() {
294 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
295 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
297 if (pic->m_enabled && pic->m_init_state) {
299 switch (pic->m_api_version) {
313void SendCursorLatLonToAllPlugIns(
double lat,
double lon) {
314 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
315 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
317 if (pic->m_enabled && pic->m_init_state) {
326 wxString decouple_sentence(sentence);
329 sigaction(SIGSEGV, NULL, &sa_all_PIM_previous);
331 struct sigaction temp;
332 sigaction(SIGSEGV, NULL, &temp);
334 temp.sa_handler = catch_signals_PIM;
335 sigemptyset(&temp.sa_mask);
340 sigaction(SIGSEGV, &temp, NULL);
342 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
343 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
345 if (pic->m_enabled && pic->m_init_state) {
348 if (sigsetjmp(env_PIM, 1)) {
352 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
367 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
371int GetJSONMessageTargetCount() {
373 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
374 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
376 if (pic->m_enabled && pic->m_init_state &&
383void SendVectorChartObjectInfo(
const wxString& chart,
const wxString& feature,
384 const wxString& objname,
double& lat,
385 double& lon,
double&
scale,
int& nativescale) {
386 wxString decouple_chart(chart);
387 wxString decouple_feature(feature);
388 wxString decouple_objname(objname);
389 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
390 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
392 if (pic->m_enabled && pic->m_init_state) {
394 switch (pic->m_api_version) {
406 decouple_objname, lat, lon,
scale,
void Notify(std::shared_ptr< const NavMsg > message)
Accept message received by driver, make it available for upper layers.
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.
double Lat
Latitude in decimal degrees.
double Hdm
Heading magnetic in degrees.
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.
Basic position fix information.
double Cog
Course over ground in degrees.
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.
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.
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 begins shutdown sequence.
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.
virtual void SetPositionFix(PlugIn_Position_Fix &pfix)
Updates plugin with current position fix data.
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.
void Write(const wxJSONValue &value, wxString &str)
Write the JSONvalue object to a JSON text.
Raw messages layer, supports sending and recieving navmsg messages.
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.
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.
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.