Skip to content

Commit 571bbff

Browse files
committed
- slave: added IMasterConnection_close function (see #35)
1 parent a36ded0 commit 571bbff

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

lib60870-C/src/iec60870/cs101/cs101_master_connection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ IMasterConnection_getApplicationLayerParameters(IMasterConnection self)
4646
{
4747
return self->getApplicationLayerParameters(self);
4848
}
49+
50+
void
51+
IMasterConnection_close(IMasterConnection self)
52+
{
53+
if (self->close)
54+
self->close(self);
55+
}
56+

lib60870-C/src/iec60870/cs101/cs101_slave.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ CS101_Slave_create(SerialPort serialPort, LinkLayerParameters llParameters, CS10
331331
self->iMasterConnection.sendACT_CON = sendACT_CON;
332332
self->iMasterConnection.sendACT_TERM = sendACT_TERM;
333333
self->iMasterConnection.getApplicationLayerParameters = getApplicationLayerParameters;
334+
self->iMasterConnection.close = NULL;
334335
self->iMasterConnection.object = self;
335336

336337
CS101_Queue_initialize(&(self->userDataClass1Queue), CS101_MAX_QUEUE_SIZE);

lib60870-C/src/iec60870/cs104/cs104_slave.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,33 +2545,41 @@ connectionHandlingThread(void* parameter)
25452545
*******************************************/
25462546

25472547
static void
2548-
_sendASDU(IMasterConnection self, CS101_ASDU asdu)
2548+
_IMasterConnection_sendASDU(IMasterConnection self, CS101_ASDU asdu)
25492549
{
25502550
MasterConnection con = (MasterConnection) self->object;
25512551

25522552
sendASDUInternal(con, asdu);
25532553
}
25542554

25552555
static void
2556-
_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool negative)
2556+
_IMasterConnection_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool negative)
25572557
{
25582558
CS101_ASDU_setCOT(asdu, CS101_COT_ACTIVATION_CON);
25592559
CS101_ASDU_setNegative(asdu, negative);
25602560

2561-
_sendASDU(self, asdu);
2561+
_IMasterConnection_sendASDU(self, asdu);
25622562
}
25632563

25642564
static void
2565-
_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu)
2565+
_IMasterConnection_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu)
25662566
{
25672567
CS101_ASDU_setCOT(asdu, CS101_COT_ACTIVATION_TERMINATION);
25682568
CS101_ASDU_setNegative(asdu, false);
25692569

2570-
_sendASDU(self, asdu);
2570+
_IMasterConnection_sendASDU(self, asdu);
2571+
}
2572+
2573+
static void
2574+
_IMasterConnection_close(IMasterConnection self)
2575+
{
2576+
MasterConnection con = (MasterConnection) self->object;
2577+
2578+
MasterConnection_close(con);
25712579
}
25722580

25732581
static CS101_AppLayerParameters
2574-
_getApplicationLayerParameters(IMasterConnection self)
2582+
_IMasterConnection_getApplicationLayerParameters(IMasterConnection self)
25752583
{
25762584
MasterConnection con = (MasterConnection) self->object;
25772585

@@ -2619,10 +2627,11 @@ MasterConnection_create(CS104_Slave slave, Socket socket, MessageQueue lowPrioQu
26192627
#endif
26202628

26212629
self->iMasterConnection.object = self;
2622-
self->iMasterConnection.getApplicationLayerParameters = _getApplicationLayerParameters;
2623-
self->iMasterConnection.sendASDU = _sendASDU;
2624-
self->iMasterConnection.sendACT_CON = _sendACT_CON;
2625-
self->iMasterConnection.sendACT_TERM = _sendACT_TERM;
2630+
self->iMasterConnection.getApplicationLayerParameters = _IMasterConnection_getApplicationLayerParameters;
2631+
self->iMasterConnection.sendASDU = _IMasterConnection_sendASDU;
2632+
self->iMasterConnection.sendACT_CON = _IMasterConnection_sendACT_CON;
2633+
self->iMasterConnection.sendACT_TERM = _IMasterConnection_sendACT_TERM;
2634+
self->iMasterConnection.close = _IMasterConnection_close;
26262635

26272636
resetT3Timeout(self);
26282637

lib60870-C/src/inc/api/iec60870_slave.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct sIMasterConnection {
6666
void (*sendASDU) (IMasterConnection self, CS101_ASDU asdu);
6767
void (*sendACT_CON) (IMasterConnection self, CS101_ASDU asdu, bool negative);
6868
void (*sendACT_TERM) (IMasterConnection self, CS101_ASDU asdu);
69+
void (*close) (IMasterConnection self);
6970
CS101_AppLayerParameters (*getApplicationLayerParameters) (IMasterConnection self);
7071
void* object;
7172
};
@@ -104,6 +105,14 @@ IMasterConnection_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool nega
104105
void
105106
IMasterConnection_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu);
106107

108+
/**
109+
* \brief Close the master connection (only for CS 104)
110+
*
111+
* Allows the slave to actively close a master connection (e.g. when some exception occurs)
112+
*/
113+
void
114+
IMasterConnection_close(IMasterConnection self);
115+
107116
/**
108117
* \brief Get the application layer parameters used by this connection
109118
*/

0 commit comments

Comments
 (0)