lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
cs101_slave.h
Go to the documentation of this file.
1 /*
2  * cs101_slave.h
3  *
4  * Copyright 2017-2022 Michael Zillgith
5  *
6  * This file is part of lib60870-C
7  *
8  * lib60870-C is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * lib60870-C is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * See COPYING file for the complete license text.
22  */
23 
24 #ifndef SRC_IEC60870_CS101_CS101_SLAVE_H_
25 #define SRC_IEC60870_CS101_CS101_SLAVE_H_
26 
33 #include "hal_serial.h"
34 #include "iec60870_common.h"
35 #include "iec60870_slave.h"
36 #include "link_layer_parameters.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
59 typedef struct sCS101_Slave* CS101_Slave;
60 
75 CS101_Slave_create(SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode);
76 
92 CS101_Slave_createEx(SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode,
93  int class1QueueSize, int class2QueueSize);
94 
100 void
102 
111 void
113 
119 void
121 
130 void
132 
136 void
138 
139 
146 void
148 
155 void
157 
165 bool
167 
174 void
176 
184 bool
186 
193 void
195 
201 void
203 
212 void
214 
224 void
226 
232 void
234 
244 
254 
261 void
263 
270 void
272 
279 void
281 
288 void
290 
297 void
299 
306 void
308 
315 void
317 
327 void
329 
336 void
338 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif /* SRC_IEC60870_CS101_CS101_SLAVE_H_ */
struct sCS101_ASDU * CS101_ASDU
Application Service Data Unit (ASDU) for the CS101/CS104 application layer.
Definition: iec60870_common.h:216
void(* IEC60870_RawMessageHandler)(void *parameter, uint8_t *msg, int msgSize, bool sent)
Callback handler for sent and received messages.
Definition: iec60870_common.h:105
void(* IEC60870_LinkLayerStateChangedHandler)(void *parameter, int address, LinkLayerState newState)
Callback handler for link layer state changes.
Definition: iec60870_common.h:91
IEC60870_LinkLayerMode
link layer mode for serial link layers
Definition: iec60870_common.h:64
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.
void CS101_Slave_setDelayAcquisitionHandler(CS101_Slave self, CS101_DelayAcquisitionHandler handler, void *parameter)
Set the handler for the delay acquisition message.
LinkLayerParameters CS101_Slave_getLinkLayerParameters(CS101_Slave self)
Returns the link layer parameters object of this slave instance.
void CS101_Slave_destroy(CS101_Slave self)
Destroy the slave instance and cleanup all resources.
CS101_AppLayerParameters CS101_Slave_getAppLayerParameters(CS101_Slave self)
Returns the application layer parameters object of this slave instance.
void CS101_Slave_enqueueUserDataClass1(CS101_Slave self, CS101_ASDU asdu)
Enqueue an ASDU into the class 1 data queue.
struct sCS101_Slave * CS101_Slave
CS101_Slave type.
Definition: cs101_slave.h:59
void CS101_Slave_stop(CS101_Slave self)
Stops the background thread that handles the link layer connections.
void CS101_Slave_setClockSyncHandler(CS101_Slave self, CS101_ClockSynchronizationHandler handler, void *parameter)
Set the handler for the clock synchronization message.
void CS101_Slave_setLinkLayerAddress(CS101_Slave self, int address)
Set the local link layer address.
void CS101_Slave_setReadHandler(CS101_Slave self, CS101_ReadHandler handler, void *parameter)
Set the handler for the read message.
bool CS101_Slave_isClass1QueueFull(CS101_Slave self)
Check if the class 1 ASDU is full.
void CS101_Slave_setLinkLayerAddressOtherStation(CS101_Slave self, int address)
Set the link layer address of the remote station.
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.
bool CS101_Slave_isClass2QueueFull(CS101_Slave self)
Check if the class 2 ASDU is full.
void CS101_Slave_start(CS101_Slave self)
Start a background thread that handles the link layer connections.
void CS101_Slave_setASDUHandler(CS101_Slave self, CS101_ASDUHandler handler, void *parameter)
Set the handler for a received ASDU.
void CS101_Slave_enqueueUserDataClass2(CS101_Slave self, CS101_ASDU asdu)
Enqueue an ASDU into the class 2 data queue.
void CS101_Slave_setCounterInterrogationHandler(CS101_Slave self, CS101_CounterInterrogationHandler handler, void *parameter)
Set the handler for the counter interrogation message.
void CS101_Slave_setResetCUHandler(CS101_Slave self, CS101_ResetCUHandler handler, void *parameter)
Set the handler for the reset CU (communication unit) message.
void CS101_Slave_setResetProcessHandler(CS101_Slave self, CS101_ResetProcessHandler handler, void *parameter)
Set the handler for the reset process message.
void CS101_Slave_setLinkLayerStateChanged(CS101_Slave self, IEC60870_LinkLayerStateChangedHandler handler, void *parameter)
Set a callback handler for link layer state changes.
void CS101_Slave_addPlugin(CS101_Slave self, CS101_SlavePlugin plugin)
Register a plugin instance with this slave instance.
void CS101_Slave_setDIR(CS101_Slave self, bool dir)
Set the value of the DIR bit when sending messages (only balanced mode)
void CS101_Slave_run(CS101_Slave self)
Receive a new message and run the link layer state machines.
void CS101_Slave_flushQueues(CS101_Slave self)
Remove all ASDUs from the class 1/2 data queues.
void CS101_Slave_setInterrogationHandler(CS101_Slave self, CS101_InterrogationHandler handler, void *parameter)
Set the handler for the general interrogation message.
void CS101_Slave_setIdleTimeout(CS101_Slave self, int timeoutInMs)
Set the idle timeout.
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)
bool(* CS101_ResetProcessHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qrp)
Handler for reset process command (C_RP_NA_1 - 105)
Definition: iec60870_slave.h:238
bool(* CS101_ReadHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, int ioa)
Handler for read command (C_RD_NA_1 - 102)
Definition: iec60870_slave.h:218
bool(* CS101_InterrogationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
Handler for interrogation command (C_IC_NA_1 - 100).
Definition: iec60870_slave.h:208
bool(* CS101_DelayAcquisitionHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, CP16Time2a delayTime)
Handler for delay acquisition command (C_CD_NA:1 - 106)
Definition: iec60870_slave.h:243
bool(* CS101_CounterInterrogationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, QualifierOfCIC qcc)
Handler for counter interrogation command (C_CI_NA_1 - 101).
Definition: iec60870_slave.h:213
bool(* CS101_ASDUHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu)
Handler for ASDUs that are not handled by other handlers (default handler)
Definition: iec60870_slave.h:248
void(* CS101_ResetCUHandler)(void *parameter)
Handler will be called when a link layer reset CU (communication unit) message is received.
Definition: iec60870_slave.h:203
bool(* CS101_ClockSynchronizationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, CP56Time2a newTime)
Handler for clock synchronization command (C_CS_NA_1 - 103)
Definition: iec60870_slave.h:233
Abstraction layer for serial ports. Has to be implemented for the serial link layer of CS 101.
Common definitions for IEC 60870-5-101/104 These types are used by CS101/CS104 master and slaves.
Common slave side definitions for IEC 60870-5-101/104 These types are used by CS101/CS104 slaves.
Definition: iec60870_common.h:112
Definition: iec60870_slave.h:179
Definition: link_layer_parameters.h:42