lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
Typedefs | Functions
CS 101 master related functions
Collaboration diagram for CS 101 master related functions:

Typedefs

typedef struct sCS101_Master * CS101_Master
 CS101_Master type.
 

Functions

CS101_Master CS101_Master_create (SerialPort port, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode mode)
 Create a new master instance. More...
 
CS101_Master CS101_Master_createEx (SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode, int queueSize)
 Create a new master instance and specify message queue size (for balanced mode) More...
 
void CS101_Master_run (CS101_Master self)
 Receive a new message and run the protocol state machine(s). More...
 
void CS101_Master_start (CS101_Master self)
 Start a background thread that handles the link layer connections. More...
 
void CS101_Master_stop (CS101_Master self)
 Stops the background thread that handles the link layer connections. More...
 
void CS101_Master_addSlave (CS101_Master self, int address)
 Add a new slave connection. More...
 
void CS101_Master_pollSingleSlave (CS101_Master self, int address)
 Poll a slave (only unbalanced mode) More...
 
void CS101_Master_destroy (CS101_Master self)
 Destroy the master instance and release all resources.
 
void CS101_Master_setDIR (CS101_Master self, bool dir)
 Set the value of the DIR bit when sending messages (only balanced mode) More...
 
void CS101_Master_setOwnAddress (CS101_Master self, int address)
 Set the own link layer address (only balanced mode) More...
 
void CS101_Master_useSlaveAddress (CS101_Master self, int address)
 Set the slave address for the following send functions. More...
 
CS101_AppLayerParameters CS101_Master_getAppLayerParameters (CS101_Master self)
 Returns the application layer parameters object of this master instance. More...
 
LinkLayerParameters CS101_Master_getLinkLayerParameters (CS101_Master self)
 Returns the link layer parameters object of this master instance. More...
 
bool CS101_Master_isChannelReady (CS101_Master self, int address)
 Is the channel ready to transmit an ASDU (only unbalanced mode) More...
 
void CS101_Master_sendLinkLayerTestFunction (CS101_Master self)
 Manually send link layer test function. More...
 
void CS101_Master_sendInterrogationCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, QualifierOfInterrogation qoi)
 send an interrogation command More...
 
void CS101_Master_sendCounterInterrogationCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, uint8_t qcc)
 send a counter interrogation command More...
 
void CS101_Master_sendReadCommand (CS101_Master self, int ca, int ioa)
 Sends a read command (C_RD_NA_1 typeID: 102) More...
 
void CS101_Master_sendClockSyncCommand (CS101_Master self, int ca, CP56Time2a time)
 Sends a clock synchronization command (C_CS_NA_1 typeID: 103) More...
 
void CS101_Master_sendTestCommand (CS101_Master self, int ca)
 Send a test command (C_TS_NA_1 typeID: 104) More...
 
void CS101_Master_sendProcessCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, InformationObject command)
 Send a process command to the controlled (or other) station. More...
 
void CS101_Master_sendASDU (CS101_Master self, CS101_ASDU asdu)
 Send a user specified ASDU. More...
 
void CS101_Master_setASDUReceivedHandler (CS101_Master self, CS101_ASDUReceivedHandler handler, void *parameter)
 Register a callback handler for received ASDUs. More...
 
void CS101_Master_setLinkLayerStateChanged (CS101_Master self, IEC60870_LinkLayerStateChangedHandler handler, void *parameter)
 Set a callback handler for link layer state changes.
 
void CS101_Master_setRawMessageHandler (CS101_Master self, IEC60870_RawMessageHandler handler, void *parameter)
 Set the raw message callback (called when a message is sent or received) More...
 
void CS101_Master_setIdleTimeout (CS101_Master self, int timeoutInMs)
 Set the idle timeout (only for balanced mode) More...
 

Detailed Description

Function Documentation

◆ CS101_Master_addSlave()

void CS101_Master_addSlave ( CS101_Master  self,
int  address 
)

Add a new slave connection.

This function creates and starts a new link layer state machine to be used for communication with the slave. It has to be called before any application data can be send/received to/from the slave.

