lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
Typedefs | Functions
CS 101 slave (serial link layer) related functions
Collaboration diagram for CS 101 slave (serial link layer) related functions:

Typedefs

typedef struct sCS101_Slave * CS101_Slave
 CS101_Slave type.
 

Functions

CS101_Slave CS101_Slave_create (SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode)
 Create a new balanced or unbalanced CS101 slave. More...
 
CS101_Slave CS101_Slave_createEx (SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode, int class1QueueSize, int class2QueueSize)
 Create a new balanced or unbalanced CS101 slave. More...
 
void CS101_Slave_destroy (CS101_Slave self)
 Destroy the slave instance and cleanup all resources. More...
 
void CS101_Slave_setDIR (CS101_Slave self, bool dir)
 Set the value of the DIR bit when sending messages (only balanced mode) More...
 
void CS101_Slave_addPlugin (CS101_Slave self, CS101_SlavePlugin plugin)
 Register a plugin instance with this slave instance. More...
 
void CS101_Slave_setIdleTimeout (CS101_Slave self, int timeoutInMs)
 Set the idle timeout. More...
 
void CS101_Slave_setLinkLayerStateChanged (CS101_Slave self, IEC60870_LinkLayerStateChangedHandler handler, void *parameter)
 Set a callback handler for link layer state changes.
 
void CS101_Slave_setLinkLayerAddress (CS101_Slave self, int address)
 Set the local link layer address. More...
 
void CS101_Slave_setLinkLayerAddressOtherStation (CS101_Slave self, int address)
 Set the link layer address of the remote station. More...
 
bool CS101_Slave_isClass1QueueFull (CS101_Slave self)
 Check if the class 1 ASDU is full. More...
 
void CS101_Slave_enqueueUserDataClass1 (CS101_Slave self, CS101_ASDU asdu)
 Enqueue an ASDU into the class 1 data queue. More...
 
bool CS101_Slave_isClass2QueueFull (CS101_Slave self)
 Check if the class 2 ASDU is full. More...
 
void CS101_Slave_enqueueUserDataClass2 (CS101_Slave self, CS101_ASDU asdu)
 Enqueue an ASDU into the class 2 data queue. More...
 
void CS101_Slave_flushQueues (CS101_Slave self)
 Remove all ASDUs from the class 1/2 data queues. More...
 
void CS101_Slave_run (CS101_Slave self)
 Receive a new message and run the link layer state machines. More...
 
void CS101_Slave_start (CS101_Slave self)
 Start a background thread that handles the link layer connections. More...
 
void CS101_Slave_stop (CS101_Slave self)
 Stops the background thread that handles the link layer connections. More...
 
CS101_AppLayerParameters CS101_Slave_getAppLayerParameters (CS101_Slave self)
 Returns the application layer parameters object of this slave instance. More...
 
LinkLayerParameters CS101_Slave_getLinkLayerParameters (CS101_Slave self)
 Returns the link layer parameters object of this slave instance. More...
 
void CS101_Slave_setResetCUHandler (CS101_Slave self, CS101_ResetCUHandler handler, void *parameter)
 Set the handler for the reset CU (communication unit) message. More...
 
void CS101_Slave_setInterrogationHandler (CS101_Slave self, CS101_InterrogationHandler handler, void *parameter)
 Set the handler for the general interrogation message. More...
 
void CS101_Slave_setCounterInterrogationHandler (CS101_Slave self, CS101_CounterInterrogationHandler handler, void *parameter)
 Set the handler for the counter interrogation message. More...
 
void CS101_Slave_setReadHandler (CS101_Slave self, CS101_ReadHandler handler, void *parameter)
 Set the handler for the read message. More...
 
void CS101_Slave_setClockSyncHandler (CS101_Slave self, CS101_ClockSynchronizationHandler handler, void *parameter)
 Set the handler for the clock synchronization message. More...
 
void CS101_Slave_setResetProcessHandler (CS101_Slave self, CS101_ResetProcessHandler handler, void *parameter)
 Set the handler for the reset process message. More...
 
