OpenCPN Partial API docs
plugin_api.cpp File Reference

Implement various ocpn_plugin.h methods. More...

#include <memory>
#include <sstream>
#include <vector>
#include <wx/event.h>
#include <wx/jsonval.h>
#include <wx/jsonreader.h>
#include "model/base_platform.h"
#include "model/comm_appmsg.h"
#include "model/comm_drv_n0183_net.h"
#include "model/comm_drv_n0183_serial.h"
#include "model/comm_drv_n2k.h"
#include "model/comm_drv_registry.h"
#include "model/comm_navmsg_bus.h"
#include "ocpn_plugin.h"

Go to the source code of this file.

Functions

vector< uint8_t > GetN2000Payload (NMEA2000Id id, ObservedEvt ev)
 Return N2K payload for a received n2000 message of type id in ev. More...
 
std::string GetN2000Source (NMEA2000Id id, ObservedEvt ev)
 Return source identifier (iface) of a received n2000 message of type id in ev.
 
std::string GetN0183Payload (NMEA0183Id id, ObservedEvt ev)
 Return payload in a received n0183 message of type id in ev.
 
std::string GetPluginMsgPayload (PluginMsgId id, ObservedEvt ev)
 
std::shared_ptr< void > GetSignalkPayload (ObservedEvt ev)
 Get SignalK status payload after receiving a message. More...
 
shared_ptr< ObservableListenerGetListener (NMEA2000Id id, wxEventType et, wxEvtHandler *eh)
 
std::shared_ptr< ObservableListenerGetListener (NMEA0183Id id, wxEventType et, wxEvtHandler *eh)
 
shared_ptr< ObservableListenerGetListener (SignalkId id, wxEventType et, wxEvtHandler *eh)
 
shared_ptr< ObservableListenerGetListener (NavDataId id, wxEventType et, wxEvtHandler *eh)
 
std::shared_ptr< ObservableListenerGetListener (PluginMsgId id, wxEventType et, wxEvtHandler *eh)
 
PluginNavdata GetEventNavdata (ObservedEvt ev)
 Return BasicNavDataMsg decoded data available in ev.
 
std::vector< DriverHandleGetActiveDrivers ()
 Comm port plugin TX support methods
More...
 
const std::unordered_map< std::string, std::string > GetAttributes (DriverHandle handle)
 Query a specific driver for attributes
More...
 
CommDriverResult WriteCommDriver (DriverHandle handle, const std::shared_ptr< std::vector< uint8_t >> &payload)
 
CommDriverResult WriteCommDriverN2K (DriverHandle handle, int PGN, int destinationCANAddress, int priority, const std::shared_ptr< std::vector< uint8_t >> &payload)
 Send a PGN message to an NMEA2000 address. More...
 
CommDriverResult RegisterTXPGNs (DriverHandle handle, std::vector< int > &pgn_list)
 Special NMEA2000 requirements NMEA2000 bus protocol device management requires that devices writing on the bus must inform all bus listeners of the specific PGNs that may be transmitted by this device. More...
 
wxString * GetpPrivateApplicationDataLocation (void)
 

Detailed Description

Implement various ocpn_plugin.h methods.

Definition in file plugin_api.cpp.

Function Documentation

◆ GetActiveDrivers()

std::vector<DriverHandle> GetActiveDrivers ( )

Comm port plugin TX support methods

Query OCPN core for a list of active drivers

Definition at line 136 of file plugin_api.cpp.

◆ GetAttributes()

const std::unordered_map<std::string, std::string> GetAttributes ( DriverHandle  handle)

Query a specific driver for attributes

Query driver attributes

Definition at line 148 of file plugin_api.cpp.

◆ GetN2000Payload()

vector<uint8_t> GetN2000Payload ( NMEA2000Id  id,
ObservedEvt  ev 
)

Return N2K payload for a received n2000 message of type id in ev.

The vector returned is described in the following example

 [147,19,                     // Header bytes, unused
  3,                          // N2K priority
  16,240,1,                   // example pgn 126992 encoded little endian
  255,                        // N2K destination address
  1,                          // N2K origin address
  255,255,255,255,            // timestamp, unused
  8,                          // count of following NMEA2000 data
  13,240,207,76,208,3,94,40,  // NMEA2000 data
  85                          // CRC byte, unused,not included in count
 ];

Definition at line 47 of file plugin_api.cpp.

◆ GetSignalkPayload()

std::shared_ptr<void> GetSignalkPayload ( ObservedEvt  ev)

Get SignalK status payload after receiving a message.

Returns
pointer to a wxJSONValue map object. Typical usage:
auto ptr = GetSignalkPayload(ev);
const auto msg = *std::static_pointer_cast<const wxJSONValue>(payload);
The map contains the following entries:
  • "Data": the parsed json message
  • "ErrorCount": int, the number of parsing errors
  • "WarningCount": int, the number of parsing warnings
  • "Errors": list of strings, error messages.
  • "Warnings": list of strings, warning messages..
  • "Context": string, message context
  • "ContextSelf": string, own ship context.

Definition at line 68 of file plugin_api.cpp.

◆ RegisterTXPGNs()

CommDriverResult RegisterTXPGNs ( DriverHandle  handle,
std::vector< int > &  pgn_list 
)

Special NMEA2000 requirements NMEA2000 bus protocol device management requires that devices writing on the bus must inform all bus listeners of the specific PGNs that may be transmitted by this device.

Once configured, this bus management process will be handled transparently by the OCPN core drivers. It is only necessary for plugins wishing to write to the NMEA2000 bus to register the specific PGNs that they anticipate using, with the selected driver.

Definition at line 220 of file plugin_api.cpp.

◆ WriteCommDriverN2K()

CommDriverResult WriteCommDriverN2K ( DriverHandle  handle,
int  PGN,
int  destinationCANAddress,
int  priority,
const std::shared_ptr< std::vector< uint8_t >> &  payload 
)

Send a PGN message to an NMEA2000 address.


Definition at line 195 of file plugin_api.cpp.