- changed server side and GOOSE pub/sub timeout handling from real time clock to use monotonic clock (LIB61850-535)

v1.6_develop
Michael Zillgith 1 day ago
parent c6bb858a3b
commit 443074f779

@ -1,7 +1,7 @@
/*
* goose_publisher.c
*
* Copyright 2013-2024 Michael Zillgith
* Copyright 2013-2025 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -79,7 +79,8 @@ GoosePublisher_createRemote(RSession session, uint16_t appId)
{
GoosePublisher self = (GoosePublisher) GLOBAL_CALLOC(1, sizeof(struct sGoosePublisher));
if (self) {
if (self)
{
self->remoteSession = session;
self->buffer = (uint8_t*) GLOBAL_MALLOC(GOOSE_MAX_MESSAGE_SIZE);
@ -139,7 +140,8 @@ GoosePublisher_destroy(GoosePublisher self)
if (self)
{
#if (CONFIG_IEC61850_L2_GOOSE == 1)
if (self->ethernetSocket) {
if (self->ethernetSocket)
{
Ethernet_destroySocket(self->ethernetSocket);
}
#endif /* (CONFIG_IEC61850_L2_GOOSE == 1) */

@ -1,7 +1,7 @@
/*
* goose_receiver.c
*
* Copyright 2014-2024 Michael Zillgith
* Copyright 2014-2025 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -100,6 +100,12 @@ GooseReceiver_create()
if (self)
{
self->buffer = (uint8_t*) GLOBAL_MALLOC(ETH_BUFFER_LENGTH);
if (self->buffer == NULL)
{
GooseReceiver_destroy(self);
return NULL;
}
}
return self;
@ -990,7 +996,7 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
matchingSubscriber->stNum = stNum;
matchingSubscriber->sqNum = sqNum;
matchingSubscriber->invalidityTime = Hal_getTimeInMs() + timeAllowedToLive;
matchingSubscriber->invalidityTime = Hal_getMonotonicTimeInMs() + timeAllowedToLive;
if (matchingSubscriber->listener != NULL)
matchingSubscriber->listener(matchingSubscriber, matchingSubscriber->listenerParameter);

@ -47,7 +47,7 @@ struct sGooseSubscriber {
bool simulation;
bool ndsCom;
uint64_t invalidityTime;
uint64_t invalidityTime; /* time when the data became invalid as monotonic time in milliseconds */
bool stateValid;
GooseParseError parseError;

@ -70,7 +70,7 @@ GooseSubscriber_isValid(GooseSubscriber self)
if (self->stateValid == false)
return false;
if (Hal_getTimeInMs() > self->invalidityTime)
if (Hal_getMonotonicTimeInMs() > self->invalidityTime)
return false;
return true;

@ -111,8 +111,8 @@ struct sControlObject
MmsValue* error;
MmsValue* addCause;
uint64_t selectTime;
uint32_t selectTimeout;
uint64_t selectTime; /* select time of a control as monotonic time in ms */
uint32_t selectTimeout; /* select timeout period in ms */
MmsValue* sboClass;
MmsValue* sboTimeout;

