OpenCPN Partial API docs
Loading...
Searching...
No Matches
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.
 
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)
 Retrieve the string in a plugin message, internal or received on the REST insterface.
 
std::shared_ptr< void > GetSignalkPayload (ObservedEvt ev)
 Get SignalK status payload after receiving a message.
 
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)
 Return listener for plugin messages, internal or received on the REST interface.
 
PluginNavdata GetEventNavdata (ObservedEvt ev)
 Return BasicNavDataMsg decoded data available in ev.
 
std::vector< DriverHandleGetActiveDrivers ()
 Comm port plugin TX support methods

 
const std::unordered_map< std::string, std::string > GetAttributes (DriverHandle handle)
 Query a specific driver for attributes

 
CommDriverResult WriteCommDriver (DriverHandle handle, const std::shared_ptr< std::vector< uint8_t > > &payload)
 Send a non-NMEA2000 message.
 
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.
 
CommDriverResult RegisterTXPGNs (DriverHandle handle, std::vector< int > &pgn_list)
 Register PGNs that this application intends to transmit for some NMEA 2000 adapters like Actisense NGT-1.
 
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

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 131 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

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 142 of file plugin_api.cpp.

◆ GetEventNavdata()

PluginNavdata GetEventNavdata ( ObservedEvt  ev)

Return BasicNavDataMsg decoded data available in ev.

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 115 of file plugin_api.cpp.

◆ GetListener() [1/5]

shared_ptr< ObservableListener > GetListener ( NavDataId  id,
wxEventType  et,
wxEvtHandler *  eh 
)

Definition at line 105 of file plugin_api.cpp.

◆ GetListener() [2/5]

std::shared_ptr< ObservableListener > GetListener ( NMEA0183Id  id,
wxEventType  et,
wxEvtHandler *  eh 
)

Definition at line 95 of file plugin_api.cpp.

◆ GetListener() [3/5]

shared_ptr< ObservableListener > GetListener ( NMEA2000Id  id,
wxEventType  et,
wxEvtHandler *  eh 
)

Definition at line 90 of file plugin_api.cpp.

◆ GetListener() [4/5]

std::shared_ptr< ObservableListener > GetListener ( PluginMsgId  id,
wxEventType  et,
wxEvtHandler *  eh 
)

Return listener for plugin messages, internal or received on the REST interface.

Definition at line 110 of file plugin_api.cpp.

◆ GetListener() [5/5]

shared_ptr< ObservableListener > GetListener ( SignalkId  id,
wxEventType  et,
wxEvtHandler *  eh 
)

Definition at line 100 of file plugin_api.cpp.

◆ GetN0183Payload()

std::string GetN0183Payload ( NMEA0183Id  id,
ObservedEvt  ev 
)

Return payload in a received n0183 message of type id in ev.

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 55 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
 ];
Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 45 of file plugin_api.cpp.

◆ GetN2000Source()

std::string GetN2000Source ( NMEA2000Id  id,
ObservedEvt  ev 
)

Return source identifier (iface) of a received n2000 message of type id in ev.

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 50 of file plugin_api.cpp.

◆ GetPluginMsgPayload()

std::string GetPluginMsgPayload ( PluginMsgId  id,
ObservedEvt  ev 
)

Retrieve the string in a plugin message, internal or received on the REST insterface.

Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 60 of file plugin_api.cpp.

◆ GetpPrivateApplicationDataLocation()

wxString * GetpPrivateApplicationDataLocation ( void  )

Definition at line 255 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.
Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 65 of file plugin_api.cpp.

◆ RegisterTXPGNs()

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

Register PGNs that this application intends to transmit for some NMEA 2000 adapters like Actisense NGT-1.

This function is required specifically for NMEA 2000 adapters like the Actisense NGT-1. For these devices, registration of transmit PGNs is required before sending any messages. This is an adapter-specific requirement, not a requirement of the NMEA 2000 standard itself.

This function is only implemented for serial NMEA 2000 adapters (specifically the Actisense NGT-1). For other connection types (TCP, UDP), the function will return success and perform no registration.

Parameters
handleThe driver handle obtained from GetActiveDrivers()
pgn_listList of PGNs this application will transmit
Returns
RESULT_COMM_NO_ERROR if registration successful RESULT_COMM_INVALID_PARMS if pgn_list is empty RESULT_COMM_INVALID_HANDLE if handle is invalid RESULT_COMM_REGISTER_PGN_ERROR if PGN registration failed

Example usage:

// Register to transmit wind data and rudder commands
std::vector<int> pgns = {130306, // Wind Data
127245}; // Rudder
auto result = RegisterTXPGNs(driver_handle, pgns);
if (result != RESULT_COMM_NO_ERROR) {
// Handle error
}
CommDriverResult RegisterTXPGNs(DriverHandle handle, std::vector< int > &pgn_list)
Register PGNs that this application intends to transmit for some NMEA 2000 adapters like Actisense NG...
Note
For Actisense NGT-1 adapters, this registration must be done before transmitting any NMEA 2000 messages. The registration remains in effect until the application closes or explicitly registers a new list. Before any device can transmit messages on an NMEA 2000 network, it must first announce which message types (PGNs) it will transmit. This allows other devices on the network to:
  • Know what data is available.
  • Request specific data from the transmitting device.
  • Properly handle network address claims.
Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 222 of file plugin_api.cpp.

◆ WriteCommDriver()

CommDriverResult WriteCommDriver ( DriverHandle  handle,
const std::shared_ptr< std::vector< uint8_t > > &  payload 
)

Send a non-NMEA2000 message.

The call is not blocking.

Parameters
handleObtained from GetActiveDrivers()
payloadMessage data, for example a complete Nmea0183 message. From 1.19: if the handle "protocol" attribute is "internal" it is parsed as <id><space><message> where the id is used when listening/ subscribing to message.
Returns
value number of bytes queued for transmission.
Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 156 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.


Examples
/home/runner/work/main/main/opencpn/include/ocpn_plugin.h.

Definition at line 197 of file plugin_api.cpp.