Skip to content

Commit

Permalink
- CS 101 slave: added timeout validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mzillgith committed Oct 25, 2019
1 parent 7bf7477 commit cdabe02
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib60870-C/src/iec60870/link_layer/link_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ LinkLayerPrimaryBalanced_handleMessage(LinkLayerPrimaryBalanced self, uint8_t fc
void
LinkLayerPrimaryBalanced_runStateMachine(LinkLayerPrimaryBalanced self)
{
/* TODO make timeouts dealing with time adjustments (time moves to past) */
uint64_t currentTime = Hal_getTimeInMs();

PrimaryLinkLayerState primaryState = self->primaryState;
Expand All @@ -1108,6 +1107,11 @@ LinkLayerPrimaryBalanced_runStateMachine(LinkLayerPrimaryBalanced self)

if (self->waitingForResponse) {

if (self->lastSendTime > currentTime) {
/* last sent time not plausible! */
self->lastSendTime = currentTime;
}

if (currentTime > (self->lastSendTime + self->linkLayer->linkLayerParameters->timeoutForAck)) {

SendFixedFrame(self->linkLayer, LL_FC_09_REQUEST_LINK_STATUS, self->otherStationAddress, true, self->linkLayer->dir, false, false);
Expand Down Expand Up @@ -1146,6 +1150,11 @@ LinkLayerPrimaryBalanced_runStateMachine(LinkLayerPrimaryBalanced self)

case PLL_LINK_LAYERS_AVAILABLE:

if (self->lastReceivedMsg > currentTime) {
/* last received message not plausible */
self->lastReceivedMsg = currentTime;
}

if ((currentTime - self->lastReceivedMsg) > (unsigned int) self->idleTimeout) {
DEBUG_PRINT ("PLL - Idle timeout detected. Send link layer test function\n");
self->sendLinkLayerTestFunction = true;
Expand Down

0 comments on commit cdabe02

Please sign in to comment.