void CS101_Slave_setDelayAcquisitionHandler (CS101_Slave self, CS101_DelayAcquisitionHandler handler, void *parameter)
 Set the handler for the delay acquisition message. More...
 
void CS101_Slave_setASDUHandler (CS101_Slave self, CS101_ASDUHandler handler, void *parameter)
 Set the handler for a received ASDU. More...
 
void CS101_Slave_setRawMessageHandler (CS101_Slave self, IEC60870_RawMessageHandler handler, void *parameter)
 Set the raw message callback (called when a message is sent or received) More...
 

Detailed Description

Function Documentation

◆ CS101_Slave_addPlugin()

void CS101_Slave_addPlugin ( CS101_Slave  self,
CS101_SlavePlugin  plugin 
)

Register a plugin instance with this slave instance.

Parameters
theplugin instance.

◆ CS101_Slave_create()

CS101_Slave CS101_Slave_create ( SerialPort  serialPort,
const LinkLayerParameters  llParameters,
const CS101_AppLayerParameters  alParameters,
IEC60870_LinkLayerMode  linkLayerMode 
)

Create a new balanced or unbalanced CS101 slave.

NOTE: The CS101_Slave instance has two separate data queues for class 1 and class 2 data. This constructor uses the default max queue size for both queues.

Parameters
serialPortthe serial port to be used
llParametersthe link layer parameters to be used
alParametersthe CS101 application layer parameters
linkLayerModethe link layer mode (either BALANCED or UNBALANCED)
Returns
the new slave instance

◆ CS101_Slave_createEx()

CS101_Slave CS101_Slave_createEx ( SerialPort  serialPort,
const LinkLayerParameters  llParameters,
const CS101_AppLayerParameters  alParameters,
IEC60870_LinkLayerMode  linkLayerMode,
int  class1QueueSize,
int  class2QueueSize 
)

Create a new balanced or unbalanced CS101 slave.

NOTE: The CS101_Slave instance has two separate data queues for class 1 and class 2 data.

Parameters
serialPortthe serial port to be used
llParametersthe link layer parameters to be used
alParametersthe CS101 application layer parameters
linkLayerModethe link layer mode (either BALANCED or UNBALANCED)
class1QueueSizesize of the class1 data queue
class2QueueSizesize of the class2 data queue
Returns
the new slave instance

◆ CS101_Slave_destroy()

void CS101_Slave_destroy ( CS101_Slave  self)

Destroy the slave instance and cleanup all resources.

Parameters
selfCS101_Slave instance

◆ CS101_Slave_enqueueUserDataClass1()

void CS101_Slave_enqueueUserDataClass1 ( CS101_Slave  self,
CS101_ASDU  asdu 
)

Enqueue an ASDU into the class 1 data queue.

Parameters
selfCS101_Slave instance
asduthe ASDU instance to enqueue

◆ CS101_Slave_enqueueUserDataClass2()

void CS101_Slave_enqueueUserDataClass2 ( CS101_Slave  self,
CS101_ASDU  asdu 
)

Enqueue an ASDU into the class 2 data queue.

Parameters
selfCS101_Slave instance
asduthe ASDU instance to enqueue

◆ CS101_Slave_flushQueues()

void CS101_Slave_flushQueues ( CS101_Slave  self)

Remove all ASDUs from the class 1/2 data queues.

Parameters
selfCS101_Slave instance

◆ CS101_Slave_getAppLayerParameters()

CS101_AppLayerParameters CS101_Slave_getAppLayerParameters ( CS101_Slave  self)

Returns the application layer parameters object of this slave instance.

Parameters
selfCS101_Slave instance
Returns
the CS101_AppLayerParameters instance used by this slave

◆ CS101_Slave_getLinkLayerParameters()

LinkLayerParameters CS101_Slave_getLinkLayerParameters ( CS101_Slave  self)

Returns the link layer parameters object of this slave instance.

Parameters
selfCS101_Slave instance
Returns
the LinkLayerParameters instance used by this slave

◆ CS101_Slave_isClass1QueueFull()

bool CS101_Slave_isClass1QueueFull ( CS101_Slave  self)

Check if the class 1 ASDU is full.

