dnp3 (C++ API) 1.1.0
dnp3::MasterChannel Class Reference

Represents a communication channel for a master station. More...

#include <dnp3.hpp>

Public Member Functions

 MasterChannel (MasterChannel &&other) noexcept
 Transfer ownership of the underlying C-type to this instance and invalidate the other instance. More...
 
 ~MasterChannel ()
 Shutdown a MasterChannel and release all resources. More...
 
void enable ()
 start communications More...
 
void disable ()
 stop communications More...
 
AssociationId add_association (uint16_t address, const AssociationConfig &config, std::unique_ptr< ReadHandler > read_handler, std::unique_ptr< AssociationHandler > association_handler, std::unique_ptr< AssociationInformation > association_information)
 Add an association to the channel. More...
 
void remove_association (const AssociationId &id)
 Remove an association from the channel. More...
 
void set_decode_level (const DecodeLevel &decode_level)
 Set the decoding level for the channel. More...
 
DecodeLevel get_decode_level ()
 Get the decoding level for the channel. More...
 
PollId add_poll (const AssociationId &id, Request &request, std::chrono::steady_clock::duration period)
 Add a periodic poll to an association. More...
 
void remove_poll (const PollId &poll_id)
 Add a periodic poll to an association. More...
 
void demand_poll (const PollId &poll_id)
 Demand the immediate execution of a poll previously created with MasterChannel::add_poll(). More...
 
void read (const AssociationId &association, Request &request, std::unique_ptr< ReadTaskCallback > callback)
 Perform a read on the association. More...
 
void read_with_handler (const AssociationId &association, Request &request, std::unique_ptr< ReadHandler > handler, std::unique_ptr< ReadTaskCallback > callback)
 Perform a read on the association. More...
 
void operate (const AssociationId &association, CommandMode mode, CommandSet &command, std::unique_ptr< CommandTaskCallback > callback)
 Asynchronously perform a command operation on the association. More...
 
void synchronize_time (const AssociationId &association, TimeSyncMode mode, std::unique_ptr< TimeSyncTaskCallback > callback)
 Asynchronously perform a time sync operation to the association. More...
 
void cold_restart (const AssociationId &association, std::unique_ptr< RestartTaskCallback > callback)
 Asynchronously perform a cold restart operation to the association. More...
 
void warm_restart (const AssociationId &association, std::unique_ptr< RestartTaskCallback > callback)
 Asynchronously perform a warm restart operation to the association. More...
 
void check_link_status (const AssociationId &association, std::unique_ptr< LinkStatusCallback > callback)
 Asynchronously perform a link status check. More...
 

Static Public Member Functions

static MasterChannel create_tcp_channel (Runtime &runtime, LinkErrorMode link_error_mode, const MasterChannelConfig &config, EndpointList &endpoints, const ConnectStrategy &connect_strategy, std::unique_ptr< ClientStateListener > listener)
 Create a master channel that connects to the specified TCP endpoint(s) More...
 
static MasterChannel create_tls_channel (Runtime &runtime, LinkErrorMode link_error_mode, const MasterChannelConfig &config, EndpointList &endpoints, const ConnectStrategy &connect_strategy, std::unique_ptr< ClientStateListener > listener, const TlsClientConfig &tls_config)
 Create a master channel that connects to the specified TCP endpoint(s) and establish a TLS session with the remote. More...
 
static MasterChannel create_serial_channel (Runtime &runtime, const MasterChannelConfig &config, const std::string &path, const SerialSettings &serial_params, std::chrono::steady_clock::duration open_retry_delay, std::unique_ptr< PortStateListener > listener)
 Create a master channel on the specified serial port. More...
 

Friends

class CppMasterChannelFriend
 

Detailed Description

Represents a communication channel for a master station.

To communicate with a particular outstation, you need to add an association with MasterChannel::add_association().

Warning
The class methods that return a value (e.g. as MasterChannel::add_association()) cannot be called from within a callback.

Constructor & Destructor Documentation

◆ MasterChannel()

dnp3::MasterChannel::MasterChannel ( MasterChannel &&  other)
inlinenoexcept

Transfer ownership of the underlying C-type to this instance and invalidate the other instance.

Note
the moved class will now throw an exception if any method is called
Parameters
otherClass from which ownership will be transfer to this instance

◆ ~MasterChannel()

dnp3::MasterChannel::~MasterChannel ( )

Shutdown a MasterChannel and release all resources.

Member Function Documentation

◆ add_association()

AssociationId dnp3::MasterChannel::add_association ( uint16_t  address,
const AssociationConfig config,
std::unique_ptr< ReadHandler read_handler,
std::unique_ptr< AssociationHandler association_handler,
std::unique_ptr< AssociationInformation association_information 
)

Add an association to the channel.

Parameters
addressDNP3 data-link address of the remote outstation
configAssociation configuration
read_handlerInterface uses to load measurement data
association_handlerAssociation specific callbacks such as time synchronization
association_informationAssociation information interface
Returns
Id of the association
Exceptions
ParamException

◆ add_poll()

PollId dnp3::MasterChannel::add_poll ( const AssociationId id,
Request request,
std::chrono::steady_clock::duration  period 
)

Add a periodic poll to an association.

Each result of the poll will be sent to the ReadHandler of the association.

Parameters
idAssociation on which to add the poll
requestRequest to perform
periodPeriod to wait between each poll (in ms)
Returns
Id of the created poll
Exceptions
ParamException

◆ check_link_status()

void dnp3::MasterChannel::check_link_status ( const AssociationId association,
std::unique_ptr< LinkStatusCallback callback 
)

Asynchronously perform a link status check.

Parameters
associationId of the association
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ cold_restart()

void dnp3::MasterChannel::cold_restart ( const AssociationId association,
std::unique_ptr< RestartTaskCallback callback 
)

