Connection

class Connection : public std::enable_shared_from_this<Connection>

connection model for connections via client component to remote servers

Public Functions

~Connection()

Close and destroy a connection to a remote server.

std::string getConnectionString() const

Getter for connectionString to remote server

Returns:

ip:port string

std::string getIP() const

Getter for ip of remote server

Returns:

ip string

std::uint_fast16_t getPort() const

Getter for port of remote server

Returns:

port number

ConnectionState getState() const

Getter for connection state

Returns:

connection state enum

void setOriginatorAddress(std::uint_fast8_t address)

Setter for originatorAddress: who is the originator of a client message.

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

std::shared_ptr<Client> getClient() const

client object reference

void connect()

Open a created connection to remote server.

void disconnect()

Close a created connection to remote server.

Returns:

information on operation success

bool isOpen() const

Test if connection to remote server is open.

Returns:

information on open state

bool isMuted() const

Test if connection to remote server is muted.

Returns:

information on muted state

bool mute()

Mute an open connection to remote server - disable messages from server to client.

Returns:

information on operation success

bool unmute()

Unmute an open connection to remote server - enabled messages from server to client.

Returns:

information on operation success

bool setMuted(bool value)

Setter for muted state.

Parameters:

value – value of new muted state (true = muted, false = unmuted)

CS104_Connection getCS104()

Getter for internal connection object.

Returns:

CS104_Connection refrence

bool setOpen()

Setter for open state: Mark connection as open.

bool setClosed()

Setter for open state: Mark connection as closed, start reconnect state.

bool prepareCommandSuccess(const std::string &cmdId, CommandProcessState state)

add command id to awaiting command result map

Parameters:
  • cmdId – unique command id

  • state – command process state

Returns:

if command preparation was successfully (no collision with active sequence)

void cancelCommandSuccess(const std::string &cmdId)

mark a command success as failed to fail fast

Parameters:

cmdId – unique command id

bool awaitCommandSuccess(const std::string &cmdId)

Wait for command confirmation and success information, release outgoing message LOCK for this command and get information on last commands success.

Parameters:

cmdId – unique command id

Returns:

information on last command success

void setCommandSuccess(std::shared_ptr<Message::IncomingMessage> message)

Set success state of last command.

Parameters:

message – incoming message

bool hasStations() const

Test if Stations exists at this NetworkStation.

Returns:

information on availability of child Station objects

Object::StationVector getStations() const

Get a list of all Stations.

Returns:

vector with object stationer

std::shared_ptr<Object::Station> getStation(std::uint_fast16_t commonAddress) const

Get a Station that exists at this NetworkStation and is identified via information object address.

Returns:

Stationer to Station or nullptr

bool hasStation(std::uint_fast16_t commonAddress) const

Test if Stations exists at this NetworkStation.

Returns:

information on availability of child Station objects

std::shared_ptr<Object::Station> addStation(std::uint_fast16_t commonAddress)

Add a Station to this Station.

void setOnReceiveRawCallback(py::object &callable)

set python callback that will be executed on incoming message

Throws:

std::invalid_argument – if callable signature does not match

void setOnSendRawCallback(py::object &callable)

set python callback that will be executed on outgoing message

Throws:

std::invalid_argument – if callable signature does not match

void setOnStateChangeCallback(py::object &callable)

set python callback that will be executed on connection state changes

Throws:

std::invalid_argument – if callable signature does not match

bool interrogation(std::uint_fast16_t commonAddress, CS101_CauseOfTransmission cause = CS101_COT_ACTIVATION, CS101_QualifierOfInterrogation qualifier = QOI_STATION, bool wait_for_response = true)

send interrogation command

Parameters:
  • commonAddress

  • cause

  • qualifier

  • wait_for_response

Throws:

std::invalid_argument – if qualifier is invalid

Returns:

success information