Parameters
addresslink layer address of the slave

◆ CS101_Master_create()

CS101_Master CS101_Master_create ( SerialPort  port,
const LinkLayerParameters  llParameters,
const CS101_AppLayerParameters  alParameters,
IEC60870_LinkLayerMode  mode 
)

Create a new master instance.

Parameters
portthe serial port to use
llParametersthe link layer parameters to use
alParametersthe application layer parameters to use
modethe link layer mode (either IEC60870_LINK_LAYER_BALANCED or IEC60870_LINK_LAYER_UNBALANCED)
Returns
the new CS101_Master instance

◆ CS101_Master_createEx()

CS101_Master CS101_Master_createEx ( SerialPort  serialPort,
const LinkLayerParameters  llParameters,
const CS101_AppLayerParameters  alParameters,
IEC60870_LinkLayerMode  linkLayerMode,
int  queueSize 
)

Create a new master instance and specify message queue size (for balanced mode)

Parameters
portthe serial port to use
llParametersthe link layer parameters to use
alParametersthe application layer parameters to use
modethe link layer mode (either IEC60870_LINK_LAYER_BALANCED or IEC60870_LINK_LAYER_UNBALANCED)
queueSizeset the message queue size (only for balanced mode)
Returns
the new CS101_Master instance

◆ CS101_Master_getAppLayerParameters()

CS101_AppLayerParameters CS101_Master_getAppLayerParameters ( CS101_Master  self)

Returns the application layer parameters object of this master instance.

Returns
the CS101_AppLayerParameters instance used by this master

◆ CS101_Master_getLinkLayerParameters()

LinkLayerParameters CS101_Master_getLinkLayerParameters ( CS101_Master  self)

Returns the link layer parameters object of this master instance.

Returns
the LinkLayerParameters instance used by this master

◆ CS101_Master_isChannelReady()

bool CS101_Master_isChannelReady ( CS101_Master  self,
int  address 
)

Is the channel ready to transmit an ASDU (only unbalanced mode)

The function will return true when the channel (slave) transmit buffer is empty.

Parameters
addressslave address of the recipient
Returns
true, if channel ready to send a new ASDU, false otherwise

◆ CS101_Master_pollSingleSlave()

void CS101_Master_pollSingleSlave ( CS101_Master  self,
int  address 
)

Poll a slave (only unbalanced mode)

NOTE: This command will instruct the unbalanced link layer to send a request for class 2 data. It is required to frequently call this message for each slave in order to receive application layer data from the slave

Parameters
addressthe link layer address of the slave

◆ CS101_Master_run()

void CS101_Master_run ( CS101_Master  self)

Receive a new message and run the protocol state machine(s).

NOTE: This function has to be called frequently in order to send and receive messages to and from slaves.

◆ CS101_Master_sendASDU()

void CS101_Master_sendASDU ( CS101_Master  self,
CS101_ASDU  asdu 
)

Send a user specified ASDU.

This function can be used for any kind of ASDU types. It can also be used for monitoring messages in reverse direction.

NOTE: The ASDU is put into a message queue and will be sent whenever the link layer state machine is able to transmit the ASDU. The ASDUs will be sent in the order they are put into the queue.

Parameters
asduthe ASDU to send

◆ CS101_Master_sendClockSyncCommand()

void CS101_Master_sendClockSyncCommand ( CS101_Master  self,
int  ca,
CP56Time2a  time 
)

Sends a clock synchronization command (C_CS_NA_1 typeID: 103)

Parameters
caCommon address of the slave/server
timenew system time for the slave/server

◆ CS101_Master_sendCounterInterrogationCommand()

void CS101_Master_sendCounterInterrogationCommand ( CS101_Master  self,
CS101_CauseOfTransmission  cot,
int  ca,
uint8_t  qcc 
)

send a counter interrogation command

Parameters
cotcause of transmission
caCommon address of the slave/server
qcc

◆ CS101_Master_sendInterrogationCommand()

void CS101_Master_sendInterrogationCommand ( CS101_Master  self,
CS101_CauseOfTransmission  cot,
int  ca,
QualifierOfInterrogation  qoi 
)