Parameters
selfCS101_Slave instance
Returns
true when the queue is full, false otherwise

◆ CS101_Slave_isClass2QueueFull()

bool CS101_Slave_isClass2QueueFull ( CS101_Slave  self)

Check if the class 2 ASDU is full.

Parameters
selfCS101_Slave instance
Returns
true when the queue is full, false otherwise

◆ CS101_Slave_run()

void CS101_Slave_run ( CS101_Slave  self)

Receive a new message and run the link layer state machines.

NOTE: Has to be called frequently, when the start/stop functions are not used. Otherwise it will be called by the background thread.

Parameters
selfCS101_Slave instance

◆ CS101_Slave_setASDUHandler()

void CS101_Slave_setASDUHandler ( CS101_Slave  self,
CS101_ASDUHandler  handler,
void *  parameter 
)

Set the handler for a received ASDU.

NOTE: This a generic handler that will only be called when the ASDU has not been handled by one of the other callback handlers.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setClockSyncHandler()

void CS101_Slave_setClockSyncHandler ( CS101_Slave  self,
CS101_ClockSynchronizationHandler  handler,
void *  parameter 
)

Set the handler for the clock synchronization message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setCounterInterrogationHandler()

void CS101_Slave_setCounterInterrogationHandler ( CS101_Slave  self,
CS101_CounterInterrogationHandler  handler,
void *  parameter 
)

Set the handler for the counter interrogation message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setDelayAcquisitionHandler()

void CS101_Slave_setDelayAcquisitionHandler ( CS101_Slave  self,
CS101_DelayAcquisitionHandler  handler,
void *  parameter 
)

Set the handler for the delay acquisition message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setDIR()

void CS101_Slave_setDIR ( CS101_Slave  self,
bool  dir 
)

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

NOTE: Default value is false (controlled 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_Slave_setIdleTimeout()

void CS101_Slave_setIdleTimeout ( CS101_Slave  self,
int  timeoutInMs 
)

Set the idle timeout.

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

Parameters
timeoutInMsthe timeout value in milliseconds

◆ CS101_Slave_setInterrogationHandler()

void CS101_Slave_setInterrogationHandler ( CS101_Slave  self,
CS101_InterrogationHandler  handler,
void *  parameter 
)

Set the handler for the general interrogation message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setLinkLayerAddress()

void CS101_Slave_setLinkLayerAddress ( CS101_Slave  self,
int  address 
)

Set the local link layer address.

Parameters
selfCS101_Slave instance
addressthe link layer address (can be either 1 or 2 byte wide).

◆ CS101_Slave_setLinkLayerAddressOtherStation()

void CS101_Slave_setLinkLayerAddressOtherStation ( CS101_Slave  self,
int  address 
)

Set the link layer address of the remote station.

Parameters
selfCS101_Slave instance
addressthe link layer address (can be either 1 or 2 byte wide).

◆ CS101_Slave_setRawMessageHandler()

void CS101_Slave_setRawMessageHandler ( CS101_Slave  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_Slave_setReadHandler()

void CS101_Slave_setReadHandler ( CS101_Slave  self,
CS101_ReadHandler  handler,
void *  parameter 
)

Set the handler for the read message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setResetCUHandler()

void CS101_Slave_setResetCUHandler ( CS101_Slave  self,
CS101_ResetCUHandler  handler,
void *  parameter 
)

Set the handler for the reset CU (communication unit) message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_setResetProcessHandler()

void CS101_Slave_setResetProcessHandler ( CS101_Slave  self,
CS101_ResetProcessHandler  handler,
void *  parameter 
)

Set the handler for the reset process message.

Parameters
handlerthe callback handler function
parameteruser provided parameter to be passed to the callback handler

◆ CS101_Slave_start()

void CS101_Slave_start ( CS101_Slave  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 slave instance you have to call the CS101_Slave_run function periodically.

Parameters
selfCS101_Slave instance

◆ CS101_Slave_stop()

void CS101_Slave_stop ( CS101_Slave  self)

Stops the background thread that handles the link layer connections.

Parameters
selfCS101_Slave instance