Asynchronously perform a cold restart operation to the association.

Parameters
associationId of the association
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ create_serial_channel()

static MasterChannel dnp3::MasterChannel::create_serial_channel ( Runtime runtime,
const MasterChannelConfig config,
const std::string &  path,
const SerialSettings serial_params,
std::chrono::steady_clock::duration  open_retry_delay,
std::unique_ptr< PortStateListener listener 
)
static

Create a master channel on the specified serial port.

The returned master must be gracefully shutdown with MasterChannel::~MasterChannel() when done.

Parameters
runtimeRuntime to use to drive asynchronous operations of the master
configGeneric configuration for the channel
pathPath to the serial device. Generally /dev/tty0 on Linux and COM1 on Windows.
serial_paramsSerial port settings
open_retry_delaydelay between attempts to open the serial port
listenerListener to receive updates on the status of the serial port
Returns
Handle to the master created, NULL if an error occurred
Exceptions
ParamException

◆ create_tcp_channel()

static MasterChannel dnp3::MasterChannel::create_tcp_channel ( Runtime runtime,
LinkErrorMode  link_error_mode,
const MasterChannelConfig config,
EndpointList endpoints,
const ConnectStrategy connect_strategy,
std::unique_ptr< ClientStateListener listener 
)
static

Create a master channel that connects to the specified TCP endpoint(s)

Parameters
runtimeRuntime to use to drive asynchronous operations of the master
link_error_modeControls how link errors are handled with respect to the TCP session
configGeneric configuration for the channel
endpointsList of IP endpoints.
connect_strategyControls the timing of (re)connection attempts
listenerTCP connection listener used to receive updates on the status of the connection
Returns
Handle to the master created, NULL if an error occurred
Exceptions
ParamException

◆ create_tls_channel()

static MasterChannel dnp3::MasterChannel::create_tls_channel ( Runtime runtime,
LinkErrorMode  link_error_mode,
const MasterChannelConfig config,
EndpointList endpoints,
const ConnectStrategy connect_strategy,
std::unique_ptr< ClientStateListener listener,
const TlsClientConfig tls_config 
)
static

Create a master channel that connects to the specified TCP endpoint(s) and establish a TLS session with the remote.

Parameters
runtimeRuntime to use to drive asynchronous operations of the master
link_error_modeControls how link errors are handled with respect to the TCP session
configGeneric configuration for the channel
endpointsList of IP endpoints.
connect_strategyControls the timing of (re)connection attempts
listenerTCP connection listener used to receive updates on the status of the connection
tls_configTLS client configuration
Returns
Handle to the master created, NULL if an error occurred
Exceptions
ParamException

◆ demand_poll()

void dnp3::MasterChannel::demand_poll ( const PollId poll_id)

Demand the immediate execution of a poll previously created with MasterChannel::add_poll().

This method returns immediately. The result will be sent to the registered ReadHandler.

This method resets the internal timer of the poll.

Parameters
poll_idId of the poll
Exceptions
ParamException

◆ disable()

void dnp3::MasterChannel::disable ( )

stop communications

Exceptions
ParamException

◆ enable()

void dnp3::MasterChannel::enable ( )

start communications

Exceptions
ParamException

◆ get_decode_level()

DecodeLevel dnp3::MasterChannel::get_decode_level ( )

Get the decoding level for the channel.

Returns
Decode level
Exceptions
ParamException

◆ operate()

void dnp3::MasterChannel::operate ( const AssociationId association,
CommandMode  mode,
CommandSet command,
std::unique_ptr< CommandTaskCallback callback 
)

Asynchronously perform a command operation on the association.

Parameters
associationId of the association
modeOperation mode
commandCommand to send
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ read()

void dnp3::MasterChannel::read ( const AssociationId association,
Request request,
std::unique_ptr< ReadTaskCallback callback 
)

Perform a read on the association.

The callback will be called once the read is completely received, but the actual values will be sent to the ReadHandler of the association.

Parameters
associationAssociation on which to perform the read
requestRequest to send
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ read_with_handler()

void dnp3::MasterChannel::read_with_handler ( const AssociationId association,
Request request,
std::unique_ptr< ReadHandler handler,
std::unique_ptr< ReadTaskCallback callback 
)

Perform a read on the association.

The callback will be called once the read is completely received, but the actual values will be sent to the ReadHandler passed as a parameter.

Parameters
associationAssociation on which to perform the read
requestRequest to send
handlerCustom ReadHandler to send the data to
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ remove_association()

void dnp3::MasterChannel::remove_association ( const AssociationId id)

Remove an association from the channel.

Parameters
idId of the association
Exceptions
ParamException

◆ remove_poll()

void dnp3::MasterChannel::remove_poll ( const PollId poll_id)

Add a periodic poll to an association.

Each result of the poll will be sent to the ReadHandler of the association.

Parameters
poll_idId of the created poll
Exceptions
ParamException

◆ set_decode_level()

void dnp3::MasterChannel::set_decode_level ( const DecodeLevel decode_level)

Set the decoding level for the channel.

Parameters
decode_levelDecoding level
Exceptions
ParamException

◆ synchronize_time()

void dnp3::MasterChannel::synchronize_time ( const AssociationId association,
TimeSyncMode  mode,
std::unique_ptr< TimeSyncTaskCallback callback 
)

Asynchronously perform a time sync operation to the association.

Parameters
associationId of the association
modeTime sync mode
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ warm_restart()

void dnp3::MasterChannel::warm_restart ( const AssociationId association,
std::unique_ptr< RestartTaskCallback callback 
)

Asynchronously perform a warm restart operation to the association.

Parameters
associationId of the association
callbackcallback invoked when the operation completes
Exceptions
ParamException

The documentation for this class was generated from the following file: