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"
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);
136 if (ppi) ppi->SetPluginMessage(
id, body);
147void SendJSONMessageToAllPlugins(
const wxString& message_id,
wxJSONValue v) {
148 wxJSONWriter w(wxJSONWRITER_NO_LINEFEEDS | wxJSONWRITER_STYLED);
152 std::make_shared<PluginMsg>(message_id.ToStdString(), out.ToStdString());
153 SendMessageToAllPlugins(message_id, out);
154 wxLogDebug(message_id);
156 LogMessage(msg,
"Json message ");
159void SendAISSentenceToAllPlugIns(
const wxString& sentence) {
161 wxString decouple_sentence(sentence);
162 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
163 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
165 if (pic->m_enabled && pic->m_init_state) {
171 std::make_shared<PluginMsg>(
"AIS", JoinLines(sentence.ToStdString()));
172 LogMessage(msg,
"AIS data ");
186 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
187 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
189 if (pic->m_enabled && pic->m_init_state) {
207 auto msg = std::make_shared<PluginMsg>(
"position-fix", MsgToString(pfix));
208 LogMessage(msg,
"application ALL gnss-fix ");
210 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
212 if (pic->m_enabled && pic->m_init_state) {
214 switch (pic->m_api_version) {
240void SendActiveLegInfoToAllPlugIns(
const ActiveLegDat* leg_info) {
242 leg.
Btw = leg_info->Btw;
243 leg.
Dtw = leg_info->Dtw;
244 leg.
wp_name = leg_info->wp_name;
245 leg.
Xte = leg_info->Xte;
246 leg.
arrival = leg_info->arrival;
247 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
248 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
250 if (pic->m_enabled && pic->m_init_state) {
252 switch (pic->m_api_version) {
268 if (ppi) ppi->SetActiveLegInfo(leg);
279bool SendMouseEventToPlugins(wxMouseEvent& event) {
281 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
282 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
284 if (pic->m_enabled && pic->m_init_state) {
286 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) {
327 if (ppi && ppi->KeyboardEventHook(event)) bret =
true;
341void SendPreShutdownHookToPlugins() {
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) {
347 switch (pic->m_api_version) {
362void SendCursorLatLonToAllPlugIns(
double lat,
double lon) {
363 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
364 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
366 if (pic->m_enabled && pic->m_init_state) {
371 auto msg = std::make_shared<PluginMsg>(
373 LogMessage(msg,
"application ALL cursor-pos ");
378 wxString decouple_sentence(sentence);
381 sigaction(SIGSEGV, NULL, &sa_all_PIM_previous);
383 struct sigaction temp;
384 sigaction(SIGSEGV, NULL, &temp);
386 temp.sa_handler = catch_signals_PIM;
387 sigemptyset(&temp.sa_mask);
392 sigaction(SIGSEGV, &temp, NULL);
394 auto msg = std::make_shared<PluginMsg>(
"NMEA-msg", sentence.ToStdString());
395 LogMessage(msg,
"internal ALL nmea-msg ");
396 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
397 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
399 if (pic->m_enabled && pic->m_init_state) {
402 if (sigsetjmp(env_PIM, 1)) {
406 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
421 sigaction(SIGSEGV, &sa_all_PIM_previous, NULL);
425int GetJSONMessageTargetCount() {
427 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
428 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
430 if (pic->m_enabled && pic->m_init_state &&
437void SendVectorChartObjectInfo(
const wxString& chart,
const wxString& feature,
438 const wxString& objname,
double& lat,
439 double& lon,
double&
scale,
int& nativescale) {
440 wxString decouple_chart(chart);
441 wxString decouple_feature(feature);
442 wxString decouple_objname(objname);
443 auto plugin_array = PluginLoader::GetInstance()->GetPlugInArray();
444 for (
unsigned int i = 0; i < plugin_array->GetCount(); i++) {
446 if (pic->m_enabled && pic->m_init_state) {
448 switch (pic->m_api_version) {
461 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.
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.