bool counterInterrogation(std::uint_fast16_t commonAddress, CS101_CauseOfTransmission cause = CS101_COT_ACTIVATION, QualifierOfCIC qualifier = IEC60870_QCC_RQT_GENERAL, bool wait_for_response = true)

send counter interrogation command

Parameters:
  • commonAddress – station address

  • cause – transmission reason

  • qualifier – parameter for counter interrogation

  • wait_for_response – blocking or non-blocking

Throws:

std::invalid_argument – if qualifier is invalid

Returns:

success information

bool clockSync(std::uint_fast16_t commonAddress, bool wait_for_response = true)

send clock synchronization command

Parameters:
  • commonAddress – station address

  • wait_for_response – blocking or non-blocking

Returns:

success information

bool test(std::uint_fast16_t commonAddress, bool with_time = true, bool wait_for_response = true)

send test command

Parameters:
  • commonAddress – station address

  • with_time – include a timestamp in the test command

  • wait_for_response – blocking or non-blocking

Returns:

success information

bool transmit(std::shared_ptr<Object::DataPoint> point, CS101_CauseOfTransmission cause, CS101_QualifierOfCommand qualifier = CS101_QualifierOfCommand::NONE)

transmit a command to a remote server

Parameters:
  • point – control point

  • cause – reason for transmission

  • qualifier – parameter for command duration

Throws:

std::invalid_argument – if point type is not supported for this operation

Returns:

if operation was successful

bool command(std::shared_ptr<Message::OutgoingMessage> message, bool wait_for_response = true, CommandProcessState state = COMMAND_AWAIT_CON)

add command id to awaiting command result map

Parameters:
  • message – outgoing message

  • wait_for_response – blocking or non-blocking

  • state – command process state

Returns:

if command preparation was successfully (no collision with active sequence)

bool read(std::shared_ptr<Object::DataPoint> point, bool wait_for_response = true)

send a point read command to remote server

Parameters:
  • point – monitoring point

  • wait_for_response – blocking or non-blocking

Throws:

std::invalid_argument – if point type is not supported for this operation

Returns:

if operation was successful

Public Static Functions

static inline std::shared_ptr<Connection> create(std::shared_ptr<Client> client, const std::string &ip, const uint_fast16_t port = IEC_60870_5_104_DEFAULT_PORT, const uint_fast32_t command_timeout_ms = 4000, const ConnectionInit init = INIT_ALL, std::shared_ptr<Remote::TransportSecurity> transport_security = nullptr, const uint_fast8_t originator_address = 0)

Create a new (still closed) connection to a remote server identified via ip and port.

Parameters:
  • client – client instance reference

  • ip – ip address or hostname of remote server

  • port – port address of remote server

  • command_timeout_ms – default timeout for command confirmation

  • init – connection initialization procedure

  • transport_security – communication encryption instance reference

  • originator_address – client identification address

Throws:

std::invalid_argument – if ip or port invalid

Returns:

owning pointer of new Connection instance

static void rawMessageHandler(void *parameter, uint_fast8_t *msg, int msgSize, bool sent)

Callback for logging incoming and outgoing byteStreams.

Warning

DEBUG FUNCTION, IN ORDER TO ACTIVE THIS CALLBACK REMOVE COMMENT WRAPPER IN Connect(connectionState)

Parameters:
  • parameter – reference to custom bound connection data

  • msg – pointer to first character of message

  • msgSize – character count of message

  • sent – direction of message

static void connectionHandler(void *parameter, CS104_Connection connection, CS104_ConnectionEvent event)

Callback to handle connection state changes.

Parameters:
  • parameter – reference to custom bound connection data

  • connection – internal CS104_Connection connection object reference

  • event – state change event (opened,closed,muted,unmuted identified via constants)

static bool asduHandler(void *parameter, int address, CS101_ASDU asdu)

Callback to handle incomming reports from remote servers.

Parameters:
  • parameter – reference to custom bound connection data

  • address – NOT USED IN CS104 - relict from CS101

  • asdu – incoming message formatted as ASDU object

Returns: