29#include <wx/jsonval.h>
30#include <wx/jsonreader.h>
31#include <wx/jsonwriter.h>
33#include "model/comm_appmsg.h"
36#include "model/nmea_log.h"
38#include "model/plugin_loader.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);
135 if (ppi) ppi->SetPluginMessage(
id, body);
146void SendJSONMessageToAllPlugins(
const wxString& message_id,
wxJSONValue v) {
147 wxJSONWriter w(wxJSONWRITER_NO_LINEFEEDS | wxJSONWRITER_STYLED);
151 std::make_shared<PluginMsg>(message_id.ToStdString(), out.ToStdString());
152 SendMessageToAllPlugins(message_id, out);
153 wxLogDebug(message_id);
155 LogMessage(msg,
"Json message ");
158void SendAISSentenceToAllPlugIns(
const wxString& sentence) {
160 wxString decouple_sentence(sentence);
161 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
162 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
164 if (pic->m_enabled && pic->m_init_state) {
170 std::make_shared<PluginMsg>(
"AIS", JoinLines(sentence.ToStdString()));
171 LogMessage(msg,
"AIS data ");
185 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
186 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
188 if (pic->m_enabled && pic->m_init_state) {
206 auto msg = std::make_shared<PluginMsg>(
"position-fix", MsgToString(pfix));
207 LogMessage(msg,
"application ALL gnss-fix ");
209 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
211 if (pic->m_enabled && pic->m_init_state) {
213 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) {
265 if (ppi) ppi->SetActiveLegInfo(leg);
276bool SendMouseEventToPlugins(wxMouseEvent& event) {
278 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
279 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
281 if (pic->m_enabled && pic->m_init_state) {
283 switch (pic->m_api_version) {
293 if (ppi && ppi->MouseEventHook(event)) bret =
true;
305bool SendKeyEventToPlugins(wxKeyEvent& event) {
307 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
308 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
310 if (pic->m_enabled && pic->m_init_state) {
313 switch (pic->m_api_version) {
322 if (ppi && ppi->KeyboardEventHook(event)) bret =
true;
336void SendPreShutdownHookToPlugins() {
337 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
338 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
340 if (pic->m_enabled && pic->m_init_state) {
342 switch (pic->m_api_version) {
356void SendCursorLatLonToAllPlugIns(
double lat,
double lon) {
357 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
358 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
360 if (pic->m_enabled && pic->m_init_state) {
365 auto msg = std::make_shared<PluginMsg>(
367 LogMessage(msg,
"application ALL cursor-pos ");
372 wxString decouple_sentence(sentence);
375 sigaction(SIGSEGV, NULL, &sa_all_PIM_previous);
377 struct sigaction temp;
378 sigaction(SIGSEGV, NULL, &temp);
380 temp.sa_handler = catch_signals_PIM;
381 sigemptyset(&temp.sa_mask);
386 sigaction(SIGSEGV, &temp, NULL);
388 auto msg = std::make_shared<PluginMsg>(
"NMEA-msg", sentence.ToStdString());
389 LogMessage(msg,
"internal ALL nmea-msg ");
390 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
391 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
393 if (pic->m_enabled && pic->m_init_state) {
396 if (sigsetjmp(env_PIM, 1)) {
400 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
415 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
419int GetJSONMessageTargetCount() {
421 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
422 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
424 if (pic->m_enabled && pic->m_init_state &&
431void SendVectorChartObjectInfo(
const wxString& chart,
const wxString& feature,
432 const wxString& objname,
double& lat,
433 double& lon,
double&
scale,
int& nativescale) {
434 wxString decouple_chart(chart);
435 wxString decouple_feature(feature);
436 wxString decouple_objname(objname);
437 auto plugin_array = PluginLoader::getInstance()->GetPlugInArray();
438 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
440 if (pic->m_enabled && pic->m_init_state) {
442 switch (pic->m_api_version) {
454 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.
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.
PluginLoader is a backend module without any direct GUI functionality.
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 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.
Raw messages layer, supports sending and recieving navmsg messages.
Hooks into gui available in model.
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.
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.