send an interrogation command

Parameters
cotcause of transmission
caCommon address of the slave/server
qoiqualifier of interrogation (20 for station interrogation)

◆ CS101_Master_sendLinkLayerTestFunction()

void CS101_Master_sendLinkLayerTestFunction ( CS101_Master  self)

Manually send link layer test function.

Together with the IEC60870_LinkLayerStateChangedHandler this function can be used to ensure that the link is working correctly

◆ CS101_Master_sendProcessCommand()

void CS101_Master_sendProcessCommand ( CS101_Master  self,
CS101_CauseOfTransmission  cot,
int  ca,
InformationObject  command 
)

Send a process command to the controlled (or other) station.

Parameters
cotthe cause of transmission (should be ACTIVATION to select/execute or ACT_TERM to cancel the command)
cathe common address of the information object
commandthe command information object (e.g. SingleCommand or DoubleCommand)

◆ CS101_Master_sendReadCommand()

void CS101_Master_sendReadCommand ( CS101_Master  self,
int  ca,
int  ioa 
)

Sends a read command (C_RD_NA_1 typeID: 102)

This will send a read command C_RC_NA_1 (102) to the slave/outstation. The COT is always REQUEST (5). It is used to implement the cyclical polling of data application function.

Parameters
caCommon address of the slave/server
ioaInformation object address of the data point to read

◆ CS101_Master_sendTestCommand()

void CS101_Master_sendTestCommand ( CS101_Master  self,
int  ca 
)

Send a test command (C_TS_NA_1 typeID: 104)

Note: This command is not supported by IEC 60870-5-104

Parameters
caCommon address of the slave/server

◆ CS101_Master_setASDUReceivedHandler()

void CS101_Master_setASDUReceivedHandler ( CS101_Master  self,
CS101_ASDUReceivedHandler  handler,
void *  parameter 
)

Register a callback handler for received ASDUs.

Parameters
handleruser provided callback handler function
parameteruser provided parameter that is passed to the callback handler

◆ CS101_Master_setDIR()

void CS101_Master_setDIR ( CS101_Master  self,
bool  dir 
)

Set the value of the DIR bit when sending messages (only balanced mode)

NOTE: Default value is true (controlling station). In the case of two equivalent stations the value is defined by agreement.

Parameters
dirthe value of the DIR bit when sending messages

◆ CS101_Master_setIdleTimeout()

void CS101_Master_setIdleTimeout ( CS101_Master  self,
int  timeoutInMs 
)

Set the idle timeout (only for balanced mode)

Time with no activity after which the connection is considered in idle (LL_STATE_IDLE) state.

Parameters
timeoutInMsthe timeout value in milliseconds

◆ CS101_Master_setOwnAddress()

void CS101_Master_setOwnAddress ( CS101_Master  self,
int  address 
)

Set the own link layer address (only balanced mode)

Parameters
addressthe link layer address to use

◆ CS101_Master_setRawMessageHandler()

void CS101_Master_setRawMessageHandler ( CS101_Master  self,
IEC60870_RawMessageHandler  handler,
void *  parameter 
)

Set the raw message callback (called when a message is sent or received)

Parameters
handleruser provided callback handler function
parameteruser provided parameter that is passed to the callback handler

◆ CS101_Master_start()

void CS101_Master_start ( CS101_Master  self)

Start a background thread that handles the link layer connections.

NOTE: This requires threads. If you don't want to use a separate thread for the master instance you have to call the CS101_Master_run function periodically.

Parameters
selfCS101_Master instance

◆ CS101_Master_stop()

void CS101_Master_stop ( CS101_Master  self)

Stops the background thread that handles the link layer connections.

Parameters
selfCS101_Master instance

◆ CS101_Master_useSlaveAddress()

void CS101_Master_useSlaveAddress ( CS101_Master  self,
int  address 
)

Set the slave address for the following send functions.

NOTE: This is always required in unbalanced mode. Some balanced slaves also check the link layer address. In this case the slave address has also to be set in balanced mode.

Parameters
addressthe link layer address of the slave to address