Client
-
class Client : public std::enable_shared_from_this<Client>
service model for IEC60870-5-104 communication as client
Public Functions
-
~Client()
Close and destroy all connections of this connection handler.
-
void start()
start reconnect thread
-
void stop()
stop reconnect thread
-
bool isRunning()
test if client is currently active
- Returns:
information on active state of client
-
void setOriginatorAddress(std::uint_fast8_t address)
Sets the originator address of all client connections to the new value if not changed per connection.
- Parameters:
address – originator address of a client message
-
std::uint_fast8_t getOriginatorAddress() const
Getter for originatorAddress: who is the originator of a client message.
- Returns:
originator address of a client message
-
bool hasConnections()
Checks if the client has active (established and not muted) connections.
- Returns:
True if there are active connections, otherwise false.
-
bool hasOpenConnections() const
Test if Client has open connections to clients.
- Returns:
information if at least one connection exists
-
std::uint_fast8_t getOpenConnectionCount() const
get number of open connections to servers
- Returns:
open connection count
-
bool hasActiveConnections() const
Test if Client has active (open and not muted) connections to servers.
- Returns:
information if at least one connection is active
-
std::uint_fast8_t getActiveConnectionCount() const
get number of active (open and not muted) connections to servers
- Returns:
active connection count
-
Remote::ConnectionVector getConnections()
Retrieves the current list of active connections established by the client.
This method provides access to the client’s connection vector, which contains shared pointers to all active connections established with remote servers.
- Returns:
A vector of shared pointers to Connection objects representing active connections.
-
bool hasConnection(const std::string &ip, std::uint_fast16_t port = IEC_60870_5_104_DEFAULT_PORT)
Checks if a connection exists for the specified IP and port.
- Parameters:
ip – The IP address to check for a connection.
port – The port number to check for a connection.
- Returns:
True if a connection exists, false otherwise.
-
std::shared_ptr<Remote::Connection> getConnection(const std::string &ip, std::uint_fast16_t port = IEC_60870_5_104_DEFAULT_PORT)
Retrieves a connection to a remote host using the specified IP address and port.
- Parameters:
ip – The IP address of the remote host.
port – The port number to connect to on the remote host.
- Returns:
A shared pointer to the established connection.
-
std::shared_ptr<Remote::Connection> addConnection(const std::string &ip, std::uint_fast16_t port = IEC_60870_5_104_DEFAULT_PORT, ConnectionInit init = INIT_ALL)
add a new remote server connection to this client and return the new connection object
- Parameters:
ip – remote terminal units ip address
port – remote terminal units port
init – communication initiation commands
- Throws:
std::invalid_argument – if ip or port invalid
- Returns:
owning pointer to new created Connection instance
-
std::shared_ptr<Remote::Connection> getConnectionFromCommonAddress(uint_fast16_t commonAddress)
Get Connection object for a certain commonAddress.
- Parameters:
commonAddress – common address that should be reached via remote connection
- Returns:
Connection
-
void reconnectAll()
reestablish lost connections
-
void disconnectAll()
close all connections to remote servers
- Returns:
information on operation success
-
void setOnNewStationCallback(py::object &callable)
set python callback that will be executed on incoming message from unknown station
- Throws:
std::invalid_argument – if callable signature does not match
Execute configured callback handlers on receiving station information from a not yet known common address.
- Parameters:
connection – A shared pointer to the connection object representing the remote connection.
common_address – The common address associated with the new station.
-
void setOnNewPointCallback(py::object &callable)
set python callback that will be executed on incoming message from unknown point
- Throws:
std::invalid_argument – if callable signature does not match
Execute configured callback handlers on receiving point information from a not yet known information object address.
- Parameters:
station – Shared pointer to the station object where the point is to be added.
io_address – The input/output address associated with the new point.
type – The type identifier for the new point, conforming to the IEC60870-5 standard.
-
void setOnEndOfInitializationCallback(py::object &callable)
set python callback that will be executed on incoming end of initialization messages
- Throws:
std::invalid_argument – if callable signature does not match
Execute configured callback handlers on receiving and end of initialization message from a station.
- Parameters:
station – A shared pointer to the station object representing the initialized station.
cause – The cause of initialization, indicating the reason for the initialization event.
-
std::uint_fast16_t getTickRate_ms() const
getter for tickRate_ms
- Returns:
minimum interval between two periodic tasks
-
void schedulePeriodicTask(const std::function<void()> &task, std::int_fast32_t interval)
Schedules a periodic task to be executed at a specified interval.
- Parameters:
task – A callable object representing the task to be executed periodically.
interval – The interval in milliseconds at which the task should be executed. Must be at least 50ms. Throws std::out_of_range if the interval is less than 50ms.
-
void scheduleTask(const std::function<void()> &task, std::int_fast32_t delay = 0)
Schedules a task to be executed after a specified delay (or instant).
The order of execution will depend on the timestamp calculated from current time + delay. The delay may be negative for high priority tasks.
- Parameters:
task – The function to be executed.
delay – The delay in milliseconds before the task is executed. A negative delay executes the task immediately.
-
inline std::string toString() const
Converts the current client instance state into a string representation.
- Returns:
A string representation of the client instance, including originator address, number of active connections, and memory address of the object.
-
~Client()