@ -285,7 +285,8 @@ struct sMmsMapping {
#endif
LinkedList controlObjects;
uint64_t nextControlTimeout; /* next timeout in one of the control state machines */
uint64_t nextControlTimeout; /* next monotonic time timeout in one of the control state machines (e.g. for select timeout) */
uint64_t nextRealTimeControlTimeout; /* next real time clock based timeout in one of the control state machines (e.g. for operTm)*/
LinkedList attributeAccessHandlers;

@ -1,7 +1,7 @@
/*
* control.c
*
* Copyright 2013-2022 Michael Zillgith
* Copyright 2013-2025 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -436,6 +436,13 @@ updateNextControlTimeout(MmsMapping* self, uint64_t timeout)
self->nextControlTimeout = timeout;
}
static void
updateNextRealTimeControlTimeout(MmsMapping* self, uint64_t timeout)
{
if (timeout < self->nextRealTimeControlTimeout)
self->nextRealTimeControlTimeout = timeout;
}
static void
setState(ControlObject* self, int newState)
{
@ -554,7 +561,7 @@ unselectObject(ControlObject* self, SelectStateChangedReason reason, MmsMapping*
}
static void
checkSelectTimeout(ControlObject* self, uint64_t currentTime, MmsMapping* mmsMapping)
checkSelectTimeout(ControlObject* self, uint64_t currentMonotonicTimeInMs, MmsMapping* mmsMapping)
{
if ((self->ctlModel == 2) || (self->ctlModel == 4))
{
@ -562,7 +569,7 @@ checkSelectTimeout(ControlObject* self, uint64_t currentTime, MmsMapping* mmsMap
{
if (self->selectTimeout > 0)
{
if (currentTime > (self->selectTime + self->selectTimeout))
if (currentMonotonicTimeInMs > (self->selectTime + self->selectTimeout))
{
if (DEBUG_IED_SERVER)
printf("IED_SERVER: select-timeout (timeout-val = %u) for control %s/%s.%s\n",
@ -729,7 +736,7 @@ resetAddCause(ControlObject* self)
}
static void
executeControlTask(MmsMapping* self, ControlObject* controlObject, uint64_t currentTimeInMs)
executeControlTask(MmsMapping* self, ControlObject* controlObject, uint64_t currentMonotonicTimeInMs)
{
int state;
@ -761,7 +768,7 @@ executeStateMachine:
{
LinkedList_add(values, controlObject->sbo);
selectObject(controlObject, Hal_getTimeInMs(), controlObject->mmsConnection, self);
selectObject(controlObject, currentMonotonicTimeInMs, controlObject->mmsConnection, self);
#if (CONFIG_IEC61850_SERVICE_TRACKING == 1)
updateGenericTrackingObjectValues(self, controlObject, IEC61850_SERVICE_TYPE_SELECT, IEC61850_SERVICE_ERROR_NO_ERROR);
@ -787,7 +794,7 @@ executeStateMachine:
{
if (checkHandlerResult == CONTROL_ACCEPTED)
{
selectObject(controlObject, Hal_getTimeInMs(), controlObject->mmsConnection, self);
selectObject(controlObject, currentMonotonicTimeInMs, controlObject->mmsConnection, self);
if (controlObject->ctlNumSt)
MmsValue_update(controlObject->ctlNumSt, controlObject->ctlNum);
@ -833,7 +840,7 @@ executeStateMachine:
}
else
{
updateNextControlTimeout(self, Hal_getTimeInMs() + 100);
updateNextControlTimeout(self, currentMonotonicTimeInMs + 100);
}
}
@ -914,22 +921,20 @@ executeStateMachine:
setState(controlObject, STATE_OPERATE);
setOpOk(controlObject, true, currentTimeInMs);
setOpOk(controlObject, true, Hal_getTimeInMs());
goto executeStateMachine;
}
else
{
updateNextControlTimeout(self, Hal_getTimeInMs() + 10);
updateNextControlTimeout(self, currentMonotonicTimeInMs + 10);
}
}
break;
case STATE_OPERATE:
{
uint64_t currentTime = Hal_getTimeInMs();
ControlHandlerResult result = operateControl(controlObject, controlObject->ctlVal, currentTime, controlObject->testMode);
ControlHandlerResult result = operateControl(controlObject, controlObject->ctlVal, currentMonotonicTimeInMs, controlObject->testMode);
if (result != CONTROL_RESULT_WAITING)
{
@ -965,13 +970,13 @@ executeStateMachine:
exitControlTask(controlObject);
setOpOk(controlObject, false, currentTimeInMs);
setOpOk(controlObject, false, Hal_getTimeInMs());
resetAddCause(controlObject);
}
else
{
updateNextControlTimeout(self, currentTimeInMs + 10);
updateNextControlTimeout(self, currentMonotonicTimeInMs + 10);
}
}
break;
@ -1481,16 +1486,21 @@ ControlObject_updateControlModel(ControlObject* self, ControlModel value, DataOb
}
void
Control_processControlActions(MmsMapping* self, uint64_t currentTimeInMs)
Control_processControlActions(MmsMapping* self, uint64_t currentMonotonicTimeInMs)
{
if (currentTimeInMs >= self->nextControlTimeout)
uint64_t currentRealTimeInMs = Hal_getTimeInMs();
if ((currentMonotonicTimeInMs >= self->nextControlTimeout) || (currentRealTimeInMs >= self->nextRealTimeControlTimeout))
{
/* invalidate nextControlTimeout */
self->nextControlTimeout = (uint64_t) 0xFFFFFFFFFFFFFFFFLLU;
/* invalidate nextRealTimeControlTimeout */
self->nextRealTimeControlTimeout = (uint64_t) 0xFFFFFFFFFFFFFFFFLLU;
LinkedList element = LinkedList_getNext(self->controlObjects);
while (element != NULL)
while (element)
{
ControlObject* controlObject = (ControlObject*) element->data;
@ -1507,7 +1517,7 @@ Control_processControlActions(MmsMapping* self, uint64_t currentTimeInMs)
if (controlObject->state == STATE_WAIT_FOR_ACTIVATION_TIME)
{
if (controlObject->operateTime <= currentTimeInMs)
if (controlObject->operateTime <= Hal_getTimeInMs())
{
/* enter state Perform Test */
setOpRcvd(controlObject, true);
@ -1539,7 +1549,7 @@ Control_processControlActions(MmsMapping* self, uint64_t currentTimeInMs)
/* leave state Perform Test */
setOpRcvd(controlObject, false);
executeControlTask(self, controlObject, currentTimeInMs);
executeControlTask(self, controlObject, currentMonotonicTimeInMs);
}
else
{
@ -1560,16 +1570,19 @@ Control_processControlActions(MmsMapping* self, uint64_t currentTimeInMs)
resetAddCause(controlObject);
}
}
else {
updateNextControlTimeout(self, controlObject->operateTime);
else
{
updateNextRealTimeControlTimeout(self, controlObject->operateTime);
}
} /* if (controlObject->state == STATE_WAIT_FOR_ACTICATION_TIME) */
else if (!((controlObject->state == STATE_UNSELECTED) || (controlObject->state == STATE_READY))) {
executeControlTask(self, controlObject, currentTimeInMs);
else if (!((controlObject->state == STATE_UNSELECTED) || (controlObject->state == STATE_READY)))
{
executeControlTask(self, controlObject, currentMonotonicTimeInMs);
}
else if (controlObject->state == STATE_READY) {
checkSelectTimeout(controlObject, currentTimeInMs, self);
else if (controlObject->state == STATE_READY)
{
checkSelectTimeout(controlObject, currentMonotonicTimeInMs, self);
}
}
@ -1900,13 +1913,13 @@ Control_readAccessControlObject(MmsMapping* self, MmsDomain* domain, char* varia
{
if (controlObject->ctlModel == 2)
{
uint64_t currentTime = Hal_getTimeInMs();
uint64_t currentMonotonicTime = Hal_getMonotonicTimeInMs();
value = &emptyString;
if (isDirectAccess == true)
{
checkSelectTimeout(controlObject, currentTime, self);
checkSelectTimeout(controlObject, currentMonotonicTime, self);
if (getState(controlObject) == STATE_UNSELECTED)
{
@ -1931,7 +1944,7 @@ Control_readAccessControlObject(MmsMapping* self, MmsDomain* domain, char* varia
if (checkResult == CONTROL_ACCEPTED)
{
selectObject(controlObject, currentTime, connection, self);
selectObject(controlObject, currentMonotonicTime, connection, self);
value = controlObject->sbo;
#if (CONFIG_IEC61850_SERVICE_TRACKING == 1)
@ -2148,9 +2161,9 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
int state = getState(controlObject);
uint64_t currentTime = Hal_getTimeInMs();
uint64_t currentMonotonicTime = Hal_getMonotonicTimeInMs();
checkSelectTimeout(controlObject, currentTime, self);
checkSelectTimeout(controlObject, currentMonotonicTime, self);
if (state != STATE_UNSELECTED)
{
@ -2212,7 +2225,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
if (checkResult == CONTROL_ACCEPTED)
{
selectObject(controlObject, currentTime, connection, self);
selectObject(controlObject, currentMonotonicTime, connection, self);
indication = DATA_ACCESS_ERROR_SUCCESS;
@ -2230,7 +2243,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
setState(controlObject, STATE_WAIT_FOR_SELECT);
updateNextControlTimeout(self, Hal_getTimeInMs() + 100);
updateNextControlTimeout(self, Hal_getMonotonicTimeInMs() + 100);
indication = DATA_ACCESS_ERROR_NO_RESPONSE;
}
@ -2295,9 +2308,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
goto free_and_return;
}
uint64_t currentTime = Hal_getTimeInMs();
checkSelectTimeout(controlObject, currentTime, self);
checkSelectTimeout(controlObject, Hal_getMonotonicTimeInMs(), self);
int state = getState(controlObject);
@ -2361,11 +2372,11 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
MmsValue* operTm = getOperParameterOperTime(value);
if (operTm != NULL)
if (operTm)
{
controlObject->operateTime = MmsValue_getUtcTimeInMs(operTm);
if (controlObject->operateTime > currentTime)
if (controlObject->operateTime > Hal_getTimeInMs())
{
controlObject->timeActivatedOperate = true;
controlObject->synchroCheck = synchroCheck;
@ -2373,7 +2384,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
controlObject->mmsConnection = connection;
CheckHandlerResult checkResult = CONTROL_ACCEPTED;
if (controlObject->checkHandler != NULL)
if (controlObject->checkHandler)
{
/* perform operative tests */
@ -2387,7 +2398,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
setState(controlObject, STATE_WAIT_FOR_ACTIVATION_TIME);
updateNextControlTimeout(self, controlObject->operateTime);
updateNextRealTimeControlTimeout(self, controlObject->operateTime);
if (DEBUG_IED_SERVER)
printf("IED_SERVER: Oper - activate time activated control\n");
@ -2441,7 +2452,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, const char
initiateControlTask(controlObject);
updateNextControlTimeout(self, currentTime);
updateNextControlTimeout(self, Hal_getMonotonicTimeInMs());
}
else
{

@ -275,7 +275,7 @@ enableLogging(LogControl* self)
self->enabled = true;
if ((self->triggerOps & TRG_OPT_INTEGRITY) && (self->intgPd != 0))
self->nextIntegrityScan = Hal_getTimeInMs();
self->nextIntegrityScan = Hal_getMonotonicTimeInMs();
else
self->nextIntegrityScan = 0;

@ -2269,6 +2269,7 @@ MmsMapping_create(IedModel* model, IedServer iedServer)
#if (CONFIG_IEC61850_CONTROL_SERVICE == 1)
self->controlObjects = LinkedList_create();
self->nextControlTimeout = 0xffffffffffffffffLLU;
self->nextRealTimeControlTimeout = 0xffffffffffffffffLLU;
#endif
#if (CONFIG_IEC61850_SETTING_GROUPS == 1)
@ -3077,7 +3078,7 @@ mmsWriteHandler(void* parameter, MmsDomain* domain, const char* variableId, int
sg->sgcb->editSG = val;
sg->editingClient = connection;
sg->reservationTimeout = Hal_getTimeInMs() + (sg->sgcb->resvTms * 1000);
sg->reservationTimeout = Hal_getMonotonicTimeInMs() + (sg->sgcb->resvTms * 1000);
MmsValue* editSg = MmsValue_getElement(sg->sgcbMmsValues, 2);
@ -4822,27 +4823,27 @@ GOOSE_processGooseEvents(MmsMapping* self, uint64_t currentTimeInMs)
static void
processPeriodicTasks(MmsMapping* self)
{
uint64_t currentTimeInMs = Hal_getTimeInMs();
uint64_t currentMonotonicTimeInMs = Hal_getMonotonicTimeInMs();
#if (CONFIG_INCLUDE_GOOSE_SUPPORT == 1)
if (self->useIntegratedPublisher)
GOOSE_processGooseEvents(self, currentTimeInMs);
GOOSE_processGooseEvents(self, currentMonotonicTimeInMs);
#endif
#if (CONFIG_IEC61850_CONTROL_SERVICE == 1)
Control_processControlActions(self, currentTimeInMs);
Control_processControlActions(self, currentMonotonicTimeInMs);
#endif
#if (CONFIG_IEC61850_REPORT_SERVICE == 1)
Reporting_processReportEvents(self, currentTimeInMs);
Reporting_processReportEvents(self, Hal_getTimeInMs());
#endif
#if (CONFIG_IEC61850_SETTING_GROUPS == 1)
MmsMapping_checkForSettingGroupReservationTimeouts(self, currentTimeInMs);
MmsMapping_checkForSettingGroupReservationTimeouts(self, currentMonotonicTimeInMs);
#endif
#if (CONFIG_IEC61850_LOG_SERVICE == 1)
Logging_processIntegrityLogs(self, currentTimeInMs);
Logging_processIntegrityLogs(self, currentMonotonicTimeInMs);
#endif
/* handle low priority MMS backgound tasks (like file upload...) */
@ -4883,8 +4884,12 @@ MmsMapping_startEventWorkerThread(MmsMapping* self)
self->reportThreadRunning = true;
Thread thread = Thread_create((ThreadExecutionFunction)eventWorkerThread, self, false);
if (thread)
{
self->reportWorkerThread = thread;
Thread_start(thread);
}
}
void
@ -4934,7 +4939,7 @@ MmsMapping_createDataSetByNamedVariableList(MmsMapping* self, MmsNamedVariableLi
DataSetEntry* lastDataSetEntry = NULL;
while (element != NULL)
while (element)
{
MmsAccessSpecifier* listEntry = (MmsAccessSpecifier*)element->data;

@ -1844,7 +1844,7 @@ checkReservationTimeout(MmsMapping* self, ReportControl* rc)
{
if (rc->reservationTimeout > 0)
{
if (Hal_getTimeInMs() > rc->reservationTimeout)
if (Hal_getMonotonicTimeInMs() > rc->reservationTimeout)
{
if (rc->resvTms != -1)
rc->resvTms = 0;
@ -2123,7 +2123,7 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char*
{
rc->reserved = true;
rc->clientConnection = connection;
rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (rc->resvTms * 1000);
if (self->rcbEventHandler)
{
@ -2141,7 +2141,7 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char*
{
if (rc->clientConnection == connection)
{
rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (rc->resvTms * 1000);
}
}
}
@ -2726,7 +2726,7 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char*
}
else
{
rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (rc->resvTms * 1000);
reserveRcb(rc, connection);
@ -2755,7 +2755,7 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char*
}
else
{
rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000);
reserveRcb(rc, connection);
@ -2845,7 +2845,7 @@ exit_function:
{
if (rc->buffered)
{
rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000);
if (rc->resvTms == 0)
{
@ -2989,7 +2989,7 @@ Reporting_disableReportControlInstance(MmsMapping* self, ReportControl* rc)
updateOwner(rc, NULL);
else if (rc->resvTms > 0)
{
rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000);
rc->reservationTimeout = Hal_getMonotonicTimeInMs() + (rc->resvTms * 1000);
}
}
@ -4360,7 +4360,7 @@ Reporting_activateBufferedReports(MmsMapping* self)
}
static void
processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs)
processEventsForReport(ReportControl* rc, uint64_t currentRealTimeInMs)
{
if ((rc->enabled) || (rc->isBuffering))
{
@ -4372,10 +4372,10 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs)
if (rc->triggered)
{
rc->triggered = false;
enqueueReport(rc, false, false, currentTimeInMs);
enqueueReport(rc, false, false, currentRealTimeInMs);
}
enqueueReport(rc, false, true, currentTimeInMs);
enqueueReport(rc, false, true, currentRealTimeInMs);
rc->gi = false;
@ -4387,18 +4387,18 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs)
{
if (rc->intgPd > 0)
{
if (currentTimeInMs >= rc->nextIntgReportTime)
if (currentRealTimeInMs >= rc->nextIntgReportTime)
{
/* send current events in event buffer before integrity report */
if (rc->triggered)
{
enqueueReport(rc, false, false, currentTimeInMs);
enqueueReport(rc, false, false, currentRealTimeInMs);
rc->triggered = false;
}
if (rc->server->syncIntegrityReportTimes)
{
rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd);
rc->nextIntgReportTime = getNextRoundedStartTime(currentRealTimeInMs, rc->intgPd);
}
else
{
@ -4406,36 +4406,36 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs)
}
/* check for system time change effects */
if ((rc->nextIntgReportTime < currentTimeInMs) ||
(rc->nextIntgReportTime > currentTimeInMs + rc->intgPd))
if ((rc->nextIntgReportTime < currentRealTimeInMs) ||
(rc->nextIntgReportTime > currentRealTimeInMs + rc->intgPd))
{
if (rc->server->syncIntegrityReportTimes)
{
rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd);
rc->nextIntgReportTime = getNextRoundedStartTime(currentRealTimeInMs, rc->intgPd);
}
else
{
rc->nextIntgReportTime = currentTimeInMs + rc->intgPd;
rc->nextIntgReportTime = currentRealTimeInMs + rc->intgPd;
}
}
enqueueReport(rc, true, false, currentTimeInMs);
enqueueReport(rc, true, false, currentRealTimeInMs);
rc->triggered = false;
}
else
{
/* check for system time change effects */
if ((rc->nextIntgReportTime < currentTimeInMs) ||
(rc->nextIntgReportTime > currentTimeInMs + rc->intgPd))
if ((rc->nextIntgReportTime < currentRealTimeInMs) ||
(rc->nextIntgReportTime > currentRealTimeInMs + rc->intgPd))
{
if (rc->server->syncIntegrityReportTimes)
{
rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd);
rc->nextIntgReportTime = getNextRoundedStartTime(currentRealTimeInMs, rc->intgPd);
}
else
{
rc->nextIntgReportTime = currentTimeInMs + rc->intgPd;
rc->nextIntgReportTime = currentRealTimeInMs + rc->intgPd;
}
}
}
@ -4444,9 +4444,9 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs)
if (rc->triggered)
{
if (currentTimeInMs >= rc->reportTime)
if (Hal_getMonotonicTimeInMs() >= rc->reportTime)
{
enqueueReport(rc, false, false, currentTimeInMs);
enqueueReport(rc, false, false, currentRealTimeInMs);
rc->triggered = false;
}
@ -4571,7 +4571,7 @@ ReportControl_valueUpdated(ReportControl* self, int dataSetEntryIndex, int flag,
if (self->inclusionFlags[dataSetEntryIndex] & flag)
{
/* report for this data set entry is already pending (bypass BufTm and send report immediately) */
self->reportTime = Hal_getTimeInMs();
self->reportTime = Hal_getMonotonicTimeInMs();
if (modelLocked)
{
@ -4579,7 +4579,7 @@ ReportControl_valueUpdated(ReportControl* self, int dataSetEntryIndex, int flag,
copyValuesToReportBuffer(self);
}
processEventsForReport(self, self->reportTime);
processEventsForReport(self, Hal_getTimeInMs());
}
if (modelLocked)
@ -4598,11 +4598,9 @@ ReportControl_valueUpdated(ReportControl* self, int dataSetEntryIndex, int flag,
if (self->triggered == false)
{
uint64_t currentTime = Hal_getTimeInMs();
MmsValue_setBinaryTime(self->timeOfEntry, currentTime);
MmsValue_setBinaryTime(self->timeOfEntry, Hal_getTimeInMs());
self->reportTime = currentTime + self->bufTm;
self->reportTime = Hal_getMonotonicTimeInMs() + self->bufTm;
}
self->triggered = true;

@ -477,7 +477,7 @@ mmsServer_fileUploadTask(MmsServer self, MmsObtainFileTask task, int taskState)
break;
case MMS_FILE_UPLOAD_STATE_FILE_OPEN_SENT: {
if (Hal_getTimeInMs() > task->nextTimeout)
if (Hal_getMonotonicTimeInMs() > task->nextTimeout)
{
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: file open timeout!\n");
@ -489,6 +489,7 @@ mmsServer_fileUploadTask(MmsServer self, MmsObtainFileTask task, int taskState)
FileSystem_closeFile(task->fileHandle);
task->fileHandle = NULL;
}
deleteFile(MmsServer_getFilesystemBasepath(self), task->destinationFilename);
}
}
@ -502,14 +503,14 @@ mmsServer_fileUploadTask(MmsServer self, MmsObtainFileTask task, int taskState)
task->state = MMS_FILE_UPLOAD_STATE_FILE_READ_SENT;
IsoConnection_sendMessage(task->connection->isoConnection, message);
task->nextTimeout = Hal_getTimeInMs() + self->requestTimeoutMs;
task->nextTimeout = Hal_getMonotonicTimeInMs() + self->requestTimeoutMs;
}
break;
case MMS_FILE_UPLOAD_STATE_FILE_READ_SENT:
if (Hal_getTimeInMs() > task->nextTimeout)
if (Hal_getMonotonicTimeInMs() > task->nextTimeout)
{
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: file read timeout!\n");
@ -521,6 +522,7 @@ mmsServer_fileUploadTask(MmsServer self, MmsObtainFileTask task, int taskState)
FileSystem_closeFile(task->fileHandle);
task->fileHandle = NULL;
}
deleteFile(MmsServer_getFilesystemBasepath(self), task->destinationFilename);
}
@ -535,13 +537,13 @@ mmsServer_fileUploadTask(MmsServer self, MmsObtainFileTask task, int taskState)
IsoConnection_sendMessage(task->connection->isoConnection, message);
task->nextTimeout = Hal_getTimeInMs() + self->requestTimeoutMs;
task->nextTimeout = Hal_getMonotonicTimeInMs() + self->requestTimeoutMs;
}
break;
case MMS_FILE_UPLOAD_STATE_FILE_CLOSE_SENT:
if (Hal_getTimeInMs() > task->nextTimeout)
if (Hal_getMonotonicTimeInMs() > task->nextTimeout)
{
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: file close timeout!\n");
@ -813,7 +815,7 @@ mmsServer_handleObtainFileRequest(MmsServerConnection connection, uint8_t* buffe
MmsServer_releaseTransmitBuffer(connection->server);
task->nextTimeout = Hal_getTimeInMs() + connection->server->requestTimeoutMs;
task->nextTimeout = Hal_getMonotonicTimeInMs() + connection->server->requestTimeoutMs;
task->state = MMS_FILE_UPLOAD_STATE_FILE_OPEN_SENT;
}

Loading…
Cancel
Save